I keep forgetting emacs terminology for Select All, so I'd like to add a new emacs command so that I can type M-x select-all RET and have it run mark-whole-buffer.

I tried adding this to my .emacs file:

(defun select-all () (mark-whole-buffer))

or this:

(defun select-all () (interactive) (mark-whole-buffer))

But these don't seem to put the names in the right "namespace" to be access via M-x, how do I get them in the right namespace?

Thanks, -Shawn

  • Oops, looks like this was my fault, the (interactive) version does work as written. – sligocki Sep 29 '10 at 22:49
  • "Select All" can also be found in the Edit menu, at least in EmacsW32. – RamyenHead Jan 26 '11 at 16:20

(interactive) tells Emacs that the function is a command, i.e. that the function can be bound to a key and executed with M-x. So (defun select-all () (interactive) (mark-whole-buffer)) should work (but (defun select-all () (mark-whole-buffer)) won't). Did you restart Emacs or evaluate the definition with C-M-x (eval-defun)? What does C-h f select-all RET show? (The help buffer should begin with “select-all is an interactive”.)

Here, a simpler alternative is

(defalias 'select-all 'mark-whole-buffer)
  • Great defalias sounds like exactly what I'm going for. In fact defun works for me now again, somebody in the office changed a file I was loading and broke my whole .emacs file (that's why defun didn't work originally). Thanks all! – sligocki Sep 29 '10 at 22:47

Well, this is already built in:

M-x mark-whole-buffer

bound to

C-x h

But, to get what you want by writing something, your second implementation works for me just fine, and I can get to it by typing M-x.

  • Like I said, I always forget what emacs calls this command, so I'm trying to make an alias. I'll give it another try, maybe I failed to load it correctly. – sligocki Sep 29 '10 at 22:28

The one with the interactive looks like it's correct, and it works for me.... did you remember to re-load your .emacs after defining it?

  • Yes, I did try reloading, but someone in the office broke a file I loaded and so my whole .emacs wasn't loading. Thanks for checking it! – sligocki Sep 29 '10 at 22:49

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.