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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
27 views

Support for fixed-length fields

I have a file which contains several lines. Each line contains of several "fields" (about 20 - 40 ), each having a fixed length of characters. There are no gaps (field1 follows fields2 and ...
ClemensFMN's user avatar
0 votes
0 answers
20 views

find etags not working right from ".txt" file

I use etags to find functions in my C code and everything works fine when I'm in a .c (or .h) file. If I use the find-tag key (M-.) when the buffer is a different type of file (.txt) the tag search ...
ned3000's user avatar
1 vote
1 answer
84 views

How does `eval-last-sexp` determine the expression for evaluation?

Context: Emacs 29.0.60 The ▬ and the empty lines after the script text below are point positions at which the interactively executed function eval-last-sexp echoes in the minibuffer and the *Messages* ...
Claudio's user avatar
  • 430
2 votes
1 answer
46 views

Why dividing long line (with lambda/interactive) in the (general.el) breaks off the Syntax coloring?

This is part of my general el config. As shown in the image, when I divide long line (that has lamda, interative) into multiple lines :which-key ...... changes color.` Why is this happening? Am I ...
Garid's user avatar
  • 589
0 votes
1 answer
148 views

Use-package :bind-keymap with car as a form

As you can see below, trying to make a cons using a backquote and a colon to evaluate a form causes an error. Surely this is a tiny mistake, but Lisp is not my cup of tea. Let's just jump to the code: ...
adentinger's user avatar
1 vote
2 answers
330 views

Why can't I compose commands `mark-whole-buffer` and `copy-region-as-kill` in Elisp code?

I am trying to write a small code snippet in Elisp. Basically, I want to create a function so that the content of the whole buffer is copied and, then, copied to the kill ring. I can achieve this by ...
Pedro Delfino's user avatar
0 votes
1 answer
53 views

Raw Syntax Descriptor for a char at POS. What is it?

What is the Raw Syntax Descriptor for a char at POS? Can I have some examples so I can understand what this thing is all about?
Dilna's user avatar
  • 1
0 votes
1 answer
52 views

Syntax propertizing an exception to Python comment rule

I want to write a mode for the Cadabra 2 computer algebra system, which has Python-like syntax, with an exception of having the hash character # as a wild card in expressions, in addition to being a ...
Andrii Kozytskyi's user avatar
0 votes
0 answers
67 views

Measuring cyclomatic complexity of nested s-exp

I would like to measure the Cyclomatic Complexity on a file or a region of elisp code. By counting the maximum number of nested s-exp.
Dilna's user avatar
  • 1
0 votes
1 answer
26 views

Why does a stray period cause an error I associate with mismatched parens?

A typo that changed (foo) to (foo . ) in my .init file caused an Invalid read syntax: ) error. I get why it's a syntax error. But why this error? I thought this error message reliably reflected ...
Leah Velleman's user avatar
2 votes
1 answer
87 views

How to support `<` and `>` as balanced parens without impacting ability to use them as comparison operators?

Languages like Erlang and Elixir use << >> for binaries and bit-string syntax, but they also use the classical < and > for comparison operators as well as -> and <- in list ...
PRouleau's user avatar
  • 786
3 votes
1 answer
147 views

How can I make `forward-sexp` handle other balanced character-pairs such as < and > or << and >>?

I am trying to find an easy and efficient way to modify the behaviour of forward-sexp to handle balanced pairs of characters not normally supported by it, such as balanced < and > and balanced &...
PRouleau's user avatar
  • 786
0 votes
0 answers
43 views

How to detect whether current major-mode allows dashes ("-") in its symbol names?

To enable smart-dash ("an Emacs minor mode which redefines the dash key to insert an underscore within C-style identifiers and a dash otherwise") after falling in love with Kebab/Lisp case, ...
Daanturo's user avatar
  • 180
1 vote
1 answer
113 views

Syntax coloring: Unable to color special syntax

I am writing a mode to color a few common syntax in a symbolic language called FORM. I am a new user of emacs and I took the help of this website to write down the following code. I modified the ...
lost-neutrino's user avatar
9 votes
2 answers
1k views

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 ....
Swiss Frank's user avatar
2 votes
2 answers
185 views

Can syntax parsing recognize the SQL '' (escape apostrophe/single quote) construct within SQL strings?

I am trying to enhance SQL mode such that editing of files of SQL code becomes more convenient, especially as far as jumping around is concerned (e.g. things like sql-goto-end-of-string etc.). I have ...
fsavigny's user avatar
2 votes
1 answer
102 views

Why needs syntax highlighting often a `revert-buffer`?

Quite frequently, syntax highlighting in a given buffer is broken (i.e., a big fraction of the code is not highlighted). This is definitely not due to syntax errors, and the point at which ...
Torsten Bronger's user avatar
4 votes
1 answer
340 views

Circular list use of "#"

Looking at this, I see (setq x '#1=(a #1#)) but this evaluates to (a #0). As I understand, this should be (a #1=(a #1#)). But then what syntax makes #0 mean #1=(a #1#)? In general what is # doing in ...
147pm's user avatar
  • 2,937
0 votes
1 answer
69 views

Completing underscored words without making _ a word character

I would like to use evil-complete-previous (or whatever) to complete strings_such_as_this, which is by default not possible. It is possible after (modify-syntax-entry ?_ "w"), but this has the ...
Toothrot's user avatar
  • 3,254
3 votes
1 answer
558 views

python interpreter within emacs fails on simple test on __main__ (syntax error)

This small program runs well in Terminal : mac2011% cat bug.py print(__name__ == "__main__") #if True: if __name__ == "__main__": print("main") else: print("not main") mac2011% python bug.py ...
Pierre ALBARÈDE's user avatar
1 vote
1 answer
498 views

How to find the matching bracket at a point in elisp?

What is a reliable way to find the matching balanced bracket (eg: {}, [], () in C or Python), which doesn't get confused by brackets in strings, or escaped brackets for e.g. Example: ["Foo]" ?\] 0 [...
ideasman42's user avatar
  • 8,556
1 vote
1 answer
108 views

forward-word and non-letter "words"

Using forward-word with this line: foo *** *** bar, I want to have the folowing behavior: foo| ***| ***| bar|, Not: foo| *** *** bar|, So, if between spaces there are only non-letter symbols, ...
A.King's user avatar
  • 53
2 votes
1 answer
658 views

Debugger entered--Lisp error: (invalid-read-syntax ")") read(#<buffer *load*>)

Launch Emacs using runemacs --debug-init and the following error occurred. any idea on how to locate the file/script of the error or how to fix it? Thanks in advance. Debugger entered--Lisp error: (...
YiC's user avatar
  • 105
1 vote
1 answer
1k views

"Symbol's value as variable is void: *" using load-file

I have this function in my config file and for some reason, I'm getting this error: Symbol's value as variable is void: *. (defun reload-config() "Reload config.org" (interactive) (load-...
Lucas Peixoto's user avatar
1 vote
1 answer
143 views

Accessing next/previous parenthesis instead of just the outermost one? (as with `syntax-ppss`)

syntax-ppss gives the surrounding parenthesis. Is it possible to get the next/previous parenthesis using this API? (which has the advantage of caching the syntax tree and working with multiple ...
ideasman42's user avatar
  • 8,556
1 vote
0 answers
60 views

Test if I am inside a paired delimiter

I have been having a problem where I want an up-sexp command that treats paired delimiters like $ in LaTeX-mode just as if they were pairs of balanced parentheses. There are hacks I can use that get ...
Zorgoth's user avatar
  • 820
2 votes
1 answer
108 views

How to use helm-occur to search the whole word?

For example, I got the following lines: 1. abc 2. abc def 3. abc_def 4. _abc 5. abc_ and I want to search only the word abc, so only the 1 and 2 lines matches, I googled a while, it says \babc\b ...
CodyChan's user avatar
  • 2,609
2 votes
1 answer
203 views

How can I make syntax-propertize skip part of the buffer?

In SPARQL, comments starts with a # and follows to the end of the line. The problem is that URI's, which is a big part of SPARQL, can also contain #, but then they are not the start of a comment. Like ...
ljos's user avatar
  • 131
6 votes
7 answers
2k views

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: ...
Sean's user avatar
  • 929
1 vote
0 answers
91 views

Keyword as comment ender (and starter)

In my previous question I asked about complex comment-start sequence and I think I figured it out, but now I have another problem. Let say we have this mode: (defconst test-font-lock-keywords '(("\\...
vonaka's user avatar
  • 171
0 votes
5 answers
326 views

Is it possible to define all keywords' function definitions as plist-get?

I really, really like Clojure-style maps: {:keyword "value" :keyword2 'value2} which can be used like (get my-map :keyword) or, even better, (:keyword my-map) Can I teach Elisp how to do this?
Sean Allred's user avatar
  • 6,871
2 votes
1 answer
131 views

Is there a syntax in Elisp for indexed getters and setters?

I want to define a struct for chores (defstruct chore name sector assignments) where the assignments slot is a vector with seven positions. I know that the above syntax will generate the getters ...
Jeff's user avatar
  • 537
6 votes
2 answers
2k views

backward-kill-word kills too much, how to make it more intelligent?

I'm looking for a way to reduce what Emacs kills when I use backward-kill-word. protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) ...
gvelasq's user avatar
  • 63
3 votes
1 answer
454 views

add a rule to syntax-propertize-rules

I have an issue outlined here that I was able to find a partial solution for. The problem involved changing perl-modes syntax table. One of the commenters pointed me to the function syntax-propertize-...
Prgrm.celeritas's user avatar
3 votes
1 answer
252 views

modify syntax table for strings in perl modes

My company uses a version of Perl where you can define by binary number using something like my $var = 'b010110110; etc. Problem is both perl-mode and cperl-mode interpret ' as the start of the string ...
Prgrm.celeritas's user avatar
3 votes
1 answer
64 views

How to treat region between conflict markers as comment?

While resolving complex conflicts manually, I usually want emacs to treat conflict markers and region between them as comment, since it breaks major-mode's syntactic analysis (fontification, electric-...
zk_phi's user avatar
  • 446
1 vote
2 answers
580 views

Syntax highlighting (in Emacs) for SQL code in log files

How can we highlight SQL code in some log files, with Emacs? Sample log file: [DEBUG][2016-05-26 09:04:51,714][FileHelper] - [realContextPath=[/server.xml]] [DEBUG][2016-05-26 10:24:22,369][...
user3341592's user avatar
2 votes
0 answers
81 views

Emacs Syntax Table Modifications [closed]

I am looking to write my own major mode. The programming language that I need to write it for has //... and /* ... */ style comments. I am having a very hard time getting the syntax tables working ...
Nick's user avatar
  • 21
7 votes
1 answer
5k views

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 ...
modulitos's user avatar
  • 2,452
4 votes
1 answer
216 views

Is the sharp dollar (#$) sign the same as load-file-name in Emacs?

I see Emacs use #$ in autoload files, but I don't known if there are any difference between #$ and load-file-name. When I use them in a file, they looks like the same and when I print them by M-: they ...
littleqz's user avatar
  • 117
0 votes
0 answers
27 views

Why does forward-word stop at this quotation mark? [duplicate]

Minimal example code, run it from emacs -Q. Note the use of unicode RIGHT SINGLE QUOTATION MARK (’) not APOSTROPHE ('). (modify-syntax-entry ?’ "w p" text-mode-syntax-table) ; that's the same syntax ...
purple_arrows's user avatar
10 votes
2 answers
140 views

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 ...
gavenkoa's user avatar
  • 3,362
1 vote
1 answer
2k views

Turn on semantic mode for C/C++

I got these lines: ;; turn on semantic (semantic-mode 1) ;; define a function which adds semantic as backup to auto-complete (defun my:add-semantic-to-autocomplete() (add-to-list 'ac-sources 'ac-...
Gabriel Răducan's user avatar
1 vote
0 answers
40 views

Consistent way to represent key sequences? [duplicate]

The macro kbd doesn't work for all desired input. For example, this results in an error: (kbd "C-H-left") edmacro-parse-keys: C-H- must prefix a single character, not left and should be written as: ...
gavenkoa's user avatar
  • 3,362
1 vote
2 answers
155 views

How to make $ not part of a symbol in tcl-mode?

Recently I found out about isearch-forward-symbol-at-point but in tcl it's rather useless, because when dereferencing a variable the $ is part of the symbol and so the symbol-at-point $var does not ...
Uwe Koloska's user avatar
1 vote
0 answers
128 views

Auto-indent problems related to syntax in Haxe-Mode

In the Haxe programming language, you can specify the type of the return value of a function with a colon. function funcName() : ReturnType { } This becomes a problem when using emacs with haxe-mode....
AccidentalRebel's user avatar
0 votes
1 answer
61 views

Strip arbitrary characters from a string?

Q: How can I strip non-word characters from a string? For an arbitrary string, how do I strip all characters with non-word syntax? Alternately, using a regexp, how do I strip out the non-alphabetic ...
Dan's user avatar
  • 32.7k
5 votes
0 answers
870 views

ps-print-buffer-with-faces with color-theme'ed dark background

Similar to Change syntax highlighting when doing ps-print-buffer-with-faces I typically use emacs with a dark background, but I'd like to print my buffer onto a white background (i.e. white paper). ...
bernie's user avatar
  • 589
5 votes
2 answers
794 views

How to keep underscores in Python within a word boundary?

When writing code in python-mode my preference would be to include underscores within a word boundary, so variable_with_underscores is treated as a single word. How would I limit my word preference ...
Jeff Bauer's user avatar
3 votes
1 answer
138 views

How can I configure imenu to ignore comments?

To configure imenu in my major mode, I need to set imenu-generic-expression to have regexps for functions. However, this is incorrectly detects things inside comments and strings that look like ...
Wilfred Hughes's user avatar