filter buffers for Ido

 

Emacs: Filtered Buffer Switching

(defvar my-always-show-regexps '("\\*\\(scratch\\|info\\|grep\\|compilation\\)\\*")
"*Buffer regexps to always show when buffer switching.")
(defvar my-never-show-regexps '("^\\s-" "^\\*" "TAGS$")
"*Buffer regexps to never show when buffer switching.")
(defvar my-ido-ignore-dired-buffers t
"*If non-nil, buffer switching should ignore dired buffers.")

(defun my-str-in-regexp-list (str regexp-list)
"Return non-nil if str matches anything in regexp-list."
(let ((case-fold-search nil))
(catch 'done
(dolist (regexp regexp-list)
(when (string-match regexp str)
(throw 'done t))))))

(defun my-ignore-buffer (name)
"Return non-nil if the named buffer should be ignored."
(or (and (not (my-str-in-regexp-list name my-always-show-regexps))
(my-str-in-regexp-list name my-never-show-regexps))
(and my-ido-ignore-dired-buffers
(save-excursion
(set-buffer name)
(equal major-mode 'dired-mode)))))
(setq ido-ignore-buffers (append ido-ignore-buffers '(my-ignore-buffer)))

Note: regexp metacharacters should be double-escape ("\\") in strings in elisp code.

你可能感兴趣的:(filter)