Emacs web mode selection word delimiters include _

461 views Asked by At

I'm unsure of how to properly describe this question, but here goes:

In emacs with I double-click to select a word, something determines which characters to select -- what is this called? (In Terminal profile preference, this is called select-by-word characters, so I'll use that phrase.)

Without web-mode, for example, if I double click the word title in image_title, it highlights only title -- that is, the underscore is recognized as a select-by-word delimiter.

Once I enabled web-mode, the behavior of select-by-word changes, and underscore is no longer a word delimiter. In the previous example, double-clicking now highlights the entire image_title. This irritates me, as I commonly want to select portions of an underscore-delimited-identifier. (In general, I'd prefer any mode not to change the default selection behavior.)

What is the option to change this behavior of web-mode?

Edit to add: in my preferred mode, if I double-click on the _ character, it does select the entire word including underscores. I like this subtle but precise control of the selection behavior.

1

There are 1 answers

1
Jeff Ward On

@lawlist - thanks for your suggestions! I wasn't able to follow the functions through entirely, but it did lead me along the correct path:

  • found double-mouse-1, searched google
  • found the mouse word selection uses a global forward-word functions
  • that page mentioned syntax-table, you mention syntax-table, and what do we have here web-mode.el contains a syntax-table (and a reference to bug #377.)

web-mode's syntax table contains, roughly line 1969 in v 11.2.2:

(defvar web-mode-syntax-table
  (let ((table (make-syntax-table)))
    (modify-syntax-entry ?_ "w" table)
    (modify-syntax-entry ?< "." table)
    (modify-syntax-entry ?> "." table)
    (modify-syntax-entry ?& "." table)
    (modify-syntax-entry ?/ "." table)
    (modify-syntax-entry ?= "." table)
    (modify-syntax-entry ?% "." table)
    table)
  "Syntax table used to reveal whitespaces.")

I assume the ?_ "w" means it's treating _ as a word character. I changed the "w" to "." and underscore is now being treated as a word boundary like I wanted!

Hooray for stack overflow, google, and github.

Also, now that I've got some correct keywords, Stack Overflow suggests this potentially helpful related answer: Changing Emacs Forward-Word Behaviour