Skip to content

Commit

Permalink
ivy.el (ivy-pulse-delay): Convert to defcustom
Browse files Browse the repository at this point in the history
  • Loading branch information
abo-abo committed Dec 18, 2018
1 parent 8222b2b commit cccc912
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -3972,28 +3972,32 @@ characters (previous if ARG is negative)."
(defvar ivy--pulse-timer nil
"Timer used to dispose of `ivy--pulse-overlay'.")

(defvar ivy-pulse-delay 0.5
"Number of seconds to display `ivy-yanked-word' highlight.")
(defcustom ivy-pulse-delay 0.5
"Number of seconds to display `ivy-yanked-word' highlight."
:type '(choice
(float :tag "Delay in seconds")
(const :tag "Disable" nil)))

(defun ivy--pulse-region (start end)
"Temporarily highlight text between START and END.
The \"pulse\" duration is determined by `ivy-pulse-delay'."
(if ivy--pulse-overlay
(let ((ostart (overlay-start ivy--pulse-overlay))
(oend (overlay-end ivy--pulse-overlay)))
;; Extend the existing overlay's region to include START..END,
;; but only if the two regions are contiguous.
(cond ((and (= start ostart) (<= end start))
(setq start oend))
((and (= start oend) (<= start end))
(setq start ostart)))
(move-overlay ivy--pulse-overlay start end))
(setq ivy--pulse-overlay (make-overlay start end))
(overlay-put ivy--pulse-overlay 'face 'ivy-yanked-word))
(when ivy--pulse-timer
(cancel-timer ivy--pulse-timer))
(setq ivy--pulse-timer
(run-at-time ivy-pulse-delay nil #'ivy--pulse-cleanup)))
(when ivy-pulse-delay
(if ivy--pulse-overlay
(let ((ostart (overlay-start ivy--pulse-overlay))
(oend (overlay-end ivy--pulse-overlay)))
;; Extend the existing overlay's region to include START..END,
;; but only if the two regions are contiguous.
(cond ((and (= start ostart) (<= end start))
(setq start oend))
((and (= start oend) (<= start end))
(setq start ostart)))
(move-overlay ivy--pulse-overlay start end))
(setq ivy--pulse-overlay (make-overlay start end))
(overlay-put ivy--pulse-overlay 'face 'ivy-yanked-word))
(when ivy--pulse-timer
(cancel-timer ivy--pulse-timer))
(setq ivy--pulse-timer
(run-at-time ivy-pulse-delay nil #'ivy--pulse-cleanup))))

(defun ivy--pulse-cleanup ()
"Cancel `ivy--pulse-timer' and delete `ivy--pulse-overlay'."
Expand Down

0 comments on commit cccc912

Please sign in to comment.