summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-11-04 15:26:04 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-11-04 15:26:04 +0100
commit44d5286dbfa8fc87dd958c9f46ab5ffaa87f4588 (patch)
tree213fe1a12d4440c1b7a3ce5eb19793303272c07d
parent91153ff14f495b53639cdcaf23489facb8027247 (diff)
downloadorg-mode-44d5286dbfa8fc87dd958c9f46ab5ffaa87f4588.tar.gz
Fix storing links in non-source edit buffers
* lisp/org-src.el (org-src--source-buffer): Rename to `org-src-source-buffer'. (org-src-source-type): New function. (org-edit-src-save): Apply renaming. * lisp/org.el (org-store-link): When in an edit buffer not editing a source block, there is no point in inserting a coderef.
-rw-r--r--lisp/org-src.el21
-rw-r--r--lisp/org.el12
2 files changed, 24 insertions, 9 deletions
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 9c462b7..4cdfad2 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -300,12 +300,6 @@ Return nil if there is no such buffer."
(eq (marker-buffer end) (marker-buffer org-src--end-marker))
(throw 'exit b))))))
-(defun org-src--source-buffer ()
- "Return source buffer edited by current buffer."
- (unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
- (or (marker-buffer org-src--beg-marker)
- (error "No source buffer available for current editing session")))
-
(defun org-src--get-lang-mode (lang)
"Return major mode that should be used for LANG.
LANG is a string, and the returned major mode is a symbol."
@@ -774,6 +768,19 @@ If BUFFER is non-nil, test it instead."
(local-variable-p 'org-src--beg-marker buffer)
(local-variable-p 'org-src--end-marker buffer))))
+(defun org-src-source-buffer ()
+ "Return source buffer edited in current buffer.
+Raise an error when current buffer is not a source editing buffer."
+ (unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
+ (or (marker-buffer org-src--beg-marker)
+ (error "No source buffer available for current editing session")))
+
+(defun org-src-source-type ()
+ "Return type of element edited in current buffer.
+Raise an error when current buffer is not a source editing buffer."
+ (unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
+ org-src--source-type)
+
(defun org-src-switch-to-buffer (buffer context)
(pcase org-src-window-setup
(`current-window (pop-to-buffer-same-window buffer))
@@ -1103,7 +1110,7 @@ Throw an error if there is no such buffer."
(beg org-src--beg-marker)
(end org-src--end-marker)
(overlay org-src--overlay))
- (with-current-buffer (org-src--source-buffer)
+ (with-current-buffer (org-src-source-buffer)
(undo-boundary)
(goto-char beg)
;; Temporarily disable read-only features of OVERLAY in order to
diff --git a/lisp/org.el b/lisp/org.el
index 17aeafb..9d6820c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9246,7 +9246,13 @@ non-nil."
((org-src-edit-buffer-p)
(let ((coderef-format (org-src-coderef-format)))
(cond
- ;; A code reference exists. Use it.
+ ;; Code references do not exist in this type of buffer.
+ ;; Pretend we're linking from the source buffer directly.
+ ((not (memq (org-src-source-type) '(example-block src-block)))
+ (with-current-buffer (org-src-source-buffer)
+ (org-store-link arg interactive?))
+ (setq link nil))
+ ;; A code reference exists. Use it.
((save-excursion
(beginning-of-line)
(re-search-forward (org-src-coderef-regexp coderef-format)
@@ -9259,12 +9265,14 @@ non-nil."
(end-of-line)
(let* ((label (read-string "Code line label: "))
(reference (format coderef-format label))
- (gc (- 79 (length link))))
+ (gc (- 79 (length reference))))
(if (< (current-column) gc)
(org-move-to-column gc t)
(insert " "))
(insert reference)
(setq link (format "(%s)" label))))
+ ;; No code reference, and non-interactive call. Don't know
+ ;; what to do. Give up.
(t (setq link nil)))))
;; We are in the agenda, link to referenced location