Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue

From: Leo Liu <[email-masked]>
Date: Fri, 10 Jan 2014 12:11:26 +0800

On 2014-01-10 11:24 +0800, Leo Liu wrote:
> But maybe eldoc-post-insert-mode (maybe even a new name
> eldoc-edit-mode?) can check on char changes instead? Is this better?

Stefan, do you think this is better? With the following patch,
eldoc-edit-mode no longer depends on post-self-insert-hook.

diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 3a7f08f5..1da6c0ab 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -173,19 +173,29 @@ (define-minor-mode eldoc-mode
    (remove-hook 'post-command-hook 'eldoc-schedule-timer)
    (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area)))
 
+(defvar-local eldoc-edit-should-print nil)
+
+(defun eldoc-after-change (beg end len)
+  (and (or (> len 0) (and (zerop len) (> end beg)))
+       (setq eldoc-edit-should-print t)))
+
 ;;;###autoload
-(define-minor-mode eldoc-post-insert-mode nil
+(define-minor-mode eldoc-edit-mode nil
   :group 'eldoc :lighter (:eval (if eldoc-mode ""
-				  (concat eldoc-minor-mode-string "|i")))
+				  (concat eldoc-minor-mode-string "|e")))
   (setq eldoc-last-message nil)
   (let ((prn-info (lambda ()
-		    (unless eldoc-mode
-		      (eldoc-print-current-symbol-info)))))
-    (if eldoc-post-insert-mode
-	(add-hook 'post-self-insert-hook prn-info nil t)
-      (remove-hook 'post-self-insert-hook prn-info t))))
+		    (when (and (not eldoc-mode) eldoc-edit-should-print)
+		      (ignore-errors (eldoc-print-current-symbol-info))
+		      (setq eldoc-edit-should-print nil)))))
+    (if eldoc-edit-mode
+	(progn
+	  (add-hook 'post-command-hook prn-info nil t)
+	  (add-hook 'after-change-functions 'eldoc-after-change nil t))
+      (remove-hook 'post-command-hook prn-info t)
+      (remove-hook 'after-change-functions 'eldoc-after-change t))))
 
-(add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-post-insert-mode)
+(add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-edit-mode)
 
 ;;;###autoload
 (defun turn-on-eldoc-mode ()
@@ -309,7 +319,7 @@ (defvar eldoc-documentation-function nil
 
 (defun eldoc-print-current-symbol-info ()
   (condition-case err
-      (and (or (eldoc-display-message-p) eldoc-post-insert-mode)
+      (and (or (eldoc-display-message-p) eldoc-edit-mode)
 	   (if eldoc-documentation-function
 	       (eldoc-message (funcall eldoc-documentation-function))
 	     (let* ((current-symbol (eldoc-current-symbol))