emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 9183a23271 1/2: compat-28: Add mark-thing-at-mou


From: ELPA Syncer
Subject: [elpa] externals/compat 9183a23271 1/2: compat-28: Add mark-thing-at-mouse
Date: Wed, 25 Jan 2023 03:57:26 -0500 (EST)

branch: externals/compat
commit 9183a2327147c29994067fd29abace55657c9686
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-28: Add mark-thing-at-mouse
---
 NEWS.org        |  1 +
 compat-26.el    |  7 +++++++
 compat-28.el    | 11 +++++++++++
 compat-tests.el | 11 ++++++++++-
 compat.texi     |  5 +++++
 5 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/NEWS.org b/NEWS.org
index 84a9331abc..a2372e81b8 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 9c209dce13..a63edbbc25 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 f068240d64..645f5cb9f5 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 9724314f5f..e8a5189de0 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 e70c63d0ee..b0822a99bb 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]