emacs-devel
[Top][All Lists]
Advanced

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

Re: eldoc support with M-:


From: Leo
Subject: Re: eldoc support with M-:
Date: Wed, 05 Oct 2011 17:20:58 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3.50 (Mac OS X 10.6.8)

On 2011-10-02 09:12 +0800, Stefan Monnier wrote:
> [ Moved away from gnu.emacs.sources where it doesn't belong any more. ]
>
>>> you will find now last version of eldoc-eval.el in GNU ELPA.
>> I wonder if it makes sense to provide a message-function to customise
>> how `message' posts its messages.
>
> I think doing it for `message' is a bit too radical.  But an
> eldoc-message-function hook would be perfectly fine, and I still hope
> (despite Thierry's failure to figure out how) that such a hook can be
> used to simplify (and integrate) eldoc-eval.el.
>
>
>         Stefan

Sounds good. How about something as shown in the attachment?

Leo

=== modified file 'lisp/emacs-lisp/eldoc.el'
--- lisp/emacs-lisp/eldoc.el    2011-01-25 04:08:28 +0000
+++ lisp/emacs-lisp/eldoc.el    2011-10-05 09:15:52 +0000
@@ -146,6 +146,11 @@
   "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 nil
+  "The function used by `eldoc-message' to display messages.
+It should receive the same arguments as `message'. If this is
+nil, `eldoc-minibuffer-message' is used.")
+
 
 ;;;###autoload
 (define-minor-mode eldoc-mode
@@ -185,8 +190,30 @@
          (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)
+  "Show messages in the mode-line when in the minibuffer.
+Otherwise, behave like function `message'."
+  (if (minibufferp)
+      (progn
+        (with-current-buffer (window-buffer (minibuffer-selected-window))
+          (unless (assq 'eldoc-mode-line-string mode-line-format)
+            (push '(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)
+        (and (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))
+  (let ((omessage eldoc-last-message)
+        (msgfunc (or eldoc-message-function #'eldoc-minibuffer-message)))
     (setq eldoc-last-message
          (cond ((eq (car args) eldoc-last-message) eldoc-last-message)
                ((null (car args)) nil)
@@ -200,8 +227,8 @@
     ;; 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 msgfunc "%s" eldoc-last-message))
+           (omessage (funcall msgfunc nil)))))
   eldoc-last-message)
 
 ;; This function goes on pre-command-hook for XEmacs or when using idle


reply via email to

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