bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36539: elec-pair.elc gets surreptitiously loaded (almost) unconditio


From: Noam Postavsky
Subject: bug#36539: elec-pair.elc gets surreptitiously loaded (almost) unconditionally at start up.
Date: Sat, 13 Jul 2019 18:41:23 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2.90 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

> Any reasons this is not yet installed on master?

Actually, I noticed a problem with it: electric-pair-mode is a global
mode, so using the local value of the hook isn't right.  I think the
updated patch below is correct.

>From ebec942f5734f2ce6916dc14706704dc1a93e62d Mon Sep 17 00:00:00 2001
From: Noam Postavsky <address@hidden>
Date: Sun, 7 Jul 2019 12:22:37 -0400
Subject: [PATCH] Don't load elec-pair in elisp-mode (Bug#36539)

* lisp/progmodes/elisp-mode.el (emacs-lisp-set-electric-text-pairs):
New function.
(emacs-lisp-mode): Add it to electric-pair-mode-hook, if elec-pair
hasn't been loaded yet.
---
 lisp/progmodes/elisp-mode.el | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index c86277a309..5204c78131 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -233,6 +233,17 @@ emacs-lisp-mode-hook
   :type 'hook
   :group 'lisp)
 
+(defun emacs-lisp-set-electric-text-pairs ()
+  (defvar electric-pair-text-pairs)
+  (let ((elisp-pairs (append '((?\` . ?\') (?‘ . ?’))
+                             electric-pair-text-pairs)))
+    (save-current-buffer
+      (dolist (buf (buffer-list))
+        (set-buffer buf)
+        (when (derived-mode-p 'emacs-lisp-mode)
+          (setq-local electric-pair-text-pairs elisp-pairs)))))
+  (remove-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs))
+
 ;;;###autoload
 (define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp"
   "Major mode for editing Lisp code to run in Emacs.
@@ -245,12 +256,12 @@ emacs-lisp-mode
   (defvar project-vc-external-roots-function)
   (lisp-mode-variables nil nil 'elisp)
   (add-hook 'after-load-functions #'elisp--font-lock-flush-elisp-buffers)
-  (unless noninteractive
-    (require 'elec-pair)
-    (defvar electric-pair-text-pairs)
-    (setq-local electric-pair-text-pairs
-                (append '((?\` . ?\') (?‘ . ?’)) electric-pair-text-pairs))
-    (setq-local electric-quote-string t))
+  (if (boundp 'electric-pair-text-pairs)
+      (setq-local electric-pair-text-pairs
+                  (append '((?\` . ?\') (?‘ . ?’))
+                          electric-pair-text-pairs))
+    (add-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs))
+  (setq-local electric-quote-string t)
   (setq imenu-case-fold-search nil)
   (add-function :before-until (local 'eldoc-documentation-function)
                 #'elisp-eldoc-documentation-function)
-- 
2.11.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]