Usage of current-buffer in emacs?
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?
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
.
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
).
I sounds like you would (also) like to know how to get the name of the current buffer interactively. Use M-: (buffer-name)
.
精彩评论