Skip to content

Commit

Permalink
On goto, show marks with delay in *evil-marks* buffer
Browse files Browse the repository at this point in the history
This commit adds functionality to the previous commit (i.e.
mark-goto-buffer-not-line), and shows marks in the *evil-marks* window after a
delay (similiar to which-key). It is especially handy to remind of which mark is
associated with which buffer.
  • Loading branch information
dalanicolai committed Feb 1, 2021
1 parent e50c095 commit 916532a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
52 changes: 52 additions & 0 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,58 @@ Columns are counted from zero."
is-global)
(evil-first-non-blank))))

(evil-define-command evil--goto-mark-list (marks &optional line-or-buffer)
(evil-show-marks marks)
(let* ((char (read-char))
(is-global (string= "Lu"
(get-char-code-property char 'general-category)))
(key (char-to-string char))
(entry (tabulated-list-get-entry)))
(while (and
entry
(not (string= (aref entry 0) key)))
(next-line)
(setq entry (tabulated-list-get-entry)))
(cond ((eobp) (message "Marker '%s' is not set in this buffer" key)
(evil-list-view-quit))
(t (evil-list-view-quit)
(switch-to-buffer (car (elt entry 3)))
(evil-goto-mark (string-to-char (elt entry 0)))
(when line-or-buffer
(unless (and evil-mark-goto-buffer-not-line
is-global)
(evil-first-non-blank)))))))

(evil-define-command evil-goto-mark-list (marks &optional line-or-buffer)
(interactive "<a>")
(with-timeout (0.6
(evil--goto-mark-list marks line-or-buffer))
(let* ((char (read-char))
(is-global (string= "Lu"
(get-char-code-property char 'general-category))))
(evil-goto-mark char)
(when line-or-buffer
(unless (and evil-mark-goto-buffer-not-line
is-global)
(evil-first-non-blank))))))

(evil-define-command evil-goto-mark-line-list (marks)
(interactive "<a>")
(evil-goto-mark-list marks t))

(defun evil-goto-mark-set ()
(if evil-mark-goto-buffer-not-line
'evil-goto-mark-list
'evil-goto-mark))

(defun evil-goto-mark-line-set ()
(if evil-mark-goto-buffer-not-line
'evil-goto-mark-line-list
'evil-goto-mark-line))

(setq evil-goto-mark-auto (evil-goto-mark-set))
(setq evil-goto-mark-line-auto (evil-goto-mark-line-set))

(evil-define-motion evil-jump-backward (count)
"Go to older position in jump list.
To go the other way, press \
Expand Down
4 changes: 2 additions & 2 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@
(define-key evil-motion-state-map "g#" 'evil-search-unbounded-word-backward)
(define-key evil-motion-state-map "$" 'evil-end-of-line)
(define-key evil-motion-state-map "%" 'evil-jump-item)
(define-key evil-motion-state-map "`" 'evil-goto-mark)
(define-key evil-motion-state-map "'" 'evil-goto-mark-line)
(define-key evil-motion-state-map "`" evil-goto-mark-auto)
(define-key evil-motion-state-map "'" evil-goto-mark-line-auto)
(define-key evil-motion-state-map "(" 'evil-backward-sentence-begin)
(define-key evil-motion-state-map ")" 'evil-forward-sentence-begin)
(define-key evil-motion-state-map "]]" 'evil-forward-section-begin)
Expand Down

0 comments on commit 916532a

Please # to comment.