branch: externals/do-at-point
commit b9771dc534d645bab0e1bfe45e800914c8f2a1e6
Author: Philip Kaludercic <[email protected]>
Commit: Philip Kaludercic <[email protected]>

    Add 'do-at-point-persist-mode'
---
 do-at-point.el | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/do-at-point.el b/do-at-point.el
index 9b47770818..b93fae9d67 100644
--- a/do-at-point.el
+++ b/do-at-point.el
@@ -229,6 +229,8 @@ invoke `do-at-point' is bound transiently."
                    #'do-at-point--next-thing)
        map))))
 
+(defvar do-at-point-persist-mode)
+
 (defun do-at-point-confirm (&optional quick)
   "Dispatch an action on the current \"thing\" being selected.
 If the optional argument QUICK is non-nil, the first applicable
@@ -254,7 +256,8 @@ action is selected."
          (func (cadr (alist-get (car choice) options)))
          (bound (cons (overlay-start do-at-point--overlay)
                       (overlay-end do-at-point--overlay))))
-    (do-at-point--mode -1)
+    (unless do-at-point-persist-mode
+      (do-at-point--mode -1))
     (when func
       (message nil)               ;clear mini buffer
       (pcase (car (func-arity func))
@@ -277,6 +280,7 @@ See the function `do-at-point-confirm' for more details."
   "Quit the selection mode and defer to \\[keyboard-quit]."
   (interactive)
   (do-at-point--mode -1)
+  (do-at-point-persist-mode -1)
   (keyboard-quit))
 
 (defun do-at-point--applicable-things ()
@@ -315,12 +319,14 @@ value of the function is always the new \"thing\"."
   "Determine the lighter for `do-at-point--mode'.
 The lighter depends on the current \"thing\" being selected."
   (let ((thing (overlay-get do-at-point--overlay 'do-at-point-thing)))
-    (and thing (format " Do-At-Point/%s" thing))))
+    (and thing (format " Do-At-Point/%s%s" thing
+                       (if do-at-point-persist-mode "*" "")))))
 
 (defvar do-at-point--mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map do-at-point--quick-map)
     (define-key map (kbd "C-<return>") #'do-at-point-confirm*)
+    (define-key map (kbd "M-<return>") #'do-at-point-persist-mode)
     (define-key map [remap keyboard-quit] #'do-at-point-quit)
     (define-key map (kbd "M-n") #'do-at-point-forward)
     (define-key map (kbd "M-p") #'do-at-point-backward)
@@ -347,6 +353,12 @@ instead."
     (delete-overlay do-at-point--overlay)
     (setq do-at-point--overlay nil)))
 
+(define-minor-mode do-at-point-persist-mode
+  "Minor mode that inhibits `do-at-point' from disabling itself.
+This is useful if you want to execute multiple actions in sequence,
+without having to re-select the object repeatedly."
+  :global nil)
+
 (defun do-at-point-forward (n)
   "Move focus N things ahead.
 By default, this will move one thing ahead."

Reply via email to