Subject: bug#37099: 26.2 Comment-dwim

From: Alan Mackenzie <[email-masked]>
Date: Wed, 21 Aug 2019 16:42:35 -0000 (UTC)

Hello, Charles.

Charles Jackson <[email-masked]> wrote:
> [-- text/plain, encoding base64, charset: UTF-8, 8 lines --]

> I would like the comment-dwim function to be able to differentiate
> end-of-line comments from whole-line comments.

OK.  What should happen when a whole-line comment becomes and end-of-line
comment (by inserting text before it), or vice versa?

> For example in java mode it would make sense for // to be the
> end-of-line comment, but if point is on an empty line then comment-dwim
> would insert /* */ with point inside the /* */ like so: /* | */ where |
> is the point location.

Why would this make sense?  For example, how big is the community of
users who would want such a facility.

A general solution to this wish would be surprisingly difficult and
time-consuming to write.  The Emacs source file, newcomment.el (which
contains the command comment-dwim) contains no representation of
different pairs of comment delimiters, and this would have to be added.

It is CC Mode here which maintains the two different pairs of comment
delimiters, /* .... */ and // .... \n.  In a CC Mode mode (such as Java
Mode) you can manually switch between the delimiter pairs with C-c C-k,
c-toggle-comment-style.

It would be relatively easy to add Lisp "advice" to the function
comment-dwim just for Java Mode, which would use c-toggle-comment-style
to set the comment delimiters after having determined the required pair
of comment delimiters.

Again, how useful a facility would this really be?  Useful enough to
justify the time and effort to write a full solution, or rather a
localised need which would best be satisfied with a careful hack (such as
outlined above)?

-- 
Alan Mackenzie (Nuremberg, Germany).