diff options
author | Dan Davison <davison@stats.ox.ac.uk> | 2010-08-17 16:46:51 -0400 |
---|---|---|
committer | Dan Davison <davison@stats.ox.ac.uk> | 2010-08-17 17:46:04 -0400 |
commit | f9cecd192dd231f163b7d99a1cf6f00d2567b09e (patch) | |
tree | 330fd7af707e219af344ecdb36a655ff311e54f7 | |
parent | 441288ee72778931c3e1853b8221f7049289df91 (diff) | |
download | org-mode-f9cecd192dd231f163b7d99a1cf6f00d2567b09e.tar.gz |
Make language major mode commands available at Org code blocks.
* ob.el (org-babel-do-in-edit-buffer): New macro to
evaluate lisp in the language major mode edit buffer.
(org-babel-do-key-sequence-in-edit-buffer): New function to call
an arbitrary key sequence in the language major mode edit
buffer
* org-src.el (org-src-switch-to-buffer): Add new allowed value
'switch-invisibly for `org-src-window-setup'.
* ob-keys.el (org-babel-key-bindings): Bind
`org-babel-do-key-sequence-in-edit-buffer' to x and C-x in
`org-babel-map'
-rw-r--r-- | lisp/ob-keys.el | 4 | ||||
-rw-r--r-- | lisp/ob.el | 22 | ||||
-rw-r--r-- | lisp/org-src.el | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/lisp/ob-keys.el b/lisp/ob-keys.el index d405e02..5ed8967 100644 --- a/lisp/ob-keys.el +++ b/lisp/ob-keys.el @@ -77,7 +77,9 @@ functions which are assigned key bindings, and see ("z" . org-babel-switch-to-session-with-code) ("\C-a" . org-babel-sha1-hash) ("a" . org-babel-sha1-hash) - ("h" . org-babel-describe-bindings)) + ("h" . org-babel-describe-bindings) + ("\C-x" . org-babel-do-key-sequence-in-edit-buffer) + ("x" . org-babel-do-key-sequence-in-edit-buffer)) "Alist of key bindings and interactive Babel functions. This list associates interactive Babel functions with keys. Each element of this list will add an entry to the @@ -482,6 +482,28 @@ of the source block to the kill ring." (org-edit-src-code)) (swap-windows))) +(defmacro org-babel-do-in-edit-buffer (&rest body) + "Evaluate BODY in edit buffer if there is a code block at point. +Return t if a code block was found at point, nil otherwise." + `(let ((org-src-window-setup 'switch-invisibly)) + (when (org-edit-src-code) + ,@body + (org-edit-src-exit) t))) + +(defun org-babel-do-key-sequence-in-edit-buffer (key) + "Read key sequence and execute the command in edit buffer. +Enter a key sequence to be executed in the language major-mode +edit buffer. For example, TAB will alter the contents of the +Org-mode code block according to the effect of TAB in the +language major-mode buffer. For languages that support +interactive sessions, this can be used to send code from the Org +buffer to the session for evaluation using the native major-mode +evaluation mechanisms." + (interactive "kEnter key-sequence to execute in edit buffer: ") + (org-babel-do-in-edit-buffer + (call-interactively + (key-binding (or key (read-key-sequence nil)))))) + (defvar org-bracket-link-regexp) ;;;###autoload (defun org-babel-open-src-block-result (&optional re-run) diff --git a/lisp/org-src.el b/lisp/org-src.el index 039681f..22c9952 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -359,6 +359,8 @@ the edited version. Optional argument CONTEXT is used by (if (eq context 'edit) (delete-other-windows)) (org-switch-to-buffer-other-window buffer) (if (eq context 'exit) (delete-other-windows))) + ('switch-invisibly + (set-buffer buffer)) (t (message "Invalid value %s for org-src-window-setup" (symbol-name org-src-window-setup)) |