1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-23 07:18:53 +00:00

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
This commit is contained in:
Eric Schulte 2010-09-19 14:47:49 -06:00
parent 5546df7f3b
commit 88b8b83951
3 changed files with 34 additions and 0 deletions

View File

@ -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}

View File

@ -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)

View 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.