Hot answers tagged

14

You need it when, in Elisp code, you want to get the value of a symbol, that is, its value when considered as a variable. Keep in mind that an Elisp symbol has several characteristics/features: It has a name (which function symbol-name gives) It might have a value, when considered as a variable (which symbol-value gives) It might name a function, when ...


12

You need the latex file to use \usepackage[utf8x]{inputenc} rather than the default \usepackage[utf8]{inputenc}. This works with standard (pdf)latex. For org export to generate this you have to set the variable org-latex-inputenc-alist accordingly. For example: (setq org-latex-inputenc-alist '(("utf8" . "utf8x"))) For the variable to be defined, you may ...


11

There is no GNU Emacs convention wrt case for Emacs-Lisp function and variable names. (There can be any number of such "conventions" that anyone could come up with, of course.) The "Emacs Lisp Style Guide" that you reference is just one person's proposed guidelines. A (very) few longstanding libraries distributed with Emacs do use two styles that you ...


11

Do i have a misconception of symbols? Aren't they just strings without double-quotes? You do indeed have a misconception. A symbol is a lisp object containing numerous properties (including its name, its variable/value slot; and its function slot; but you can in fact set arbitrary properties on them, and many symbols have more than just the above). A ...


10

`C' shows `>' if you have marked the buffer to be displayed, `D' if you have marked it for deletion, and `.' for the buffer from which you came (current). `R' shows `%' if the buffer is read-only. `M' shows `*' if the buffer is modified, and `S' if you have marked it for saving.


10

(Doh, @Drew already put some of the following up. Anyway, here's some additional detail.) As the manual page on symbol components explains, there are four components (cells) to each symbol: its print name cell, its value cell, its function definition, and its property list. Either the value cell or the function cell may be void, and the property list may ...


10

It turns the symbol into a keyword. See chapter 12.2 Variables that Never Change in the Emacs Lisp manual. Keywords are frequently used to identify named arguments to Lisp functions and macros. When the implementation of define-minor-mode needs to know whether the mode should be global or not, it walks down the list of arguments looking for :global, then ...


9

You are right that make-symbol will create a keyword that is not eq to any existing keyword, and intern might pollute the global obarray with the new symbol. In between those, you have intern-soft, which returns the symbol if it has already been created, or nil if it hasn't: ELISP> (intern-soft ":key-1") nil ELISP> :key-1 :key-1 ELISP> (intern-soft ...


9

They are usually used as keys ("properties") in a property list. E.g the variable org-publish-project-alist contains one or more property lists with keys like :base-directory, :publishing-directory, :publishing-function etc. The Org mode manual shows a simple example and a more complex example of setting this variable. You should also read the doc ...


8

There's no name space in Emacs lisp, so people use various prefixes to avoid name clash. Section D.1 of Emacs lisp reference manual recommends using a short prefix followed by one or two hyphen(s): • You should choose a short word to distinguish your program from other Lisp programs. The names of all global symbols in your program, that is ...


8

Here's a bit of historical reference (I haven't been born yet when the described events took place, so maybe someone more knowledgeable will correct me. All this is from reading old articles and some books). Having dispensed with the disclaimer, it seems like back in the days of Fortran vs Lisp "symbolic" was a kind of a buzzword as "object oriented" is ...


7

Small demo: (setq v1 10) ;;10 v1 ;;10 (setq v2 'v1) ;;v1 v2 ;;v1 (symbol-value v2) ;;10


7

Perhaps I'm not understanding the question correctly. But if you want a keyword (i.e., you want to satisfy keywordp) then you want the symbol to be interned in the global obarray, obarray. It must be interned there to satisfy keywordp, AFAICT, and C-h f keywordp says so. So the answer to your question, AFAICT, is just to use intern. I feel like you are ...


7

It really depends on the use cases. Generally speaking, symbol properties are "low-level" / "internal" features and one should not use them for "user-level" stuff. However, there is a place for everything :-) A few points you might want to consider are: Speed: symbol properties are the fastest, closely followed by hash tables; alists are slow. It is ...


6

You're confusing make-symbol and intern. make-symbol is used specifically when you want such an equality not to hold.


6

'list and "list" are different datatypes: ELISP> (type-of 'list) symbol ELISP> (type-of "list") string Note that they even show up differently in your example -- it's the difference between list and "list". But why do they show up twice? Well, because the REPL displays anything printed out, but also prints out the return value of the s-expression. ...


