unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice
@ 2022-05-29 21:57 Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-05-30 18:24 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-05-29 21:57 UTC (permalink / raw)
  To: 55716

Package: Emacs
Version: 29.0.50


latex-mode started to impose the old `plain` comment-style a few months
ago, which I find rather annoying and not very user-friendly.
At first, I thought it was a bug somewhere in my config, but I now see
that it comes from:

    commit 0870ebb3cbfcb097d85eea5eacaf992dd88ed204
    Author: Lars Ingebrigtsen <larsi@gnus.org>
    Date:   Thu Jan 28 07:09:18 2021 +0100
    
        Allow commenting out white space lines in latex-mode
        
        * lisp/newcomment.el (comment-region-default-1): Allow commenting
        out whitespace-only regions (bug#41793).
        
        * lisp/textmodes/tex-mode.el (latex--comment-region): Use it.
        (latex-mode): Set a comment style shim.

    diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
    index c4e4864da17..ce665e61656 100644
    --- a/lisp/textmodes/tex-mode.el
    +++ b/lisp/textmodes/tex-mode.el
    @@ -1169,7 +1169,12 @@ latex-mode
       (setq-local outline-regexp latex-outline-regexp)
       (setq-local outline-level #'latex-outline-level)
       (setq-local forward-sexp-function #'latex-forward-sexp)
    -  (setq-local skeleton-end-hook nil))
    +  (setq-local skeleton-end-hook nil)
    +  (setq-local comment-region-function #'latex--comment-region)
    +  (setq-local comment-style 'plain))
    +
    +(defun latex--comment-region (beg end &optional arg)
    +  (comment-region-default-1 beg end arg t))
     
     ;;;###autoload
     (define-derived-mode slitex-mode latex-mode "SliTeX"

The commit message doesn't explain why it changes `comment-style`.
Was that an oversight?


        Stefan






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice
  2022-05-29 21:57 bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-05-30 18:24 ` Lars Ingebrigtsen
  2022-05-31 12:26   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-30 18:24 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 55716

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> The commit message doesn't explain why it changes `comment-style`.
> Was that an oversight?

Yes, sort of.  The change is wrong, and should be fixed a different way,
I think.

The problem is that if you have this:

---
foo

bar
---

and comments out the blank line in the middle with `M-x comment-region',
you get

---
foo
          %%
bar
---

Which doesn't seem right, so I assumed that `indent' didn't work for
latex-mode.  But that's probably a bug in the `indent' version instead,
because `indent' should work in general.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice
  2022-05-30 18:24 ` Lars Ingebrigtsen
@ 2022-05-31 12:26   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-05-31 18:27     ` Lars Ingebrigtsen
  2022-05-31 18:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-05-31 12:26 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 55716

Lars Ingebrigtsen [2022-05-30 20:24:33] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> The commit message doesn't explain why it changes `comment-style`.
>> Was that an oversight?
>
> Yes, sort of.  The change is wrong, and should be fixed a different way,
> I think.
>
> The problem is that if you have this:
>
> ---
> foo
>
> bar
> ---
>
> and comments out the blank line in the middle with `M-x comment-region',
> you get
>
> ---
> foo
>           %%
> bar
> ---
>
> Which doesn't seem right, so I assumed that `indent' didn't work for
> latex-mode.

Before your patch, this didn't comment out anything since it skipped
empty lines, thus the problem didn't exist.

> But that's probably a bug in the `indent' version instead,
> because `indent' should work in general.

Yes, it's a new problem introduced by the new functionality of
commenting out empty lines (and it probably affects more than just the
`indent` style, since most styles (other than `plain`) try to indent the
comment, IIRC).


        Stefan






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice
  2022-05-31 12:26   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-05-31 18:27     ` Lars Ingebrigtsen
  2022-05-31 18:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-31 18:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 55716

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Before your patch, this didn't comment out anything since it skipped
> empty lines, thus the problem didn't exist.

Yes, that's the problem I was trying to fix.

>> But that's probably a bug in the `indent' version instead,
>> because `indent' should work in general.
>
> Yes, it's a new problem introduced by the new functionality of
> commenting out empty lines (and it probably affects more than just the
> `indent` style, since most styles (other than `plain`) try to indent the
> comment, IIRC).

Yup.  I've now reverted the change, and is reopening the bug report.  I
guess it has to be fixed in the various indenting styles instead.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice
  2022-05-31 12:26   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-05-31 18:27     ` Lars Ingebrigtsen
@ 2022-05-31 18:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-06-01  2:33       ` Lars Ingebrigtsen
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-05-31 18:54 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 55716

> Yes, it's a new problem introduced by the new functionality of
> commenting out empty lines (and it probably affects more than just the
> `indent` style, since most styles (other than `plain`) try to indent the
> comment, IIRC).

I suspect that the patch below would fix it.


        Stefan


diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 95adf9f90a1..ebf4357f4fe 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1177,6 +1177,10 @@ comment-region-internal
 		(setq max-indent (max max-indent (current-column)))
 		(not (or (eobp) (progn (forward-line) nil)))))
 
+          ;; In case there's only whitespace, we could try to look at
+          ;; surrounding text for inspiration, but we'll just use 0 instead.
+          (when (eq min-indent (point-max)) (setq min-indent 0))
+
 	  (setq max-indent
 		(+ max-indent (max (length cs) (length ccs))
                    ;; Inserting ccs can change max-indent by (1- tab-width)
@@ -1297,9 +1301,9 @@ comment-region-default-1
 	;; In Lisp and similar modes with one-character comment starters,
 	;; double it by default if `comment-add' says so.
 	;; If it isn't indented, triple it.
-	(if (and (null arg) (not multi-char))
-	    (setq numarg (* comment-add (if triple 2 1)))
-	  (setq numarg (1- (prefix-numeric-value arg))))
+	(setq numarg (if (and (null arg) (not multi-char))
+	                 (* comment-add (if triple 2 1))
+	               (1- (prefix-numeric-value arg))))
 
 	(comment-region-internal
 	 beg end






^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice
  2022-05-31 18:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-06-01  2:33       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-01  2:33 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 55716

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> I suspect that the patch below would fix it.

Makes sense to me, I think.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-01  2:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-29 21:57 bug#55716: 29.0.50; latex-mode overrides my `comment-style` choice Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-30 18:24 ` Lars Ingebrigtsen
2022-05-31 12:26   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-31 18:27     ` Lars Ingebrigtsen
2022-05-31 18:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-01  2:33       ` Lars Ingebrigtsen

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).