summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-02-01 15:51:28 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-02-01 15:51:28 +0100
commite490d2766f77c79075998e97626a3eec31560909 (patch)
tree79e5ee8a5023069f7862ab5047d1acdece18f613
parent75ece165078fbe1432de07c0c3dc3c92679f41d1 (diff)
parentb4cc12fc32a7713d97d9641777fb9c3983aac03a (diff)
downloadorg-mode-e490d2766f77c79075998e97626a3eec31560909.tar.gz
Merge branch 'maint'
-rw-r--r--lisp/ob-core.el19
1 files changed, 15 insertions, 4 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 15f999b..cf18399 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -980,13 +980,24 @@ with a prefix argument then this is passed on to
(defmacro org-babel-do-in-edit-buffer (&rest body)
"Evaluate BODY in edit buffer if there is a code block at point.
Return t if a code block was found at point, nil otherwise."
- `(let ((org-src-window-setup 'switch-invisibly))
- (when (and (org-babel-where-is-src-block-head)
+ (declare (debug (body)))
+ `(let* ((element (org-element-at-point))
+ ;; This function is not supposed to move point. However,
+ ;; `org-edit-src-code' always moves point back into the
+ ;; source block. It is problematic if the point was before
+ ;; the code, e.g., on block's opening line. In this case,
+ ;; we want to restore this location after executing BODY.
+ (outside-position
+ (and (<= (line-beginning-position)
+ (org-element-property :post-affiliated element))
+ (point-marker)))
+ (org-src-window-setup 'switch-invisibly))
+ (when (and (org-babel-where-is-src-block-head element)
(org-edit-src-code))
(unwind-protect (progn ,@body)
- (org-edit-src-exit))
+ (org-edit-src-exit)
+ (when outside-position (goto-char outside-position)))
t)))
-(def-edebug-spec org-babel-do-in-edit-buffer (body))
(defun org-babel-do-key-sequence-in-edit-buffer (key)
"Read key sequence and execute the command in edit buffer.