Webpresence of Philip K.

Lesser known functionalities in core Emacs

15 June, 2021

While reading EmacsWiki or browsing the Emacs Source Code itself, one often encounters libraries and packages that are unrightfully underappreciated.

Here I’d like to briefly collect a few packages and libraries from core Emacs that could be useful, and I’d like to use more.

The years next to each section indicate when these features were added to Emacs (or at least my best guess).

M-x find-library autoinsert RET (1985)

The main command here is auto-insert, with a dash.

This command can easily be confused with abbrev or yasnippet. But both of these are meant expand abbrevations (e.g. “lag” to “ladies and gentlemen”) or interactive snippets (e.g. “err” to an error handling block in Go).

Auto-insert is instead intended to be used when a new file is created: Create an empty HTML buffer, and then run M-x auto-insert – after querying the title a skeleton of a HTML file is generated.

This can even be added to a mode hook:

(add-hook 'html-mode-hook #'auto-insert)

Emacs will make sure that you actual want auto-insertion to take place, and then proceed like above.

All in all, it is a useful mode, especially for well structured file formats that might be hard to memorize. The main reason I think auto-insert is not talked about that much is that not that many major modes are supported out-of-the-box. The user option auto-insert-alist, that defines the behaviour for a file type only has 13 entries, for these file types:

  1. C/C++ (header and main program)
  2. Makefiles
  3. HTML
  4. LaTeX and BibTeX
  5. Shell Scripts
  6. Ada
  7. Man pages (not mdoc)
  8. .dir-locals.el (useful but usually not needed because add-dir-local-variable exists)
  9. Emacs Lisp files
  10. TeXinfo

Adding support for more modes, both for modes in Emacs itself and third-party code would probably help to make this more useful.

M-x find-library htmlfontify RET (2002)

Most people use htmlize, I suspect mainly because Org-mode uses it too.

html-fontify is basically the same story, just built in and it ignores the current theme. While maybe a disadvantage, I personally was more frequently annoyed when exporting a .org file while using a dark theme, and only later noticing that the resulting HTML is hard to read.

The main use I have for this library is exporting the public part of my personal configuration to my website, using this command:

(defun local/export-config ()
  "Export this configuration as HTML to personal WWW directory."
  (interactive)
  (require 'htmlfontify)
  (let ((hfy-default-face-def '((t :family "monospace")))
        (hfy-display-class '((background . light)
                             (class . color)))
        (hfy-optimizations nil))
    (with-current-buffer (find-file-noselect (locate-user-emacs-file "init.el"))
      (with-current-buffer (htmlfontify-buffer user-emacs-directory "init.el")
        (write-region (point-min) (point-max)
                      "~/Code/web/www/data/files/init.el.html")
        (kill-buffer (current-buffer))))))

I am not sure why this library is overlooked. I had to guess, I’d say it is because it is unwieldy to use, and the internals a bit messy.

M-x find-library package-x RET (2007)

package.el is widely known, and the de-facto default for distributing and installing third-party packages. Recently I stumbled upon its forgotten relative, package-x.el. Instead of downloading and maintaining packages, it is mean to be used for creating your own package archives.

From what I see, it was created by Tom Tromey to maintain the original ELPA.

It’s basic use is to set package-archive-upload-base to a TRAMP directory, usually pointing to a directory hosted by a web server, and then uploading packages using package-upload-file. You can either upload a singular file, or a tar archive when a package consists of multiple files. It should be possible to extend this to directories, along the lines of invoking package-install-from-buffer in a Dired buffer.

One of the reasons this feature is not talked about a lot is that it is somewhat inconvenient to use: Only a single mirror can be specified, and some of the functionality such as creating maintaining log and RSS feed of new versions is not accessible without writing one’s own elisp – in other words nothing a patch or two couldn’t fix.

M-x find-library type-break RET (1994)

This is for anyone who wants to use something like the Pomodoro Technique1 to make sure they don’t work for too long.

There is one caveat – to quote the commentary:

This package relies on the assumption that you live entirely in Emacs, as the author does. If that’s not the case for you (e.g. you often suspend Emacs or work in other windows) then this won’t help very much;

All you need to do to use this is enable type-break-mode and optionally configure type-break-interval and type-break-good-rest-interval (the defaults are 60 minute sessions and 10 minute breaks).

It does the job, though it’s interface can be annoying with the warnings it displays in the echo area, and the breaks are started manually, by default. That might be one of the reasons this library is not talked about that much?

M-x find-library strokes RET (1997)

Interesting and perhaps controversial for mouse-haters. The idea is to configure a system, where particular movements of the mouse trigger the invocation of some command – just like how every key press runs a command.

The details on how to use this is explained by running the command strokes-help, the main gist is:

  1. Activate strokes-mode
  2. Define and bind a stroke with strokes-global-set-stroke
  3. Invoke the stroke by pressing shift and the middle-mouse button

The last part might be an issue for laptop users, or people with bad mice. The main issue with this feature is probably the flimsily mouse-support in Emacs, for anything beyond simple clicking and dragging. Nevertheless, strokes can recognise the patters one draws and manages to associate similar mouse-movements.

A lot of people (falsely) shun using a mouse with more advanced editors, as a matter of principle. While I disagree with the insistence on doing everything with the keyboard, I do understand why most people probably don’t want to draw an snake or a triangle with their mouse too often.

M-x find-library mode-local RET (2004)

Finally a interesting library for configurations. More precisely, the macro setq-mode-local allows the user to configure variables only for certain major modes. E.g.

(setq-mode-local go-mode compile-command "go build")

would make sure that for every go-mode buffer, the variable compile-command is initialise properly. The alternative would be something like

(add-hook 'go-mode-hook
	  (lambda ()
	    (setq-local compile-command "go-build")))

But there is no reason to stick to inconvenience and repeat patterns with Lisp.

This macro is probably most interesting for people with simple configurations2. I could imagine it being more popular, but am also not sure if there are any issues that should be mentioned.

Bonus: M-x find-library shortdoc RET (2020)

The newest addition, that has not been officially released as of writing, is interesting for people learning and using Elisp.

In short, it provides a brief overview of related functions and examples. For example, to find out what you can do with a buffer, type

M-x shortdoc-display-group RET buffer RET

and a buffer is displayed that might start with something like this:

Buffer Basics

(current-buffer)

Return the current buffer as a Lisp object.

(current-buffer)

eg. ⇒ #<buffer shortdoc.el>


(bufferp object)

Return t if OBJECT is an editor buffer.

(bufferp 23)

⇒ `nil`

(buffer-live-p object)

Return t if OBJECT is a buffer which has not been killed.

(buffer-live-p some-buffer)

eg. ⇒ `t`

In addition to the manual invocation, an indication to a “shortdoc” group is also added to the regular help buffers of some functions.

As this feature is new – not even a year old – it makes sense that it is little known. I for one appreciate it and hope that it will find more use in the future.


These have been a few packages I think deserve some more attention than they currently receive. Between the well known and impressive features already built-in to Emacs (Org, Calc, Gnus, …) and those I don’t even know how to use (MPC, SES), this posts means to show that there is still space to appreciate what Emacs has to offer out of the box.


  1. From my understanding type-break is somewhat simpler.↩︎

  2. I have unknowingly replicated the same feature in my own package via the more general :local-set macro.↩︎