emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Indent code with TAB in Org buffer
@ 2010-08-15  6:43 Dan Davison
  2010-08-15  7:42 ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Davison @ 2010-08-15  6:43 UTC (permalink / raw)
  To: emacs org-mode mailing list

[-- Attachment #1: Type: text/plain, Size: 340 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: src-block-tab.diff --]
[-- Type: text/x-diff, Size: 870 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 5 bytes --]


Dan

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-16  7:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-15  6:43 [PATCH] Indent code with TAB in Org buffer Dan Davison
2010-08-15  7:42 ` Carsten Dominik
2010-08-15 23:00   ` Dan Davison
2010-08-16  6:56     ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).