Links: Improve following links in entry

This commit is contained in:
Carsten Dominik 2009-08-29 20:11:14 +02:00
parent 8a0ae0d3e5
commit 99365e3961
2 changed files with 42 additions and 40 deletions

View File

@ -5585,12 +5585,14 @@ at the text of the entry itself."
(interactive "P")
(let* ((marker (or (get-text-property (point) 'org-hd-marker)
(get-text-property (point) 'org-marker)))
(buffer (and marker (marker-buffer marker)))
(txt (concat (buffer-substring (point-at-bol) (point-at-eol))
"\n"
(and marker
(org-agenda-get-some-entry-text marker 100)))))
(org-offer-links-from-string txt arg buffer)))
(buffer (and marker (marker-buffer marker))))
(unless buffer (error "Don't know where to look for links"))
(with-current-buffer buffer
(save-excursion
(save-restriction
(widen)
(goto-char marker)
(org-offer-links-in-entry arg))))))
(defun org-agenda-copy-local-variable (var)
"Get a variable from a referenced buffer and install it here."

View File

@ -7892,10 +7892,7 @@ application the system uses for this file type."
(concat org-plain-link-re "\\|"
org-bracket-link-regexp "\\|"
org-angle-link-re))))
(org-offer-links-from-string (buffer-substring
(point-at-bol)
(save-excursion
(outline-next-heading) (point)))))
(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))
(org-footnote-action))
@ -8055,44 +8052,47 @@ application the system uses for this file type."
(move-marker org-open-link-marker nil)
(run-hook-with-args 'org-follow-link-hook)))
(defun org-offer-links-from-string (string &optional nth reference-buffer)
"Offer links in STRING and follow the selected link.
If NTH is an integer immediately pick the NTH link found.
REFERENCE-BUFFER is the buffer that should be current when following the
link to retrieve the value of `org-link-abbrev-alist-local', from, which is
needed for the interpretation of abbreviated links."
(defun org-offer-links-in-entry (&optional nth)
"Offer links in the curren entry and follow the selected link.
If there is only one link, follow it immediately as well.
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)
(in-emacs (if (integerp nth) nil nth))
end
links link c)
(with-temp-buffer
(insert string)
(goto-char (point-min))
(while (re-search-forward re nil t)
(save-excursion
(org-back-to-heading t)
(setq end (save-excursion (outline-next-heading) (point)))
(while (re-search-forward re end t)
(push (match-string 0) links))
(setq links (reverse links))
(unless links (error "No links"))
(unless (and (integerp nth) (>= (length links) nth))
(save-excursion
(save-window-excursion
(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)))
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*"))))
(setq nth (- c ?0)))
(setq links (reverse links)))
(cond
((null links) (error "No links"))
((equal (length links) 1)
(setq link (car links)))
((and (integerp nth) (>= (length links) nth))
(setq link (nth (1- nth) links)))
(t ; we have to select a link
(save-excursion
(save-window-excursion
(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)))
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*"))))
(setq nth (- c ?0))
(unless (and (integerp nth) (>= (length links) nth))
(error "Invalid link selection"))
(setq link (nth (1- nth) links)
nth nil))
(org-open-link-from-string link nil reference-buffer)))
(setq link (nth (1- nth) links))))
(org-open-link-from-string link in-emacs (current-buffer))))
;;;; Time estimates