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

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

[elpa] master 3b6c898 303/399: counsel.el (counsel-mark-ring): Add previ


From: Oleh Krehel
Subject: [elpa] master 3b6c898 303/399: counsel.el (counsel-mark-ring): Add preview by candidate
Date: Sat, 20 Jul 2019 14:57:45 -0400 (EDT)

branch: master
commit 3b6c898354d4b8c8e4f5ed555ae0f722b04facba
Author: SAITOU Keita <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-mark-ring): Add preview by candidate
---
 counsel.el | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/counsel.el b/counsel.el
index 08e7868..fca4d4b 100644
--- a/counsel.el
+++ b/counsel.el
@@ -3555,11 +3555,26 @@ This variable has no effect unless
 
 ;;* Misc. Emacs
 ;;** `counsel-mark-ring'
+(defvar counsel--mark-ring-calling-point 0
+  "Internal variable to remember calling position.")
+
+(defun counsel--mark-ring-unwind ()
+  "Return back to calling position of `counsel-mark-ring'."
+  (goto-char counsel--mark-ring-calling-point))
+
+(defun counsel--mark-ring-update-fn ()
+  "Show preview by candidate."
+  (let ((linenum (string-to-number (ivy-state-current ivy-last))))
+    (unless (= linenum 0)
+      (with-ivy-window
+        (forward-line (- linenum (line-number-at-pos)))))))
+
 (defun counsel-mark-ring ()
   "Browse `mark-ring' interactively.
 Obeys `widen-automatically', which see."
   (interactive)
-  (let ((cands
+  (let ((counsel--mark-ring-calling-point (point))
+        (cands
          (save-excursion
            (save-restriction
              ;; Widen, both to save `line-number-at-pos' the trouble
@@ -3579,6 +3594,7 @@ Obeys `widen-automatically', which see."
     (if cands
         (ivy-read "Mark: " cands
                   :require-match t
+                  :update-fn #'counsel--mark-ring-update-fn
                   :action (lambda (cand)
                             (let ((pos (cdr-safe cand)))
                               (when pos
@@ -3588,6 +3604,7 @@ Obeys `widen-automatically', which see."
                                     (error "\
 Position of selected mark outside accessible part of buffer")))
                                 (goto-char pos))))
+                  :unwind #'counsel--mark-ring-unwind
                   :caller 'counsel-mark-ring)
       (message "Mark ring is empty"))))
 



reply via email to

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