Hot answers tagged

13

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 ...


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 ...


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 ...


9

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 ...


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

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 ...


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 ...


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 ...


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 ...


7

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


6

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 ...


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. ...


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

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


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

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) ...


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 ...


3

It isn't equivalent. If you test the symbol of a defvar'd variable with special-variable-p you get t, however this is not the case for your code. This bit must be set for the variable to be usable with dynamic binding. There doesn't appear to be a way to set this bit, other than by using special forms like defvar, defalias or the defcustom macro (which ...


3

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 ...


3

See C-hig (elisp)Symbol Type In contrast to its use in strings, however, a backslash in the name of a symbol simply quotes the single character that follows the backslash. For example, in a string, ‘\t’ represents a tab character; in the name of a symbol, however, ‘\t’ merely quotes the letter ‘t’. So the symbol foobar\? is in fact exactly what ...


3

Try this: (let ((name "foo")) (fset (intern name) (lambda (x) (* 2 x)))) (foo 21) ; 42 Brief explanation: (intern name) creates a symbol with the given name and adds it to the list of accessible symbols (that is what interning means). But if the symbol with that name already exists, it does nothing; just returns the already existing symbol. And (lambda …) ...


3

From the manual Section 9.2. "Symbol Components": Most symbols can have any Lisp object as a value, but certain special symbols have values that cannot be changed; these include nil and t, and any symbol whose name starts with ‘:’ (those are called keywords). See Constant Variables. This page can be reached with M-: (info "(elisp)Symbol Components") <...


2

You can use the built-in backward-kill-sexp. (global-set-key (kbd "M-DEL") 'backward-kill-sexp) This has the unwanted effect of adding whatever was deleted to the kill ring. To fix this you can try: (defun backward-delete-sexp (arg) (interactive "P") (delete-region (point) (progn (backward-sexp arg) (point))))


2

Two ways to go: 1) Either write proper TeX expressions (instead of unicode) and let org just display them as utf-8 characters (with C-c C-x \) . http://orgmode.org/manual/Special-symbols.html Or 2) Load a TeX package which translates your utf-8 characters into the proper math expressions. For example https://www.ctan.org/pkg/unicode-math?lang=en.


2

Yes, make the variable buffer-local, and turn the mode on in a given buffer, to use it. Your code can of course test whether the mode is on in a given buffer.


2

Here's a partial answer to this question. The short and not entirely satisfying version seems to be: use intern. :key-1 satisfies both: (symbolp :key-1) ; => t (keywordp :key-1) ; => t While (make-symbol ":key-1") satisfies the first but not the second: (symbolp (make-symbol ":key-1")) ; => t (keywordp (...


2

You can do it by using Malabarba's Nameless package, it is available from both GNU ELPA and MELPA. You probably want to customize the nameless-global-aliases and nameless-prefix user options. Something like: (setq nameless-global-aliases '(("i" . "ivan"))) (setq nameless-prefix "/") and open your init.el then M-x nameless-mode.


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