Tag Archives: windows

How to use Locate from Emacs on Windows

If you are like me, you like to:

  • Live in Emacs as much as possible to avoid context-switching
  • Set up Emacs so your environment abstracts the OS as much as possible

Being able to sit down at any of my computers and type M-x locate in Emacs is a requirement for me, even if It’s running Windows underneath.

In this post I’ll describe how to set up a locate(1) command on Windows 10, and how to access it from Emacs.

Step 1. Install Locate32

Download and install locate32 on your machine. It doesn’t have an installer, it just gives you a directory full of things, including the locate.exe binary. I put mine in "C:/Users/rml/Programs/locate32/", and added that location to my Windows %PATH%.

Step 2. Tell Emacs where to find it

In Emacs, set the value of the locate-command variable to wherever you ended up putting it. Here’s where it is on my machine:

(setq locate-command "c:/Users/rml/Programs/locate32/locate.exe")

Step 3. Locate all the things

Now when you run the M-x locate command from inside Emacs, it should give you a Dired buffer of results, the same way it does on other systems. Because it’s Dired, you can hit enter on a filename to visit it or mark files in various ways and then operate on them.

Here’s what it looks like on my Windows 10 laptop if I search for the text “svn”:

Advertisements

Set up Gnus on Windows

There are many “set up Gnus to read email from Emacs on Windows” posts. This one is mine. Unlike the 10,000 others on the internet, this one actually worked for me.

A nice thing is that, with a few tweaks, this setup also works on UNIX-like machines.

PREREQUISITES

OVERVIEW

At a high level, the way this all works is that:

  • A mail server is out there on the interwebs somewhere
  • stunnel runs locally, and creates an encrypted “tunnel” between a port on the mail server and a port on the local machine

  • Emacs (Gnus) connects to the local port and fetches mail from there (as far as it knows)

STEP 1. INSTALL AND CONFIGURE STUNNEL

Download and install stunnel for Windows:
https://www.stunnel.org/downloads.html

I use Fastmail, so the following configuration worked for me. I put it in the file ‘C:/Users/rml/_stunnel.conf’.

# Windows stunnel config

# 1. GLOBAL OPTIONS

debug = 7
output = C:/Users/rml/Desktop/stunnel.log

# 2. SERVICE-LEVEL OPTIONS

[IMAP (rmloveland@fastmail.fm) Incoming]
client = yes
accept = 127.0.0.1:143
connect = mail.messagingengine.com:993

[SMTP (rmloveland@fastmail.fm) Outgoing]
client = yes
accept = 127.0.0.1:465
connect = mail.messagingengine.com:465

If memory serves, you will need to do some messing around with stunnel to get it to read from a config file other than the default. Luckily it puts a little icon in the notification tray that you can right-click to get it to do things such as edit the config file or view the log file. From there, you should be able to get the config in shape as shown above.

In the particular case of Fastmail, you’ll need to set up an app password via its web UI. See your email provider’s documentation for more information.

STEP 2. CONFIGURE GNUS

On the Emacs side, we need Gnus to ask the right port on the local machine for mail. Here’s what I did:

(setq send-mail-function 'smtpmail-send-it
message-send-mail-function 'smtpmail-send-it
smtpmail-smtp-server "localhost"
smtpmail-smtp-service 465
smtpmail-stream-type nil
smtpmail-default-smtp-server "localhost")

This is the part of your Gnus config that tells it how to talk to stunnel; all of the other Gnus things are beyond the scope of this article. If you need more Gnus info, you should be able to get something going using the EmacsWiki:
https://www.emacswiki.org/emacs/CategoryGnus