summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2022-12-16 18:26:14 +0200
committerEli Zaretskii <eliz@gnu.org>2022-12-16 18:26:14 +0200
commit12424cf31daec921e3b4a4029d99787d0e506f09 (patch)
tree69a3a2f29967f47e41469f8bd481b9f4d2e81dd1
parentb29be11a6f387c92508beafcbc8f58799a3e3e06 (diff)
downloademacs-12424cf31daec921e3b4a4029d99787d0e506f09.tar.gz
New option for selecting symbols by double-clicking
* lisp/mouse.el (mouse-1-double-click-prefer-symbols): New user option. (mouse-skip-word): If 'mouse-1-double-click-prefer-symbols' is non-nil, skip over the entire symbol at point. (Bug#60080)
-rw-r--r--lisp/mouse.el20
1 files changed, 18 insertions, 2 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el
index f72ab4fc642..095d30a2856 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -105,6 +105,15 @@ point at the click position."
:type 'boolean
:version "22.1")
+(defcustom mouse-1-double-click-prefer-symbols nil
+ "If non-nil, double-clicking Mouse-1 attempts to select the symbol at click.
+
+If nil, the default, double-clicking Mouse-1 on a word-constituent
+character will select only the word at click location, which could
+select fewer characters than the symbol at click."
+ :type 'boolean
+ :version "30.1")
+
(defcustom mouse-drag-and-drop-region-scroll-margin nil
"If non-nil, the scroll margin inside a window when dragging text.
If the mouse moves this many lines close to the top or bottom of
@@ -1800,10 +1809,17 @@ The region will be defined with mark and point."
;; Commands to handle xterm-style multiple clicks.
(defun mouse-skip-word (dir)
"Skip over word, over whitespace, or over identical punctuation.
+If `mouse-1-double-click-prefer-symbols' is non-nil, skip over symbol.
If DIR is positive skip forward; if negative, skip backward."
(let* ((char (following-char))
- (syntax (char-to-string (char-syntax char))))
- (cond ((string= syntax "w")
+ (syntax (char-to-string (char-syntax char)))
+ sym)
+ (cond ((and mouse-1-double-click-prefer-symbols
+ (setq sym (bounds-of-thing-at-point 'symbol)))
+ (goto-char (if (< dir 0)
+ (car sym)
+ (cdr sym))))
+ ((string= syntax "w")
;; Here, we can't use skip-syntax-forward/backward because
;; they don't pay attention to word-separating-categories,
;; and thus they will skip over a true word boundary. So,