tags:

views:

72

answers:

2

I'm using emacs and I have written a script which uses "current-buffer". However the emacs system doesn't recognise "current-buffer". When I try "M - x current-buffer" i get the response:

no match

: Any idea what I'm doing wrong?

+2  A: 

Do I interpret you correct that you have created a function named current-buffer that you want to be available with M-x current-buffer?

To enable functions to be called by M-x function-name the function needs to be marked as interactive.

A sample from the emacs manual:

(defun multiply-by-seven (number)       ; Interactive version.
       "Multiply NUMBER by seven."
       (interactive "p")
       (message "The result is %d" (* 7 number)))

The (interactive "p") part makes the function callable from the minibuffer (through M-x).

Anders Abel
I haven't created a function called "current-buffer", but I do know what you mean about functions needing to be interactive, I just didn't know if it applied to "current-buffer". Is there any way to output the value of "current-buffer"?
Zubair
If current-buffer isn't an interactive function, you cannot call it from the minibuffer. One simple solution is to create your own interactive wrapper function.
Anders Abel
Where should I send the output of the function? In "message"?
Zubair
+5  A: 

current-buffer is not an interactive function. That is, can't be invoked interactively via M-x as you've tried to do. You can execute non-interactive lisp-code directly by using eval-expression as follows:

M-: (current-buffer) RET

Notice that you have to enter a proper lisp expression. If you want to capture the value in a variable, something like this

M-: (setq xyzzy (current-buffer)) RET

will store the current buffer into the variable xyzzy.

Dale Hagglund
When i try "M-: (current-buffer) RET" I get the answer "Trailing garbage following expression"
Zubair
Sorry, RET means to hit the return key. This is one of the conventions in emacs's builtin documentation.
Dale Hagglund
Yes, this works... thanks a million!
Zubair