GNU bug report logs - #19528
25.0.50; Add electric-pair-local-mode

Previous Next

Package: emacs;

Reported by: Tom Willemse <tom <at> ryuslash.org>

Date: Wed, 7 Jan 2015 15:06:02 UTC

Severity: wishlist

Found in version 25.0.50

Done: joaotavora <at> gmail.com (João Távora)

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Tom Willemse <tom <at> ryuslash.org>
Subject: bug#19528: closed (Re: electric-pair-mode as a minor mode?)
Date: Sat, 28 Mar 2015 15:48:03 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#19528: 25.0.50; Add electric-pair-local-mode

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 19528 <at> debbugs.gnu.org.

-- 
19528: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19528
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: joaotavora <at> gmail.com (João Távora)
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Yuri D'Elia <wavexx <at> thregr.org>, Tom Willemse <tom <at> ryuslash.org>,
 19528-done <at> debbugs.gnu.org, emacs-devel <at> gnu.org
Subject: Re: electric-pair-mode as a minor mode?
Date: Sat, 28 Mar 2015 15:47:32 +0000
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> Tom Willemse <tom <at> ryuslash.org> writes:
>> Not to be a nuisance, but I wrote a patch for that some time ago and I'm
>> still waiting on a response:
>> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19528
>
> João, can you take a look at that?

Looks pretty good so I just pushed:

    commit 40b3dcd2c06e30048be0bdc32861148a53660c90
    Author: Tom Willemse <tom <at> ryuslash.org>
    Date:   Sat Mar 28 14:43:33 2015 +0000
     
        New `electric-pair-local-mode'
        
        Fixes: big#19528
        
        * lisp/elec-pair.el (electric-pair-local-mode): New command.
        (electric-pair-mode): Mention `electric-pair-local-mode' in the
        docstring.

Didn't check for Tom's copyright assignment since I believe it counts as
a trivial patch (<15loc).

João

[Message part 3 (message/rfc822, inline)]
From: Tom Willemse <tom <at> ryuslash.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; Add electric-pair-local-mode
Date: Wed, 07 Jan 2015 16:05:04 +0100
[Message part 4 (text/plain, inline)]
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.

[0001-Add-electric-pair-local-mode.patch (text/x-diff, inline)]
From b8fd61d4b380cddb8a5c51c392c6aa4ac9e3d1e5 Mon Sep 17 00:00:00 2001
From: Tom Willemse <tom <at> ryuslash.org>
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  <tom <at> ryuslash.org>
+
+	* 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  <sds <at> gnu.org>
 
 	* 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


This bug report was last modified 10 years and 46 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.