summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLe Wang <le.wang@agworld.com.au>2012-11-18 05:39:51 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-11-30 13:11:27 (GMT)
commit206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05 (patch)
tree0682b1388edbe35e3ccb68246407500a51da0f24
parent8783b893119354aaf76cf5861942d3cbffef323d (diff)
downloadorg-mode-206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05.zip
org-mode-206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05.tar.gz
org-src: Fix org-edit-src-code for empty blocks and block with just an empty line
* lisp/org-src.el (org-edit-src-code): Use marker with insertion type t to track end and remove hack requiring delete from beg to (1- end).
-rw-r--r--lisp/org-src.el20
1 files changed, 15 insertions, 5 deletions
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 75db1d7..97ee8c5 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -215,11 +215,22 @@ buffer."
(setq org-edit-src-saved-temp-window-config (current-window-configuration)))
(let* ((mark (and (org-region-active-p) (mark)))
(case-fold-search t)
- (info (org-edit-src-find-region-and-lang))
+ (info
+ ;; If the src region consists in no lines, we insert a blank
+ ;; line.
+ (let* ((temp (org-edit-src-find-region-and-lang))
+ (beg (nth 0 temp))
+ (end (nth 1 temp)))
+ (if (>= end beg) temp
+ (goto-char beg)
+ (insert "\n")
+ (org-edit-src-find-region-and-lang))))
(full-info (org-babel-get-src-block-info 'light))
(org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
(beg (make-marker))
- (end (make-marker))
+ ;; Move marker with inserted text for case when src block is
+ ;; just one empty line, i.e. beg == end.
+ (end (copy-marker nil t))
(allow-write-back-p (null code))
block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
begline markline markcol line col transmitted-variables)
@@ -689,10 +700,9 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
(kill-buffer buffer))
(goto-char beg)
(when allow-write-back-p
- (delete-region beg (max beg (1- end)))
+ (delete-region beg (max beg end))
(unless (string-match "\\`[ \t]*\\'" code)
- (insert code)
- (delete-char 1))
+ (insert code))
(goto-char beg)
(if single (just-one-space)))
(if (memq t (mapcar (lambda (overlay)