Hot answers tagged

26

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)) This has the advantage that it changes depending on the language: foo-bar is one symbol in lisp-mode but two symbols (separated by -) in c-mode.


25

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 ...


16

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 ...


13

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"))) ;; For Javascript (add-hook 'js2-mode-hook #'(lambda () (modify-syntax-entry ?_ "w"))) It also works in regular emacs. With ...


13

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: This ^;;\\s-*\n\\|^\n becomes (rx (or (and line-start ";;" (0+ space) ?\n) (and line-start ?\n))) This [ \t\n]*:\\([^:]...


13

Well, s-expressions are essentially “abstract syntax”, in the sense that they are merely a concrete syntax for abstract syntax trees, and thus any language can be represented as s-expressions, and manipulated with s-expression commands. Hence, syntax-ppss speaking of “Sexps” is simply the Lisp way to talk about abstract syntax trees. Practically, though, ...


11

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. (add-hook 'c-mode-common-...


9

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: define ...


7

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\\|def\\)\\)[_[:alnum:]]+[[:digit:]]+"


7

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.


7

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 ...


7

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. ...


7

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)))


6

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 ...


6

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


6

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) word-combining-...


6

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’. 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 ...


5

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. As ...


5

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-...


5

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 ‘$&*+...


4

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: ...


4

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,...


4

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: (global-syntax-subword-mode) (setq syntax-subword-...


4

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-...


4

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 mentioned here https://flake8.readthedocs.io/en/latest/config.html#global


4

The answer is that you can't do it "right". But you can do the following: (defalias 'my/perl-syntax-propertize-function (syntax-propertize-rules ("\\('\\)[bh]" (1 ".")))) (add-hook 'perl-mode-hook (lambda () (add-function :before (local 'syntax-propertize-function) #'my/perl-syntax-propertize-function))) ...


4

Yes and no. No, because chore-assignment doesn't let you modify what's inside the value of the assignment slot; it only lets you modify the assignment slot itself. Instead, Lisp has setf, which has some really good tricks up its sleeves. The first argument to setf is a PLACE, which is any expression which can be interpreted as a place to store a value. ...


3

I'm afraid that the answer is no - there is no easy, out-of-the-box way to do that. This has been discussed in the Emacs Dev mailing list a few times now, as a possible extension to Emacs Lisp. Well, not just for Isearch but for regexps in general. Here are two interesting threads about it: 1 and 2.


3

Emacs 24 defines forward-whitespace, which moves by whitespace-delimited words (i.e. anything but whitespace is considered a word constituent), but oddly not backward-whitespace. It only treats space, tab and newline as whitespace, not other Unicode whitespace or characters defined as whitespace. When going forward, it moves to the beginning of the next word,...


3

This appears to be coming from the function org-flag-drawer. Use C-h f to find where this function is defined, and modify it to also give the buffer name: (defun org-flag-drawer (flag) "When FLAG is non-nil, hide the drawer we are within. Otherwise make it visible." (save-excursion (beginning-of-line 1) (when (looking-at "^[ \t]*:[a-zA-Z][a-...


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