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?

有帮助吗?

解决方案

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

其他提示

For info on backquotes, see http://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html.

# starts the reader syntax, for instance #' is a reader alias for function. For more info see http://definitelyaplug.b0.cx/post/emacs-reader/

The #' is a short hand for using functions, for more details see here: http://www.gnu.org/software/emacs/manual/html_node/elisp/Anonymous-Functions.html

Backslash \ has two functions: it quotes the special characters (including ‘\’), and it introduces additional special constructs. More here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexps.html#Regexps

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top