Subject: 25.0.50; Add electric-pair-local-mode

From: Tom Willemse <[email-masked]>
Date: Wed, 07 Jan 2015 16:05:04 +0100

Hello Emacs devs,

Attached is a patch to add `electric-pair-local-mode'. It's almost an
exact copy of `electric-indent-local-mode'. I like using
`electric-pair-mode', except in Lisp-like languages where I prefer
paredit, so having a local mode is useful to me.

I've tried mentioning it in the same places as
`electric-indent-local-mode', I hope I did it right.

Please let me know what you think.

>From b8fd61d4b380cddb8a5c51c392c6aa4ac9e3d1e5 Mon Sep 17 00:00:00 2001
From: Tom Willemse <[email-masked]>
Date: Wed, 7 Jan 2015 04:04:06 +0100
Subject: [PATCH] Add electric-pair-local-mode

* elec-pair.el (electric-pair-local-mode): New command.
(electric-pair-mode): Mention `electric-pair-local-mode' in the
docstring.
---
 doc/emacs/programs.texi |  4 +++-
 etc/NEWS                |  5 +++++
 lisp/ChangeLog          |  6 ++++++
 lisp/elec-pair.el       | 16 +++++++++++++++-
 4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi
index 8f6111d..248e72c 100644
--- a/doc/emacs/programs.texi
+++ b/doc/emacs/programs.texi
@@ -870,7 +870,9 @@ mode to skip whitespace forward before deciding whether to skip over
 the closing delimiter.
 @end itemize
 
-To toggle Electric Pair mode, type @kbd{M-x electric-pair-mode}.
+To toggle Electric Pair mode, type @kbd{M-x electric-pair-mode}.  To
+toggle the mode in a single buffer, use @kbd{M-x
+electric-pair-local-mode}.
 
 @node Comments
 @section Manipulating Comments
diff --git a/etc/NEWS b/etc/NEWS
index 4d704ce..8709c39 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -469,6 +469,11 @@ As a result of the above, these commands are now obsolete:
 `find-tag-other-window', `find-tag-other-frame', `find-tag-regexp',
 `tags-apropos' and `tags-loop-continue'.
 
+** Electric Pair mode
+
++++
+*** New buffer-local `electric-pair-local-mode'.
+
 ** Obsolete packages
 
 ---
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 71889ce..646bd90 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2015-01-07  Tom Willemse  <[email-masked]>
+
+	* elec-pair.el (electric-pair-local-mode): New command.
+	(electric-pair-mode): Mention `electric-pair-local-mode' in the
+	docstring.
+
 2015-01-06  Sam Steingold  <[email-masked]>
 
 	* shell.el (shell-display-buffer-actions): Remove,
diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
index 2cede62..70f3a8a 100644
--- a/lisp/elec-pair.el
+++ b/lisp/elec-pair.el
@@ -557,7 +557,8 @@ (define-minor-mode electric-pair-mode
 
 Electric Pair mode is a global minor mode.  When enabled, typing
 an open parenthesis automatically inserts the corresponding
-closing parenthesis.  (Likewise for brackets, etc.)."
+closing parenthesis.  (Likewise for brackets, etc.). To toggle
+the mode in a single buffer, use `electric-pair-local-mode'."
   :global t :group 'electricity
   (if electric-pair-mode
       (progn
@@ -571,6 +572,19 @@ (define-minor-mode electric-pair-mode
     (remove-hook 'self-insert-uses-region-functions
                  #'electric-pair-will-use-region)))
 
+;;;###autoload
+(define-minor-mode electric-pair-local-mode
+  "Toggle `electric-pair-mode' only in this buffer."
+  :variable (buffer-local-value 'electric-pair-mode (current-buffer))
+  (cond
+   ((eq electric-pair-mode (default-value 'electric-pair-mode))
+    (kill-local-variable 'electric-pair-mode))
+   ((not (default-value 'electric-pair-mode))
+    ;; Locally enabled, but globally disabled.
+    (electric-pair-mode 1)                ; Setup the hooks.
+    (setq-default electric-pair-mode nil) ; But keep it globally disabled.
+    )))
+
 (provide 'elec-pair)
 
 ;;; elec-pair.el ends here
-- 
2.2.1