28

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 rather than word boundaries (setq-default evil-symbol-word-search t)) This has the advantage that it changes depending on the language: foo-bar is one ...


26

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


14

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


12

You can check if the current character is a comment character by using the syntax table: (looking-at "\\s<"). The regexp \\s< will match any character with the "comment start" syntax; \\s> will match those with "comment end" syntax. Another option is the variable comment-start, which is the string inserted by comment-dwim and friends. It ...


10

AFAIK the example you give are actually 2-char comment delimiters, except that depending on the 3rd character, these comments are treated in different ways (but always as comments in the sense that the semantics of the code is unaffected). So, the support offered by Emacs's syntax tables should be sufficient in most cirsumstances. If you want to highlight ...


10

Inside your hook put this: (setq comment-start "% "). Also, this will explain why: comment-region is an interactive compiled Lisp function. (comment-region BEG END &optional ARG) Comment or uncomment each line in the region. With just C-u prefix arg, uncomment each line in region BEG .. END. Numeric prefix ARG means use ARG comment ...


8

They are documented in the manual, but it doesn't use the word “fence”. The characters ! and | are listed as “generic comment delimiters” and “generic string delimiters” in the syntax class reference. These characters were introduced in Emacs 20.1. Quoting the NEWS file: There are two new syntax-codes, ! and | (numeric values 14 and 15). A character ...


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


7

You need to add backticks as a string delimiter to the js-mode syntax table like this: (modify-syntax-entry ?` "\"" js-mode-syntax-table) More information here.


7

For the record, ES6 template string literals are supported out-of-the-box in js2-mode, complete with font-locking for the interpolated variables as well.


6

Speed is a good reason to let the paren-matching be performed by syntax-tables where possible. In your case, the "parens" are not multi-char, so you can definitely use syntax-tables for them. In order to avoid treating -> as a paren closer, you can setup a syntax-propertize-function which modifies the syntax of those > which appear in ->. ...


5

Taken from syntax.h: /* A syntax table is a chartable whose elements are cons cells (CODE+FLAGS . MATCHING-CHAR). MATCHING-CHAR can be nil if the char is not a kind of parenthesis. The low 8 bits of CODE+FLAGS is a code, as follows: */ enum syntaxcode { Swhitespace, /* for a whitespace character */ Spunct, /* for random ...


5

Try (modify-syntax-entry ?# ". 1" js-mode-syntax-table) (modify-syntax-entry ?! ". 2b" js-mode-syntax-table) Reference


5

The syntax of ~ is changed by org-mode itself: as part of the definition of the mode, the file org.el contains (modify-syntax-entry ?~ "_") inside (define-derived-mode org-mode...). Since the command org-mode is not necessarily run at the time the file is loaded, you need to put your modification in to org-mode-hook instead, e.g. (add-hook 'org-mode-hook (...


4

Here are two possibilities: Use subword-mode. It is designed to do what you request. Emacs’s word commands recognize upper case letters in StudlyCapsIdentifiers as word boundaries. When Subword mode is enabled, the minor mode indicator , appears in the mode line. Change the syntax class of uppercase letters to something other than word-constituent....


4

Q2: is there something that works like [:symbol:] would? At the moment I use ugly handmade regexes like [[:word:]_+=], listing just a few specific symbols that I know will occur in my application. You could use the special \s syntax which references characters with a specific syntax class in a regular expression. In your case, w is the syntax class of word ...


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

Solution You can temporarily make - and _ be considered as part of the word in the syntax-table (defun sort-words (reverse beg end) "Sort words in region alphabetically, in REVERSE if negative. Prefixed with negative \\[universal-argument], sorts in reverse. The variable `sort-fold-case' determines whether alphabetic case affects the sort order. See `...


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

What about this. (defun dotted-symbol-at-point () (with-syntax-table (make-syntax-table (syntax-table)) (modify-syntax-entry ?. "_") (thing-at-point 'symbol)))


4

How can I make it to completely skip the commented out line? "Skipping lines" is not an inherent capability of regular expressions. Regexps either do or do not match whatever input they are given. The line skipping logic merely can be (and in Emacs world, usually is) built around regular expressions. Without further examples of your code or intent I cannot ...


3

Sort using symbol boundaries Here's a solution that came to me after reading OP's answer about what defines a "word": (defun sort-symbols (reverse beg end) (interactive "*P\nr") (sort-regexp-fields reverse "\\_<.*?\\_>" "\\&" beg end)) This version uses the symbol-boundary atoms (\_< and \_>). I think this solution makes the most sense,...


3

As far as I understand, in emacs -- word boundary is when next to a "w" syntax class stands char of some other class. This is in contrast to things like sentence-end which is determined by matching a regexp (sentence-end returns regexp). Emacs lisp mode inherits standard-syntax-table: ;; from lisp-mode.el: (defvar emacs-lisp-mode-syntax-table (let ((...


3

Or you just wait for Emacs 25.1 to come out. It's fixed there.


3

If you want to do something in every mode then you can use after-change-major-mode-hook to run your code.


3

Your approach almost works, but you can't only modify the syntax for the opening { if you want that to match the closing }, so you need both of: (modify-syntax-entry ?{ "(}") (modify-syntax-entry ?} "){") For the second part of your question, see: C-hf with-syntax-table C-hig (elisp)Syntax Table Functions


3

I do not know a shortcut for identifier regexps. Maybe, that is due to the complicated rules that exist for identifiers of some languages. Nevertheless you can define your own format strings and convert them by format-spec to regexps with identifiers. The following lisp code defines a function my-re for transforming extended regular expressions with %i as ...


2

(defun clojure-syntax-propertize-array-class (beg end) "Put word `syntax-table' property on \"[Lfoo.Bar;\"." (let ((word-syntax (string-to-syntax "w"))) (put-text-property beg end 'syntax-table nil) (save-excursion (goto-char beg) (while (re-search-forward (rx (and (group ?\[) ?L ...


2

Such is developed here: https://github.com/emacs-berlin/general-close Feel free to send bug-reports and feature requests. See also http://lists.gnu.org/archive/html/emacs-devel/2013-09/msg00512.html


2

Use macro with-syntax-table. You create a syntax table (e.g. inheriting from the current table), then change the syntax of any chars you want in that new table, then pass that table to with-syntax-table, wrapping your code (e.g. your function) with the macro. Within the context of the macro, your code will use the syntax table you specify. (If you have an ...


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