From 522ef218db9d10eb8326c04e49dc691c7b34d180 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Mon, 31 Aug 2009 09:09:04 +0200 Subject: [PATCH] Links: Improve offering entry links when there are many an duplicate ones --- lisp/ChangeLog | 3 +++ lisp/org.el | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 321a56798..40d321938 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2009-08-31 Carsten Dominik + * org.el (org-offer-links-in-entry): Improve working with many and + duplicate links. + * org-agenda.el (org-agenda-show-1): Make more consistent with normal cycling. (org-agenda-cycle-show): Make more consistent with normal cycling. diff --git a/lisp/org.el b/lisp/org.el index c50281e70..f88645253 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7891,7 +7891,8 @@ application the system uses for this file type." (not (org-in-regexp (concat org-plain-link-re "\\|" org-bracket-link-regexp "\\|" - org-angle-link-re)))) + org-angle-link-re "\\|" + "[ \t]:[^ \t\n]+:[ \t]*$")))) (org-offer-links-in-entry in-emacs)) ((org-at-timestamp-p t) (org-follow-timestamp-link)) ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p)) @@ -8059,7 +8060,7 @@ If NTH is an integer immediately pick the NTH link found." (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|" "\\(" org-angle-link-re "\\)\\|" "\\(" org-plain-link-re "\\)")) - (cnt 0) + (cnt ?0) (in-emacs (if (integerp nth) nil nth)) end links link c) @@ -8068,7 +8069,7 @@ If NTH is an integer immediately pick the NTH link found." (setq end (save-excursion (outline-next-heading) (point))) (while (re-search-forward re end t) (push (match-string 0) links)) - (setq links (reverse links))) + (setq links (org-uniquify (reverse links)))) (cond ((null links) (error "No links")) @@ -8082,12 +8083,21 @@ If NTH is an integer immediately pick the NTH link found." (delete-other-windows) (with-output-to-temp-buffer "*Select Link*" (princ "Select link\n\n") - (mapc (lambda (l) (princ (format "[%d] %s\n" (incf cnt) l))) + (mapc (lambda (l) + (if (not (string-match org-bracket-link-regexp l)) + (princ (format "[%c] %s\n" (incf cnt) + (org-remove-angle-brackets l))) + (if (match-end 3) + (princ (format "[%c] %s (%s)\n" (incf cnt) + (match-string 3 l) (match-string 1 l))) + (princ (format "[%c] %s\n" (incf cnt) + (match-string 1 l)))))) links)) (org-fit-window-to-buffer (get-buffer-window "*Select Link*")) (message "Select link to open:") (setq c (read-char-exclusive)) (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*")))) + (when (equal c ?q) (error "Abort")) (setq nth (- c ?0)) (unless (and (integerp nth) (>= (length links) nth)) (error "Invalid link selection"))