emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r112065: * simple.el (eval-expression


From: Leo Liu
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112065: * simple.el (eval-expression-minibuffer-setup-hook): New hook.
Date: Sun, 17 Mar 2013 23:00:37 +0800
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 112065
fixes bug: http://debbugs.gnu.org/13978
committer: Leo Liu <address@hidden>
branch nick: trunk
timestamp: Sun 2013-03-17 23:00:37 +0800
message:
  * simple.el (eval-expression-minibuffer-setup-hook): New hook.
  (eval-expression): Run it.
  
  Extend eldoc to display info in the mode-line. 
  * emacs-lisp/eldoc.el (eldoc-post-insert-mode): New minor mode.
  (eldoc-mode-line-string): New variable.
  (eldoc-minibuffer-message): New function.
  (eldoc-message-function): New variable.
  (eldoc-message): Use it.
  (eldoc-display-message-p)
  (eldoc-display-message-no-interference-p): Support
  eldoc-post-insert-mode.
modified:
  lisp/ChangeLog
  lisp/emacs-lisp/eldoc.el
  lisp/simple.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-03-17 10:33:57 +0000
+++ b/lisp/ChangeLog    2013-03-17 15:00:37 +0000
@@ -1,3 +1,18 @@
+2013-03-17  Leo Liu  <address@hidden>
+
+       Extend eldoc to display info in the mode-line.  (Bug#13978)
+       * emacs-lisp/eldoc.el (eldoc-post-insert-mode): New minor mode.
+       (eldoc-mode-line-string): New variable.
+       (eldoc-minibuffer-message): New function.
+       (eldoc-message-function): New variable.
+       (eldoc-message): Use it.
+       (eldoc-display-message-p)
+       (eldoc-display-message-no-interference-p): Support
+       eldoc-post-insert-mode.
+
+       * simple.el (eval-expression-minibuffer-setup-hook): New hook.
+       (eval-expression): Run it.
+
 2013-03-17  Roland Winkler  <address@hidden>
 
        * emacs-lisp/crm.el (completing-read-multiple): Ignore empty

=== modified file 'lisp/emacs-lisp/eldoc.el'
--- a/lisp/emacs-lisp/eldoc.el  2013-02-18 01:30:27 +0000
+++ b/lisp/emacs-lisp/eldoc.el  2013-03-17 15:00:37 +0000
@@ -146,6 +146,10 @@
   "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'.")
+
 
 ;;;###autoload
 (define-minor-mode eldoc-mode
@@ -170,6 +174,20 @@
    (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))))
+
+(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')."
   (interactive)
@@ -188,6 +206,37 @@
          (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 +252,9 @@
     ;; 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 +272,23 @@
 ;; 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' uses 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))))
 
 
 ;;;###autoload

=== modified file 'lisp/simple.el'
--- a/lisp/simple.el    2013-02-20 16:37:06 +0000
+++ b/lisp/simple.el    2013-03-17 15:00:37 +0000
@@ -1291,6 +1291,9 @@
             (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 (exp &optional insert-value)
@@ -1308,9 +1311,11 @@
 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)


reply via email to

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