*scratch*
您可以在相同模式或(我的偏好)在 mode 中的任何其他缓冲区中或任何其他缓冲区中评估 Emacs-Lisp sexps emacs-lisp-mode
。
In *scratch*
you need only hit C-j
(newline) after a sexp to evaluate it. In an emacs-lisp-mode
buffer you can, as you said, use C-x C-e
after a sexp. Or you can use M-x evaluate-region
after selecting one or more sexps. As always, C-h m
in any mode tells you about it, and usually lists important key bindings.
You can also check a global variable value using C-h v SOME-VAR
. And you can evaluate any sexp on the fly from the minibuffer, using M-:
. For example: M-: (setq foo (+ 42 (length bar)))
Wrt the debugger:
As @sds mentioned, debug-on-error
puts you in the debugger when an error is raised. You can also set debug-on-quit
and then enter the debugger using C-g
to quit (e.g., during a loop).
If you know the function you want to debug, you can use M-x debug-on-entry
.
Step through the debugger using d
, or skip to the end of a step using c
. Use q
to quit the debugger.
You can also insert calls to function debug
in source code, as debugger entry points: (debug)
.
The backtrace in the debugger is always more informative if you load the relevant source file e.g., foo.el
, instead of the byte-compiled file, e.g., foo.elc
. So before you use M-x debug-on-entry
use C-h f
to find out which file the function is defined in, and then load that file using M-x load-file /path/to/the/file.el
.
There is also another debugger, besides debug
-- look for edebug
in the Elisp manual. Some people prefer edebug
; I prefer debug
.