branch: master commit bcc0cb0891875ef12d997c3d90c3fd9c155fc8c5 Author: Adam Porter <a...@alphapapa.net> Commit: Oleh Krehel <ohwoeo...@gmail.com>
avy.el (avy-org-refile-as-child): Don't refile when avy aborted And ensure refiled heading is visible by calling org-reveal in the after-refile hook. When the avy session is aborted with C-g, avy--generic-jump returns t. Now we detect that and do not attempt to refile. Fixes #258 --- avy.el | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/avy.el b/avy.el index 569b604..4b92b87 100644 --- a/avy.el +++ b/avy.el @@ -2014,17 +2014,23 @@ The window scope is determined by `avy-all-windows' (ARG negates it)." "Refile current heading as first child of heading selected with `avy.'" ;; Inspired by `org-teleport': http://kitchingroup.cheme.cmu.edu/blog/2016/03/18/Org-teleport-headlines/ (interactive) - (let ((rfloc (save-excursion - (let* ((org-reverse-note-order t) - (pos (avy-with avy-goto-line - (avy--generic-jump (rx bol (1+ "*") (1+ space)) - nil avy-style) - (point))) - (filename (buffer-file-name (or (buffer-base-buffer (current-buffer)) - (current-buffer))))) - (list nil filename nil pos))))) - ;; org-refile must be called outside of the excursion - (org-refile nil nil rfloc))) + (let* ((org-reverse-note-order t) + (marker (save-excursion + (avy-with avy-goto-line + (unless (eq 't (avy--generic-jump (rx bol (1+ "*") (1+ space)) + nil avy-style)) + ;; `avy--generic-jump' returns t when aborted with C-g. + (point-marker))))) + (filename (buffer-file-name (or (buffer-base-buffer (marker-buffer marker)) + (marker-buffer marker)))) + (rfloc (list nil filename nil marker)) + ;; Ensure the refiled heading is visible. + (org-after-refile-insert-hook (if (member 'org-reveal org-after-refile-insert-hook) + org-after-refile-insert-hook + (cons #'org-reveal org-after-refile-insert-hook)))) + (when marker + ;; Only attempt refile if avy session was not aborted. + (org-refile nil nil rfloc)))) (defun avy-org-goto-heading-timer (&optional arg) "Read one or many characters and jump to matching Org headings.