Search code examples
selectemacscursorcpu-wordexpand

How to select string that is connected with dot on Emacs


I want to select the whole word connected with dot. Is there any function in Emacs doing this.

Example:

123.456.[7]89
  1. Cursor is on "7".

  2. Apply "???function".

  3. Region "123.456.789" is selected.

    [123.456.789]

Is there "???function" in Emacs?


Solution

  • Here's a solution:

    (defun mark-whole-word ()
      (interactive)
      (let ((table (syntax-table)))
        (modify-syntax-entry ?. "w" table)
        (with-syntax-table table
          (backward-word)
          (set-mark (point))
          (forward-word))))
    

    The key here is modifying the syntax. So if you replace ?. with ?- above, you can mark similarly 123-456-789.