Carsten Dominik writes: > On Aug 15, 2010, at 8:43 AM, Dan Davison wrote: > >> With this patch TAB in a code block aligns the code according to the >> major mode. The macro could be used to do the same thing for other >> commands (i.e. allow other commands to be invoked in the Org buffer, >> but >> actually carried out in the code buffer.) >> >> Patch attached and in branch src-block-tab at >> git@github.com:dandavison/org-devel.git. >> >> diff --git a/lisp/org-src.el b/lisp/org-src.el >> index baa2b11..fc15a83 100644 >> --- a/lisp/org-src.el >> +++ b/lisp/org-src.el >> @@ -435,6 +435,19 @@ 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." >> + `(when (org-edit-src-code) > > Wow, an excursion to the temp buffer for every TAB call > in a source code block? > > Sounds heavy. But I see that it could be nice together with > the new fontification stuff. My gut feeling would be to have > both of these feature off by default. But I have not tried > them yet. Hi Carsten, In a small code block the TAB is actually not bad at all, but in a big one there's a delay (that's worst case scenario: a netbook with an atom processor). I think it's clear that automatic fontification as you type by emacs font-lock should be turned off by default. We could consider fontification of code blocks e.g. on start up, and when folding/unfolding, but let's discuss that in a separate thread. We can go one further with the tab command, and supply a general mechanism for calling major mode commands from the src buffer (patch attached): (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)))))) So I'm proposing to bind that within the org-babel keymap (currently C-c C-v x, and C-c C-v C-x). That way for example: - C-c C-v C-x TAB :: indent code natively and with an interactive R session: - C-c C-v C-x C-c C-c :: `ess-eval-function-or-paragraph-and-step' I've included a variable `org-src-indent-natively' to control the native TAB by default (currently defaulting to off, seeing as the C-v C-v x alternative is always available). Eric and I are planning on providing the inverse also: exposing the babel keymap when in the edit buffer. Dan patch attached and at git@github.com:dandavison/org-devel.git[1] branch src-block-tab