Subject: bug#77823: 31.0.50; M-j regression since commit 4c6b1712a4d

From: Elijah Gabe Pérez <[email-masked]>
Date: Fri, 18 Apr 2025 21:46:34 -0600

Sean Whitton <[email-masked]> writes:

>>> In other modes, block comments might be the most common form of comment,
>>> however.
>>
>> AFAIK "the most common form of comment" is what `comment-start/end`
>> is for.
>>
>>
>>         Stefan "who still doesn't know what block-comment-start/end is for"
>
> I'm not sure either.  Maybe we should back out Elijah's change and
> implement the actual user functionality he wants (the new minor mode) in
> some other way?

In that case, I've written a patch for that:

>From 38d5b5db88651bbfcb443e207ea83b9414f3598d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= <[email-masked]>
Date: Fri, 18 Apr 2025 21:27:29 -0600
Subject: [PATCH] ; Revert block comments settings and use a different
 variable.

---
 lisp/electric.el                     | 24 ++++++++++++++----------
 lisp/emacs-lisp/lisp-mode.el         |  3 +--
 lisp/newcomment.el                   |  9 ++++-----
 lisp/nxml/nxml-mode.el               |  3 +--
 lisp/progmodes/c-ts-common.el        |  6 ++----
 lisp/progmodes/go-ts-mode.el         |  3 +--
 lisp/progmodes/js.el                 |  3 +--
 lisp/progmodes/json-ts-mode.el       |  3 +--
 lisp/progmodes/lua-ts-mode.el        |  3 +--
 lisp/progmodes/opascal.el            |  3 +--
 lisp/progmodes/pascal.el             |  3 +--
 lisp/progmodes/typescript-ts-mode.el |  3 +--
 lisp/textmodes/css-mode.el           |  5 +----
 lisp/textmodes/sgml-mode.el          |  3 +--
 14 files changed, 31 insertions(+), 43 deletions(-)

diff --git a/lisp/electric.el b/lisp/electric.el
index da5fa973757..c8c1756b5be 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -733,31 +733,35 @@ electric-quote-local-mode
 
 ;;; Electric comment block
 
