質問

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?

役に立ちましたか?

解決 2

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.

他のヒント

I use expand-region:

(require 'expand-region)
(global-set-key (kbd "C-=") 'er/expand-region)

so I press C-= once and it selects 789; I press it a second time and it selects 123.456.789. It works nice with strings, lines, statements from different languages.

Home: https://github.com/magnars/expand-region.el

Install it with ELPA (M-x list-packages).

ps: http://wikemacs.org/index.php/Elpa

@abo-abo's answer is good.

Just as another data point, you can also use command thing-region (from library thing-cmds.el -- Thing-At-Point Commands) for this. It prompts you for a type of THING to select. Just accept the default THING type, sexp, and you get what you requested in this case.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top