From: "Kévin Le Gouguec" <kevin.legouguec@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: Org Mode list <emacs-orgmode@gnu.org>,
Emacs developers <emacs-devel@gnu.org>
Subject: Re: Reconciling org-mode idiosyncrasies with Emacs core
Date: Mon, 04 May 2020 12:45:24 +0200 [thread overview]
Message-ID: <87y2q89dx7.fsf@gmail.com> (raw)
In-Reply-To: <87ees6fp8r.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Wed, 29 Apr 2020 14:30:44 +0200")
[-- Attachment #1: Type: text/plain, Size: 314 bytes --]
Hi Nicolas,
I took a stab at making RET obey electric-indent-mode in org-mode. I've
got something working; I'd like to ask for a review before moving on to
Changelog and ORG-NEWS entries (and tackling C-j… and maybe writing a
few unit tests?).
Here's the patch, with some additional comments below:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-return.patch --]
[-- Type: text/x-patch, Size: 2515 bytes --]
diff --git a/lisp/org.el b/lisp/org.el
index e82463046..681328d96 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17644,20 +17644,32 @@ call `open-line' on the very first character."
(org-table-insert-row)
(open-line n)))
-(defun org-return (&optional indent)
+(defun org--newline (indent arg interactive)
+ "Call `newline-and-indent' or just `newline'.
+
+If INDENT is non-nil, call `newline-and-indent' with ARG to
+indent unconditionally; otherwise, call `newline' with ARG and
+INTERACTIVE, which can trigger indentation if
+`electric-indent-mode' is enabled."
+ (if indent
+ (newline-and-indent arg)
+ (newline arg interactive)))
+
+(defun org-return (&optional indent arg interactive)
"Goto next table row or insert a newline.
Calls `org-table-next-row' or `newline', depending on context.
When optional INDENT argument is non-nil, call
-`newline-and-indent' instead of `newline'.
+`newline-and-indent' with ARG, otherwise call `newline' with ARG
+and INTERACTIVE.
When `org-return-follows-link' is non-nil and point is on
a timestamp or a link, call `org-open-at-point'. However, it
will not happen if point is in a table or on a \"dead\"
object (e.g., within a comment). In these case, you need to use
`org-open-at-point' directly."
- (interactive)
+ (interactive "*i\nP\np")
(let ((context (if org-return-follows-link (org-element-context)
(org-element-at-point))))
(cond
@@ -17708,23 +17720,20 @@ object (e.g., within a comment). In these case, you need to use
(t (org--align-tags-here tags-column))) ;preserve tags column
(end-of-line)
(org-show-entry)
- (if indent (newline-and-indent) (newline))
+ (org--newline indent arg interactive)
(when string (save-excursion (insert (org-trim string))))))
;; In a list, make sure indenting keeps trailing text within.
- ((and indent
- (not (eolp))
+ ((and (not (eolp))
(org-element-lineage context '(item)))
(let ((trailing-data
(delete-and-extract-region (point) (line-end-position))))
- (newline-and-indent)
+ (org--newline indent arg interactive)
(save-excursion (insert trailing-data))))
(t
;; Do not auto-fill when point is in an Org property drawer.
(let ((auto-fill-function (and (not (org-at-property-p))
auto-fill-function)))
- (if indent
- (newline-and-indent)
- (newline)))))))
+ (org--newline indent arg interactive))))))
(defun org-return-indent ()
"Goto next table row or insert a newline and indent.
[-- Attachment #3: Type: text/plain, Size: 1918 bytes --]
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Kévin Le Gouguec <kevin.legouguec@gmail.com> writes:
>
>> Do you think a patch that
>>
>> - tweaked org-return (bound to RET) to default its INDENT argument to
>> the current value of electric-indent-mode,
After taking an in-depth look at 'org-return' and 'newline', I decided
to "let the knife do the work" and simply keep calling 'newline', though
with additional arguments:
- INTERACTIVE is what makes 'newline' run 'post-self-insert-hook' (thus
triggering indentation through electric-indent-mode),
- ARG wasn't strictly necessary, but it seemed harmless to add it, and
it allows inserting multiple newlines, thus removing one more "Org
idiosyncrasy".
I felt that introducing org--newline made the code clearer, but I can
understand if it seems too trivial to keep. I took the liberty of using
this function in the "list item" case too, otherwise there's no way to
indent the trailing text.
> The change will not appear overnight in Org, i.e., not in Org stable's
> branch (Org 9.3.X), and it will be announced in ORG-NEWS.
I'll work on ORG-NEWS (plus Changelog entries, plus unit tests) as soon
as I'm confident that my approach is satisfactory.
(Out of curiosity, could it be argued that this is solving a "bug" in
org-mode and, as such, could be committed to Emacs core first, then
backported to the org-mode repository? I don't feel strongly either
way, I wouldn't want to make things more complicated for Org
maintainers.)
Now for C-j, in order to minimize breakage (for anyone calling
org-return-indent from Lisp code) and simplify disabling the new
behaviour (by simply turning off electric-indent-mode in Org), should we
bind C-j to a new function? E.g.:
(defun org-return-and-maybe-indent ()
(interactive)
(org-return (not electric-indent-mode)))
Thank you for your time.
next prev parent reply other threads:[~2020-05-04 10:45 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-26 15:43 Convert some files from outline-mode to org-mode Stefan Kangas
2020-04-26 16:13 ` Clément Pit-Claudel
2020-04-26 18:36 ` Stefan Monnier
2020-04-26 19:52 ` Stefan Kangas
2020-04-26 20:54 ` Stefan Monnier
2020-04-26 22:53 ` Clément Pit-Claudel
2020-04-26 16:16 ` H. Dieter Wilhelm
2020-04-26 17:22 ` Alan Mackenzie
2020-04-26 19:29 ` Stefan Kangas
2020-04-26 21:54 ` Kévin Le Gouguec
2020-04-26 22:09 ` Stefan Monnier
2020-04-26 22:41 ` Drew Adams
2020-04-27 7:20 ` Kévin Le Gouguec
2020-04-27 15:23 ` Drew Adams
2020-04-27 15:31 ` Jean-Christophe Helary
2020-04-27 7:39 ` Kévin Le Gouguec
2020-04-27 14:27 ` Reveal-mode (was: Convert some files from outline-mode to org-mode) Stefan Monnier
2020-04-27 10:23 ` Convert some files from outline-mode to org-mode Alan Mackenzie
2020-04-27 11:45 ` Kévin Le Gouguec
2020-04-27 20:30 ` Juri Linkov
2020-04-27 21:24 ` Drew Adams
2020-04-27 23:05 ` John Yates
2020-04-28 2:51 ` Richard Stallman
2020-05-24 6:23 ` Bastien
2020-04-28 15:12 ` Nicolas Goaziou
2020-04-28 16:41 ` H. Dieter Wilhelm
2020-04-28 17:56 ` Nicolas Goaziou
2020-04-28 19:22 ` H. Dieter Wilhelm
2020-04-28 23:35 ` Juri Linkov
2020-04-29 10:53 ` Nicolas Goaziou
2020-04-29 11:37 ` Reconciling org-mode idiosyncrasies with Emacs core (was: Convert some files from outline-mode to org-mode) Kévin Le Gouguec
2020-04-29 12:30 ` Reconciling org-mode idiosyncrasies with Emacs core Nicolas Goaziou
2020-05-04 10:45 ` Kévin Le Gouguec [this message]
2020-05-04 14:50 ` Nicolas Goaziou
2020-05-04 16:14 ` Kévin Le Gouguec
2020-05-06 14:54 ` [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode (was: Reconciling org-mode idiosyncrasies with Emacs core) Kévin Le Gouguec
2020-05-07 10:48 ` [PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode Nicolas Goaziou
2020-05-07 12:03 ` Kévin Le Gouguec
2020-05-07 12:21 ` Nicolas Goaziou
2020-05-07 16:45 ` Kévin Le Gouguec
2020-05-07 16:50 ` Kévin Le Gouguec
2020-05-07 19:38 ` Nicolas Goaziou
2020-05-24 6:25 ` Bastien
2020-05-07 13:53 ` Stefan Monnier
2020-05-07 15:33 ` Kévin Le Gouguec
2020-05-24 6:23 ` Convert some files from outline-mode to org-mode Bastien
2020-05-24 6:18 ` Bastien
2020-04-27 12:14 ` H. Dieter Wilhelm
2020-05-24 6:13 ` Bastien
2020-04-26 18:40 ` Stefan Monnier
2020-05-24 6:15 ` Bastien
2020-04-27 2:23 ` Richard Stallman
2020-04-27 6:37 ` Michael Albinus
2020-04-27 7:12 ` tomas
2020-04-28 2:49 ` Richard Stallman
2020-04-28 9:40 ` Michael Albinus
2020-04-29 3:30 ` Richard Stallman
2020-05-24 6:16 ` Bastien
2020-04-27 9:59 ` Po Lu
2020-04-27 14:36 ` Stefan Monnier
2020-04-27 14:49 ` Jean-Christophe Helary
2020-04-29 3:27 ` Howard Melman
2020-04-29 3:52 ` Jean-Christophe Helary
2020-04-29 13:54 ` Howard Melman
2020-04-29 14:08 ` Jean-Christophe Helary
2020-04-29 14:17 ` Nicolas Goaziou
2020-04-29 14:52 ` Howard Melman
2020-04-29 14:03 ` Stefan Kangas
2020-04-30 10:25 ` H. Dieter Wilhelm
2020-05-07 21:01 ` Stefan Kangas
2020-05-08 17:50 ` Yuri Khan
2020-05-08 17:55 ` Stefan Kangas
2020-05-24 6:35 ` Bastien
2020-04-29 17:52 ` Alan Mackenzie
2020-04-29 19:19 ` Howard Melman
2020-04-30 2:24 ` Richard Stallman
2020-05-24 6:04 ` Bastien
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y2q89dx7.fsf@gmail.com \
--to=kevin.legouguec@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=emacs-orgmode@gnu.org \
--cc=juri@linkov.net \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.