From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#66670: [PATCH] Use buffer-local comment-continue in comment-indent-new-line Date: Sat, 21 Oct 2023 18:15:24 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39732"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 66670@debbugs.gnu.org, monnier@gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 22 00:16:45 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1quKGz-000A8G-2E for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 22 Oct 2023 00:16:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quKGp-0007qD-Ao; Sat, 21 Oct 2023 18:16:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1quKGn-0007q0-Te for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2023 18:16:33 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1quKGn-000802-LX for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2023 18:16:33 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1quKHF-0000xs-KA for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2023 18:17:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Oct 2023 22:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66670 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66670-submit@debbugs.gnu.org id=B66670.16979265673622 (code B ref 66670); Sat, 21 Oct 2023 22:17:01 +0000 Original-Received: (at 66670) by debbugs.gnu.org; 21 Oct 2023 22:16:07 +0000 Original-Received: from localhost ([127.0.0.1]:45207 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quKGJ-0000wI-Sa for submit@debbugs.gnu.org; Sat, 21 Oct 2023 18:16:07 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:42129) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quKGE-0000vX-BO for 66670@debbugs.gnu.org; Sat, 21 Oct 2023 18:16:02 -0400 In-Reply-To: (Stefan Monnier's message of "Sat, 21 Oct 2023 17:23:35 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272943 Archived-At: Stefan Monnier writes: >> ;; Recreate comment-continue from comment-start. >> - ;; FIXME: wrong if comment-continue was set explicitly! >> ;; FIXME: use prev line's continuation if available. >> - (comment-continue nil)) >> + (comment-continue (if (local-variable-p 'comment-continue) >> + comment-continue >> + nil))) > > Are you sure? `comment-continue` is very rarely set globally. > Usually it's set buffer-locally by `comment-normalize-vars`. Or by the major-mode! But yes, I see your point, this patch is effectively removing the (comment-continue nil) definition. I guess that the (comment-continue nil) definition is there in the first place so that comment-normalize-vars recalculates it based on comment-start, which is the comment prefix from the previous line? So we therefore copy the prefix from the previous line? Should we just recalculate comment-continue directly in comment-indent-new-line instead, if necessary? Although even if we did that, I don't see any clear way to know that we should use the configured comment-continue instead of trying to copy the previous line. Should we maybe just not copy the comment prefix from the previous line at all, if comment-continue is non-nil? >> +(ert-deftest local-comment-continue-in-comment-indent-new-line () >> + (with-temp-buffer >> + (setq-local comment-start "/* ") >> + (setq-local comment-end "*/") > ^^ > Out of symmetry, I'd have expected a SPC here. > >> + (insert "foo") >> + (newline) >> + (insert "bar") >> + (forward-line -1) >> + (end-of-line) >> + (comment-region (point-min) (point-max)) >> + (should (equal (thing-at-point 'line) "/* foo\n")) >> + (comment-indent-new-line) > > You should also test it with that very same comment but when > `comment-start` and `comment-end` have been set to something like > "// " and "". Will do.