Subject: Re: bug#79047: Add some multi-character pairs to some major modes.

From: Elijah Gabe Pérez <[email-masked]>
Date: Thu, 07 Aug 2025 23:37:35 -0600

Eli Zaretskii <[email-masked]> writes:

>> From: Elijah Gabe Pérez <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked],  [email-masked]
>> Date: Mon, 04 Aug 2025 14:03:58 -0600
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> > Can we please have a patch to install, which incorporates all the
>> > discussions we had here?
>> 
>> Sorry for the delay.
>> 
>> Here is the patch:
>
> Thanks.  It LGTM, but why isn't the change in Texinfo called out in
> NEWS, like you did with lua-ts-mode?

I'm not sure it needs to be in NEWS, it's a very small change.  In
lua-ts-mode I announced it because it uses a new option to enable the
feature.

However if it needs to be in NEWS, here is a patch which includes it:
>From dd672cc34d6842ccf32610d5b2c75cd197087b2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= <[email-masked]>
Date: Mon, 4 Aug 2025 12:47:18 -0600
Subject: [PATCH] Add multi-character pairs to lua-ts-mode and texinfo-mode.

* etc/NEWS: Add entry for lua-ts-mode changes.
* lisp/progmodes/lua-ts-mode.el
(lua-ts-auto-close-block-comments): New user option.
(lua-ts-mode): Add '--[[ ]]' pairs to 'electric-pair-pairs' only
if 'lua-ts-auto-close-block-comments' is non-nil.
* lisp/textmodes/texinfo.el (texinfo-mode): Add "`` ''" pairs to
'electric-pair-pairs'.
* test/lisp/progmodes/lua-ts-mode-tests.el
(lua-ts-test-auto-close-block-comments): Add new test.
---
 etc/NEWS                                 | 15 +++++++++++
 lisp/progmodes/lua-ts-mode.el            | 13 ++++++++++
 lisp/textmodes/texinfo.el                |  9 +++++++
 test/lisp/progmodes/lua-ts-mode-tests.el | 33 ++++++++++++++++++++++++
 4 files changed, 70 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index e12a9dcb127..ffbad5f0613 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -878,6 +878,13 @@ build tags for the test commands.
 The 'go-ts-mode-test-flags' user option is available to set a list of
 additional flags to pass to the go test command line.
 
+** Lua-ts mode
+
+---
+*** New user option 'lua-ts-auto-close-block-comments'.
+When non-nil, inserting a block comment "--[[" will close it by
+inserting its respective "]]".  By default, this is disabled.
+
 ** Java-ts mode
 
 +++
@@ -929,6 +936,14 @@ characters in CJK texts.  For example, 'A' is converted to 'Ａ', '1' is
 converted to '１', etc.  Companion commands 'halfwidth-region' and
 'halfwidth-word' perform the opposite conversion.
 
+** Texinfo Mode
+
+---
+*** texinfo-mode now can auto-close the ``'' pairs.
+Now inserting `` in 'texinfo-mode' will close it by inserting its
+respective ''.
+
+
 ** ASM mode
 
 ---
diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el
index 5e58d4c071d..3df36e329b3 100644
--- a/lisp/progmodes/lua-ts-mode.el
+++ b/lisp/progmodes/lua-ts-mode.el
@@ -74,6 +74,11 @@ lua-ts-indent-offset
   :safe 'natnump
   :version "30.1")
 
+(defcustom lua-ts-auto-close-block-comments nil
+  "If non-nil, inserting a block comment \"--[[\" will insert its respective \"]]\"."
+  :type 'boolean
+  :version "31.1")
+
 (defcustom lua-ts-luacheck-program "luacheck"
   "Location of the Luacheck program."
   :type 'file
@@ -675,6 +680,14 @@ lua-ts-mode
     (setq-local comment-start-skip "--\\s-*")
     (setq-local comment-end "")
 
+    ;; Pairs.
+    (when (and lua-ts-auto-close-block-comments
+               (boundp 'electric-pair-pairs))
+      (setq-local electric-pair-pairs
+                  (cons
+                   '("--\\[\\[" . "\n]")
+                   electric-pair-pairs)))
+
     ;; Font-lock.
     (setq-local treesit-font-lock-settings lua-ts--font-lock-settings)
     (setq-local treesit-font-lock-feature-list
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 58ab5f16806..e14c1669ae7 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -505,6 +505,15 @@ texinfo-mode
   (setq-local syntax-propertize-function texinfo-syntax-propertize-function)
   (setq-local add-log-current-defun-function #'texinfo-current-defun-name)
 
+  ;; Pairs settings
+  (when (boundp 'electric-pair-pairs)
+    (setq-local electric-pair-pairs
+                (cons
+                 ;; `` '' pairs
+                 '("\\(?:^\\|[[:space:]]\\)``"
+                   . "''")
+                 electric-pair-pairs)))
+
   ;; Outline settings.
   (setq-local outline-heading-alist
 	      ;; We should merge `outline-heading-alist' and
diff --git a/test/lisp/progmodes/lua-ts-mode-tests.el b/test/lisp/progmodes/lua-ts-mode-tests.el
index b14e9518451..b3267367e90 100644
--- a/test/lisp/progmodes/lua-ts-mode-tests.el
+++ b/test/lisp/progmodes/lua-ts-mode-tests.el
@@ -25,6 +25,7 @@
 (require 'hideshow)
 (require 'treesit)
 (require 'which-func)
+(require 'elec-pair)
 
 (ert-deftest lua-ts-test-indentation ()
   (skip-unless (treesit-ready-p 'lua t))
@@ -61,6 +62,38 @@ lua-ts-test-hideshow
     (should (= 0 (length (overlays-in (point-min) (point-max)))))
     (hs-minor-mode -1)))
 
+;; from: electric-tests.el
+(defun call-with-saved-electric-modes (fn)
+  (let ((saved-electric (if electric-pair-mode 1 -1))
+        (saved-layout (if electric-layout-mode 1 -1))
+        (saved-indent (if electric-indent-mode 1 -1))
+        (blink-paren-function nil))
+    (electric-pair-mode -1)
+    (electric-layout-mode -1)
+    (electric-indent-mode -1)
+    (unwind-protect
+        (funcall fn)
+      (electric-pair-mode saved-electric)
+      (electric-indent-mode saved-indent)
+      (electric-layout-mode saved-layout))))
+
+;; from: electric-tests.el
+(defmacro save-electric-modes (&rest body)
+  (declare (indent defun) (debug t))
+  `(call-with-saved-electric-modes (lambda () ,@body)))
+
+(ert-deftest lua-ts-test-auto-close-block-comments ()
+  (save-electric-modes
+   (with-temp-buffer
+     (dlet ((lua-ts-auto-close-block-comments t))
+       (electric-pair-mode 1)
+       (lua-ts-mode)
+       (insert "--")
+       (let ((last-command-event ?\[))
+         (ert-simulate-command '(self-insert-command 1))
+         (ert-simulate-command '(self-insert-command 1)))
+       (should (equal "--[[\n]]" (buffer-string)))))))
+
 (provide 'lua-ts-mode-tests)
 
 ;;; lua-ts-mode-tests.el ends here
-- 
2.50.1

-- 
- E.G via Gnus and Org.