Bladeren bron

ob-tangle: Fix `org-babel-detangle'

* lisp/ob-tangle.el (org-babel-tangle-jump-to-org): Preserve position
  in source block only if it doesn't put point outside of the block.

Reported-by: Frederick Giasson <fred@curbside.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-06/msg00008.html>
Nicolas Goaziou 6 jaren geleden
bovenliggende
commit
8b9c1e15df
1 gewijzigde bestanden met toevoegingen van 5 en 3 verwijderingen
  1. 5 3
      lisp/ob-tangle.el

+ 5 - 3
lisp/ob-tangle.el

@@ -581,10 +581,12 @@ which enable the original code blocks to be found."
 		  (t (org-babel-next-src-block (1- n)))))
         (org-babel-goto-named-src-block block-name))
       (goto-char (org-babel-where-is-src-block-head))
-      ;; Preserve location of point within the source code in tangled
-      ;; code file.
       (forward-line 1)
-      (forward-char (- mid body-start))
+      ;; Try to preserve location of point within the source code in
+      ;; tangled code file.
+      (let ((offset (- mid body-start)))
+	(when (> end (+ offset (point)))
+	  (forward-char offset)))
       (setq target-char (point)))
     (org-src-switch-to-buffer target-buffer t)
     (goto-char target-char)