Fix storing link in edit buffer

* lisp/org.el (org-store-link): When creating a link from an edit
  buffer, re-use label on current line, if any.  Give up if call is
  non-interactive, as it would otherwise ask for user's input.

Reported-by: Samuel Wales <samologist@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/97902>
This commit is contained in:
Nicolas Goaziou 2015-05-31 01:54:49 +02:00
parent f6c75f2e41
commit 9e1591cbd0
1 changed files with 25 additions and 18 deletions

View File

@ -9735,25 +9735,32 @@ active region."
desc (or (plist-get org-store-link-plist desc (or (plist-get org-store-link-plist
:description) link)))) :description) link))))
;; Store a link from a source code buffer ;; Store a link from a source code buffer.
((org-src-edit-buffer-p) ((org-src-edit-buffer-p)
(let (label gc) (cond
((save-excursion
(beginning-of-line)
(looking-at (concat (format org-coderef-label-format "\\(.*?\\)")
"[ \t]*$")))
(setq link (format "(%s)" (org-match-string-no-properties 1))))
((org-called-interactively-p 'any)
(let (label)
(while (or (not label) (while (or (not label)
(save-excursion (org-with-wide-buffer
(save-restriction
(widen)
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward (re-search-forward
(regexp-quote (format org-coderef-label-format label)) (regexp-quote (format org-coderef-label-format label))
nil t)))) nil t)))
(when label (message "Label exists already") (sit-for 2)) (when label (message "Label exists already") (sit-for 2))
(setq label (read-string "Code line label: " label))) (setq label (read-string "Code line label: " label)))
(end-of-line 1) (end-of-line)
(setq link (format org-coderef-label-format label)) (setq link (format org-coderef-label-format label))
(setq gc (- 79 (length link))) (let ((gc (- 79 (length link))))
(if (< (current-column) gc) (org-move-to-column gc t) (insert " ")) (if (< (current-column) gc) (org-move-to-column gc t)
(insert " ")))
(insert link) (insert link)
(setq link (concat "(" label ")") desc nil))) (setq link (concat "(" label ")") desc nil)))
(t (setq link nil))))
;; We are in the agenda, link to referenced location ;; We are in the agenda, link to referenced location
((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name)) ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))