aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-25 09:00:13 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-25 09:00:13 +0100
commit9183a2327147c29994067fd29abace55657c9686 (patch)
tree5c1ae68765ebb177ea0fe615d829dd62e94d2bab
parent41460f01f0a808c9e8855f41417ded8cf804f442 (diff)
compat-28: Add mark-thing-at-mouse
-rw-r--r--NEWS.org1
-rw-r--r--compat-26.el7
-rw-r--r--compat-28.el11
-rw-r--r--compat-tests.el11
-rw-r--r--compat.texi5
5 files changed, 34 insertions, 1 deletions
diff --git a/NEWS.org b/NEWS.org
index 84a9331..a2372e8 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -3,6 +3,7 @@
* Development
- compat-27: Add ~file-name-unquote~.
+- compat-28: Add ~mark-thing-at-mouse~.
- compat-29: Replace ~string-lines~ with version from Emacs 29, support optional
KEEP-NEWLINES argument.
diff --git a/compat-26.el b/compat-26.el
index 9c209dc..a63edbb 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -490,6 +490,13 @@ inode-number and device-number."
(error "Wrong attribute name '%S'" attr))))
(nreverse result)))
+;;;; Defined in mouse.el
+
+(compat-defvar mouse-select-region-move-to-beginning nil ;; <compat-tests:thing-at-mouse>
+ "Effect of selecting a region extending backward from double click.
+Nil means keep point at the position clicked (region end);
+non-nil means move point to beginning of region.")
+
;;;; Defined in image.el
(compat-defun image-property (image property) ;; <compat-tests:image-property>
diff --git a/compat-28.el b/compat-28.el
index f068240..645f5cb 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -710,6 +710,17 @@ where the mouse button is clicked to find the thing nearby."
(mouse-set-point event)
(bounds-of-thing-at-point thing)))
+;;;; Defined in mouse.el
+
+(compat-defun mark-thing-at-mouse (click thing) ;; <compat-tests:thing-at-mouse>
+ "Activate the region around THING found near the mouse CLICK."
+ (when-let ((bounds (bounds-of-thing-at-mouse click thing)))
+ (goto-char (if mouse-select-region-move-to-beginning
+ (car bounds) (cdr bounds)))
+ (push-mark (if mouse-select-region-move-to-beginning
+ (cdr bounds) (car bounds))
+ t 'activate)))
+
;;;; Defined in macroexp.el
(compat-defun macroexp-warn-and-return (msg form &optional _category _compile-only _arg) ;; <compat-tests:macroexp-warn-and-return>
diff --git a/compat-tests.el b/compat-tests.el
index 9724314..e8a5189 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -138,8 +138,17 @@
(let ((event `(mouse-1 (,(selected-window) 1 (0 . 0) 0))))
(set-window-buffer nil (current-buffer))
(insert "http://emacs.org/")
+ (goto-char (point-min))
(should-equal "http://emacs.org/" (thing-at-mouse event 'url))
- (should-equal '(1 . 18) (bounds-of-thing-at-mouse event 'url))))))
+ (should-equal '(1 . 18) (bounds-of-thing-at-mouse event 'url))
+ (should-not (region-active-p))
+ (mark-thing-at-mouse event 'url)
+ (should-equal (point) 18)
+ (should-equal '((1 . 18)) (region-bounds))
+ (let ((mouse-select-region-move-to-beginning t))
+ (mark-thing-at-mouse event 'url))
+ (should-equal (point) 1)
+ (should-equal '((1 . 18)) (region-bounds))))))
(ert-deftest dolist-with-progress-reporter ()
(let (y)
diff --git a/compat.texi b/compat.texi
index e70c63d..b0822a9 100644
--- a/compat.texi
+++ b/compat.texi
@@ -1923,6 +1923,11 @@ the position in @var{event} where the mouse button is clicked to find
the thing nearby.
@end defun
+@c based on lisp/mouse.el
+@defun mark-thing-at-mouse click thing
+Activate the region around @var{thing} found near the mouse @var{click}.
+@end defun
+
@c based on lisp/emacs-lisp/macroexp.el
@defun macroexp-file-name
Return the name of the file in which the code is currently being