better code block demarcation

* lisp/ob.el (org-babel-demarcate-block): Copy headers and indent to
  column of point when a block is split.
This commit is contained in:
Eric Schulte 2011-09-04 17:06:07 -06:00
parent 0b6de9a026
commit 0d580520cc
1 changed files with 12 additions and 5 deletions

View File

@ -1334,6 +1334,8 @@ is created. In both cases if the region is demarcated and if the
region is not active then the point is demarcated." region is not active then the point is demarcated."
(interactive "P") (interactive "P")
(let ((info (org-babel-get-src-block-info 'light)) (let ((info (org-babel-get-src-block-info 'light))
(headers (progn (org-babel-where-is-src-block-head)
(match-string 4)))
(stars (concat (make-string (or (org-current-level) 1) ?*) " "))) (stars (concat (make-string (or (org-current-level) 1) ?*) " ")))
(if info (if info
(mapc (mapc
@ -1346,11 +1348,16 @@ region is not active then the point is demarcated."
(buffer-substring (point-at-bol) (buffer-substring (point-at-bol)
(point-at-eol))) (point-at-eol)))
(delete-region (point-at-bol) (point-at-eol))) (delete-region (point-at-bol) (point-at-eol)))
(insert (concat (if (looking-at "^") "" "\n") (insert (concat
indent "#+end_src\n" (if (looking-at "^") "" "\n")
(if arg stars indent) "\n" indent "#+end_src\n"
indent "#+begin_src " lang (if arg stars indent) "\n"
(if (looking-at "[\n\r]") "" "\n"))))) indent "#+begin_src " lang
(if (> (length headers) 1)
(concat " " headers) headers)
(if (looking-at "[\n\r]")
""
(concat "\n" (make-string (current-column) ? )))))))
(move-end-of-line 2)) (move-end-of-line 2))
(sort (if (region-active-p) (list (mark) (point)) (list (point))) #'>)) (sort (if (region-active-p) (list (mark) (point)) (list (point))) #'>))
(let ((start (point)) (let ((start (point))