unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: PEDRO ANDRES ARANDA GUTIERREZ <paranda@it.uc3m.es>,
	emacs-devel@gnu.org, Yuri Khan <yuri.v.khan@gmail.com>
Subject: RE: Just a thought about comment-line
Date: Sun, 31 May 2020 14:53:46 -0700 (PDT)	[thread overview]
Message-ID: <6b91b604-938b-4325-94bd-ba5fd36c02f5@default> (raw)
In-Reply-To: <jwvimgc6iah.fsf-monnier+emacs@gnu.org>

> >> It automatically decides whether to comment or to uncomment, indeed.
> >
> > Precisely.  It's a compromise, and not a
> > great one (IMO).  Better to have two
> > commands, one for block commenting and the
> > other for end-of-line commenting.
> 
> I have never seen someone comment a comment.
> Do you have a use case for it?

Commenting out some code, perhaps temporarily.

Doing so regardless of whether some, or all, of
it is already commented out.  And maybe doing
so again, with a larger scope.  And then maybe
uncommenting the outermost commenting level.
And so on.

But let me be clear that I'm expressing, first
of all, my personal preference.  I don't say
that everyone has to, will, or should prefer it.

That said, I do think that Emacs itself should
provide such behavior, e.g. some such command,
out of the box.  Whether it gets a default
binding, or the default binding, is a different
story.  (In fact, it has one, `comment-line',
but it suffers from the problem raised in this
thread.)

There have been previous discussions here about
the question.[1]  And although I said the same
then as now, it was others who raised the
question in the first place.  And other
suggestions given were along the same lines as
what I offered.

The result of the last such discussion was the
addition of command `comment-line' - again, to
comment whole lines.  It, however, suffers from
the behavior complained about in this thread:
it comments an extra line when the region ends
at bol.

Finally, if you think there's no use case for
such comment nesting ("comment a comment", as
you say), then maybe you can explain why Common
Lisp was so foolish as to provide for such a
non-use case - with a specific, separate
comment syntax, no less.

The use case is described this way by CLTL2
(I already gave the URL):

  The main purpose of this construct is to allow
  "commenting out" of blocks of code or data.
  The balancing rule allows such blocks to contain
  pieces already so commented out. In this respect
  the #|...|# syntax of Common Lisp differs from
  the /*...*/ comment syntax used by PL/I and C.

`comment-dwim' gets you partway there.

> > It's not just that it has to correctly guess
> > what you mean.  It's also that _you_ have to
> > guess what it's guessing you mean. ;-)
> 
> That in nature of DWIM commands, yes.

That's a general problem with DWIM, commands, yes.

But this one, with 10 different behaviors, for 10
different conditional situations, suffers from it
in spades.  (IMHO.)

Since I use `M-;' only for end-of-line comments
I don't suffer from its congeries of behaviors.
And if others are fine with the trade-offs it
makes, that's fine too.  I haven't suggested
changing or removing `comment-dwim' - it doesn't
bother me, the way I use it.

> >> Right, as a general rule, the LF char belongs to the line that it
> >> terminates, so a position at BOL is really "between lines".
> >> Of course, that would require a special case when START=END=BOL.
> >
> > That special case is what `comment-region-lines'
> > handles.
> 
> At the detriment of the other case.

How so?  In what "other case" does it fall down?

I don't claim it always does what every Mr. WXYZ
wants.  I say that its behavior is straightforward
and useful, and it's easy to know what behavior
you'll get.

And I don't argue that Emacs should adopt the
exact same code.  `comment-line' could be fixed,
for example, so that it doesn't suffer from the
problem raised in this thread.

And there are a couple other improvements that
could be made to `comment-line' at the same time,
which I suggested when it was added, 5 years ago.[2]

> > It just does this:
> > (comment-region BOL EOL PREFIX-ARG).
> 
> But that's what the OP complained about when you do
> 
>     C-a C-SPC
>     C-n C-n M-x comment-region-lines RET
> 
> where it ends up commenting 3 lines, even though
> there are only 2 lines enclosed in the region.

No, it does not.  With that recipe it comments only
the two lines enclosed in the region.  Full code:

(defun comment-region-lines (beg end &optional arg)
  (interactive "*r\nP")
  (when (> beg end)
    (setq beg  (prog1 end (setq end  beg))))
  (let ((bol  (save-excursion
                (goto-char beg)
                (line-beginning-position)))
        (eol  (save-excursion
                (goto-char end)
                (if (bolp)
                    (point)
                  (line-end-position)))))
    (comment-region bol eol arg)))
____

[1] https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00900.html

[2] https://lists.gnu.org/archive/html/emacs-devel/2015-02/msg00491.html



  reply	other threads:[~2020-05-31 21:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-31  7:39 Just a thought about comment-line PEDRO ANDRES ARANDA GUTIERREZ
2020-05-31  9:57 ` Yuri Khan
2020-05-31 16:58   ` Drew Adams
2020-05-31 17:15     ` Stefan Monnier
2020-05-31 18:05       ` Drew Adams
2020-05-31 19:05         ` Stefan Monnier
2020-05-31 21:53           ` Drew Adams [this message]
2020-05-31 17:42     ` Dmitry Gutov
2020-05-31 18:08       ` Drew Adams
2020-05-31 18:31         ` Dmitry Gutov
2020-05-31 21:54           ` Drew Adams
2020-06-01  5:18             ` PEDRO ANDRES ARANDA GUTIERREZ
2020-06-01  5:29               ` PEDRO ANDRES ARANDA GUTIERREZ
2020-05-31 14:40 ` Eli Zaretskii
2020-05-31 16:53 ` Drew Adams
2020-06-01  6:14 ` Clément Pit-Claudel

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=6b91b604-938b-4325-94bd-ba5fd36c02f5@default \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=paranda@it.uc3m.es \
    --cc=yuri.v.khan@gmail.com \
    /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).