Emacs Buffer Loop: Avoid Scratches and Message Buffers

Hi, I have enabled the loop loop by placing the following commands in my .emacs

(global-set-key (kbd "<C-tab>") 'bury-buffer) 

But while cycling, how can I avoid looping through messages and script buffers that are always on any emacs buffer list. I never use these buffers and do not get ocular when cycling through my buffer list

+7
source share
4 answers

If you never use a zero buffer, just add this to your .emacs to automatically close it:

(kill-buffer "* scratch *")

I also found this code in the Emacs wiki which should do what you want:

 ; necessary support function for buffer burial (defun crs-delete-these (delete-these from-this-list) "Delete DELETE-THESE FROM-THIS-LIST." (cond ((car delete-these) (if (member (car delete-these) from-this-list) (crs-delete-these (cdr delete-these) (delete (car delete-these) from-this-list)) (crs-delete-these (cdr delete-these) from-this-list))) (t from-this-list))) ; this is the list of buffers I never want to see (defvar crs-hated-buffers '("KILL" "*Compile-Log*")) ; might as well use this for both (setq iswitchb-buffer-ignore (append '("^ " "*Buffer") crs-hated-buffers)) (defun crs-hated-buffers () "List of buffers I never want to see, converted from names to buffers." (delete nil (append (mapcar 'get-buffer crs-hated-buffers) (mapcar (lambda (this-buffer) (if (string-match "^ " (buffer-name this-buffer)) this-buffer)) (buffer-list))))) ; I'm sick of switching buffers only to find KILL right in front of me (defun crs-bury-buffer (&optional n) (interactive) (unless n (setq n 1)) (let ((my-buffer-list (crs-delete-these (crs-hated-buffers) (buffer-list (selected-frame))))) (switch-to-buffer (if (< n 0) (nth (+ (length my-buffer-list) n) my-buffer-list) (bury-buffer) (nth n my-buffer-list))))) (global-set-key [(control tab)] 'crs-bury-buffer) (global-set-key [(control meta tab)] (lambda () (interactive) (crs-bury-buffer -1))) 

You will need to add buffers from scratch and messages to the crs-hated-buffers variable, for example:

 (add-to-list 'crs-hated-buffers "*Messages*") (add-to-list 'crs-hated-buffers "*scratch*") 
+7
source
Luke answered your specific question. In my personal experience, looping is more useful as the most recently used stack instead of the standard Emacs looping functions. That is, the buffers you used recently should bubble up to the top of the stack, similar to how alt-tab works on Windows.

There are quite a few packages that implement this on the wiki . buffer-stack one I recommend. It has a list of excluded buffers by default, I have included my buffer-stack-suppl , which performs the same filtering of the main mode. If you ask questions about buffer-stack , I will try my best to help.

+5
source

All the buffers that I did not use, for example, scratches, messages and improvements, ruined my workflow.

I managed to completely get rid of them without breaking emacs.

Posted first here and pasted below:

Put this in your .emacs:

 ;; Makes *scratch* empty. (setq initial-scratch-message "") ;; Removes *scratch* from buffer after the mode has been set. (defun remove-scratch-buffer () (if (get-buffer "*scratch*") (kill-buffer "*scratch*"))) (add-hook 'after-change-major-mode-hook 'remove-scratch-buffer) ;; Removes *messages* from the buffer. (setq-default message-log-max nil) (kill-buffer "*Messages*") ;; Removes *Completions* from buffer after you've opened a file. (add-hook 'minibuffer-exit-hook '(lambda () (let ((buffer "*Completions*")) (and (get-buffer buffer) (kill-buffer buffer))))) ;; Don't show *Buffer list* when opening multiple files at the same time. (setq inhibit-startup-buffer-menu t) ;; Show only one active window when opening multiple files at the same time. (add-hook 'window-setup-hook 'delete-other-windows) 

Bonus:

 ;; No more typing the whole yes or no. Just y or n will do. (fset 'yes-or-no-p 'y-or-np) 
+3
source

Well, if you use ido-mode to loop between buffers, you can set ido-ignore-buffers to match the buffers you want to ignore. From the documentation:

A list of regular expressions or functions matching buffer names to ignore. For example, traditional behavior is not a list of buffers whose names begin with a space for which the regular expression is "". See Source File for an example of functions that filter buffer names.

For more information on ido-mode see: Introduction to ido-mode

+1
source

All Articles