When I double click 'abcd_efg', emacs selects the part 'abcd' or 'efg' depending on what I click. How can I select the whole string 'abcd_efg' instead? Thank you.
3 Answers
Either do what @jcubic suggested or just double-click the _
char in the symbol name. That's what I do.
That way, you can do either: select a word (e.g., a piece of a symbol name) or select an entire symbol name. Yes, you have to pay a little more attention to where you click, but you get more flexibility.
You can call (modify-syntax-entry ?_ "w")
that will define underscore as part of the word.
I use this one, which I slightly modified from a google post (https://groups.google.com/forum/#!topic/gnu.emacs.help/9UDFLLjBeKU)
(defun get-word-boundary ()
"Return the boundary of the current word.
The return value is of the form: (cons pos1 pos2).
"
(save-excursion
(let (p1 p2)
(progn
(skip-chars-backward "-A-Za-z0-9_.") ;; here you can choose which symbols to use
(setq p1 (point))
(skip-chars-forward "-A-Za-z0-9_.") ;; put the same here
(setq p2 (point)))
(cons p1 p2)
))
)
(defun select-word ()
"Mark the url under cursor."
(interactive)
; (require 'thingatpt)
(let (bds)
(setq bds (get-word-boundary))
(set-mark (car bds))
(goto-char (cdr bds))
)
)
(global-set-key [double-mouse-1] 'select-word)