Subject: bug#36539: elec-pair.elc gets surreptitiously loaded (almost) unconditionally at start up.

From: Noam Postavsky <[email-masked]>
Date: Sun, 07 Jul 2019 14:47:51 -0400

Alan Mackenzie <[email-masked]> writes:

> Just as a matter of interest, I commented out the pertinent form in
> emacs-lisp-mode, did a make bootstrap, emacs -Q, and elec-pair.elc was
> still present in my Emacs.  :-(
>
> I don't know why, or how, but it is.  With your patch (below), have you
> tested whether or not elec-pair.elc hasn't been loaded on starting
> Emacs?  If it hasn't been loaded, you've found some trick that eludes
> me.

How are you checking?  M-: (featurep 'elec-pair) RET returns nil for me.

Assuming you have help-enable-completion-auto-load set to t (the
default), it's pretty easy to load various things just by hitting TAB in
response to describe-function or describe-variable.

>> +  (add-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs t)
>
> Shouldn't that be .....-text pairs nil t), to make a local value of the
>                                    ^^^
> hook?  The remove-hook (above) seems to be expecting a local value.

Oops, yes, thanks for catching that.

>> +  (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
>> 
>
> As a matter of interest, what is that 2.11.0 that I keep seeing at the
> bottom of patches?

Looks like 'git format-patch' adds the git version at the bottom.

$ git --version
git version 2.11.0

>From c3a99c7260e07692c8d02a9cd9d38f6ef188311c Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
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.
---
 lisp/progmodes/elisp-mode.el | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index c86277a309..78a87f2d32 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -233,6 +233,12 @@ emacs-lisp-mode-hook
   :type 'hook
   :group 'lisp)
 
+(defun emacs-lisp-set-electric-text-pairs ()
+  (defvar electric-pair-text-pairs)
+  (setq-local electric-pair-text-pairs
+              (append '((?\` . ?\') (?‘ . ?’)) electric-pair-text-pairs))
+  (remove-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs t))
+
 ;;;###autoload
 (define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp"
   "Major mode for editing Lisp code to run in Emacs.
@@ -245,12 +251,8 @@ 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))
+  (add-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs nil t)
+  (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