From efb2ce9c12feee122e61e153e65503a43b5138bf Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Tue, 19 Feb 2013 10:02:34 +0100 Subject: [PATCH] org.el: Fix `org-next-link' and use it for `org-previous-link' * org.el (org-next-link): New parameter `search-backward'. Fix bug when at a link with no 'org-link face, e.g., in a DONE headline. Throw a message instead of an error. (org-previous-link): Use `org-next-link'. --- lisp/org.el | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 5569c7e16..c80a16927 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9870,45 +9870,35 @@ If it decides that it is not responsible for this link, it must return nil to indicate that that Org-mode can continue with other options like exact and fuzzy text search.") -(defun org-next-link () +(defun org-next-link (&optional search-backward) "Move forward to the next link. If the link is in hidden text, expose it." - (interactive) + (interactive "P") (when (and org-link-search-failed (eq this-command last-command)) (goto-char (point-min)) (message "Link search wrapped back to beginning of buffer")) (setq org-link-search-failed nil) (let* ((pos (point)) (ct (org-context)) - (a (assoc :link ct))) - (if a (goto-char (nth 2 a))) - (if (re-search-forward org-any-link-re nil t) + (a (assoc :link ct)) + (srch-fun (if search-backward 're-search-backward 're-search-forward))) + (cond (a (goto-char (nth (if search-backward 1 2) a))) + ((looking-at org-any-link-re) + ;; Don't stay stuck at link without an org-link face + (forward-char (if search-backward -1 1)))) + (if (funcall srch-fun org-any-link-re nil t) (progn (goto-char (match-beginning 0)) (if (outline-invisible-p) (org-show-context))) (goto-char pos) (setq org-link-search-failed t) - (error "No further link found")))) + (message "No further link found")))) (defun org-previous-link () "Move backward to the previous link. If the link is in hidden text, expose it." (interactive) - (when (and org-link-search-failed (eq this-command last-command)) - (goto-char (point-max)) - (message "Link search wrapped back to end of buffer")) - (setq org-link-search-failed nil) - (let* ((pos (point)) - (ct (org-context)) - (a (assoc :link ct))) - (if a (goto-char (nth 1 a))) - (if (re-search-backward org-any-link-re nil t) - (progn - (goto-char (match-beginning 0)) - (if (outline-invisible-p) (org-show-context))) - (goto-char pos) - (setq org-link-search-failed t) - (error "No further link found")))) + (funcall 'org-next-link t)) (defun org-translate-link (s) "Translate a link string if a translation function has been defined."