diff --git a/lisp/ob-keys.el b/lisp/ob-keys.el index e9ba3d9..f953110 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) ("\C-a" . org-babel-sha1-hash) ("a" . org-babel-sha1-hash) - ("h" . org-babel-describe-bindings)) + ("h" . org-babel-describe-bindings) + ("\C-x" . org-src-do-key-sequence-in-edit-buffer) + ("x" . org-src-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 diff --git a/lisp/org-src.el b/lisp/org-src.el index baa2b11..c9e6f73 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -321,6 +321,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)) @@ -435,6 +437,31 @@ the fragment in the Org-mode buffer." (message "%s" msg) t))) +(defmacro org-src-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-src-do-key-sequence-in-edit-buffer (&optional key) + "Read key sequence and execute the command in edit buffer." + (interactive) + (org-src-do-in-edit-buffer + (call-interactively + (key-binding (or key (read-key-sequence nil)))))) + +(defvar org-src-indent-natively nil + "If non-nil, TAB in a code block indents the code as if it were +called in the edit buffer.") + +(defun org-src-tab-command () + "Do what TAB does in the edit buffer for code block at point." + (and org-src-indent-natively + (org-src-do-key-sequence-in-edit-buffer (kbd "TAB")))) + +(add-hook 'org-tab-first-hook 'org-src-tab-command) (defun org-edit-src-find-region-and-lang () "Find the region and language for a local edit. Return a list with beginning and end of the region, a string representing