2

When I learn GNU Emacs Lisp, I get very confused about the code.

(looking-back "\\s)" 1)

I don't know what the \\s) stand for?I know it can mach the character ), and I want to know the rule of the matching string. Why not use the regular expression?

Drew
  • 27,527
  • 6
  • 62
  • 88
noah_le
  • 69
  • 1
  • 7

1 Answers1

2

"I don't know what the \\s) stand for? I know it can mach the character ), and I want to know the rule of the matching string."

\s) matches one occurrence of a character with syntax class "close parenthesis".

See the Elisp manual, node Syntax Class Table.

Open parenthesis characters: (

Close parenthesis characters: )

Characters used in dissimilar pairs to surround sentences or expressions. Such a grouping is begun with an open parenthesis character and terminated with a close. Each open parenthesis character matches a particular close parenthesis character, and vice versa. Normally, Emacs indicates momentarily the matching open parenthesis when you insert a close parenthesis. *Note Blinking::.

In human languages, and in C code, the parenthesis pairs are (), [], and {}. In Emacs Lisp, the delimiters for lists and vectors (() and []) are classified as parenthesis characters.

Drew
  • 27,527
  • 6
  • 62
  • 88
  • To add to the above answer, in a string, `\ ` is a special character, so needs to be escaped as `\\ `. So after string processing, `"\s"` becomes `\s` which is an Emacs extension to regular expressions to handle a commonly encountered case in parsing programming languages (for syntax highlighting etc). [markdown also needs special treatment of `\ ` in some cases] – JSON Aug 18 '17 at 03:29
  • The Emacs Lisp pass the "\\s" to the C program to match the string?Thanks, I get it. – noah_le Aug 20 '17 at 15:26