Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude "hated buffers" from switch-to-buffer list

Tags:

emacs

I have this in my .emacs:

(global-set-key "\M-s" 'switch-to-buffer)

And also:

(defvar crs-hated-buffers
  '("KILL" "*Compile-Log*" "*Buffer List*" "*Messages*" "*Occur*"
    "*Completions*" "*compilation*" "TAGS" "*scratch*" "*grep*"
    "source" "headers"))
(setq iswitchb-buffer-ignore (append '(
    "^ "
    "^\\*Buffer"
    "^\\*Completions\\*"
    "^\\*tramp"
    "^\\*Dired log\\*"
    "^\\*Quail Completions\\*"
    "^\\*Disabled Command\\*"
    "^TAGS"
    )
    crs-hated-buffers))

How do I exclude these hated buffers from the switch-to-buffer list?

like image 420
SFbay007 Avatar asked Nov 14 '13 21:11

SFbay007


2 Answers

Maybe something like:

(global-set-key [?\M-s] 'my-switch-to-buffer)

(defun my-switch-to-buffer ()
  (interactive)
  (let ((completion-regexp-list '("\\`[^*]"
                                  "\\`\\([^T]\\|T\\($\\|[^A]\\|A\\($\\|[^G]\\|G\\($\\|[^S]\\|S.\\)\\)\\)\\).*")))
    (call-interactively 'switch-to-buffer)))

It probably deserves a feature-request via M-x report-emacs-bug.

like image 166
Stefan Avatar answered Oct 13 '22 10:10

Stefan


You might have a look to ErgoEmacs' "switch to user buffer" functions: http://www.ergoemacs.org/emacs/elisp_next_prev_user_buffer.html

He excludes all internal buffers (the ones starting by *), which can be a problem if you're used to using magit, shell or even grep buffers.

«Emacs often generates a lot internal buffers that users are not interested in cycling thru. ⁖ {scratch, Messages, shell, Shell Command Output, Occur, Completions, Apropos, info, …}. You might define your own next-user-buffer that skips emacs's buffers, and you might define next-emacs-buffer that cycles thru just the emacs's buffers. »

I myself find I don't need that kind of filter since I use ido to switch buffers.

like image 21
Ehvince Avatar answered Oct 13 '22 12:10

Ehvince