2

I have the following line of code in my .emacs file:

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

This key-binding allows me to C-<tab> my way around Emacs. However, because of certain buffers that I have open by default this becomes very tedious. So I would like a function that switches to the next buffer unless the next buffer is a certain file/buffer. More specifically the following buffers:

  1. *GNU Emacs*
  2. *scratch*
  3. *Messages*
  4. .emacs

Note: Just because I want to skip them when I call next-buffer does not mean that I want to kill that buffer. I rather just get to it by pressing C-x b.

3

The "abort after twenty attempts" code in the ErgoEmacs functions -- presumably to avoid loops -- is kinda ugly and arbitrary.

I'm inclined to suggest using my answer from Make emacs next-buffer skip *Messages* buffer instead.

  • 1
    King Shimkus: I've rolled back your edit to include the code, because in general I prefer to have these things in just the one location, so that if I ever make improvements, there aren't multiple places which need to be edited. It's all part of the StackExchange network, so I'm sure that the typical concerns about off-site links shouldn't apply (If S.O. isn't available, then I doubt that E.SE is either). – phils Dec 4 '14 at 23:48
  • 1
    p.s. Anyone upvoting this, please consider upvoting the linked answer on S.O. instead? There are problems with the accepted answer to that question, so I'd prefer the votes went that way. – phils Dec 6 '14 at 2:03
1

Here are some functions to cycle through user's buffers:

(defun xah-next-user-buffer ()
  "Switch to the next user buffer.
 (buffer name does not start with “*”.)"
  (interactive)
  (next-buffer)
  (let ((i 0))
    (while (and (string-equal "*" (substring (buffer-name) 0 1)) (< i 20))
      (setq i (1+ i)) (next-buffer))))

(defun xah-previous-user-buffer ()
  "Switch to the previous user buffer.
 (buffer name does not start with “*”.)"
  (interactive)
  (previous-buffer)
  (let ((i 0))
    (while (and (string-equal "*" (substring (buffer-name) 0 1)) (< i 20))
      (setq i (1+ i)) (previous-buffer))))

And here are some functions to cycle through Emacs buffers:

(defun xah-next-emacs-buffer ()
  "Switch to the next emacs buffer.
 (buffer name that starts with “*”)"
  (interactive)
  (next-buffer)
  (let ((i 0))
    (while (and (not (string-equal "*" (substring (buffer-name) 0 1))) (< i 20))
      (setq i (1+ i)) (next-buffer))))

(defun xah-previous-emacs-buffer ()
  "Switch to the previous emacs buffer.
 (buffer name that starts with “*”)"
  (interactive)
  (previous-buffer)
  (let ((i 0))
    (while (and (not (string-equal "*" (substring (buffer-name) 0 1))) (< i 20))
      (setq i (1+ i)) (previous-buffer))))

The next step will be to set some custom shortcuts.

Courtesy of ErgoEmacs.

  • Though this code is still helpful. I was looking for code that skips certain buffers ( including user buffers ). I apologize as I should of put a user buffer in my question. Thanks though... – Luke Dec 4 '14 at 23:34

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.