From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WHAKN8byr16sLwAA0tVLHw (envelope-from ) for ; Mon, 04 May 2020 10:47:34 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id gE9xBdHyr16xeQAA1q6Kng (envelope-from ) for ; Mon, 04 May 2020 10:47:45 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E3C6094402F for ; Mon, 4 May 2020 10:47:43 +0000 (UTC) Received: from localhost ([::1]:46898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVYdU-0002KB-6J for larch@yhetil.org; Mon, 04 May 2020 06:47:44 -0400 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 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 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) 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) From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= To: Juri Linkov Subject: Re: Reconciling org-mode idiosyncrasies with Emacs core 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> Date: Mon, 04 May 2020 12:45:24 +0200 In-Reply-To: <87ees6fp8r.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Wed, 29 Apr 2020 14:30:44 +0200") Message-ID: <87y2q89dx7.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Org Mode list , Emacs developers Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: 0.09 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=eognqfzA; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Scan-Result: default: False [0.09 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.49431757567703]; DWL_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; R_DKIM_REJECT(1.00)[gmail.com:s=20161025]; HAS_ATTACHMENT(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.14), country: US(-0.00), ip: 2001:470:142::17(-0.49)]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:-]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[kevinlegouguec@gmail.com,emacs-orgmode-bounces@gnu.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; URIBL_BLOCKED(0.00)[nicolasgoaziou.fr:email]; MIME_GOOD(-0.10)[multipart/mixed,text/plain,text/x-patch]; HAS_LIST_UNSUB(-0.01)[]; RECEIVED_SPAMHAUS_PBL(0.00)[109.13.143.200:received]; FORGED_SENDER_MAILLIST(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : SPF not aligned (relaxed),none] X-TUID: rUhJlInTjbpr --=-=-= 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. --=-=-=--