Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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
up vote 9 down vote accepted

(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)
share|improve this answer
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.

share|improve this answer
+1 because I didn't know about C-x h! – Brian Postow Sep 29 '10 at 22:23
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
Ah, now it works. – sligocki Sep 29 '10 at 22:48

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?

share|improve this answer
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .