Hot answers tagged

42 votes

How to treat underscore as part of the word?

The following snippet will make Evil treat an Emacs symbol as a word. (with-eval-after-load 'evil (defalias #'forward-evil-word #'forward-evil-symbol) ;; make evil-search-word look for symbol ...
user avatar
  • 999
37 votes
Accepted

How to treat underscore as part of the word?

The simplest workaround: use ciW to select a whitespace-delimited word. The bigger issue has to do with the value of the _ character in the syntax table. The issue is that _ is, by default, a symbol ...
user avatar
  • 31.1k
16 votes

How to treat underscore as part of the word?

The spacemacs FAQ offers the following language-specific solution: ;; For python (add-hook 'python-mode-hook #'(lambda () (modify-syntax-entry ?_ "w"))) ;; For ruby (add-hook 'ruby-mode-hook #'(...
user avatar
  • 269
16 votes

how to detect if inside a matched pair?

syntax-ppss might be of help here. It returns a list that also has these elements: element 0: depth in parens element 3: non-nil if inside a string You could use it like this: (or (> (nth 0 (...
user avatar
  • 1,886
13 votes
Accepted

Does elisp have regexp literals?

One option is to use the rx macro to construct your expressions using sexps. Your example becomes (rx "some" (group "regexp")) Here are a couple more examples from the commentary section in rx.el, ...
user avatar
  • 19.4k
11 votes

Treat symbols as words in prog modes

Take a look at superword-mode and subword-mode. Superword treats underscores as part of a word instead of a boundary, so foo_bar would be treated as a single word. Subword does the opposite but for ...
user avatar
  • 4,004
10 votes
Accepted

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

Each major mode has its own syntax and syntax table. If you just put (modify-syntax-entry ?_ "w") in your init file, it gets evaluated in the buffer that is current when your init file is loaded -- ...
user avatar
  • 70.1k
8 votes

Does elisp have regexp literals?

No it does not have regexp literals, but many find pcre2el to be a helpful alternative. Specifically using it from elisp like this: (rxt-pcre-to-elisp "(abc|def)\\w+\\d+") ;; => "\\(\\(?:abc\\|...
user avatar
8 votes
Accepted

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

You can have a look at the built-in library SMIE (stands for Simple-Minded Indentation Engine). Despite the name, indentation is only one of the features it provides. This is the method used by many ...
user avatar
  • 4,113
8 votes
Accepted

Does word syntax take script into account?

This specific behaviour of forward-word can be controlled by the variables word-combining-categories and word-separating-categories. If you want to ignore the script completely, it is sufficient to ...
user avatar
  • 3,361
8 votes
Accepted

How to customize the line character length in elpy?

If you want to customize per project basis, you can create a setup.cfg with custom config like this [flake8] max-line-length = 160 If you want to change this globally, you can change flake8 config as ...
user avatar
7 votes

How can I nest one syntax table in another?

Ok, let's get some basics straight. Nesting syntax tables is possible Syntax tables don't have to be global to the entire buffer. You can apply them as text properties to specific regions. This ...
user avatar
  • 22.4k
7 votes
Accepted

How to keep underscores in Python within a word boundary?

Add a hook to modify the python-mode-syntax-table: ;; Keep underscores within a word boundary (add-hook 'python-mode-hook (lambda () (modify-syntax-entry ?_ "w" python-mode-syntax-table)))
user avatar
6 votes
Accepted

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

The [:blank:] character class matches only the SPC and TAB characters. The other two match whitespace based on the active syntax table. There does not seem to be a difference between [:space:] and \...
user avatar
  • 19.4k
6 votes

How can I nest one syntax table in another?

You don't want to nest one syntax table (which is a vector structure) inside another, you want to set up a buffer where, depending on the position, one syntax table would be used instead of the other. ...
user avatar
  • 3,278
6 votes

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

There is no single standard way, because there are different use cases. If you are writing such code manually, in your init file for example, then you might prefer the (kbd ...) format, because the ...
user avatar
  • 70.1k
6 votes

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

(global-set-key [?\M-r] 'some-command) is the "native" way. All others are built on top of this one, basically.
user avatar
  • 25.4k
6 votes
Accepted

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

Ask Emacs. M-x elisp-index-search RET #$ RET Internally, the dynamic loading of documentation strings is accomplished by writing compiled files with a special Lisp reader construct, ‘#@COUNT’. ...
user avatar
  • 43.8k
6 votes
Accepted

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

Use C-u C-c C-c. See python-shell-buffer-substring function docstring: When optional argument NOMAIN is non-nil everything under an if __name__ == '__main__' block will be removed. And python-...
user avatar
  • 2,185
5 votes
Accepted

Some warnings and unexpected indentation with SMIE

Regarding 2, the problem is simple: your major-mode function needs to set comment-start. This part has nothing to do with SMIE. Regarding 3, I'm not sure exactly what it is you're doing (where is ...
user avatar
  • 25.4k
5 votes
Accepted

Is is possible to treat any symbol in the buffer as word when moving around?

Since the answer is picked from the comment from @kaushalmodi, I cannot choose the comment as an answer, so I post this as the right answer. According to comment from @kaushalmodim, syntax-subword is ...
user avatar
  • 2,559
5 votes

How to keep underscores in Python within a word boundary?

It's bird, it's a plane, it's superword-mode: Superword mode is a buffer-local minor mode. Enabling it changes the definition of words such that symbols characters are treated as parts of ...
user avatar
  • 12.2k
5 votes
Accepted

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

You have an extra right paren, ), somewhere in your init file. Here's one way to find it: Start Emacs using emacs -Q (no init file). Visit this file - the one that Emacs was trying to load when it ...
user avatar
  • 70.1k
4 votes

How to treat underscore as part of the word?

The evil FAQ says if you want the underscore to be recognised as a word character: (modify-syntax-entry ?_ "w") Alternatively, you can change the w shortcut to move by symbols instead of by words: (...
user avatar
4 votes

How to treat underscore as part of the word?

Emacs 24 introduced superword-mode, a minor mode that treats underscores as part of words. evil-mode respects this setting. Here is the documentation: (superword-mode &optional ARG) ...
user avatar
4 votes

For what languages is `syntax-ppss` appropriate?

Adding to @lunaryorn's answer, I think syntax-ppss just rely on the robustness of emacs's syntax table system, which works for comment and string in most languages. But if the language has syntax that ...
user avatar
  • 1,706
4 votes
Accepted

Treat symbols as words in prog modes

Emacs should already use "the appropriate word boundaries for the syntax of the current language". If it does not then file a bug for the major mode for that language. But maybe you don't really ...
user avatar
  • 70.1k
4 votes

What's the difference between words and symbols?

This answer addresses your question title: "What's the difference between words and symbols". It does not speak only to the body of your question, which is about symbol syntax, which has been answered ...
user avatar
  • 70.1k
4 votes
Accepted

What's the difference between words and symbols?

Word constituents: ‘w’ Parts of words in human languages. These are typically used in variable and command names in programs. All upper- and lower-case letters, and the digits, are typically word ...
user avatar
  • 6,071

Only top scored, non community-wiki answers of a minimum length are eligible