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'.
This commit is contained in:
Bastien Guerry 2013-02-19 10:02:34 +01:00
parent c64c599221
commit efb2ce9c12
1 changed files with 11 additions and 21 deletions

View File

@ -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 nil to indicate that that Org-mode can continue with other options
like exact and fuzzy text search.") like exact and fuzzy text search.")
(defun org-next-link () (defun org-next-link (&optional search-backward)
"Move forward to the next link. "Move forward to the next link.
If the link is in hidden text, expose it." If the link is in hidden text, expose it."
(interactive) (interactive "P")
(when (and org-link-search-failed (eq this-command last-command)) (when (and org-link-search-failed (eq this-command last-command))
(goto-char (point-min)) (goto-char (point-min))
(message "Link search wrapped back to beginning of buffer")) (message "Link search wrapped back to beginning of buffer"))
(setq org-link-search-failed nil) (setq org-link-search-failed nil)
(let* ((pos (point)) (let* ((pos (point))
(ct (org-context)) (ct (org-context))
(a (assoc :link ct))) (a (assoc :link ct))
(if a (goto-char (nth 2 a))) (srch-fun (if search-backward 're-search-backward 're-search-forward)))
(if (re-search-forward org-any-link-re nil t) (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 (progn
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(if (outline-invisible-p) (org-show-context))) (if (outline-invisible-p) (org-show-context)))
(goto-char pos) (goto-char pos)
(setq org-link-search-failed t) (setq org-link-search-failed t)
(error "No further link found")))) (message "No further link found"))))
(defun org-previous-link () (defun org-previous-link ()
"Move backward to the previous link. "Move backward to the previous link.
If the link is in hidden text, expose it." If the link is in hidden text, expose it."
(interactive) (interactive)
(when (and org-link-search-failed (eq this-command last-command)) (funcall 'org-next-link t))
(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"))))
(defun org-translate-link (s) (defun org-translate-link (s)
"Translate a link string if a translation function has been defined." "Translate a link string if a translation function has been defined."