[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-hydra 93d925d 121/395: counsel.el (counsel-mark--ge
From: |
Basil L. Contovounesios |
Subject: |
[elpa] externals/ivy-hydra 93d925d 121/395: counsel.el (counsel-mark--get-candidates): Extract |
Date: |
Thu, 25 Feb 2021 08:31:45 -0500 (EST) |
branch: externals/ivy-hydra
commit 93d925d0e3c1cf0e357d5bbd773b62f83a79a17a
Author: MoHKale <mohkalsin@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>
counsel.el (counsel-mark--get-candidates): Extract
Re #2247
---
counsel.el | 76 ++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 47 insertions(+), 29 deletions(-)
diff --git a/counsel.el b/counsel.el
index bf17bfa..a7b27c5 100644
--- a/counsel.el
+++ b/counsel.el
@@ -3880,15 +3880,6 @@ This variable has no effect unless
Obeys `widen-automatically', which see."
(interactive)
(let* ((counsel--mark-ring-calling-point (point))
- (width (length (number-to-string (line-number-at-pos (point-max)))))
- (fmt (format "%%%dd %%s" width))
- (make-candidate
- (lambda (mark)
- (goto-char (marker-position mark))
- (let ((linum (line-number-at-pos))
- (line (buffer-substring
- (line-beginning-position) (line-end-position))))
- (propertize (format fmt linum line) 'point (point)))))
(marks (copy-sequence mark-ring))
(marks (delete-dups marks))
(marks
@@ -3896,28 +3887,55 @@ Obeys `widen-automatically', which see."
(if (equal (mark-marker) (make-marker))
marks
(cons (copy-marker (mark-marker)) marks)))
- (cands
- ;; Widen, both to save `line-number-at-pos' the trouble
- ;; and for `buffer-substring' to work.
- (save-excursion
- (save-restriction
- (widen)
- (mapcar make-candidate marks)))))
- (if cands
- (ivy-read "Mark: " cands
- :require-match t
- :action (lambda (cand)
- (let ((pos (get-text-property 0 'point cand)))
- (when pos
- (unless (<= (point-min) pos (point-max))
- (if widen-automatically
- (widen)
- (error "\
-Position of selected mark outside accessible part of buffer")))
- (goto-char pos))))
- :caller 'counsel-mark-ring)
+ (candidates (counsel-mark--get-candidates marks)))
+ (if candidates
+ (counsel-mark--ivy-read candidates 'counsel-mark-ring)
(message "Mark ring is empty"))))
+(defun counsel-mark--get-candidates (marks)
+ "Convert a list of MARKS into mark candidates.
+candidates are simply strings formatted to have the line number of the
+associated mark prepended to them and having an extra text property of
+point to indicarte where the candidate mark is."
+ (when marks
+ (save-excursion
+ (save-restriction
+ ;; Widen, both to save `line-number-at-pos' the trouble
+ ;; and for `buffer-substring' to work.
+ (widen)
+ (let* ((width (length (number-to-string (line-number-at-pos
(point-max)))))
+ (fmt (format "%%%dd %%s" width)))
+ (mapcar (lambda (mark)
+ (goto-char (marker-position mark))
+ (let ((linum (line-number-at-pos))
+ (line (buffer-substring
+ (line-beginning-position)
(line-end-position))))
+ (propertize (format fmt linum line) 'point (point))))
+ marks))))))
+
+(defun counsel-mark--ivy-read (candidates caller)
+ "call `ivy-read' with sane defaults for traversing marks.
+CANDIDATES should be an alist with the `car' of the list being
+the string displayed by ivy and the `cdr' being the point that
+mark should take you to.
+
+NOTE This has been abstracted out into it's own method so it can
+be used by both `counsel-mark-ring' and `counsel-evil-marks'"
+ (ivy-read "Mark: " candidates
+ :require-match t
+ :update-fn #'counsel--mark-ring-update-fn
+ :action (lambda (cand)
+ (let ((pos (get-text-property 0 'point cand)))
+ (when pos
+ (unless (<= (point-min) pos (point-max))
+ (if widen-automatically
+ (widen)
+ (error "\
+Position of selected mark outside accessible part of buffer")))
+ (goto-char pos))))
+ :unwind #'counsel--mark-ring-unwind
+ :caller caller))
+
(ivy-configure 'counsel-mark-ring
:update-fn #'counsel--mark-ring-update-fn
:unwind-fn #'counsel--mark-ring-unwind
- [elpa] externals/ivy-hydra d837871 030/395: ivy.el (ivy-thing-at-point): Don't hang when pinging machine, (continued)
- [elpa] externals/ivy-hydra d837871 030/395: ivy.el (ivy-thing-at-point): Don't hang when pinging machine, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra aef2538 040/395: ivy-test.el (ivy--split): Add test, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra b603d89 045/395: counsel.el: Fix typos, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra e32f14d 067/395: targets/plain.el (ivy-use-virtual-buffers): Enable, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 529cc08 071/395: ivy-test.el (ivy-swiper-wgrep): Disable on 24.5, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1b3d0a3 072/395: ivy.el (ivy--split): Fix for "\\" input, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra e2f1fe1 068/395: swiper.el (swiper--query-replace-updatefn): Fix bug, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 4fbd5a9 081/395: ivy-test.el (ivy-completing-read): Add test, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 83f04c0 092/395: counsel.el (counsel-flycheck): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 99c02cc 109/395: ivy.el (ivy-partial): Fix ivy-regex mistaken for ivy-text, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 93d925d 121/395: counsel.el (counsel-mark--get-candidates): Extract,
Basil L. Contovounesios <=
- [elpa] externals/ivy-hydra 3119994 144/395: ivy.el (ivy--tramp-prefix-p): Fix regression, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 82331ed 147/395: Revert "Don't hardcode C-s and C-r", Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 8386220 173/395: swiper.el (swiper-isearch): Save mark, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra c84bc31 164/395: ivy.el (ivy--magic-file-slash): Use "///" instead of "//" on Windows, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 7c0f16d 155/395: swiper.el (swiper--re-builder): Genaralize search-default-mode, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 40a7731 199/395: ivy.el (ivy-switch-buffer-transformer): Change how remote dirs are displayed, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 5f430f4 198/395: ivy.el (ivy-switch-buffer-transformer): Fix for virtual buffers, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 9e0803c 226/395: ivy.el (ivy--remote-name): Extract and use the file name, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 7ed3d85 223/395: Move recent varalias before its referent, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 136ae0e 194/395: Add command for play/pause current song, Basil L. Contovounesios, 2021/02/25