with (ido-switch-buffer)
, when I type stuff
, "*magit: stuff*"
comes before Stuff.txt
.
the sorting seems to be done by recency, rather than the buffer name. more generally, a custom sort function would be nice.
Here is what I use:
(require 'dash)
(require 's)
(add-hook 'ido-make-buffer-list-hook 'my/ido-stars-to-end)
(defun my/ido-stars-to-end ()
"Put \"*starred*\" buffers at the end of the ido candidates list."
(ido-to-end (--filter (s-starts-with-p "*" it)
ido-temp-list)))
EDIT: as mentioned in a comment, the code above will put all "starred" buffers at the end of the list, even the currently selected one if its name contains an asterisk. A slightly modified version avoiding that effect would be:
(require 'dash)
(require 's)
(add-hook 'ido-make-buffer-list-hook 'my/ido-stars-to-end)
(defun my/ido-stars-to-end ()
"Put \"*starred*\" buffers at the end of the ido candidates list."
(ido-to-end (--filter (and (s-starts-with-p "*" it)
(not (equal it (buffer-name))))
ido-temp-list)))
(defun my/ido-stars-to-end () (ido-to-end (-filter (lambda (it) (and (s-starts-with-p "*" it) (not (equal it (buffer-name))) ) ) ido-temp-list))) (add-hook 'ido-make-buffer-list-hook 'my/ido-stars-to-end)
the essential part is a new filter lambda: (-filter (lambda (it) (and (s-starts-with-p "*" it) (not (equal it (buffer-name))))))
If you want just for ido locally and not across tramp listings, then try this function that was originally made for buffers with @ in names and I modified for * in names:
(defun ido-sort-on-stars-to-end ()
(message ido-current-directory)
(setq ido-temp-list
(sort ido-temp-list
(lambda (a b)
if (not (or (char-equal (string-to-char a) ?*) (char-equal (string-to-char b) ?*)))
(time-less-p
(sixth (file-attributes (concat ido-current-directory b))
(sixth (file-attributes (concat ido-current-directory a)))))
nil)))
(ido-to-end
(delq nil (mapcar
(lambda (x) (and (string-match-p "^\\.." x) x))
ido-temp-list))))