org-babel-demarcate-block now works before first headline

fix suggested by Dan Davison

* lisp/ob.el (org-babel-demarcate-block): better initialization of stars
This commit is contained in:
Eric Schulte 2010-09-21 09:34:50 -06:00
parent 26b9263926
commit 0ec264ddf7
1 changed files with 4 additions and 5 deletions

View File

@ -1138,15 +1138,15 @@ split. When called from outside of a code block a new code block
is created. In both cases if the region is demarcated and if the 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))) (let ((info (org-babel-get-src-block-info))
(stars (concat (make-string (or (org-current-level) 1) ?*) " ")))
(if info (if info
(mapc (mapc
(lambda (place) (lambda (place)
(save-excursion (save-excursion
(goto-char place) (goto-char place)
(let ((lang (nth 0 info)) (let ((lang (nth 0 info))
(indent (make-string (nth 6 info) ? )) (indent (make-string (nth 6 info) ? )))
(stars (concat (make-string (org-current-level) ?*) " ")))
(when (string-match "^[[:space:]]*$" (when (string-match "^[[:space:]]*$"
(buffer-substring (point-at-bol) (buffer-substring (point-at-bol)
(point-at-eol))) (point-at-eol)))
@ -1160,8 +1160,7 @@ region is not active then the point is demarcated."
(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))
(body (delete-and-extract-region (body (delete-and-extract-region
(if (region-active-p) (mark) (point)) (point))) (if (region-active-p) (mark) (point)) (point))))
(stars (concat (make-string (org-current-level) ?*) " ")))
(insert (concat (if (looking-at "^") "" "\n") (insert (concat (if (looking-at "^") "" "\n")
(if arg (concat stars "\n") "") (if arg (concat stars "\n") "")
"#+begin_src " (read-from-minibuffer "Lang: ") "\n" "#+begin_src " (read-from-minibuffer "Lang: ") "\n"