diff options
author | Eric Schulte <schulte.eric@gmail.com> | 2010-09-19 14:47:49 -0600 |
---|---|---|
committer | Eric Schulte <schulte.eric@gmail.com> | 2010-09-20 08:27:20 -0600 |
commit | 88b8b839511ebec20388108c98853588addb6fa7 (patch) | |
tree | b0be55e586e745851fd0c64ecb4d8e0321fd444a | |
parent | 5546df7f3b7e73d4d530ce0719751bd0182c1154 (diff) | |
download | org-mode-88b8b839511ebec20388108c98853588addb6fa7.tar.gz |
interactive demarcation of code blocks
Thanks to Richard Riley for the initial idea and implementation
* lisp/ob.el (org-babel-demarcate-block): interactive demarcation of
code blocks
* lisp/ob-keys.el (org-babel-key-bindings): key bindings for block
demarcation
* doc/orgcard.tex: documentation in the ref card
-rw-r--r-- | doc/orgcard.tex | 1 | ||||
-rw-r--r-- | lisp/ob-keys.el | 2 | ||||
-rw-r--r-- | lisp/ob.el | 31 |
3 files changed, 34 insertions, 0 deletions
diff --git a/doc/orgcard.tex b/doc/orgcard.tex index 2430c33..8a49976 100644 --- a/doc/orgcard.tex +++ b/doc/orgcard.tex @@ -483,6 +483,7 @@ formula, \kbd{:=} a field formula. \key{go to the head of the current code block}{C-c C-v u} \key{go to the next code block}{C-c C-v n} \key{go to the previous code block}{C-c C-v p} +\key{demarcate a code block}{C-c C-v d} \key{execute the next key sequence in the code edit buffer}{C-c C-v x} \key{execute all code blocks in current buffer}{C-c C-v b} \key{execute all code blocks in current subtree}{C-c C-v s} diff --git a/lisp/ob-keys.el b/lisp/ob-keys.el index ff730c6..c27d7fd 100644 --- a/lisp/ob-keys.el +++ b/lisp/ob-keys.el @@ -67,6 +67,8 @@ functions which are assigned key bindings, and see ("b" . org-babel-execute-buffer) ("\C-s" . org-babel-execute-subtree) ("s" . org-babel-execute-subtree) + ("\C-d" . org-babel-demarcate-block) + ("d" . org-babel-demarcate-block) ("\C-t" . org-babel-tangle) ("t" . org-babel-tangle) ("\C-f" . org-babel-tangle-file) @@ -1129,6 +1129,37 @@ With optional prefix argument ARG, jump backward ARG many source blocks." (error (error "No previous code blocks"))) (goto-char (match-beginning 0)) (org-show-context)) +;;;###autoload +(defun org-babel-demarcate-block (&optional arg) + "Wrap or split the code in the region or on the point. +When called from inside of a code block the current block is +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 +region is not active then the point is demarcated." + (interactive "P") + (let ((info (org-babel-get-src-block-info))) + (if info + (mapc + (lambda (place) + (save-excursion + (goto-char place) + (let ((lang (nth 0 info)) + (indent (make-string (nth 6 info) ? )) + (stars (concat (make-string (org-current-level) ?*) " "))) + (insert (concat (if (looking-at "^") "" "\n") + indent "#+end_src\n" + (if arg stars indent) "\n" + indent "#+begin_src " lang + (if (looking-at "[\n\r]") "" "\n"))) + (when arg (previous-line) (move-end-of-line 1))))) + (sort (if (region-active-p) (list (mark) (point)) (list (point))) #'>)) + (insert (concat (if (looking-at "^") "" "\n") + (if arg (concat stars "\n") "") + "#+begin_src " (read-from-minibuffer "Lang: ") "\n" + (delete-and-extract-region (or (mark) (point)) (point)) + "\n#+end_src")) + (previous-line) (move-end-of-line 1)))) + (defvar org-babel-lob-one-liner-regexp) (defun org-babel-where-is-src-block-result (&optional insert info hash indent) "Find where the current source block results begin. |