How to check if a variable is set to what in elisp/emacs?
Let's say I have the following lin开发者_高级运维e in .emacs file.
(setq-default default-directory "~/Desktop/mag")
How can I check the value for `default-directory' in elisp?
Added
I asked this question as I need to check the value of default-directory based on this question.
The elisp code should change the default directory when I click C-x C-f, but I still get ~/, not ~/Desktop/mag. So, I need to check what value the default-directory has.
If you're at the console you can type C-h v, which will prompt you for a variable name. Type in default-directory (or any other name) and you'll get a buffer with some info about that variable, including its value.
The elisp function you're running is describe-variable:
(describe-variable VARIABLE)
I figured this out by C-h k C-h v. C-h k shows you what function the next key or key sequence would call.
If you just want to check the value, you can run the following from the *scratch* buffer:
(print default-directory) <ctrl-j>
The *scratch* buffer allows you to evaluate lisp on the fly. You must hit ctrl-j after to evaluate.
As previously stated, C-h v
is the easiest way to find out a variables value. To make it even better, place your cursor on the variable you want to know about, and then run C-h v
, and it will default to the word under the cursor. Really handy.
Try:
(print default-directory)
write the above code in one line inside of emacs, got to the end of the line and hit C-x C-e
If you just want to see the variable value in the echo area (less of a mess), try:
(defun describe-variable-short (var)
(interactive "vVariable: ")
(message (format "%s: %s" (symbol-name var) (symbol-value var))) )
(global-set-key "\C-hV" 'describe-variable-short)
精彩评论