Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do these symbols mean in Emacs Lisp?

Tags:

emacs

elisp

When I read some elisp code, I found something like:

(\,(* 2 \#1)) 

\,(format "%s %s id%d %s" \1 \2 (+1 \#) \3)

#'(bla bla)

What does the symbol like "\,", "#", "#'" mean? Which session should I look into for those kind of things?

like image 643
enchanter Avatar asked May 02 '14 10:05

enchanter


1 Answers

\, is special in replacements when using query-replace-regexp. It means "evaluate the following elisp expression, and use the resulting value in the replacement".

n.b. It's not special elsewhere (that I'm aware of), so that should be the usage you've seen.

\# is also special in the replacement string, and is substituted with the number of replacements made thus far. (i.e. an incrementing counter).

\#N (where N is a number) is a variant of \N which treats the group in question as a number rather than a string, which is useful when the expression you're evaluating requires a number.

So (\,(* 2 \#1)) would be a replacement which evaluates the expression (* 2 \#1), multiplying the number matched by the first group of the regexp by 2 to produce some value N, such that the final replacement is (N).

You can find these detailed in the manual.

C-hig (emacs) RET followed by a search for the syntax in question. e.g. C-s \, with a repeated C-s if the search fails (as it will) to find a match in the subsequent nodes.

#'... is short-hand for (function ...) which is a variant of '... / (quote...) which indicates that the quoted object is a function.

As this is elisp syntax, you find it in the elisp manual:

C-hig (elisp) RET

You can either use C-s #' or in this case it's indexed, so I #' RET also works.

(In general check the index first, and then use isearch.)

like image 72
phils Avatar answered Sep 28 '22 15:09

phils