From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= Newsgroups: gmane.emacs.devel,gmane.emacs.orgmode Subject: Re: Reconciling org-mode idiosyncrasies with Emacs core Date: Mon, 04 May 2020 12:45:24 +0200 Message-ID: <87y2q89dx7.fsf@gmail.com> References: <20200426172206.GC18629@ACM> <87y2qhnc9a.fsf@gmail.com> <20200427102311.GA4976@ACM> <87mu6xtano.fsf@gmail.com> <87k120ohsq.fsf@mail.linkov.net> <87blnbir01.fsf@nicolasgoaziou.fr> <87o8rbmbfa.fsf@mail.linkov.net> <87k11yftqo.fsf@nicolasgoaziou.fr> <87pnbqo74t.fsf_-_@gmail.com> <87ees6fp8r.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="48070"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Org Mode list , Emacs developers To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 04 12:46:24 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jVYcA-000CO3-MP for ged-emacs-devel@m.gmane-mx.org; Mon, 04 May 2020 12:46:22 +0200 Original-Received: from localhost ([::1]:44696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVYc9-0001ID-LI for ged-emacs-devel@m.gmane-mx.org; Mon, 04 May 2020 06:46:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVYbK-0000IT-Fy; Mon, 04 May 2020 06:45:30 -0400 Original-Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:45957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jVYbJ-0007Qb-Av; Mon, 04 May 2020 06:45:30 -0400 Original-Received: by mail-wr1-x434.google.com with SMTP id k1so1451622wro.12; Mon, 04 May 2020 03:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=yO2F9QJ9uMhdXEQBcH2flaX+lWUAXWJG425aFjJ0kA4=; b=eognqfzAB3KUY7YlueAogZ0KYuhLeJs/TLfXS0CFU0QubjgzOPgImwDPg8RqAhZiLW 63I6CEMAEBxqfrwaUlcxc7nb5Mh0UQRABpC6gptZkm5cUWdVT0r+SyBhQz5dIjb41cS7 FpPwbCfEc1oy1L4NaZlht1f2pXata7vEYzWqaM1gu8nURUcYOslHRFP6tGjWmujuWCDv qpEga4AbsbnRs0DGw20FAN7jlEm7eLOg5NzFYY7WOMS/xddG6qKZhIFaH1O0es2Mjfig tZYSvYbgfHnimbOuFFszTktf790n7klSO+PIi0h6TmIVTzCBQHFI7oOwVJhKoUOZuIh7 UErA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=yO2F9QJ9uMhdXEQBcH2flaX+lWUAXWJG425aFjJ0kA4=; b=jOeY/6oM1ZJ5tHBHyr/MTpJ191pLa/degyCoacA9qEF4otjWH/FPdY8PMI77wwHSH5 lQEF2/PO0Yevg/nEHv6d/w/qiT1EOVYbPw5QTDGPcJaIS7s13hTNsRHx6HNtrEPGE98x 32Nhrg3T3IVqEQWmRpmWzaCrMfJJwdz4cLrhiUqlw8la6aRW3nzQuc/7pSsDnEQDjgE7 MOGnVjAGNptD8Ev7shQNBEBGz8RDJgB8DxargjAQr9Qjop27Mje6v65xnRl0b40ooaAQ oJmvnhUtz1s17jl6PtELGXufqOB8gJOuFzx0+kUUVEqZzDjvQWQAUXK3RdYYLWO9cHDe DC6A== X-Gm-Message-State: AGi0Puahl1094kkciBUbcybBGRZyQcGshLiRUO57g3kmxieX5gtxgoQl hUYJTq5WaQK3hKyE6Ei5ZnULbHo3znAWkw== X-Google-Smtp-Source: APiQypLXOEfnZ8cYjg0mgQW7/HO7ElXc4hH3ERjY4PZKxQd0Y1ohszN8D1hRSBWJlAVbt4FMSf9srA== X-Received: by 2002:adf:9564:: with SMTP id 91mr19093727wrs.246.1588589127206; Mon, 04 May 2020 03:45:27 -0700 (PDT) Original-Received: from my-little-tumbleweed (200.143.13.109.rev.sfr.net. [109.13.143.200]) by smtp.gmail.com with ESMTPSA id x13sm13610826wmc.5.2020.05.04.03.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 03:45:25 -0700 (PDT) In-Reply-To: <87ees6fp8r.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Wed, 29 Apr 2020 14:30:44 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=kevin.legouguec@gmail.com; helo=mail-wr1-x434.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:248805 gmane.emacs.orgmode:128844 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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=E2=80=A6 and maybe writing= a few unit tests?). Here's the patch, with some additional comments below: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=org-return.patch 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. --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Nicolas Goaziou writes: > K=C3=A9vin Le Gouguec 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. --=-=-=--