Skip to content

Commit

Permalink
Implement highlight a duration when preview line changed (#16)
Browse files Browse the repository at this point in the history
* highlight a duration when preview line changed

* goto-line-preview-hl-duration accept nil

---------

Co-authored-by: LiuYinCarl <bearcarl@qq.com>
  • Loading branch information
LiuYinCarl and LiuYinCarl committed Feb 6, 2024
1 parent cc8d28d commit 5cc4755
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ Or you can bind it globally to replace `goto-line`:
(global-set-key [remap goto-line] 'goto-line-preview)
```

## Change hightlight color or duration

```el
;; Highlight 1.5 seconds when change preview line
(setq goto-line-preview-hl-duration 1.5)
;; Change highlight background color to white
(setq goto-line-preview-hl-color "white")
```

If you want to close highlight, set `goto-line-preview-hl-duration` to 0 or `nil`.

## 🛠️ Contribute

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
Expand Down
21 changes: 20 additions & 1 deletion goto-line-preview.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
:group 'goto-line-preview
:type 'hook)

(defcustom goto-line-preview-hl-duration 1
"Duration of highlight when change preview line."
:group 'goto-line-preview
:type 'integer)

(defcustom goto-line-preview-hl-color "DimGray"
"Background color of highlight when change preview line."
:group 'goto-line-preview
:type 'string)

(defvar goto-line-preview--prev-window nil
"Record down the previous window before we do preivew display.")

Expand All @@ -57,12 +67,21 @@
(defvar goto-line-preview--relative-p nil
"Flag to see if this command relative.")

(defun goto-line-preview--highlight ()
"Keep highlight for a fixed time."
(if goto-line-preview-hl-duration
(let ((overlay (make-overlay (line-beginning-position) (line-end-position))))
(overlay-put overlay 'face `(:background ,goto-line-preview-hl-color))
(sit-for goto-line-preview-hl-duration)
(delete-overlay overlay))))

(defun goto-line-preview--do (line-num)
"Do goto LINE-NUM."
(save-selected-window
(select-window goto-line-preview--prev-window)
(goto-char (point-min))
(forward-line (1- line-num))))
(forward-line (1- line-num))
(goto-line-preview--highlight)))

(defun goto-line-preview--do-preview ()
"Do the goto line preview action."
Expand Down

0 comments on commit 5cc4755

Please sign in to comment.