unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Spencer Baugh <sbaugh@janestreet.com>
To: 66670@debbugs.gnu.org
Cc: Stefan Monnier <monnier@gnu.org>
Subject: bug#66670: [PATCH] Use buffer-local comment-continue in comment-indent-new-line
Date: Sat, 21 Oct 2023 16:08:42 -0400	[thread overview]
Message-ID: <ierfs23g2lx.fsf@janestreet.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 673 bytes --]

Tags: patch


This fixes a remaining issue with whitespace values of comment-continue,
as described in https://github.com/ocaml/tuareg/issues/216

Namely, the fixes done so far don't cover comment-indent-new-line.

In GNU Emacs 29.1.50 (build 12, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2023-10-19 built on
 igm-qws-u22796a
Repository revision: 9163e634e296435aa7a78bc6b77b4ee90666d2ac
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Rocky Linux 8.8 (Green Obsidian)

Configured using:
 'configure --config-cache --with-x-toolkit=lucid
 --with-gif=ifavailable'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-buffer-local-comment-continue-in-comment-indent-.patch --]
[-- Type: text/patch, Size: 2766 bytes --]

From 9fab95f193eb7da9e6787122b885d1de29b5b657 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Sat, 21 Oct 2023 16:05:05 -0400
Subject: [PATCH] Use buffer-local comment-continue in comment-indent-new-line

As the FIXME said, comment-indent-new-line was wiping out the value of
comment-continue even if it had been set explicitly.  Checking
local-variable-p should be sufficient to fix this.

This makes comment-indent-new-line work properly if comment-continue
can't be recalculated from comment-start, such as if comment-continue
is all whitespace.

* lisp/newcomment.el (comment-indent-new-line): Don't set
comment-continue to nil if it's local-variable-p.
* test/lisp/newcomment-tests.el
(local-comment-continue-in-comment-indent-new-line): Add a test.
---
 lisp/newcomment.el            |  5 +++--
 test/lisp/newcomment-tests.el | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 9ae7de70a0e..b217f700f22 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1541,9 +1541,10 @@ comment-indent-new-line
                                     (cadr (assoc comment-style
                                                  comment-styles))))
                      ;; 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)))
                 (comment-indent continuep))
 	      (save-excursion
 		(let ((pt (point)))
diff --git a/test/lisp/newcomment-tests.el b/test/lisp/newcomment-tests.el
index cb0f304c463..9851b4c2c45 100644
--- a/test/lisp/newcomment-tests.el
+++ b/test/lisp/newcomment-tests.el
@@ -36,4 +36,21 @@ test-uncomment-space-comment-continue
               (uncomment-region (point-min) (point-max))
               (buffer-string))))))
 
+(ert-deftest local-comment-continue-in-comment-indent-new-line ()
+  (with-temp-buffer
+    (setq-local comment-start "/* ")
+    (setq-local comment-end "*/")
+    (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)
+    (should (equal (thing-at-point 'line) " * \n"))
+    (setq-local comment-continue "   ")
+    (comment-indent-new-line)
+    (should (equal (thing-at-point 'line) "   \n"))))
+
 ;;; newcomment-tests.el ends here
-- 
2.39.3


             reply	other threads:[~2023-10-21 20:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-21 20:08 Spencer Baugh [this message]
2023-10-21 21:23 ` bug#66670: [PATCH] Use buffer-local comment-continue in comment-indent-new-line Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-21 22:15   ` Spencer Baugh
2023-10-22  4:11     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ierfs23g2lx.fsf@janestreet.com \
    --to=sbaugh@janestreet.com \
    --cc=66670@debbugs.gnu.org \
    --cc=monnier@gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).