GNU bug report logs - #16346
24.3; electric-pair-mode close-paren issue

Previous Next

Package: emacs;

Reported by: Leo Liu <sdl.web <at> gmail.com>

Date: Sun, 5 Jan 2014 02:58:02 UTC

Severity: normal

Found in version 24.3

Done: Leo Liu <sdl.web <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16346 in the body.
You can then email your comments to 16346 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to joaotavora <at> gmail.com, monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sun, 05 Jan 2014 02:58:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leo Liu <sdl.web <at> gmail.com>:
New bug report received and forwarded. Copy sent to joaotavora <at> gmail.com, monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Sun, 05 Jan 2014 02:58:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; electric-pair-mode close-paren issue
Date: Sun, 05 Jan 2014 10:57:02 +0800
In some of the eldoc-documentation-function's when used by
eldoc-post-insert-mode, for example octave-eldoc-function, the eldoc
(calltip) is only shown after inserting the ( and inside the ().

The new feature introduced to electric-pair-mode fails the above by
triggering two successive runs of post-self-insert-hook, one for
inserting the open-paren and the other for the close-paren. Thus the
eldoc message is immediately cleared by the second run.

My impression is if a user didn't type ) it should not trigger
post-self-insert-hook. WDYT?

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sun, 05 Jan 2014 11:52:02 GMT) Full text and rfc822 format available.

Message #8 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: joaotavora <at> gmail.com (João Távora)
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sun, 05 Jan 2014 11:49:34 +0000
Leo Liu <sdl.web <at> gmail.com> writes:

> In some of the eldoc-documentation-function's when used by
> eldoc-post-insert-mode, for example octave-eldoc-function, the eldoc
> (calltip) is only shown after inserting the ( and inside the ().
>
> The new feature introduced to electric-pair-mode fails the above by
> triggering two successive runs of post-self-insert-hook, one for
> inserting the open-paren and the other for the close-paren. Thus the
> eldoc message is immediately cleared by the second run.

Are you sure this is only with the new features?

> My impression is if a user didn't type ) it should not trigger
> post-self-insert-hook. WDYT?

The idea of inserting matchers with
self-insert-command is to allow other hooks to run recursively, but it
has some problems as described by the FIXME's that I found before my
changes electric-pair-mode.

Indeed, it wasn't "self inserted" it, it was "electric
inserted". electric-pair--insert is this abstraction and it's used to
insert matchers. It does some rebinding of vars to keep other modes like
blink-matching-paren from interfering. Maybe eldoc-mode deserves a place
in there?

   (defun electric-pair--insert (char)
     (let ((last-command-event char)
           (blink-matching-paren nil)
           (electric-pair-mode nil)
           (eldoc-mode nil))
       (self-insert-command 1)))

Haven't tested though... Will have little time the coming weeks, sorry.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sun, 05 Jan 2014 15:31:01 GMT) Full text and rfc822 format available.

Message #11 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: joaotavora <at> gmail.com (João Távora)
Cc: 16346 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sun, 05 Jan 2014 23:30:47 +0800
On 2014-01-05 19:49 +0800, João Távora wrote:
> Are you sure this is only with the new features?

Yes.

>> My impression is if a user didn't type ) it should not trigger
>> post-self-insert-hook. WDYT?
>
> The idea of inserting matchers with
> self-insert-command is to allow other hooks to run recursively, but it
> has some problems as described by the FIXME's that I found before my
> changes electric-pair-mode.

But this may break the other half of stuff using post-self-insert-hook?

> Indeed, it wasn't "self inserted" it, it was "electric
> inserted". electric-pair--insert is this abstraction and it's used to
> insert matchers. It does some rebinding of vars to keep other modes like
> blink-matching-paren from interfering. Maybe eldoc-mode deserves a place
> in there?
>
>    (defun electric-pair--insert (char)
>      (let ((last-command-event char)
>            (blink-matching-paren nil)
>            (electric-pair-mode nil)
>            (eldoc-mode nil))
>        (self-insert-command 1)))
>
> Haven't tested though... Will have little time the coming weeks, sorry.

Add (eldoc-post-insert-mode nil) fixes this bug.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sun, 05 Jan 2014 19:28:01 GMT) Full text and rfc822 format available.

