Category Archives: emacs

Reading these posts, you can probably tell that I really, really like the Emacs text editor.

View my Emacs configuration.

Check out Planet Emacsen to read other Emacs geeks’ blogs. For all things Emacs, check out the EmacsWiki.

New to Emacs? Start here:

2015-11-23 Emacs News

Links from, Hacker News,, Youtube, the Emacs commit log, the changes to the Emacs NEWS file, and emacs-devel

Past Emacs News round-ups

Mail with Gnus on Windows

I use Gmail for my mail because it:

  • synchronizes with my phone, which is handy for notifications and quick replies
  • filters most of the spam for me
  • works with a few interesting extensions such as Boomerang for Gmail

However, I like the way the Gnus mail/news client in Emacs gives me a much more keyboard-friendly way to manage lots of mail, and I can even write code to partially automate some of my common operations.

I used to have my config in in ~/.gnus, but people might find it handy, so I’ve added it to my public Emacs configuration.

I like using Gmane to read mailing lists, and I use IMAP to read my Gmail.

(setq gnus-select-method '(nnnil ""))
(setq gnus-secondary-select-methods
      '((nntp "")
        (nnimap ""
                (nnimap-address "")
                (nnimap-server-port 993)
                (nnimap-stream ssl)
                (nnimap-authenticator login))))

I have two-factor authentication enabled for Gmail, so I set up an app-specific password for Gnus. I have an ~/.authinfo file set up with something like:

machine login [email protected] password mysecretapppassword
machine login [email protected] password mysecretapppassword port 993
machine login [email protected] password mysecretapppassword port 587

(I should probably get around to using GPG to automatically encrypt and decrypt this file.)

Sending e-mail on Windows was a bit of a pain. Fortunately, I eventually found something that works. I’ve configured emailrelay to accept the mail and forward it to Gmail. The server starts with this batch file:

start "emailrelay" "C:\Program Files (x86)\emailrelay\emailrelay.exe" --as-proxy --client-auth "C:/sacha/.emailrelay" --client-tls --log --pid-file "C:\Program Files (x86)\emailrelay\" --spool-dir C:\sacha\tmp\emailrelay

Sending queued mail works with this batch file:

"c:\Program Files (x86)\emailrelay\emailrelay.exe" --as-client --client-auth c:\sacha\.emailrelay --client-tls --spool-dir c:\sacha\tmp\emailrelay

I should probably get around to using --as-proxy properly, since it still seems to hold mail until I explicitly send it.

Some more config. Not sure how much of this is needed.

(setq message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials '(("localhost" 25 "[email protected]" nil))
      smtpmail-auth-credentials '(("localhost" 25 "[email protected]" nil))
      smtpmail-default-smtp-server "localhost"
      smtpmail-smtp-server "localhost"
      smtpmail-smtp-service 25
      smtpmail-local-domain "")
