emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Daniel Pittman <daniel@rimspace.net>
To: emacs-orgmode@gnu.org
Subject: Automatically indent text when return is hit in an org buffer.
Date: Mon, 10 Dec 2007 15:31:43 +1100	[thread overview]
Message-ID: <87abojxj9s.fsf@enki.rimspace.net> (raw)

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 <daniel@cybersource.com.au>           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	other threads:[~2007-12-10  5:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-10  4:31 Daniel Pittman [this message]
2007-12-11 10:43 ` Automatically indent text when return is hit in an org buffer Bastien
2007-12-11 11:17   ` Daniel Pittman
2007-12-17  8:30     ` Carsten Dominik
2007-12-17  8:25 ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87abojxj9s.fsf@enki.rimspace.net \
    --to=daniel@rimspace.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).