From: Eshel Yaron Date: Sat, 21 Sep 2024 10:15:16 +0000 (+0200) Subject: Teach Electric Pair mode about prefix arguments X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cc9c7c45a25d51bdaf0b82a9ea1d1d28588303e5;p=emacs.git Teach Electric Pair mode about prefix arguments * lisp/elec-pair.el (electric-pair--insert): New arg TIMES. (electric-pair-inhibit-if-helps-balance) (electric-pair-post-self-insert-function) (electric-pair-open-newline-between-pairs-psif) (electric-pair-skip-if-helps-balance): Respect prefix arg. (electric-pair-delete-pair): Delete ARG chars, not just 1. * test/lisp/electric-tests.el (autowrapping-multi-1) (autowrapping-multi-2): New tests. * doc/emacs/programs.texi (Matching): Mention prefix arg support in Electric Pair mode documentation. * etc/NEWS: Announce it. (Bug#72437) (cherry picked from commit a7192fd7b7355f13ff3002dba14c6acdabad5b5e) --- diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index d5be29dfd23..7694ed1a706 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -1029,7 +1029,9 @@ one, no insertion takes places, and that position is simply skipped over. If the region is active (@pxref{Mark}), insertion of a delimiter operates on the region: the characters in the region are enclosed in a pair of matching delimiters, leaving point after the -delimiter you typed. +delimiter you typed. If you provide a prefix argument when inserting +a delimiter, the numeric value of that prefix argument specifies the +number of pairs to insert. These variables control additional features of Electric Pair mode: diff --git a/etc/NEWS b/etc/NEWS index 541e5edfe80..30b8c8fae98 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -133,6 +133,12 @@ This option, if non-nil, makes 'delete-pair' push a mark at the end of the region enclosed by the deleted delimiters. This makes it easy to act on that region. For example, we can highlight it using 'C-x C-x'. ++++ +** Electric Pair mode can now pair multiple delimiters at once. +You can now insert or wrap text with multiple sets of parentheses and +other matching delimiters at once with Electric Pair mode, by providing +a prefix argument when inserting one of the delimiters. + * Changes in Specialized Modes and Packages in Emacs 31.1 diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el index 41f0550e711..8d10ea80073 100644 --- a/test/lisp/electric-tests.el +++ b/test/lisp/electric-tests.el @@ -628,6 +628,22 @@ baz\"\"" (skip-chars-backward "\"") (mark-sexp -1))) +(define-electric-pair-test autowrapping-multi-1 + "foo" "(" :expected-string "(((((foo)))))" :expected-point 6 + :bindings '((current-prefix-arg . 5)) + :fixture-fn (lambda () + (electric-pair-mode 1) + (mark-sexp 1))) + +(define-electric-pair-test autowrapping-multi-2 + "foo" ")" :expected-string "(((((foo)))))" :expected-point 14 + :bindings '((current-prefix-arg . 5)) + :fixture-fn (lambda () + (electric-pair-mode 1) + (goto-char (point-max)) + (skip-chars-backward "\"") + (mark-sexp -1))) + ;;; Electric quotes (define-electric-pair-test electric-quote-string