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

From: Stefan Monnier <[email-masked]>
Date: Sat, 19 Apr 2025 00:41:01 -0400

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

IIRC, the recent changes also added setting to
`block-comment-start/end` in CC-modes, so there may need to be more reversals.

>  (define-minor-mode electric-block-comment-mode
>    "Toggle automatic closing of block comments (Electric Block Comment mode).
>  
> +When enabled, typing the beginning of a block comment closes it inserting their
> +corresponding block comment end."

So, IIUC what is meant by "block comment" here is a comment that's not
closed by the next EOL but by some other sequence of characters.

Interesting cases to consider:

- In SNMP mode, IIRC, comments take the shape of

       -- a comment --

  so you have to check `syntax-ppss` to figure out if the `--` that was
  just inserted was a comment starter or ender.

- In OPascal mode there is more than one kind of "block
  comment":

        { a comment }
        (* another comment *)
        /* yet another comment */

  so your `electric-block-comments` should probably support not just
  a single pair but a list of pairs.

- It might make sense to extend this to related constructs and/or to
  merge it into `electric-pair-mode`.
  By related constructs, I'm thinking of things like [OCaml's
  quotations](https://caml.inria.fr/pub/docs/tutorial-camlp4/tutorial004.html)
  that take the form `<:FOO<...>>` or [OCaml's quoted
  strings](https://ocaml.org/manual/5.2/lex.html#quoted-string-id)
  that look like `{FOO|...|FOO}`.

        Stefan