From: Spencer Baugh <sbaugh@janestreet.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 66670@debbugs.gnu.org, monnier@gnu.org
Subject: bug#66670: [PATCH] Use buffer-local comment-continue in comment-indent-new-line
Date: Sat, 21 Oct 2023 18:15:24 -0400 [thread overview]
Message-ID: <ier4jijfwqr.fsf@janestreet.com> (raw)
In-Reply-To: <jwvttqj3c8y.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 21 Oct 2023 17:23:35 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> 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.
next prev parent reply other threads:[~2023-10-21 22:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-21 20:08 bug#66670: [PATCH] Use buffer-local comment-continue in comment-indent-new-line Spencer Baugh
2023-10-21 21:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-21 22:15 ` Spencer Baugh [this message]
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=ier4jijfwqr.fsf@janestreet.com \
--to=sbaugh@janestreet.com \
--cc=66670@debbugs.gnu.org \
--cc=monnier@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).