]> git.eshelyaron.com Git - emacs.git/commitdiff
New minor mode 'show-paren-local-mode'
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 11 Sep 2021 02:11:53 +0000 (05:11 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 11 Sep 2021 02:12:20 +0000 (05:12 +0300)
* lisp/paren.el (show-paren--delete-overlays):
New function, extracted from show-paren-mode.
(show-paren-local-mode): New minor mode.
(show-paren-mode): Update docstring to mention it (bug#29381).

* doc/emacs/programs.texi (Matching): Update show-paren-mode section.

doc/emacs/programs.texi
etc/NEWS
lisp/paren.el

index 09216c278b1b0aa3409368e4af5379bcdac1533c..522c092c3b37e2800bc969bd2048f43cb770fc33 100644 (file)
@@ -813,7 +813,8 @@ displayed.  The default is 102400.
 of automatic matching.  Whenever point is before an opening delimiter
 or after a closing delimiter, the delimiter, its matching delimiter,
 and optionally the text between them are highlighted.  To toggle Show
-Paren mode, type @kbd{M-x show-paren-mode}.  To customize it, type
+Paren mode, type @kbd{M-x show-paren-mode}.  To toggle it in single
+buffer, type @kbd{M-x show-paren-local-mode}.  To customize it, type
 @kbd{M-x customize-group @key{RET} paren-showing}.  The customizable
 options which control the operation of this mode include:
 
index ea7bb6b10ae526c0e653618089fa4d4a216ab75e..50cf0748b1ba2cbccf6c7607ff832d15a46663da 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -983,6 +983,10 @@ achieve that.
 It used to be enabled when Emacs is started in GUI mode but not when started
 in text mode.  The cursor still only actually blinks in GUI frames.
 
+** New minor mode 'show-paren-local-mode'.
+It serves as a local counterpart for 'show-paren-mode', allowing you
+to toggle it separately in different buffers.
+
 \f
 * Changes in Specialized Modes and Packages in Emacs 28.1
 
index a45a08abd36ab8306c415e1acf6730b56fa39ecf..708605f794439eaf53a085266cc315cf044a3302 100644 (file)
@@ -101,9 +101,11 @@ its position."
 (define-minor-mode show-paren-mode
   "Toggle visualization of matching parens (Show Paren mode).
 
-Show Paren mode is a global minor mode.  When enabled, any
-matching parenthesis is highlighted in `show-paren-style' after
-`show-paren-delay' seconds of Emacs idle time."
+When enabled, any matching parenthesis is highlighted in `show-paren-style'
+after `show-paren-delay' seconds of Emacs idle time.
+
+This is a global minor mode.  To toggle the mode in a single buffer,
+use `show-paren-local-mode'."
   :global t :group 'paren-showing
   ;; Enable or disable the mechanism.
   ;; First get rid of the old idle timer.
@@ -114,8 +116,28 @@ matching parenthesis is highlighted in `show-paren-style' after
                                 show-paren-delay t
                                 #'show-paren-function))
   (unless show-paren-mode
-    (delete-overlay show-paren--overlay)
-    (delete-overlay show-paren--overlay-1)))
+    (show-paren--delete-overlays)))
+
+(defun show-paren--delete-overlays ()
+  (delete-overlay show-paren--overlay)
+  (delete-overlay show-paren--overlay-1))
+
+;;;###autoload
+(define-minor-mode show-paren-local-mode
+  "Toggle `show-paren-mode' only in this buffer."
+  :variable (buffer-local-value 'show-paren-mode (current-buffer))
+  (cond
+   ((eq show-paren-mode (default-value 'show-paren-mode))
+    (unless show-paren-mode
+      (show-paren--delete-overlays))
+    (kill-local-variable 'show-paren-mode))
+   ((not (default-value 'show-paren-mode))
+    ;; Locally enabled, but globally disabled.
+    (show-paren-mode 1)                ; Setup the timer.
+    (setq-default show-paren-mode nil) ; But keep it globally disabled.
+    )
+   (t ;; Locally disabled only.
+    (show-paren--delete-overlays))))
 
 (defun show-paren--unescaped-p (pos)
   "Determine whether the paren after POS is unescaped."