From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id OPXxHF8pNWP+bgEAbAwnHQ (envelope-from ) for ; Thu, 29 Sep 2022 07:13:03 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id sMgKHV8pNWPa2AAAauVa8A (envelope-from ) for ; Thu, 29 Sep 2022 07:13:03 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.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 3E15E26BCF for ; Thu, 29 Sep 2022 07:13:02 +0200 (CEST) Received: from localhost ([::1]:54548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odlr1-0002Gg-Rc for larch@yhetil.org; Thu, 29 Sep 2022 01:13:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odloo-0002GT-QQ for emacs-orgmode@gnu.org; Thu, 29 Sep 2022 01:10:43 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:46824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odlom-0002YV-N2 for emacs-orgmode@gnu.org; Thu, 29 Sep 2022 01:10:42 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 8-20020a17090a0b8800b00205d8564b11so291615pjr.5 for ; Wed, 28 Sep 2022 22:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date; bh=lYrIRtsuSYYIWI7+sD0ay6FPekW8S1deBLGAUekabmo=; b=Jd6uFGu0723LTPH+/vRU6fvqYLgL4x38uImphuFgjWU+KkLo54SmCirDZSeqjn3uPk cfzcMLmoNi0MYcsl7thHx1xLGtH2MffXyrzKXYT2NtpqoOw8YHBA8hcXKcFRgcLzboHk 0BYNHgIlp9KLssIFl1YOOWNIARoV0oIm9jIXQFQCdU5A9VVT6Seu4XRFDsOw01w4uoel CIfA+9fA0J07Is+daJIsHIyXSdHKhEeiNpssrCDruQY+5gTyy5bVTOEh9AEQNqyqG5yV 92AnAXA9+FH8FWq78aAHw9iIsOqdiyGpzEv4ThgXd7qlZh5nxy39NbeDN7TFLMjboN/b +b8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date; bh=lYrIRtsuSYYIWI7+sD0ay6FPekW8S1deBLGAUekabmo=; b=Jyrkwju8Jd8Hev4OShY4gDmayyqoRd44c76Jy8EHnXUW1WJRbQgoQvSX5rp5dslNCR KfU4QnchDnG7Ch6xZ9q2vP4/iy4AaQUTHRhoy/FSt3NqbZauaciEVNrq3UaQ+q8Ne5lT xr/SNJ+VGYoXiiakq8EkU4S29vhIYC9qeWmzW1HCipopM7KkN64D/eQdFNGJT38eQSq4 rWxkXE6RNXlmIWISvKrJNmo16s2GjdHUpO4Ou8LzU94YPPfIRVbcdOyiuf4bn751BXlW N7E1lyLXwjQSc0GfFg0cdd1Yc+RqgFqQC3nTlBVZ239ZkoGSXKLnkuMHb98fLdMCXqKO T6fw== X-Gm-Message-State: ACrzQf0GlU1HATcjQiP+8JLqDy0+FuSQ/NiUzzZ55K2fmDZAKXcBIHgU e7fAsS/bQ8wdvo7P5R50Z4s= X-Google-Smtp-Source: AMsMyM5d/+9nPcdcb9fMgMkgmexBGlUxHCKC8VRd0QcS3G3yBiWTs7d1bnWeFN1smbHvoJ9pjGyZ2A== X-Received: by 2002:a17:902:b944:b0:179:fdb0:1c39 with SMTP id h4-20020a170902b94400b00179fdb01c39mr1690474pls.98.1664428238080; Wed, 28 Sep 2022 22:10:38 -0700 (PDT) Received: from localhost ([2409:8970:a80:3a4:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id s12-20020a17090a5d0c00b002029e3d5cb8sm2465446pji.34.2022.09.28.22.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 22:10:37 -0700 (PDT) From: Ihor Radchenko To: Kaushal Modi Cc: Richard Lawrence , Marco Wahl , Tim Cross , emacs-org list , Nicolas Goaziou Subject: Re: [PATCH] Fix org-comment-line-break-function In-Reply-To: References: <87lf18fue9.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> <87v90cpcdx.fsf@yandex.com> <87ilwcf31l.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> <87pmqjkai3.fsf@gmail.com> <87fsrffknl.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> <87czmijtrp.fsf@gmail.com> <87o861o9sh.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> <87h7btpfbt.fsf@gmail.com> <87zgpli5nc.fsf@gmail.com> <871r2suhw2.fsf@gmail.com> <87v901oost.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> Date: Thu, 29 Sep 2022 13:11:24 +0800 Message-ID: <877d1m9343.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664428382; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=A07s9qNX22SZlOJqF1EBATtkclxpGLS7/qMhqbcDZGs=; b=S/hKR7kcpLFxN1GVFm0F7BWXhbgM7/oFj78uhpKJ0ziynbTpEvPcwwDrFlASqXn6zFzZoJ PJ3ZyfQ/2y3WT1/IHxq3YnXNKAGB/ugZFyyJkm9/J7AuzCQe4ArYSCGae9Bukka4OjVqfR lyFJlb6bysSOnNj4LTVm5k1GlkWaAeOqE/7bApumEWVJwNNUW7W/Kh0/vQHAMjy8wTMetl TzOSlwSXqVlrFyZj0YgCgTBIJObq5PFnpAN+n4SZiqfigTOdRvtKQ6Ecy+q/m12rwHg25i uVLkSscJN/B3vSD+jgl09dk1ILnxrR4ee8p/Aq5iv1bWirWpvYIgaUCzFnfoqw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664428382; a=rsa-sha256; cv=none; b=FMdFcOL8YoibJXMVBBCD1HP/nKz+FQIb2a+VjcyStTwMLnyRjVm9R7e+wKifqMOrkfO0W1 zS/giVmo835XBpILLWQQ2TkD8Rz5H2/S4Nc7KmLmN+TWRbpK24QJcyxCzIbjvIl5yb/MZ/ wRfjbAzQf6uR8E8vcIB2RnXPfBniR4+5bBplA/CQVh6unauDR98VaFIT3xurnEyM1Zd6m9 r1D/KkQ14+21Q7+bofynip/PAHURwiLnb3jDTIzxPMO1ltCh7TR+H5uVfOBqSBAu6ejQh/ 33Sll03qs+9WC6yktPkMH/A/UT3jav6L8135vnUr6uYbpajPqsOG/Z6yJJsxWQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=Jd6uFGu0; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 9.95 X-Spam: Yes Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=Jd6uFGu0; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 3E15E26BCF X-Spam-Score: 9.95 X-Migadu-Spam: Yes X-Migadu-Scanner: scn1.migadu.com X-TUID: trftd52wYqYH --=-=-= Content-Type: text/plain Kaushal Modi writes: > Hi Nicolas, > > I have added few tests in the updated patch pasted in this email. > I have made the tests for (call-interactive #'default-indent-new-line) > because that the interactive function M-j is bound to by default. > > Can you please review and commit it? The machine I am on right now does not > allow external ssh access. Unfortunately, we cannot rely on the built-in `comment-indent-new-line' to fill Org comments. This is because Emacs uses a complex entanglement of regexp heuristics to determine comment at point and its boundaries. I am attaching an alternative patch to fix the issue using Org element parser. Note that I reused your tests. Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-comment-line-break-function-Avoid-built-in-Emacs.patch >From ded35b55ca694e3eb831878160ac37ceec48b08e Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Thu, 29 Sep 2022 13:02:46 +0800 Subject: [PATCH] org-comment-line-break-function: Avoid built-in Emacs comment machinery * lisp/org.el (org-comment-line-break-function): Rely on Org parser (`org-adaptive-fill-function') to determine comment filling. Handle nil values of `fill-prefix' correctly. * testing/lisp/test-org.el (test-org/default-indent-new-line): New test. Written by Kaushal Modi https://list.orgmode.org/CAFyQvY36DkBSNy2mPxDNZWeoTjUK8mAqgJM-zHxNamfReqGkuQ@mail.gmail.com/ Reported-by: Richard Lawrence Link: https://list.orgmode.org/87lf18fue9.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me/ --- lisp/org.el | 18 ++++++++++++------ testing/lisp/test-org.el | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 036384a04..5ff60baf6 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19295,12 +19295,18 @@ (defun org-comment-line-break-function (&optional soft) "Break line at point and indent, continuing comment if within one. The inserted newline is marked hard if variable `use-hard-newlines' is true, unless optional argument SOFT is -non-nil." - (if soft (insert-and-inherit ?\n) (newline 1)) - (save-excursion (forward-char -1) (delete-horizontal-space)) - (delete-horizontal-space) - (indent-to-left-margin) - (insert-before-markers-and-inherit fill-prefix)) +non-nil. + +This function is a simplified version of `comment-indent-new-line' +that bypasses the complex Emacs machinery dealing with comments. +We instead rely on Org parser, utilizing `org-adaptive-fill-function'" + (let ((fill-prefix (org-adaptive-fill-function))) + (if soft (insert-and-inherit ?\n) (newline 1)) + (save-excursion (forward-char -1) (delete-horizontal-space)) + (delete-horizontal-space) + (indent-to-left-margin) + (when fill-prefix + (insert-before-markers-and-inherit fill-prefix)))) ;;; Fixed Width Areas diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 1b4157d0e..4a6a3a0b0 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1405,6 +1405,26 @@ (ert-deftest test-org/indent-region () (org-indent-region (point-min) (point-max)) (buffer-string))))) +(ert-deftest test-org/default-indent-new-line () + "Test behavior of default binding `M-j'." + ;; Calling `M-j' when point is not in an Org comment: + (should + (equal "* Some heading\n" + (org-test-with-temp-text "* Some heading" + (call-interactively #'default-indent-new-line) + (buffer-string)))) + ;; Calling `M-j' when point is in an Org comment: + (should + (equal "# Some Org comment\n# " + (org-test-with-temp-text "# Some Org comment" + (call-interactively #'default-indent-new-line) + (buffer-string)))) + (should + (equal "# Some Org\n# comment" + (org-test-with-temp-text "# Some Org comment" + (call-interactively #'default-indent-new-line) + (buffer-string))))) + ;;; Editing -- 2.35.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92 --=-=-=--