Exclude "hateful buffers" from the list of switches to the buffer

I have this in my .emacs:

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

And:

 (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 to exclude these hated buffers from the switch list to the buffer?

+6
source share
3 answers

Maybe something like:

 (global-set-key [?\Ms] '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 through the Mx report-emacs-bug .

+5
source

You can see the ErgoEmacs "switch to user buffer" functions: http://www.ergoemacs.org/emacs/elisp_next_prev_user_buffer.html

It excludes all internal buffers (those starting with *), which can be a problem if you are used to using magit, shell, or even grep buffers.

"Emacs often generates a lot of internal buffers that users are not interested in looping. ⁖ {scratches, messages, shell, shell command output, Occur, Completions, Apropos, info, ...}. You can define your own next custom buffer, which skips emacs buffers, and you can define next-emacs-buffer, which loops through only emacs buffers. "

I myself find that I do not need such a filter, since I use ido to switch buffers.

+1
source

You should consider going down a different path in order to handle your difficulties with switch buffers:

First, if you are not using it yet, consider using ido-mode. It makes it easy to open files, switch buffers, and more. Especially with the following settings:

 (custom-set-variables '(ido-enable-flex-matching t) '(ido-everywhere t) '(ido-mode t)) 

Secondly, specifically for switching buffers, I would recommend setting this in the init.el file:

 (define-key global-map "\Cx\Cb" 'bs-show) 

This gives you a much larger overview of what buffers you have and what you want to do with them, for example, close or switch to them, all in a neat pop-up window.

0
source

Source: https://habr.com/ru/post/958106/


All Articles