2

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.

2

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)))
| improve this answer | |
  • How do I make it ignore (not push to the end) current buffer (when current buffer is "starred")? – seriyPS Apr 9 at 9:30
  • 1
    Ok, managed to make it by myself: (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)))))) – seriyPS Apr 9 at 9:56
  • 1
    thanks, I edited my post to account for your comment! – François Févotte Apr 9 at 10:11
1

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))))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.