Skip to content

Commit

Permalink
counsel.el (counsel-mark-ring): Add highlight by candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
yonta authored and astoff committed Jan 1, 2021
1 parent 9a7f081 commit cd8c83b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -3555,16 +3555,37 @@ This variable has no effect unless

;;* Misc. Emacs
;;** `counsel-mark-ring'
(defface counsel--mark-ring-highlight
'((t (:inherit highlight)))
"Face for current `counsel-mark-ring' line.")

(defvar counsel--mark-ring-overray nil
"Intarnal overray to highlight line by candidate of `counsel-mark-ring'.")

(defun counsel--mark-ring-add-highlight ()
"Add highlight to current line."
(setq counsel--mark-ring-overray
(make-overlay (line-beginning-position) (1+ (line-end-position))))
(with-ivy-window
(overlay-put counsel--mark-ring-overray 'face
'counsel--mark-ring-highlight)))

(defun counsel--mark-ring-delete-highlight ()
"If `counsel-mark-ring' have highlight, delete highlight."
(if counsel--mark-ring-overray (delete-overlay counsel--mark-ring-overray)))

(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))
(goto-char counsel--mark-ring-calling-point)
(counsel--mark-ring-delete-highlight))

(defun counsel--mark-ring-update-fn ()
"Show preview by candidate."
(let ((linenum (string-to-number (ivy-state-current ivy-last))))
(counsel--mark-ring-delete-highlight)
(unless (= linenum 0)
(with-ivy-window
(forward-line (- linenum (line-number-at-pos)))))))
Expand Down

0 comments on commit cd8c83b

Please sign in to comment.