1

I'm looking for a way to include some filtering in the other-buffer method in emacs. Currently calling other-buffer pulls up the last most recent buffer, but the problem with this is that buffers that get modified by external processes keep coming up as other-buffer. I would like to implement some sort of filtering in other-buffer.

Currently I use evil with C-^ bound to other-buffer, and I have some tail.el buffers active, and when I try to switch bufffers the tail buffers keep popping up.

Is there some alternative to other-buffer or could someone scratch up some code to implement this, Thanks.

jagguli
  • 631
  • 1
  • 7
  • 21
  • 1
    are you sure you are really speaking of `other-window`? The rest of your question (speaking of most recent buffers) rather makes me think of `next-buffer`... `other-window` doesn't have any notion of recent window/buffer: it cycles among windows always in the same order, depending on splitting geometry. – François Févotte Jul 26 '13 at 07:00
  • i use evil and the C-^ is bound to the evil-buffer command , looking at the code for that it looks like its calling other-buffer... oh sorry that should have been other-buffer not other-window.. – jagguli Jul 27 '13 at 04:19
  • 1
    Ok, the difficult part here is knowing WHEN you don't want to switch to the tail buffers. Someone could write something to skip the tail buffers but then you'd have to find another way to switch to them when you DO want to. – Malabarba Jul 27 '13 at 09:02
  • I use ibuffer also, so i could use that to switch tail buffers. Its only when I'm using this C-^ combination I don't want to switch to a tail buffer, besides I have written a simple function to switch to switch to or create tail buffers. When editing files and switching between I dont want the tail buffer to jump up in between, and I get trapped in the tailbuffer because it uses a different keymap. – jagguli Jul 27 '13 at 12:11
  • The basic logic would be something like this (defun other-buffer-ex () (switch-buffer (if (eq other-buffer-mode "itail-mode") (next-buffer) (other-buffer)))) – jagguli Jul 30 '13 at 03:43
  • Are you sure C-^ is bound to other-buffer? This function is not interactive and doesn't switch the buffer. – Malabarba Jul 30 '13 at 07:57
  • C-^ is bound to evil-buffer which calls other-buffer – jagguli Jul 31 '13 at 06:36

2 Answers2

2

What has worked for me is winner-mode - it's like an undo, but for window configurations.

Here's my setup:

(winner-mode)
(global-set-key (kbd "<f7>") 'winner-undo)
(global-set-key (kbd "C-<f7>") 'winner-redo)

Also I'd recommend other-window on some very cheap shortcut, since it's a command that's used a lot.

I've put it on C-p, since I didn't appreciate the inconsistency that one of the direction keys is so far away from others. I've got previous-line on C-h instead, so now my direction keys are n h f b - they're almost together!

And I didn't really miss the defaults on C-h, since f1 has the same functionality.

abo-abo
  • 20,038
  • 3
  • 50
  • 71
0

Ok so I got some workable solution but its not perfect it using bits from this answer: emacs lisp, how to get buffer major mode?

(defun buffer-mode (buffer-or-string)
"Returns the major mode associated with a buffer."
(with-current-buffer buffer-or-string (format "%s" major-mode)))

(defun other-buffer-ex ()
(interactive)
(switch-to-buffer
(if (string-equal (buffer-mode (other-buffer)) "comint-mode") (next-buffer) (other-buffer))))

Community
  • 1
  • 1
jagguli
  • 631
  • 1
  • 7
  • 21