1

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.

Jeff Ward
  • 16,563
  • 6
  • 48
  • 57
  • 1
    The problem with posting a potential answer to this question is that the Emacs developers have been changing the inner workings of the functions in `mouse.el` between the various versions and the future releases. Your version of Emacs may be different that what others are using. What you need to do is press `C-h k` and then one left-click to see the two functions that are called. Then you need to `M-x find-function` to follow the trail to the function responsible for selecting the region. Once you do that, you need to make a new function with a custom syntax table -- `with-syntax-table`. – lawlist Jun 10 '15 at 17:07
  • 1
    You need to use `with-syntax-table` because you don't want to alter the `syntax-table` used by the major-mode in the current buffer -- you only want a temporary syntax table for the duration of the select region component of the function at issue. For example, you could copy the syntax table used by `text-mode`, or simply create and define your own. Once you locate the function at issue, you might be able to wrap it with an advice to use the temporary syntax table -- most Emacs users treat source code as sacred and they feel better about using advice instead of creating a new function. :) – lawlist Jun 10 '15 at 17:10

1 Answers1

0

@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

Community
  • 1
  • 1
Jeff Ward
  • 16,563
  • 6
  • 48
  • 57
  • I'm not familiar with web-mode, but *if* web-mode relies upon the syntax of the character you are modifying for anything (e.g., highlighting, folding, or something else), then the proposed revision may break something. If that is the case, then you may wish to consider a temporary modification of the actual function at issue with something like `with-syntax-table`: http://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Table-Functions.html – lawlist Jun 10 '15 at 21:03