** splitting code blocks
:PROPERTIES:
:DATE: 2010-09-19
:END:
- with indentation
#+begin_src emacs-lisp
(defun org-babel-previous-src-block (&optional arg)
"Jump to the previous source block.
With optional prefix argument ARG, jump backward ARG many source blocks."
(interactive "P")
(condition-case nil
(re-search-backward org-babel-src-block-regexp nil nil (or arg 1))
(error (error "No previous code blocks")))
(goto-char (match-beginning 0)) (org-show-context))
#+end_src
#+begin_src emacs-lisp
(defun org-babel-split-block-maybe (&optional arg)
"Split the current source code block on the cursor."
(interactive "p")
((lambda (info)
(if info
(let ((lang (nth 0 info))
(indent (nth 6 info))
(stars (make-string (org-current-level) ?*)))
(insert (concat (if (looking-at "^") "" "\n")
(make-string indent ? ) "#+end_src\n"
(if arg stars (make-string indent ? )) "\n"
(make-string indent ? ) "#+begin_src " lang
(if (looking-at "[\n\r]") "" "\n "))))
(message "Not in src block.")))
(org-babel-get-src-block-info)))
#+end_src