Questions tagged [syntax]

is for grammar, structure, and order of language elements. Emacs provides many facilities for correcting syntax errors, building complex syntactic structures from simpler ones, and applying rules of composition with syntactical correctness.

Emacs covers a wide range of topics related to , which typically applies to programming (and data) languages, especially to Emacs Lisp. Some of these topics also have their own tags. For example:

Use additional tags besides as appropriate.

71 questions
52
votes
8 answers

How to treat underscore as part of the word?

I use Emacs + evil mode. When I position the cursor on e (in normal state) in a chunk of text such as abc_def_ghi, ciw (change inner word) changes only the def part of the string, while Vim would change the entire abc_def_ghi. How can I force evil…
Kossak
  • 1,159
  • 1
  • 9
  • 18
16
votes
2 answers

how to detect if inside a matched pair?

Q: is there a general way to detect whether or not point is inside a matched pair of characters? That is: is there a general predicate function (or something) that can determine if point is in-between a matched pair or some arbitrarily-chosen…
Dan
  • 32,584
  • 6
  • 98
  • 168
15
votes
2 answers

Does elisp have regexp literals?

The sheer number of backslashes my regexps require is pretty crazy. Does elisp have regexp literals, so I can write something like rx"some\(regexp\)" instead of "some\\(regexp\\)"
nosefrog
  • 795
  • 6
  • 9
12
votes
3 answers

Treat symbols as words in prog modes

There are a number of commands in Emacs which apply to "words." Examples include forward-word, kill-word, upcase-word, mark-word, transpose-words, etc. The definition of "word" seems to vary a bit between the commands. For example, forward-word…
nispio
  • 8,175
  • 2
  • 35
  • 73
12
votes
2 answers

For what languages is `syntax-ppss` appropriate?

I've been looking at a way of detecting whether point is on a comment by looking at how the current buffer is fontified. Smartparens defines sp-point-in-comment, which relies on syntax-ppss. However, it seems that syntax-ppss and parse-partial-sexp…
Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
10
votes
2 answers

Does word syntax take script into account?

I call count-words-region (M-x =) on US/RU/IPA string: HelloПривheləʊ The following message is printed: Region has 1 line, 4 words, and 14 characters. All symbols have w syntax, but differ in script: (char-syntax ?H) ; ?w (char-syntax ?П) ;…
gavenkoa
  • 3,352
  • 19
  • 36
10
votes
2 answers

Is there a standard/recommended syntax for defining a keyboard binding?

I have seen all of the following for defining a keyboard binding. All of these work (at least on MS Windows). I don't know if there is another way to do the same thing. I am wondering if there is a standard or recommended way to define a keyboard…
Name
  • 7,689
  • 4
  • 38
  • 84
9
votes
2 answers

How to 'modify-syntax-entry' for a major mode?

Following this answer, when I type (modify-syntax-entry ?_ "w") and do M-x eval-region, it has the effect I'm looking for, albeit only for that buffer. I've put (modify-syntax-entry ?_ "w") in my .emacs file, however and after restarting, it's not…
Swiss Frank
  • 247
  • 1
  • 10
9
votes
2 answers

Make forward-sexp recognize blocks defined by keywords, not just parentheses

In a language (julia) that has blocks defined by keywords such as for..end, begin..end, as well as parentheses, what is a good way to skip over such a block? Also, end is not only a block keyword, but also a valid identifier used in other…
Kirill
  • 1,019
  • 7
  • 19
8
votes
1 answer

In regular expressions, what's the difference between [:blank:], [:space:], and \s-?

I've been playing around with rx lately, and I just noticed there are (at least) 3 different ways of indicating whitespaces in regular expressions. [:blank:] [:space:] \s- What are the differences between each of them? Does it depend on the…
Malabarba
  • 22,878
  • 6
  • 78
  • 163
8
votes
2 answers

How can I nest one syntax table in another?

I've written a simple mode for handling JSON. It uses the derived machinery to re-use most of json-mode's code. However one addition is you can insert elisp into the JSON text which is evaluated at JSON submission time. For example an excerpt of the…
stsquad
  • 4,626
  • 28
  • 45
7
votes
1 answer

How to customize the line character length in elpy?

I am using elpy for my Python development, but I would like to set the per-line character limit to 120 instead of the default 80 used by PEP8. Any suggestions on how I can do this? Even better, it would be great if I can customize this setting on a…
modulitos
  • 2,432
  • 1
  • 18
  • 36
7
votes
0 answers

How do I parse a simple grammar and obtain a syntax tree in Emacs lisp?

How can I construct a parse tree from a string and a simple grammar? Semantic seems very tricky, and SMIE does not seem to produce a parse tree. Here's an example, assuming a language that looks like this: BLAH [ FOO "aaa"; "bbb" | BAR [ "ccc" |…
Clément
  • 3,924
  • 1
  • 22
  • 37
7
votes
3 answers

What's the difference between words and symbols?

When defining a syntax table for a major mode, I can define both word constituents and symbol constituents. When should I use each? For example, given a programming language that writes variables in snake case foo_bar, should _ be part of a word or…
Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
6
votes
7 answers

Easily changing matching quotes

Not infrequently, I want to change the delimiters of a string from single quotes to double quotes, or vice versa. This is so annoying a process I wonder if there's an easier way. What I do now is: delete the opening or closing quote type the…
Sean
  • 929
  • 4
  • 13
1
2 3 4 5