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

Suppose I add a new word count function to my .emacs file to count words:

(defun word-count nil "Count words in buffer" (interactive) (shell-command-on-region (point-min) (point-max) "wc -w"))

I remember there being a way to run a function by typing the function name, but I don't remember how. What key sequence do I type before I type word-count, enter?

share|improve this question

I figured it out. It's M-x. That's what I assumed it was, but it didn't work the first time because emacs doesn't recognize a new function in .emacs until you restart emacs.

share|improve this answer
In addition to restarting, you can also use M-x load-file to reread .emacs, or use M-x eval-region to evaluate an arbitrary piece of elisp (in this case your defun). – KeithB Mar 17 '10 at 20:39
You can accomplish the same by M-x load-file and then ` ~/.emacs` (or whatever the path to your .emacs is) – Nifle Mar 17 '10 at 20:39
And another alternative: place point (the cursor) at the closing paren for the new function and hit C-x C-e or run eval-last-sexp. – Joe Casadonte Mar 19 '10 at 20:39

You must log in to answer this question.