Message #14 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: joaotavora <at> gmail.com (João Távora)
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sun, 05 Jan 2014 19:25:32 +0000
Leo Liu <sdl.web <at> gmail.com> writes:
>> Are you sure this is only with the new features?
> Yes.

Funny, `electric-pair--insert' was also being called with the previous
`electric-pair-mode' to insert matchers and it didn't change. The
previous version did sometimes match ( didn't it? :)

> But this may break the other half of stuff using
> post-self-insert-hook?

Yes, more or less I think that was the gist of the FIXME notes that
Stefan had added there. OTOH, it's useful, for example, when newlines
are inserted. electric-indent-mode has a chance to kick in there.

Let's look at this this way, if the user pressed `(', `)' and `C-b' in
sucession, what would that "half of stuff" do? This is what
electric-pair more or less emulates.

On the other hand, we can decide to insert matchers using simple
`insert'. Stefan any thoughts?

> Add (eldoc-post-insert-mode nil) fixes this bug.

Nice, looks good, maybe you could commit this and maybe add a test or
two. I can only look at this at the end of the week, sorry.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sun, 05 Jan 2014 23:14:03 GMT) Full text and rfc822 format available.

Message #17 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sun, 05 Jan 2014 18:13:28 -0500
> Add (eldoc-post-insert-mode nil) fixes this bug.

FWIW, I find eldoc-post-insert-mode suffers from many problems.
I'd appreciate if someone who likes eldoc-post-insert-mode explains to
me the advantages it sees in comparison to the "default"
post-command-hook mode, so we can maybe find a better way to get the
same result.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Mon, 06 Jan 2014 00:49:01 GMT) Full text and rfc822 format available.

Message #20 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16346 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Mon, 06 Jan 2014 08:48:24 +0800
On 2014-01-06 07:13 +0800, Stefan Monnier wrote:
> FWIW, I find eldoc-post-insert-mode suffers from many problems.
> I'd appreciate if someone who likes eldoc-post-insert-mode explains to
> me the advantages it sees in comparison to the "default"
> post-command-hook mode, so we can maybe find a better way to get the
> same result.

I might be the only one using it (exclusively) :( but I am open to
change.

The idea behind eldoc-post-insert-mode is not to show the eldoc messages
all the time which can be kinda distracting. Some editing environments
(maybe Matlab) also only show the arglist after inserting (.

In general I find the arglist (eldoc) most useful when editing text.
When browsing code it is most of the time easy to guess from context.

Also getting the arglist can be expensive. For example in octave it has
to ask the running process (which can get stuck when the process is in
the middle of doing something else). In other cases it has to make
remote calls.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Thu, 09 Jan 2014 16:13:02 GMT) Full text and rfc822 format available.

Message #23 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Thu, 09 Jan 2014 11:12:47 -0500
> The idea behind eldoc-post-insert-mode is not to show the eldoc messages
> all the time which can be kinda distracting. Some editing environments
> (maybe Matlab) also only show the arglist after inserting (.

But you can get the same result with suitable use of eldoc-remove-command.

> In general I find the arglist (eldoc) most useful when editing text.

Agreed.  But I usually need it *just before* typing.  IOW, I navigate to
the point where I want to write, then look at the eldoc info, then start
typing.  Sometimes the navigation is not in eldoc-message-commands, so
I need to do something like "C-b C-f" to get eldoc to come up, but with
eldoc-post-insert-mode it's worse, because the obvious "equivalent" of
"SPC DEL" does not end with a self-insert so I need to do SPC, then read
eldoc, then DEL which I find even more annoying.

> Also getting the arglist can be expensive. For example in octave it has
> to ask the running process (which can get stuck when the process is in
> the middle of doing something else). In other cases it has to make
> remote calls.

Not sure why that's relevant.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Fri, 10 Jan 2014 03:25:03 GMT) Full text and rfc822 format available.

Message #26 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16346 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Fri, 10 Jan 2014 11:24:24 +0800
On 2014-01-10 00:12 +0800, Stefan Monnier wrote:
> But you can get the same result with suitable use of eldoc-remove-command.

But in case of a read-only buffer, one may want the normal eldoc to show
arglist. So there is two use cases: one when editing and the other when
reading others code. I only enable eldoc-mode manually i.e. M-x
eldoc-mode when I need it.

>> In general I find the arglist (eldoc) most useful when editing text.
>
> Agreed.  But I usually need it *just before* typing.  IOW, I navigate to
> the point where I want to write, then look at the eldoc info, then start
> typing.  Sometimes the navigation is not in eldoc-message-commands, so
> I need to do something like "C-b C-f" to get eldoc to come up, but with
> eldoc-post-insert-mode it's worse, because the obvious "equivalent" of
> "SPC DEL" does not end with a self-insert so I need to do SPC, then read
> eldoc, then DEL which I find even more annoying.

But then when you go anywhere that you don't want to edit code (such as
just to copy some text) eldoc also prints the arglist. The latter
happens more often in my editing habit that it can be annoying.

But maybe eldoc-post-insert-mode (maybe even a new name
eldoc-edit-mode?) can check on char changes instead? Is this better?

>> Also getting the arglist can be expensive. For example in octave it has
>> to ask the running process (which can get stuck when the process is in
>> the middle of doing something else). In other cases it has to make
>> remote calls.
>
> Not sure why that's relevant.

For example, if a heavy job is running in the inferior octave buffer,
one normally don't want any movement to send a request to it asking for
arglist. It is my impression that eldoc might do that.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Fri, 10 Jan 2014 04:12:01 GMT) Full text and rfc822 format available.

Message #29 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16346 <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
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))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Fri, 10 Jan 2014 14:15:02 GMT) Full text and rfc822 format available.

Message #32 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Fri, 10 Jan 2014 09:14:07 -0500
>> But you can get the same result with suitable use of eldoc-remove-command.
> But in case of a read-only buffer, one may want the normal eldoc to show
> arglist.  So there is two use cases: one when editing and the other when
> reading others code.  I only enable eldoc-mode manually i.e. M-x
> eldoc-mode when I need it.

So you want an eldoc-subdued-mode which only gives you info in some very
restricted cases (e.g. self-insert-command) and which you can
dynamically enable/disable in specific buffers.

Making eldoc-message-commands buffer-local would let us do that fairly easily.

> But then when you go anywhere that you don't want to edit code (such as
> just to copy some text) eldoc also prints the arglist.

Right.  And it doesn't bother me because if I don't want to see the
eldoc info, I just don't look at the echo area.

> The latter happens more often in my editing habit that it can
> be annoying.

We obviously have different tastes/habits ;-)

> But maybe eldoc-post-insert-mode (maybe even a new name
> eldoc-edit-mode?) can check on char changes instead?

I don't understand what you mean by "char changes".
Ah, you mean using an after-change-function?  I don't really like that.
I'm not sure what problem it is supposed to avoid.

>>> Also getting the arglist can be expensive. For example in octave it has
>>> to ask the running process (which can get stuck when the process is in
>>> the middle of doing something else). In other cases it has to make
>>> remote calls.
>> Not sure why that's relevant.
> For example, if a heavy job is running in the inferior octave buffer,
> one normally don't want any movement to send a request to it asking for
> arglist.

But neither do you want to send such a request just because you inserted
a char.  So, the problem really applies to bother cases.  I find it hard
to believe that the problem would really be much more serious in one
case then in the other: either it's serious in both cases, or it's
bearable in both cases.


        Stefan


PS: I think some version of eldoc-mode should be enabled by default.
It's too late for 24.4, but: for the one after.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Fri, 10 Jan 2014 16:47:02 GMT) Full text and rfc822 format available.

Message #35 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16346 <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sat, 11 Jan 2014 00:46:37 +0800
On 2014-01-10 22:14 +0800, Stefan Monnier wrote:
> So you want an eldoc-subdued-mode which only gives you info in some very
> restricted cases (e.g. self-insert-command) and which you can
> dynamically enable/disable in specific buffers.
>
> Making eldoc-message-commands buffer-local would let us do that fairly easily.
>
>> But then when you go anywhere that you don't want to edit code (such as
>> just to copy some text) eldoc also prints the arglist.
>
> Right.  And it doesn't bother me because if I don't want to see the
> eldoc info, I just don't look at the echo area.

I haven't built that habit. If there is nothing to show in the status
area show nothing which is what I expect. In practice, even if my eyes
don't literally look at the echo area, they still grab a bit of my
attention.

> We obviously have different tastes/habits ;-)
>
>> But maybe eldoc-post-insert-mode (maybe even a new name
>> eldoc-edit-mode?) can check on char changes instead?
>
> I don't understand what you mean by "char changes".
> Ah, you mean using an after-change-function?  I don't really like that.
> I'm not sure what problem it is supposed to avoid.

The SPC DEL thing that you mentioned and this bug.

[snipped 9 lines]
> But neither do you want to send such a request just because you inserted
> a char.  So, the problem really applies to bother cases.  I find it hard
> to believe that the problem would really be much more serious in one
> case then in the other: either it's serious in both cases, or it's
> bearable in both cases.
>
>
>         Stefan
>
>
> PS: I think some version of eldoc-mode should be enabled by default.
> It's too late for 24.4, but: for the one after.

OK I don't mind taking eldoc-post-insert-mode out completely. Let me
know if you want me to. It is new in 24.4 so better go now if it has to
go. I can put it in my init file if I need it.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Fri, 10 Jan 2014 17:21:02 GMT) Full text and rfc822 format available.

Message #38 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Fri, 10 Jan 2014 12:20:49 -0500
>>> But maybe eldoc-post-insert-mode (maybe even a new name
>>> eldoc-edit-mode?) can check on char changes instead?
>> I don't understand what you mean by "char changes".
>> Ah, you mean using an after-change-function?  I don't really like that.
>> I'm not sure what problem it is supposed to avoid.
> The SPC DEL thing that you mentioned

Ah, right, it would cause the DEL to also emit the eldoc info.

> and this bug.

Using a buffer-local eldoc-message-commands which only contains
self-insert-command would also fix this bug.

> OK I don't mind taking eldoc-post-insert-mode out completely.  Let me
> know if you want me to.  It is new in 24.4 so better go now if it has to
> go.  I can put it in my init file if I need it.

I think the idea is fine, but using post-self-insert-hook turns out to
be a bad idea, I think (tho I liked it, initially).
Could you try and re-implement it as a minor mode that enables
eldoc-mode and tweaks eldoc-message-commands buffer-locally, to see if
that works better?


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sat, 11 Jan 2014 04:39:02 GMT) Full text and rfc822 format available.

Message #41 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16346 <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sat, 11 Jan 2014 12:38:31 +0800
On 2014-01-11 01:20 +0800, Stefan Monnier wrote:
> I think the idea is fine, but using post-self-insert-hook turns out to
> be a bad idea, I think (tho I liked it, initially).
> Could you try and re-implement it as a minor mode that enables
> eldoc-mode and tweaks eldoc-message-commands buffer-locally, to see if
> that works better?

The following patch seems to do it. Comments?

=== modified file 'lisp/emacs-lisp/eldoc.el'
--- lisp/emacs-lisp/eldoc.el	2014-01-06 23:34:05 +0000
+++ lisp/emacs-lisp/eldoc.el	2014-01-11 04:31:35 +0000
@@ -62,6 +62,11 @@
   :type 'number
   :group 'eldoc)
 
+(defcustom eldoc-print-after-edit nil
+  "If non-nil eldoc info is only shown when editing."
+  :type 'boolean
+  :group 'eldoc)
+
 ;;;###autoload
 (defcustom eldoc-minor-mode-string (purecopy " ElDoc")
   "String to display in mode line when ElDoc Mode is enabled; nil for none."
@@ -150,6 +155,16 @@
   "The function used by `eldoc-message' to display messages.
 It should receive the same arguments as `message'.")
 
+(defvar eldoc-edit-message-commands
+  (let ((cmds (make-vector 31 0))
+	(re (regexp-opt '("delete" "insert" "edit" "electric" "newline"))))
+    (mapatoms (lambda (s)
+		(and (commandp s)
+		     (string-match re (symbol-name s))
+		     (intern (symbol-name s) cmds)))
+	      obarray)
+    cmds))
+
 
 ;;;###autoload
 (define-minor-mode eldoc-mode
@@ -168,25 +183,13 @@
   (setq eldoc-last-message nil)
   (if eldoc-mode
       (progn
+	(when eldoc-print-after-edit
+	  (setq-local eldoc-message-commands eldoc-edit-message-commands))
 	(add-hook 'post-command-hook 'eldoc-schedule-timer nil t)
 	(add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t))
-   (remove-hook 'post-command-hook 'eldoc-schedule-timer)
-   (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area)))
-
-;;;###autoload
-(define-minor-mode eldoc-post-insert-mode nil
-  :group 'eldoc :lighter (:eval (if eldoc-mode ""
-				  (concat eldoc-minor-mode-string "|i")))
-  (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))))
-
-;; FIXME: This changes Emacs's behavior when the file is loaded!
-(add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-post-insert-mode)
+    (kill-local-variable 'eldoc-message-commands)
+    (remove-hook 'post-command-hook 'eldoc-schedule-timer t)
+    (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t)))
 
 ;;;###autoload
 (defun turn-on-eldoc-mode ()
@@ -264,8 +267,10 @@
 ;; This doesn't seem to be required for Emacs 19.28 and earlier.
 (defun eldoc-pre-command-refresh-echo-area ()
   (and eldoc-last-message
-       (if (eldoc-display-message-no-interference-p)
-           (eldoc-message eldoc-last-message)
+       (if (and (eldoc-display-message-no-interference-p)
+		(symbolp this-command)
+		(intern-soft (symbol-name this-command) eldoc-message-commands))
+	   (eldoc-message eldoc-last-message)
          (setq eldoc-last-message nil))))
 
 ;; Decide whether now is a good time to display a message.
@@ -283,9 +288,7 @@
 ;; Check various conditions about the current environment that might make
 ;; it undesirable to print eldoc messages right this instant.
 (defun eldoc-display-message-no-interference-p ()
-  (and eldoc-mode
-       (not executing-kbd-macro)
-       (not (and (boundp 'edebug-active) edebug-active))))
+  (not (or executing-kbd-macro (bound-and-true-p edebug-active))))
 
 
 ;;;###autoload
@@ -309,7 +312,7 @@
   ;; This is run from post-command-hook or some idle timer thing,
   ;; so we need to be careful that errors aren't ignored.
   (with-demoted-errors "eldoc error: %s"
-    (and (or (eldoc-display-message-p) eldoc-post-insert-mode)
+    (and (eldoc-display-message-p)
 	 (if eldoc-documentation-function
 	     (eldoc-message (funcall eldoc-documentation-function))
 	   (let* ((current-symbol (eldoc-current-symbol))

=== modified file 'lisp/simple.el'
--- lisp/simple.el	2014-01-09 01:59:19 +0000
+++ lisp/simple.el	2014-01-11 04:28:32 +0000
@@ -1387,6 +1387,7 @@
         (lambda ()
           (add-hook 'completion-at-point-functions
                     #'lisp-completion-at-point nil t)
+	  (eldoc-mode 1)
           (run-hooks 'eval-expression-minibuffer-setup-hook))
       (read-from-minibuffer prompt initial-contents
                             read-expression-map t





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sat, 11 Jan 2014 05:36:01 GMT) Full text and rfc822 format available.

Message #44 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sat, 11 Jan 2014 00:35:24 -0500
>> I think the idea is fine, but using post-self-insert-hook turns out to
>> be a bad idea, I think (tho I liked it, initially).
>> Could you try and re-implement it as a minor mode that enables
>> eldoc-mode and tweaks eldoc-message-commands buffer-locally, to see if
>> that works better?
> The following patch seems to do it.  Comments?

Looks good from here.  How do you like its behavior?


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sat, 11 Jan 2014 06:12:02 GMT) Full text and rfc822 format available.

Message #47 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16346 <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sat, 11 Jan 2014 14:11:38 +0800
On 2014-01-11 13:35 +0800, Stefan Monnier wrote:
> Looks good from here.  How do you like its behavior?
>
>
>         Stefan

Seems to work well for me.

If you have no objection I will install the following final patch. Have
to build eldoc-edit-message-commands at the time of enabling eldoc-mode
because loading packages may add new edit commands. (time penalty is
about 0.03s, hope this isn't too bad.)

=== modified file 'lisp/emacs-lisp/eldoc.el'
--- lisp/emacs-lisp/eldoc.el	2014-01-06 23:34:05 +0000
+++ lisp/emacs-lisp/eldoc.el	2014-01-11 06:10:50 +0000
@@ -62,6 +62,12 @@
   :type 'number
   :group 'eldoc)
 
+(defcustom eldoc-print-after-edit nil
+  "If non-nil eldoc info is only shown when editing.
+Changing the value requires toggling `eldoc-mode'."
+  :type 'boolean
+  :group 'eldoc)
+
 ;;;###autoload
 (defcustom eldoc-minor-mode-string (purecopy " ElDoc")
   "String to display in mode line when ElDoc Mode is enabled; nil for none."
@@ -150,6 +156,16 @@
   "The function used by `eldoc-message' to display messages.
 It should receive the same arguments as `message'.")
 
+(defun eldoc-edit-message-commands ()
+  (let ((cmds (make-vector 31 0))
+	(re (regexp-opt '("delete" "insert" "edit" "electric" "newline"))))
+    (mapatoms (lambda (s)
+		(and (commandp s)
+		     (string-match re (symbol-name s))
+		     (intern (symbol-name s) cmds)))
+	      obarray)
+    cmds))
+
 
 ;;;###autoload
 (define-minor-mode eldoc-mode
@@ -168,25 +184,13 @@
   (setq eldoc-last-message nil)
   (if eldoc-mode
       (progn
+	(when eldoc-print-after-edit
+	  (setq-local eldoc-message-commands (eldoc-edit-message-commands)))
 	(add-hook 'post-command-hook 'eldoc-schedule-timer nil t)
 	(add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t))
-   (remove-hook 'post-command-hook 'eldoc-schedule-timer)
-   (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area)))
-
-;;;###autoload
-(define-minor-mode eldoc-post-insert-mode nil
-  :group 'eldoc :lighter (:eval (if eldoc-mode ""
-				  (concat eldoc-minor-mode-string "|i")))
-  (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))))
-
-;; FIXME: This changes Emacs's behavior when the file is loaded!
-(add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-post-insert-mode)
+    (kill-local-variable 'eldoc-message-commands)
+    (remove-hook 'post-command-hook 'eldoc-schedule-timer t)
+    (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t)))
 
 ;;;###autoload
 (defun turn-on-eldoc-mode ()
@@ -264,8 +268,10 @@
 ;; This doesn't seem to be required for Emacs 19.28 and earlier.
 (defun eldoc-pre-command-refresh-echo-area ()
   (and eldoc-last-message
-       (if (eldoc-display-message-no-interference-p)
-           (eldoc-message eldoc-last-message)
+       (if (and (eldoc-display-message-no-interference-p)
+		(symbolp this-command)
+		(intern-soft (symbol-name this-command) eldoc-message-commands))
+	   (eldoc-message eldoc-last-message)
          (setq eldoc-last-message nil))))
 
 ;; Decide whether now is a good time to display a message.
@@ -283,9 +289,7 @@
 ;; Check various conditions about the current environment that might make
 ;; it undesirable to print eldoc messages right this instant.
 (defun eldoc-display-message-no-interference-p ()
-  (and eldoc-mode
-       (not executing-kbd-macro)
-       (not (and (boundp 'edebug-active) edebug-active))))
+  (not (or executing-kbd-macro (bound-and-true-p edebug-active))))
 
 
 ;;;###autoload
@@ -309,7 +313,7 @@
   ;; This is run from post-command-hook or some idle timer thing,
   ;; so we need to be careful that errors aren't ignored.
   (with-demoted-errors "eldoc error: %s"
-    (and (or (eldoc-display-message-p) eldoc-post-insert-mode)
+    (and (eldoc-display-message-p)
 	 (if eldoc-documentation-function
 	     (eldoc-message (funcall eldoc-documentation-function))
 	   (let* ((current-symbol (eldoc-current-symbol))

=== modified file 'lisp/progmodes/octave.el'
--- lisp/progmodes/octave.el	2014-01-10 10:35:36 +0000
+++ lisp/progmodes/octave.el	2014-01-11 06:02:44 +0000
@@ -154,12 +154,8 @@
     ["Insert Function"              octave-insert-defun t]
     ["Update Function File Comment" octave-update-function-file-comment t]
     "---"
-    ["Function Syntax Hints" (call-interactively
-                              (if (fboundp 'eldoc-post-insert-mode)
-                                  'eldoc-post-insert-mode
-                                'eldoc-mode))
-     :style toggle :selected (or (bound-and-true-p eldoc-post-insert-mode)
-				 (bound-and-true-p eldoc-mode))
+    ["Function Syntax Hints" (eldoc-mode 'toggle)
+     :style toggle :selected (bound-and-true-p eldoc-mode)
      :help "Display function signatures after typing `SPC' or `('"]
     ["Delimiter Matching"           show-paren-mode
      :style toggle :selected show-paren-mode

=== modified file 'lisp/simple.el'
--- lisp/simple.el	2014-01-09 01:59:19 +0000
+++ lisp/simple.el	2014-01-11 04:28:32 +0000
@@ -1387,6 +1387,7 @@
         (lambda ()
           (add-hook 'completion-at-point-functions
                     #'lisp-completion-at-point nil t)
+	  (eldoc-mode 1)
           (run-hooks 'eval-expression-minibuffer-setup-hook))
       (read-from-minibuffer prompt initial-contents
                             read-expression-map t





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16346; Package emacs. (Sun, 12 Jan 2014 03:36:01 GMT) Full text and rfc822 format available.

Message #50 received at 16346 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16346 <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sat, 11 Jan 2014 22:35:32 -0500
> If you have no objection I will install the following final patch.

OK


        Stefan




Reply sent to Leo Liu <sdl.web <at> gmail.com>:
You have taken responsibility. (Sun, 12 Jan 2014 04:22:02 GMT) Full text and rfc822 format available.

Notification sent to Leo Liu <sdl.web <at> gmail.com>:
bug acknowledged by developer. (Sun, 12 Jan 2014 04:22:03 GMT) Full text and rfc822 format available.

Message #55 received at 16346-done <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16346-done <at> debbugs.gnu.org
Subject: Re: bug#16346: 24.3; electric-pair-mode close-paren issue
Date: Sun, 12 Jan 2014 12:21:50 +0800
Fixed 24.4

On 2014-01-12 11:35 +0800, Stefan Monnier wrote:
>> If you have no objection I will install the following final patch.
>
> OK
>
>
>         Stefan

OK installed and closing this bug. Thanks for your time.

Leo




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 09 Feb 2014 12:24:04 GMT) Full text and rfc822 format available.

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

Previous Next


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