emacs-orgmode
[Top][All Lists]
Advanced

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

[Orgmode] Automatically indent text when return is hit in an org buffer.


From: Daniel Pittman
Subject: [Orgmode] Automatically indent text when return is hit in an org buffer.
Date: Mon, 10 Dec 2007 15:31:43 +1100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/23.0.60 (gnu/linux)

G'day.  I am a fan of `newline-and-indent', and turn it on for most of
the modes I routinely use, since it is almost always what I want done.

org-mode rebinds the "return" key to `org-return', which acts
intelligently in the face of tables -- and calls `newline' hard-coded in
other cases.

I would like to preserve that intelligence, but also to use
`newline-and-indent', so generated this patch to implement my desired
behaviour.

By default this changes nothing: org behaves exactly the same way as it
did previously.


If this isn't the right approach I am happy to rework the patch to
better match the rest of the software.


Finally, while I believe that this is a trivial change and will not need
assignment papers anyway I can note two things:

 * there are copyright assignments from me to the FSF on record already
   for Emacs and constituents, so I don't know if I need a new
   assignment.

 * I am happy to disclaim this if necessary.

Regards,
        Daniel
-- 
Daniel Pittman <address@hidden>           Phone: 03 9621 2377
Level 4, 10 Queen St, Melbourne             Web: http://www.cyber.com.au
Cybersource: Australia's Leading Linux and Open Source Solutions Company


diff --git a/org/org.el b/org/org.el
--- a/org/org.el
+++ b/org/org.el
@@ -555,6 +555,13 @@ and a boolean flag as cdr."
   :type '(list
          (cons (const heading) (boolean))
          (cons (const plain-list-item) (boolean))))
+
+(defcustom org-return-and-indent nil
+  "Should `org-return' automatically indent the next line?
+Non-nil means, automatically indent the inserted line by calling
+`newline-and-indent' rather than `newline' when return is hit."
+  :group 'org-edit-structure
+  :type 'boolean)
 
 (defcustom org-insert-heading-hook nil
   "Hook being run after inserting a new heading."
@@ -26288,12 +26295,13 @@ Calls `org-table-next-row' or `newline',
 Calls `org-table-next-row' or `newline', depending on context.
 See the individual commands for more information."
   (interactive)
-  (cond
-   ((bobp) (newline))
-   ((org-at-table-p)
-    (org-table-justify-field-maybe)
-    (call-interactively 'org-table-next-row))
-   (t (newline))))
+  (let ((newline (if org-return-and-indent #'newline-and-indent #'newline)))
+    (cond
+     ((bobp) (funcall newline))
+     ((org-at-table-p)
+      (org-table-justify-field-maybe)
+      (call-interactively 'org-table-next-row))
+     (t (funcall newline)))))
 
 
 (defun org-ctrl-c-minus ()





reply via email to

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