Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a variable is set to what in elisp/emacs?

Tags:

emacs

elisp

Let's say I have the following line 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.

like image 712
prosseek Avatar asked Jul 29 '10 21:07

prosseek


People also ask

What is SETQ in Emacs?

Special Form: (setq [symbol form]...) This special form is the most common method of changing a variable's value. Each SYMBOL is given a new value, which is the result of evaluating the corresponding FORM. The current binding of the symbol is changed. 'setq' does not evaluate SYMBOL; it sets the symbol that you write.

What does #' mean in Emacs Lisp?

#'... is short-hand for (function ...) which is simply a variant of '... / (quote ...) that also hints to the byte-compiler that it can compile the quoted form as a function.


2 Answers

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.

like image 170
Paul Rubel Avatar answered Oct 05 '22 09:10

Paul Rubel


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.

like image 45
Starkey Avatar answered Oct 05 '22 09:10

Starkey