Browse Source

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'
Dan Davison 10 years ago
parent
commit
f9cecd192d
3 changed files with 27 additions and 1 deletions
  1. 3 1
      lisp/ob-keys.el
  2. 22 0
      lisp/ob.el
  3. 2 0
      lisp/org-src.el

+ 3 - 1
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

+ 22 - 0
lisp/ob.el

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

+ 2 - 0
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))