The following snippet will make Evil treat an Emacs symbol as a word.
(defalias #'forward-evil-word #'forward-evil-symbol)
;; make evil-search-word look for symbol rather than word boundaries
(setq-default evil-symbol-word-search t))
This has the advantage that it changes depending on the language:
is one ...
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 constituent in the syntax table, and you want to treat it as a word constituent.
If you're using emacs 24.4, you could try enabling superword-mode. I haven't ...
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 #'(lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'js2-mode-hook #'(lambda () (modify-syntax-entry ?_ "w")))
It also works in regular emacs. With ...
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 (syntax-ppss)) 0)
(nth 3 (syntax-ppss)))
With a properly set up syntax-table in the buffer (for strings and matching parens) the function should do what you ...
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, to get an idea of how rx works:
(rx (or (and line-start ";;" (0+ space) ?\n)
(and line-start ?\n)))
This [ \t\n]*:\\([^:]...
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 camelCase, so fooBar is treated as two words instead of one.
It sounds like the behavior you want is for cc-mode to use superword-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 -- not in a C/C++ buffer.
To evaluate that sexp when in a C/C++ buffer you can put it in a function, which you add to the mode hook. For example (untested):
No it does not have regexp literals, but many find pcre2el to be a helpful alternative.
Specifically using it from elisp like this:
;; => "\\(\\(?:abc\\|def\\)\\)[_[:alnum:]]+[[:digit:]]+"
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 modes (including ruby-mode, mentioned in a comment), to provide sexp movement and indentation.
Deploying SMIE for a language is roughly a two-steps job:
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 add the pair (nil . nil) to the first list, e.g.
(let ((word-combining-categories (cons '(nil . nil)
If you want to customize per project basis, you can create a setup.cfg with custom config like this
max-line-length = 160
If you want to change this globally, you can change flake8 config as mentioned here https://flake8.pycqa.org/en/latest/user/configuration.html#user-configuration
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 means
you can indeed apply the elisp syntax table only to regions
surrounded by backticks.
How do you do that?
Here's one way you can do that. This method does it ...
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 \s-. The latter is an instance of the general \scode pattern for matching based on a syntax class.
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.
The other answer describes how to do this using the syntax-table text property. Here's how to do it using one of the "multiple major mode" packages, mmm-mode. ...
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 argument to kbd uses the same notation that Emacs uses when it communicates with you about key bindings (in *Help*, for example).
But if you are creating ...
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’. This construct skips the next COUNT characters.
It also uses the ‘#$’ construct, which stands for “the name of this
file, as a string”. Do not use these ...
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 point? what does the buffer contain? what command have you run?). But I suggest to first concentrate on indentation of the non-comment parts of the code.
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 great, it is exactly what I need. You can install it using package.el.
Here is my configuration in init.el:
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 words: e.g., in ‘superword-mode’,
"this_is_a_symbol" counts as one word.
It's a minor mode, so you can set it in a hook the normal way: (add-hook 'python-mode-...
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 barfed:
C-x C-f /Users/user/.emacs
Comment out 1/2 of that file (roughly), using M-x comment-region.
Do M-x eval-buffer.
If you get an error, then comment out ...
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.
When optional argument SEND-MAIN is non-nil, allow execution of
code inside blocks delimited by if __name__== '__main__':.
When called ...
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:
(defalias 'forward-evil-word 'forward-evil-symbol)
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)
Toggle superword movement and editing (Superword mode).
With a prefix argument ARG, enable Superword mode if ARG is
positive, and disable it otherwise. If ...
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 syntax table can't capture, and if the mode did't build a parser to add syntax properties to the right places, syntax-ppss would fail.
Try this in html-mode:
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 mean words. Maybe you mean symbol syntax, not word syntax. Emacs distinguishes the two.
For symbol syntax, use symbol commands, not word commands: forward-symbol,...
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 well by @Nsukami.
There are two very different meanings of the word symbol in Emacs:
symbol syntax, which involves word-constituent characters plus symbol-...
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 constituents.
Symbol constituents: ‘_’
Extra characters used in variable and command names along with word constituents. Examples include the characters ‘$&*+...