6

If KEYWORD is indeed always a symbol (in particular a keyword symbol) then IMO there's no special reason to use format. But there's no special reason not to, either: "better readability" is opinion-based, and performance difference is probably negligible. But if it's not sure to be a symbol then using format with "%s" ensures that the ...


5

As mentioned in the comments, you have to turn on this setting to see how macro-expansion works more precisely. Note that it only changes how macroexpand is displayed, the macros still work the same in either case: (setq print-gensym t) Then the first instance expands to (incorrect): (let ((max 0)) (let ((i 1) (max 3)) (while (<= i max) ...


5

You'd just need to load proper unicode support in LaTeX via unicode-math and fontspec. Then you'd need to compile with xelatex or lualatex. See the docstring of the following variables: org-latex-packages-alist, org-latex-pdf-process and org-latex-compiler (the latter is introduced in Org 9). In the development version of Org you could do something like ...


5

Nothing is set in stone or enforced. That said, I highly recommend the lower-case and hyphens style. The only relevant thing I've found is in custom.texi: As described in @ref{Commands}, each Emacs command is a Lisp function whose definition provides for interactive use. Like every Lisp function, a command has a function name, which usually consists ...


5

Don't quote buffer-assassin when passing it to ninrod--protection. In your advice-functions, buffer-assassin is a variable, the value of which is the originial function. When you pass it quoted, buffer-assassin in ninrod--protection will have the value 'buffer-assassin (i.e. the symbol itself), so apply will try calling a (global) function named like that, ...


5

Emacs Lisp is a Lisp 2, which means only just what you described: the same symbol can have separate values as (1) a variable and (2) a function. (We call only #1 the "value" of the symbol.) Some other Lisp variants, such as Scheme, are Lisp 1s. There are advantages and disadvantages for each. What's the advantage of having separate variable and function ...


5

Yes, sure - use mapatoms: (defun find-symbols-having-properties (properties) (let (ret) (mapatoms (lambda (s) (when (cl-loop for prop in properties thereis (get s prop)) (push s ret)))) ret)) Now, to get all the "things", we need to do (find-symbols-having-properties '(beginning-...


5

I think the documentation you've linked to is comprehensive on the matter of their value: In Emacs Lisp, certain symbols normally evaluate to themselves. These include nil and t, as well as any symbol whose name starts with ‘:’ (these are called keywords). => The value of the keyword :foo is :foo. These symbols cannot be rebound, nor can their values ...


4

(intern "name") returns the interned symbol name make-symbol returns a new uninterned symbol, which is entirely distinct from the symbol with the face properties. Refer to C-hig (elisp) Creating Symbols RET


4

OK, it looks like the symbol needs to be "interned". http://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Symbols.html This works as expected: (require (intern "test"))


4

The thingatpt.el API works as follows: (thing-at-point 'symbol) ;=> foo (beginning-of-thing 'symbol) ;=> 42 (end-of-thing 'symbol) ;=> 45 (bounds-of-thing-at-point 'symbol) ;=> (42 . 45) While it's not 100% reliable as it relies on (forward-thing 'symbol) to do the right thing, it's pretty good and one of the better APIs in Emacs. Give it a ...


4

I am certain that the answer is no, and that variables are the only kind of buffer-local bindings provided by elisp. (I'm sure one of the elisp language maintainers will correct me if I'm wrong about this.) There are a handful of other kinds of "local" values (such as frame parameters, and terminal-local variables), and other things may also be associated ...


4

To add a tiny bit to what others have said - Think of keywords as constants like t and nil, whose values are themselves (symbols). That is, like t and nil they are self-evaluating. The general use case for keywords is that instead of having only the two basic names "t" and "nil" you can use any name you like -- just prefix it with :. This ...


4

Is there a reason this is preferable to using symbol-name? No, I think it just comes down to style and context. E.g. I can imagine someone preferring to consistently use format everywhere, because it can handle more than just symbols, and the format string can be easily changed. See also Drew's answer. I would've expected symbol-name to be better in terms ...


Only top voted, non community-wiki answers of a minimum length are eligible