org-edit-src-code doesn't seem to be unescaping correctly.  For
example, calling org-edit-src-code on

#+begin_src org
  ,* h
#+end_src

puts ",* h", not "* h", in the source buffer.  When exiting, ",*" is
escaped again, resulting in

#+begin_src org
  ,,* h
#+end_src

The attached patch moves the unescaping call from org-edit-src-code to
org-src--edit-element so that the source string is unescaped
regardless of whether it was passed as an argument or extracted
directly from the buffer.

>From a78db0610f769517a146b0a9fc58f81d0381d511 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <k...@kyleam.com>
Date: Thu, 21 May 2015 23:18:37 -0400
Subject: [PATCH] org-src.el: Unescape source block on edit

* lisp/org-src.el (org-src--edit-element): Unescape code string.
  (org-edit-src-code): Let org-src--edit-element handle unescaping of
  code string.
---
 lisp/org-src.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index d82068d..8fcb7aa 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -380,7 +380,8 @@ (defun org-src--edit-element
 	 (beg (copy-marker (car area)))
 	 (end (copy-marker (cdr area) t))
 	 (old-edit-buffer (org-src--edit-buffer beg end))
-	 (contents (or contents (buffer-substring-no-properties beg end))))
+	 (contents (org-unescape-code-in-string
+		    (or contents (buffer-substring-no-properties beg end)))))
     (if (and old-edit-buffer
 	     (or (not org-src-ask-before-returning-to-edit-buffer)
 		 (y-or-n-p "Return to existing edit buffer ([n] will revert changes)? ")))
@@ -833,7 +834,7 @@ (defun org-edit-src-code (&optional code edit-buffer-name)
 		      (unless (looking-at "[ \t]*$") (insert ind))
 		      (forward-line)))))
 	      (org-escape-code-in-region (point-min) (point-max))))
-       (and code (org-unescape-code-in-string code)))
+       code)
       ;; Finalize buffer.
       (org-set-local 'org-coderef-label-format
 		     (or (org-element-property :label-fmt element)
-- 
2.4.1

--
Kyle

Reply via email to