From 916532a354254a78b3980ab20161470fe8ad101a Mon Sep 17 00:00:00 2001 From: Daniel Nicolai Date: Mon, 1 Feb 2021 10:30:42 +0100 Subject: [PATCH] On goto, show marks with delay in *evil-marks* buffer 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. --- evil-commands.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ evil-maps.el | 4 ++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 7678fdbb9..719662a09 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -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 "") + (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 "") + (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 \ diff --git a/evil-maps.el b/evil-maps.el index 91ed47eb5..8b71533ef 100644 --- a/evil-maps.el +++ b/evil-maps.el @@ -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)