Nicolas Martyanoff – Brain dump About

Buffer ordering with Helm

I have been using Emacs for some time, and ido has always been my favourite way to switch buffers.

But recently I discovered and started using Helm, a package based on incremental completion which can provide lots of interesting features. One of them being buffer switching.

The simplest way to use Helm to switch buffers is helm-buffers-list. Personally I use C-x b:

(global-set-key (kbd "C-x b") 'helm-buffers-list)

I really like that helm-buffer-list orders buffers using the last time they were used. However as soon as I start typing something to narrow the selection, Helm switches to a different ordering based on the length of buffer names. A bug report was submitted, but apparently, this is the intended behaviour.

Fortunately, it is possible to override this behaviour, as suggested in another Github issue. Ordering is done in the helm-buffers-sort-transformer function; we could replace it, but it is cleaner to advise it.

(defun nm-around-helm-buffers-sort-transformer (candidates source)
  candidates)

(advice-add 'helm-buffers-sort-transformer
            :override #'nm-around-helm-buffers-sort-transformer)

This way we keep the LRU-style ordering even when narrowing the selection.

Share the word!

Liked my article? Follow me on Twitter or on Mastodon to see what I'm up to.