+(defvar-local electric-block-comments nil
+  "List which contains block comment to insert `electric-block-comment-mode'.
+Must be in the form:
+ (START . END)
+Where START and END are respectively block comment start and end.")
+
 (defun electric-block-comment-post-self-insert-function ()
   "Function that `electric-block-comment' adds to `post-self-insert-hook'.
-This closes block comment with `block-comment-end' when `block-comment-start'
-is typed."
-  (when (and block-comment-start block-comment-end
-             ;; Check if we are exactly behind a `block-comment-start'
+This closes block comments according to `electric-block-comments'."
+  (when (and ;; Check if we are exactly behind the block comment start
              (save-excursion
                (save-match-data
-                 (re-search-backward (regexp-quote block-comment-start)
-                                     (- (point) (length block-comment-start))
+                 (re-search-backward (regexp-quote (car electric-block-comments))
+                                     (- (point) (length (car electric-block-comments)))
                                      t)))
              ;; And if there is not anything front us
              (looking-at-p (concat "[^[:space:]]")))
     (insert " ")
     (save-excursion
-      (insert (concat " " block-comment-end)))))
+      (insert (concat " " (cdr electric-block-comments))))))
 
 (define-minor-mode electric-block-comment-mode
   "Toggle automatic closing of block comments (Electric Block Comment mode).
 
-When enabled, typing `block-comment-start' closes it inserting their
-corresponding `block-comment-end'."
+When enabled, typing the beginning of a block comment closes it inserting their
+corresponding block comment end."
   :group 'electricity
   :version "31.1"
-  (if electric-block-comment-mode
+  (if (and electric-block-comment-mode (consp electric-block-comments))
       (add-hook 'post-self-insert-hook
                 #'electric-block-comment-post-self-insert-function 10 t)
     (remove-hook 'post-self-insert-hook
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index f27baae1b36..4c856338a64 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -828,8 +828,7 @@ lisp-mode
 	      "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
   (setq-local comment-end-skip "[ \t]*\\(\\s>\\||#\\)")
   (setq-local font-lock-comment-end-skip "|#")
-  (setq-local block-comment-start "#|")
-  (setq-local block-comment-end "|#")
+  (setq-local electric-block-comments '("#|" . "|#"))
   (setq imenu-case-fold-search t))
 
 (defun lisp-find-tag-default ()
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index eb36f91104d..945187e863f 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -56,6 +56,7 @@
 ;; - spill auto-fill of comments onto the end of the next line.
 ;; - uncomment-region with a consp (for blocks) or somehow make the
 ;;   deletion of continuation markers less dangerous.
+;; - drop block-comment-<foo> unless it's really used.
 ;; - uncomment-region on a subpart of a comment.
 ;; - support gnu-style "multi-line with space in continue".
 ;; - somehow allow comment-dwim to use the region even if transient-mark-mode
@@ -182,11 +183,9 @@ uncomment-region-function
 Applicable at least in modes for languages like fixed-format Fortran where
 comments always start in column zero.")
 
-(defvar block-comment-start nil
-  "String to insert to start a new block comment, or nil if no supported.")
-
-(defvar block-comment-end nil
-  "String to insert to end a new block comment, or nil if no supported.")
+;; ?? never set
+(defvar block-comment-start nil)
+(defvar block-comment-end nil)
 
 (defvar comment-quote-nested t
   "Non-nil if nested comments should be quoted.
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 994b2779d1a..66a1e82ec27 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -529,8 +529,7 @@ nxml-mode
   (setq-local comment-start-skip "<!--[ \t\r\n]*")
   (setq-local comment-end "-->")
   (setq-local comment-end-skip "[ \t\r\n]*-->")
-  (setq-local block-comment-start "<!--")
-  (setq-local block-comment-end "-->")
+  (setq-local electric-block-comments '("<!--" . "-->"))
   (setq-local comment-line-break-function #'nxml-newline-and-indent)
   (setq-local comment-quote-nested-function #'nxml-comment-quote-nested)
   (setq-local comment-continue "") ; avoid double-hyphens as a padding
diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el
index 56c8ae49000..409277696a7 100644
--- a/lisp/progmodes/c-ts-common.el
+++ b/lisp/progmodes/c-ts-common.el
@@ -282,8 +282,7 @@ c-ts-common-comment-setup
  - `comment-end'
  - `comment-start-skip'
  - `comment-end-skip'
- - `block-comment-start'
- - `block-comment-end'
+ - `electric-block-comments'
  - `adaptive-fill-mode'
  - `adaptive-fill-first-line-regexp'
  - `paragraph-start'
@@ -300,8 +299,7 @@ c-ts-common-comment-setup
               (rx (* (syntax whitespace))
                   (group (or (syntax comment-end)
                              (seq (+ "*") "/")))))
-  (setq-local block-comment-start "/*")
-  (setq-local block-comment-end "*/")
+  (setq-local electric-block-comments '("/*" . "*/"))
   (setq-local adaptive-fill-mode t)
   (setq-local adaptive-fill-function #'c-ts-common--adaptive-fill-prefix)
   ;; Always accept * or | as prefix, even if there's only one line in
diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index e1736fe9208..17c7b19f3be 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -692,8 +692,7 @@ go-work-ts-mode
     (setq-local comment-start "// ")
     (setq-local comment-end "")
     (setq-local comment-start-skip (rx "//" (* (syntax whitespace))))
-    (setq-local block-comment-start "/*")
-    (setq-local block-comment-end "*/")
+    (setq-local electric-block-comments '("/*" . "*/"))
 
     ;; Indent.
     (setq-local indent-tabs-mode t
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 243329de7ae..2a19be0df56 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3781,8 +3781,7 @@ js--mode-setup
   (setq-local comment-start "// ")
   (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
   (setq-local comment-end "")
-  (setq-local block-comment-start "/*")
-  (setq-local block-comment-end "*/")
+  (setq-local electric-block-comments '("/*" . "*/"))
   (setq-local fill-paragraph-function #'js-fill-paragraph)
   (setq-local normal-auto-fill-function #'js-do-auto-fill)
 
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 9d374119810..a5d0c6ce8ba 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -142,8 +142,7 @@ json-ts-mode
   (setq-local comment-start "// ")
   (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
   (setq-local comment-end "")
-  (setq-local block-comment-start "/*")
-  (setq-local block-comment-end "*/")
+  (setq-local electric-block-comments '("/*" . "*/"))
 
   ;; Electric
   (setq-local electric-indent-chars
diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el
index dc129277778..553072e72f2 100644
--- a/lisp/progmodes/lua-ts-mode.el
+++ b/lisp/progmodes/lua-ts-mode.el
@@ -673,8 +673,7 @@ lua-ts-mode
     (setq-local comment-start "--")
     (setq-local comment-start-skip "--\\s-*")
     (setq-local comment-end "")
-    (setq-local block-comment-start "--[[" )
-    (setq-local block-comment-end "]]")
+    (setq-local electric-block-comments '("--[[" . "]]"))
 
     ;; Font-lock.
     (setq-local treesit-font-lock-settings lua-ts--font-lock-settings)
diff --git a/lisp/progmodes/opascal.el b/lisp/progmodes/opascal.el
index 9dcaff9645e..08458afa29c 100644
--- a/lisp/progmodes/opascal.el
+++ b/lisp/progmodes/opascal.el
@@ -1768,8 +1768,7 @@ opascal-mode
   (setq-local comment-start "// ")
   (setq-local comment-start-skip "\\(?://\\|(\\*\\|{\\)[ \t]*")
   (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*)\\|}\\)")
-  (setq-local block-comment-start "(*")
-  (setq-local block-comment-end "*)"))
+  (setq-local electric-block-comments '("(*" . "*)")))
 
 (provide 'opascal)
 ;;; opascal.el ends here
diff --git a/lisp/progmodes/pascal.el b/lisp/progmodes/pascal.el
index 113cf68c8d6..901e2e0cc47 100644
--- a/lisp/progmodes/pascal.el
+++ b/lisp/progmodes/pascal.el
@@ -348,8 +348,7 @@ pascal-mode
   (setq-local comment-start "{")
   (setq-local comment-start-skip "(\\*+ *\\|{ *")
   (setq-local comment-end "}")
-  (setq-local block-comment-start "(*")
-  (setq-local block-comment-end "*)")
+  (setq-local electric-block-comments '("(*" . "*)"))
   (add-hook 'completion-at-point-functions 'pascal-completions-at-point nil t)
   ;; Font lock support
   (setq-local font-lock-defaults '(pascal-font-lock-keywords nil t))
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index a2049ba2d64..476fb952131 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -665,8 +665,7 @@ tsx-ts-mode
     ;; Comments.
     (setq-local comment-start "// ")
     (setq-local comment-end "")
-    (setq-local block-comment-start "/*")
-    (setq-local block-comment-end "*/")
+    (setq-local electric-block-comments '("/*" . "*/"))
     (setq-local comment-start-skip (rx (or (seq "/" (+ "/"))
                                            (seq "/" (+ "*")))
                                        (* (syntax whitespace))))
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index e3f295c3412..2cfe199da38 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1858,8 +1858,7 @@ css-base-mode
   (setq-local comment-start-skip "/\\*+[ \t]*")
   (setq-local comment-end "*/")
   (setq-local comment-end-skip "[ \t]*\\*+/")
-  (setq-local block-comment-start "/*")
-  (setq-local block-comment-end "*/")
+  (setq-local electric-block-comments '("/*" . "*/"))
   (setq-local electric-indent-chars
               (append css-electric-keys electric-indent-chars))
   ;; The default "." creates ambiguity with class selectors.
@@ -2083,8 +2082,6 @@ scss-mode
   "Major mode to edit \"Sassy CSS\" files."
   (setq-local comment-start "// ")
   (setq-local comment-end "")
-  (setq-local block-comment-start "/*")
-  (setq-local block-comment-end "*/")
   (setq-local comment-continue " *")
   (setq-local comment-start-skip "/[*/]+[ \t]*")
   (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)")
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 4dbc6839c68..f4737e28afa 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -622,8 +622,7 @@ sgml-mode
   (setq-local indent-line-function #'sgml-indent-line)
   (setq-local comment-start "<!-- ")
   (setq-local comment-end " -->")
-  (setq-local block-comment-start "<!--")
-  (setq-local block-comment-end "-->")
+  (setq-local electric-block-comments '("<!--" . "-->"))
   (setq-local comment-indent-function #'sgml-comment-indent)
   (setq-local comment-line-break-function #'sgml-comment-indent-new-line)
   (setq-local skeleton-further-elements '((completion-ignore-case t)))
-- 
2.49.0

-- 
                                          - E.G via GNU Emacs and Org.