3

Let's say I have a Linux directory that looks like

-rw-r--r--  1 hooked se     0 Sep 16 16:02 a
-rw-r--r--  1 hooked se     0 Sep 16 16:02 b
-rw-r--r--  1 hooked se     0 Sep 16 16:02 c

When I type emacs * it opens all three files but it puts me in the middle of the buffer chain. For example when I run it, I start off at c and NextBuffer takes me along the chain

c -> b -> *Messages* -> *scratch* -> a ->

This is really, really annoying. I'd like to open up emacs and have the order be any of the permutations

c -> b -> a -> *Messages* -> *scratch* -> 
b -> a -> c -> *Messages* -> *scratch* -> 
a -> b -> c -> *Messages* -> *scratch* -> 
...

Is there a way I can open up files along the "start" of the buffer list? I'm opening the files from a Bash CLI Ubuntu 14.04 if that makes a difference.

  • To put your question the other way, would it be alright if the *Messages*, *scratch* and other *..* buffers never showed up while cycling through the buffers using next-buffer? – Kaushal Modi Sep 16 '15 at 20:37
  • @kaushalmodi yes! that would work too -- I never end up using them (I'm not even 100% sure what they are for). – Hooked Sep 16 '15 at 20:51
  • The behavior you want sems like the most natural one, so I suggest you file a bug-report for that. – Stefan Sep 17 '15 at 0:51
  • @Stefan I'll do that. What is the official repo/bug report site for emacs? I'm assuming that github.com/emacs-mirror/emacs isn't it. – Hooked Sep 17 '15 at 2:12
  • You file a bug report by doing M-x report-emacs-bug from within emacs. That will format an email for you. It would have the email address, subject and a pregenerated body with debug info. You should then add info on what you think the bug is and how to recreate that. You can then send the email from within emacs or choose to copy everything and email that using your convenient client. – Kaushal Modi Sep 17 '15 at 2:40
4

Interesting problem. One solution which will give you the c -> b -> a -> *Messages* -> *scratch* permutation is putting this in your .emacs or .emacs.d/init.el file:

(defun bury-messages-and-scratch ()
  (mapcar #'bury-buffer '("*Messages*" "*scratch*")))

(add-hook 'emacs-startup-hook #'bury-messages-and-scratch)

First, I defined a function which calls mapcar. mapcar will apply a function (in this case, bury-buffer) to each element in the sequence provided. So what I wrote in one line is equivalent to these two:

(bury-buffer "*Messages*")
(bury-buffer "*scratch*")

bury-buffer will put the specified buffer at the end of the list of all buffers. next-buffer uses this list to cycle through buffers.

In order to get Emacs to call this burying function each time it starts, the function needs to be attached to a hook. Specifically, the hook we want is emacs-startup-hook. The documentation for this hook (which you can access using C-h v emacs-startup-hook RET) states: "Normal hook run after loading init files and handling the command line."

You can read about mapcar or bury-buffer or add-hook using C-h f <function-name> RET.

  • 1
    For someone not familiar with the internals of emacs (or LISP) can you break down what you did here so I can learn from it? – Hooked Sep 16 '15 at 20:52
  • 1
    @Hooked Sure, no problem. One moment. – nanny Sep 16 '15 at 20:54

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.