unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Leo Liu <sdl.web@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 13978@debbugs.gnu.org
Subject: bug#13978: 24.3; New minor mode eldoc-post-insert-mode
Date: Sun, 17 Mar 2013 10:56:25 +0800	[thread overview]
Message-ID: <m1mwu2ybs6.fsf@gmail.com> (raw)
In-Reply-To: <jwvy5dnauut.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 16 Mar 2013 17:55:21 -0400")

[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]

On 2013-03-17 05:55 +0800, Stefan Monnier wrote:
> It's looking fairly good.  Questions and comments inline below.

Thanks for the time.

> I'd call it eval-expression-minibuffer-setup-hook or maybe I'd just call
> an emacs-lisp-minibuffer-mode (which might need to not be an actual
> major-mode for technical reasons, but could try to be close to one).
>
> I'd like to move towards using major modes in the minibuffer, so we
> might as well plan for that future.

I renamed it to eval-expression-minibuffer-setup-hook for now. The major
mode is a nice idea which I'll find another time to do it. I want the
font-locking to work as well. For the moment font-lock-mode ignores all
invisible buffers.

> Please give it `eldoc-minibuffer-message' as default value rather
> than nil.  Better yet give it `message' as default value and set it to
> a different value for in-minibuffer use.

Done!

> Shouldn't that be called `eldoc-minibuffer-mode'?
> And why not just use eldoc-mode?

eldoc-post-insert-mode can work everywhere not just in the minibuffer.
The idea is from me finding eldoc-mode too distracting by printing
'constantly' to the echo area. Thus eldoc-post-insert-mode only shows
the info when you are typing. (For me it shows the info at the moment I
need it ;)).

> I removed (not (eq (selected-window) (minibuffer-window)) and (not
> cursor-in-echo-area) from my eldoc-display-message-no-interference-p
> and haven't noticed any downside, so maybe we can just do that and avoid
> creating eldoc-print-current-symbol-info-1 and eldoc-minibuffer-mode.

Done.

>         Stefan

Leo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Implement-eldoc-post-insert-mode.patch --]
[-- Type: text/x-patch, Size: 6463 bytes --]

From 4e4335d3cd3ee8f5e5f9d426e399f39b0aff05c5 Mon Sep 17 00:00:00 2001
From: Leo Liu <sdl.web@gmail.com>
Date: Sun, 17 Mar 2013 10:44:21 +0800
Subject: [PATCH] Implement eldoc-post-insert-mode

http://debbugs.gnu.org/13978
---
 lisp/emacs-lisp/eldoc.el | 79 ++++++++++++++++++++++++++++++++++++++----------
 lisp/simple.el           | 11 +++++--
 2 files changed, 71 insertions(+), 19 deletions(-)

diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 0f018573..0b78530c 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -146,6 +146,10 @@ (defvar eldoc-current-idle-delay eldoc-idle-delay
   "Idle time delay currently in use by timer.
 This is used to determine if `eldoc-idle-delay' is changed by the user.")
 
+(defvar eldoc-message-function 'eldoc-minibuffer-message
+  "The function used by `eldoc-message' to display messages.
+It should receive the same arguments as `message'.")
+
 \f
 ;;;###autoload
 (define-minor-mode eldoc-mode
@@ -169,6 +173,19 @@ (define-minor-mode eldoc-mode
    (remove-hook 'post-command-hook 'eldoc-schedule-timer)
    (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area)))
 
+(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))))
+
+(add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-post-insert-mode)
+
 ;;;###autoload
 (defun turn-on-eldoc-mode ()
   "Unequivocally turn on ElDoc mode (see command `eldoc-mode')."
@@ -188,6 +205,37 @@ (defun eldoc-schedule-timer ()
          (setq eldoc-current-idle-delay eldoc-idle-delay)
          (timer-set-idle-time eldoc-timer eldoc-idle-delay t))))
 
