[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [PATCH] Indent code with TAB in Org buffer

From: Dan Davison
Subject: [Orgmode] [PATCH] Indent code with TAB in Org buffer
Date: Sun, 15 Aug 2010 02:43:57 -0400
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux)

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

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)
+(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)
+     ,@body
+     (org-edit-src-exit) t))
+(defun org-src-tab-command ()
+  "Do what TAB does in the edit buffer for code block at point."
+  (org-src-do-in-edit-buffer
+   (funcall (key-binding (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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]