(setq send-mail-function 'smtpmail-send-it)
(setq smtpmail-smtp-server "")
(setq smtpmail-smtp-service 25)
(setq user-mail-address "[email protected]")

Hide HTML mail. I need to fiddle with this some more, since Gnus still tries to display them. Sometimes my Gnus crashes when it tries to display HTML mail.

(setq mm-discouraged-alternatives
      '("text/html" "text/richtext")
      (-difference mm-automatic-display '("text/html" "text/enriched" "text/richtext")))

Hide quoted text.

(setq gnus-treat-hide-citation t)

Get smarter about filtering depending on what I reed or mark. I use ! (tick) for marking threads as something that interests me.

(setq gnus-use-adaptive-scoring t)
(setq gnus-default-adaptive-score-alist
       (gnus-ticked-mark (subject 10))
       (gnus-killed-mark (subject -5))
       (gnus-catchup-mark (subject -1))))

2015-11-18 Emacs Hangout

Coding, e-mail, LaTeX, and more. Enjoy!

Event page:


  • 0:02 Podcasts
  • 0:03 sweetgreen – ordering salad
  • 0:14 Windows
  • 0:16 exwm – emacs window manager
  • 0:18 Android development
  • 0:21 Org Mode
  • 0:25 mail, search, notmuch, mairix, filtering, Gmail tabs
  • 0:37 TRAMP, rsync, firestarter, mosh
  • 0:43 stumpwm, conkeror
  • 0:47 concurrency, guile
  • 0:51 dash
  • 0:52 packages
  • 0:53 edit with Emacs (Chrome extension), Cocoa text system on Mac OS X
  • 0:57 railwaycat, spaceline (modeline from spacemacs)
  • 1:04 preview latex, knitr, sweave, Org tables in LaTeX
  • 1:09 spacemacs, vim
  • 1:16 multiple cursors, keyboard macros
  • 1:18 eshell, shells
  • 1:19 volatile-highlights, undo tree
  • 1:21 beacon-mode
  • 1:24 helm-show-kill-ring
  • 1:25 experimenting with versions of code, git-timemachine, undo-tree timestamps and diffs

Text chat:

me 9:30 PM notmuch, mairix
Will Monroe 9:31 PM thanks!
Puneeth Chaganti 9:33 PM Hi everyone.
me 9:34 PM nnmail-split-methods
Puneeth Chaganti 9:36 PM I use imapfilter for my non-gmail account.
Diego Berrocal 9:36 PM what about the gmail one?
Will Monroe 9:36 PM these are excellent suggestions for a new gnus user Puneeth, thank you for org2blog!
Puneeth Chaganti 9:37 PM I don’t yet use gmail with mu4e. Just not sure how long downloading all my mail would take.
Diego Berrocal 9:38 PM ^ better ssh
Will Monroe 9:39 PM Puneeth, I’ve used mu4e with offlineimap to download lots of gmail. It did take a lot of time for ~4GB to download.
Puneeth Chaganti 9:40 PM Yeah, I’m also subscribed to a lot of lists that are filterd out using email filters, but I’m afraid getting new mail also would be really slow. I have a better internet connection these days. May be I should try.
Diego Berrocal 9:41 PM doesn’t gnus freeze your emacs sometimes?
me 9:41 PM I’ve been using for many mailing lists. The web interface has been a bit wonky, but the NNTP through Gnus seems okay.
Diego Berrocal 9:41 PM it did on me last time I used it (years ago) Link to Window Manager:
Puneeth Chaganti 9:44 PM
Will Monroe 9:46 PM Bye everyone! It was nice talking with you.
Daniel Gopar 9:48 PM Diego do you have an example of using firestarter with rsync? Do you have your init.el uploaded in Github or somwhere?
Diego Berrocal 9:49 PM unfortunately it’s not in my config anymore I’ll try to make a blog post
Daniel Gopar 9:50 PM sweet \o/ Let me know if you end up creating a post
Diego Berrocal 9:50 PM yeah \o/
Puneeth Chaganti 9:52 PM Yes, I found it useful too. Thanks for doing those posts, Sacha
me 9:53 PM
Diego Berrocal 9:53 PM not more scrolling through MELPA twitter now edit-with-emacs ^
Bryan Maass 9:54 PM edit-with-emacs
Howard Melman 9:56 PM
Bryan Maass 9:56 PM
me 9:58 PM Reddit discussion of spaceline
me 9:59 PM
Bryan Garza 10:03 PM
me 10:07 PM (org) Tables in arbitrary syntax From Joseph:
Bryan Garza 10:19 PM
Diego Berrocal 10:25 PM git-timemachine
me 10:27 PM (setq undo-tree-visualizer-timestamps t)<br> (setq undo-tree-visualizer-diff t)
Daniel Gopar 10:28 PM Diego can you put a link to your site?
Diego Berrocal 10:30 PM ^

For more information about Emacs Hangouts, see

2015-11-16 Emacs News

Links from, Hacker News,, Youtube, the Emacs commit log, and the changes to the Emacs NEWS file.

Past Emacs News round-ups

2015-11-09 Emacs News

Links from, Hacker News,, Youtube, and the Emacs commit log.

Past Emacs News round-ups

Capturing links quickly with emacsclient, org-protocol, and Chrome Shortcut Manager on Microsoft Windows 8

Since I’ll be snipping lots of Emacs-related resources and organizing them into Emacs news roundups, I figured it was time to get org-protocol working.

Step 1: Get emacsclient to work

I was getting the error “No connection could be made because the target machine actively refused it.” I needed to change my Windows Firewall rules. From the Windows Firewall screen, I clicked on Advanced settings and chose Inbound Rules. On the Programs and Services tab, I confirmed that the right Emacs binary was selecI looked for the rules for GNU Emacs, consolidating them down to two rules (UDP and TCP). I limited the scope to local/remote On the advanced tab, I selected all the profiles and changed edge traversal to blocked.

I was still getting the error despite a fresh M-x server-start. After I deleted the contents of ~/.emacs.d/server and did another M-x server-start. When I ran emacsclient test.txt from the command-line, it correctly opened the file in my existing Emacs instance. Hooray!

Step 2: Load org-protocol

I added org-protocol to the org-modules variable so that Org would load it when Emacs reaches the (org-load-modules-maybe t) in my config. Since I didn’t want to restart Emacs, I also evaluated (load-library "org-protocol") to load it.

Step 3: Register the protocol

I ran an org-protocol.reg that set up the appropriate org protocol entry:

Windows Registry Editor Version 5.00

"URL Protocol"=""
@="URL:Org Protocol"



@="\"c:\\Program Files (x86)\\GNU Emacs 24.4\\bin\\emacsclientw.exe\"  \"%1\""

You can find a similar one in the org-protocol documentation.

Step 4: Add support to Chrome

I wanted something a bit different from the org-capture extensions available for Chrome. In particular, I wanted:

  • a keyboard-friendly way to quickly store a link
  • a keyboard-friendly way to capture a link with some notes

The Shortcut Manager extension for Chrome lets you specify your own keyboard shortcuts for running short Javascript. Inline Javascript doesn’t work on all sites. For example, Github blocks it with the following error: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src". Either the 'unsafe-inline' keyword, a hash ('...'), or a nonce ('nonce-...') is required to enable inline execution. Still, it works for many sites, so it’s a start. Here are the shortcuts I put together.

l Store link
L Store link (prompt for title, default to selection or document title)
c Capture link (prompt for template)

You can import them by going to Chrome’s More Tools > Extensions screen and choosing the Options link for Shortcut Manager. From there, use Import settings.

// ==UserScript==
// @ShortcutManager
// @name Store link
// @namespace XPrUJhE4wRsC
// @key l
// @include *
// ==/UserScript==
var storeLink = function(){
  var selection = window.getSelection().toString();
  var uri = 'org-protocol://store-link://' +
        encodeURIComponent(window.location.href) + '/' +
        encodeURIComponent(selection || document.title);
  window.location = uri;
  return uri;

// ==UserScript==
// @ShortcutManager
// @name Capture link
// @namespace XPrUJhE4wRsC
// @key c
// @include *
// ==/UserScript==
var captureLink =function(){
  var uri = 'org-protocol://capture://' +
        encodeURIComponent(window.location.href) + '/' +
        encodeURIComponent(document.title) + '/' +
  window.location = uri;
  return uri;

// ==UserScript==
// @ShortcutManager
// @name Store link with prompt
// @namespace XPrUJhE4wRsC
// @key Shift+l
// @include *
// ==/UserScript==
var storeLinkWithPrompt = function(){
  var selection = window.getSelection().toString();
  var uri = 'org-protocol://store-link://' +
        encodeURIComponent(window.location.href) + '/' +
        encodeURIComponent(window.prompt('Title', selection || document.title));
  window.location = uri;
  return uri;

Shortcut Manager looks like a really useful extension. Here are some other shortcuts I set up:

x close the current tab
r reload (cacheless)
t open a new tab
n select the right tab
p select the left tab
b back
f forward

Step 5: Add shortcuts for managing stored links

I added my/org-insert-link and org-insert-last-stored-link to my main hydra, which is on my hh keychord. my/org-insert-link is like org-insert-link, except it adds a newline if the cursor is at an Org link so that we don’t trigger org-insert-link‘s behaviour of editing links.

(defun my/org-insert-link ()
  (when (org-in-regexp org-bracket-link-regexp 1)
    (goto-char (match-end 0))
    (insert "\n"))
  (call-interactively 'org-insert-link))

(key-chord-define-global "hh"
                         (defhydra my/key-chord-commands ()
                           ;; ...
                           ("L" my/org-insert-link)
                           ("l" org-insert-last-stored-link)
                           ;; ...

This lets me quickly insert a bunch of links with a key sequence like h h l l l l or select a link to insert with h h L. C-y (yank) pulls in the URL of the last stored link, too.

Let’s see how this works out!