+(defvar eldoc-mode-line-string nil)
+(put 'eldoc-mode-line-string 'risky-local-variable t)
+
+(defun eldoc-minibuffer-message (format-string &rest args)
+  "Display messages in the mode-line when in the minibuffer.
+Otherwise work like `message'."
+  (if (minibufferp)
+      (progn
+	(with-current-buffer
+	    (window-buffer
+	     (or (window-in-direction 'above (minibuffer-window))
+		 (minibuffer-selected-window)
+		 (get-largest-window)))
+	  (unless (and (listp mode-line-format)
+		       (assq 'eldoc-mode-line-string mode-line-format))
+	    (setq mode-line-format
+		  (list "" '(eldoc-mode-line-string
+			     (" " eldoc-mode-line-string " "))
+			mode-line-format))))
+	(add-hook 'minibuffer-exit-hook
+		  (lambda () (setq eldoc-mode-line-string nil))
+		  nil t)
+	(cond
+	 ((null format-string)
+	  (setq eldoc-mode-line-string nil))
+	 ((stringp format-string)
+	  (setq eldoc-mode-line-string
+		(apply 'format format-string args))))
+	(force-mode-line-update))
+    (apply 'message format-string args)))
+
 (defun eldoc-message (&rest args)
   (let ((omessage eldoc-last-message))
     (setq eldoc-last-message
@@ -203,8 +251,9 @@ (defun eldoc-message (&rest args)
     ;; they are Legion.
     ;; Emacs way of preventing log messages.
     (let ((message-log-max nil))
-      (cond (eldoc-last-message (message "%s" eldoc-last-message))
-	    (omessage (message nil)))))
+      (cond (eldoc-last-message
+	     (funcall eldoc-message-function "%s" eldoc-last-message))
+	    (omessage (funcall eldoc-message-function nil)))))
   eldoc-last-message)
 
 ;; This function goes on pre-command-hook for XEmacs or when using idle
@@ -222,25 +271,23 @@ (defun eldoc-pre-command-refresh-echo-area ()
 ;; Decide whether now is a good time to display a message.
 (defun eldoc-display-message-p ()
   (and (eldoc-display-message-no-interference-p)
-       ;; If this-command is non-nil while running via an idle
-       ;; timer, we're still in the middle of executing a command,
-       ;; e.g. a query-replace where it would be annoying to
-       ;; overwrite the echo area.
-       (and (not this-command)
-	    (symbolp last-command)
-	    (intern-soft (symbol-name last-command)
-			 eldoc-message-commands))))
+       ;; `eldoc-post-insert-mode' use no timers.
+       (or (not eldoc-mode)
+	   ;; If this-command is non-nil while running via an idle
+	   ;; timer, we're still in the middle of executing a command,
+	   ;; e.g. a query-replace where it would be annoying to
+	   ;; overwrite the echo area.
+	   (and (not this-command)
+		(symbolp last-command)
+		(intern-soft (symbol-name last-command)
+			     eldoc-message-commands)))))
 
 ;; 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
+  (and (or eldoc-mode eldoc-post-insert-mode)
        (not executing-kbd-macro)
-       (not (and (boundp 'edebug-active) edebug-active))
-       ;; Having this mode operate in an active minibuffer/echo area causes
-       ;; interference with what's going on there.
-       (not cursor-in-echo-area)
-       (not (eq (selected-window) (minibuffer-window)))))
+       (not (and (boundp 'edebug-active) edebug-active))))
 
 \f
 ;;;###autoload
diff --git a/lisp/simple.el b/lisp/simple.el
index 526cc64c..42253645 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1235,6 +1235,9 @@ (defun eval-expression-print-format (value)
             (format " (#o%o, #x%x, %s)" value value char-string)
           (format " (#o%o, #x%x)" value value)))))
 
+(defvar eval-expression-minibuffer-setup-hook nil
+  "Hook run by `eval-expression' when entering the minibuffer.")
+
 ;; We define this, rather than making `eval' interactive,
 ;; for the sake of completion of names like eval-region, eval-buffer.
 (defun eval-expression (eval-expression-arg
@@ -1253,9 +1256,11 @@ (defun eval-expression (eval-expression-arg
 this command arranges for all errors to enter the debugger."
   (interactive
    (list (let ((minibuffer-completing-symbol t))
-	   (read-from-minibuffer "Eval: "
-				 nil read-expression-map t
-				 'read-expression-history))
+	   (minibuffer-with-setup-hook
+	       (lambda () (run-hooks 'eval-expression-minibuffer-setup-hook))
+	     (read-from-minibuffer "Eval: "
+				   nil read-expression-map t
+				   'read-expression-history)))
 	 current-prefix-arg))
 
   (if (null eval-expression-debug-on-error)
-- 
1.8.2


  reply	other threads:[~2013-03-17  2:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-16 19:23 bug#13978: 24.3; New minor mode eldoc-post-insert-mode Leo Liu
2013-03-16 21:55 ` Stefan Monnier
2013-03-17  2:56   ` Leo Liu [this message]
2013-03-17  3:39     ` Dmitry Gutov
2013-03-17  3:57       ` Leo Liu
2013-03-17  4:01         ` Dmitry Gutov
2013-03-17  4:09           ` Leo Liu
2013-03-17 12:10             ` Dmitry Gutov
2013-03-17 13:04             ` Stefan Monnier
2013-03-17 13:51               ` Leo Liu
2013-03-17 15:21                 ` Leo Liu
2013-03-17 15:26                 ` Stefan Monnier
2013-03-17 15:55                   ` Leo Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1mwu2ybs6.fsf@gmail.com \
    --to=sdl.web@gmail.com \
    --cc=13978@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).