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

From: Elijah Gabe Pérez <[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:

>From 94a413740bf19dc3d86a10fad3786c7632992239 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                                 |  7 +++++++
 lisp/progmodes/lua-ts-mode.el            | 13 +++++++++++++
 lisp/textmodes/texinfo.el                |  9 +++++++++
 test/lisp/progmodes/lua-ts-mode-tests.el | 12 ++++++++++++
 4 files changed, 41 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index e12a9dcb127..253eda9edb2 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 inserting
+its respective "]]".  By default, this is disabled.
+
 ** Java-ts 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..44940335776 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,17 @@ lua-ts-test-hideshow
     (should (= 0 (length (overlays-in (point-min) (point-max)))))
     (hs-minor-mode -1)))
 
+(ert-deftest lua-ts-test-auto-close-block-comments ()
+  (with-temp-buffer
+    (setq-local lua-ts-auto-close-block-comments t)
+    (electric-pair-local-mode)
+    (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.