aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLeo Liu2013-03-17 23:00:37 +0800
committerLeo Liu2013-03-17 23:00:37 +0800
commit69489f1dd666ed3a7cd01d621225d591b601e6a7 (patch)
tree7d469083c69bdacffa5695a2abb33236568b7e7c /lisp
parent6db423a92abf874f1780b8ddb2786dff4fc5b942 (diff)
downloademacs-69489f1dd666ed3a7cd01d621225d591b601e6a7.tar.gz
emacs-69489f1dd666ed3a7cd01d621225d591b601e6a7.zip
* 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. Fixes: debbugs:13978
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/emacs-lisp/eldoc.el80
-rw-r--r--lisp/simple.el11
3 files changed, 87 insertions, 19 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1f9724e17fd..3c771a893ca 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12013-03-17 Leo Liu <sdl.web@gmail.com>
2
3 Extend eldoc to display info in the mode-line. (Bug#13978)
4 * emacs-lisp/eldoc.el (eldoc-post-insert-mode): New minor mode.
5 (eldoc-mode-line-string): New variable.
6 (eldoc-minibuffer-message): New function.
7 (eldoc-message-function): New variable.
8 (eldoc-message): Use it.
9 (eldoc-display-message-p)
10 (eldoc-display-message-no-interference-p): Support
11 eldoc-post-insert-mode.
12
13 * simple.el (eval-expression-minibuffer-setup-hook): New hook.
14 (eval-expression): Run it.
15
12013-03-17 Roland Winkler <winkler@gnu.org> 162013-03-17 Roland Winkler <winkler@gnu.org>
2 17
3 * emacs-lisp/crm.el (completing-read-multiple): Ignore empty 18 * emacs-lisp/crm.el (completing-read-multiple): Ignore empty
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 5a6b486dcd0..d2730a28eaa 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -146,6 +146,10 @@ directly. Instead, use `eldoc-add-command' and `eldoc-remove-command'.")
146 "Idle time delay currently in use by timer. 146 "Idle time delay currently in use by timer.
147This is used to determine if `eldoc-idle-delay' is changed by the user.") 147This is used to determine if `eldoc-idle-delay' is changed by the user.")
148 148
149(defvar eldoc-message-function 'eldoc-minibuffer-message
150 "The function used by `eldoc-message' to display messages.
151It should receive the same arguments as `message'.")
152
149 153
150;;;###autoload 154;;;###autoload
151(define-minor-mode eldoc-mode 155(define-minor-mode eldoc-mode
@@ -170,6 +174,20 @@ expression point is on."
170 (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area))) 174 (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area)))
171 175
172;;;###autoload 176;;;###autoload
177(define-minor-mode eldoc-post-insert-mode nil
178 :group 'eldoc :lighter (:eval (if eldoc-mode ""
179 (concat eldoc-minor-mode-string "|i")))
180 (setq eldoc-last-message nil)
181 (let ((prn-info (lambda ()
182 (unless eldoc-mode
183 (eldoc-print-current-symbol-info)))))
184 (if eldoc-post-insert-mode
185 (add-hook 'post-self-insert-hook prn-info nil t)
186 (remove-hook 'post-self-insert-hook prn-info t))))
187
188(add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-post-insert-mode)
189
190;;;###autoload
173(defun turn-on-eldoc-mode () 191(defun turn-on-eldoc-mode ()
174 "Unequivocally turn on ElDoc mode (see command `eldoc-mode')." 192 "Unequivocally turn on ElDoc mode (see command `eldoc-mode')."
175 (interactive) 193 (interactive)
@@ -188,6 +206,37 @@ expression point is on."
188 (setq eldoc-current-idle-delay eldoc-idle-delay) 206 (setq eldoc-current-idle-delay eldoc-idle-delay)
189 (timer-set-idle-time eldoc-timer eldoc-idle-delay t)))) 207 (timer-set-idle-time eldoc-timer eldoc-idle-delay t))))
190 208
209(defvar eldoc-mode-line-string nil)
210(put 'eldoc-mode-line-string 'risky-local-variable t)
211
212(defun eldoc-minibuffer-message (format-string &rest args)
213 "Display messages in the mode-line when in the minibuffer.
214Otherwise work like `message'."
215 (if (minibufferp)
216 (progn
217 (with-current-buffer
218 (window-buffer
219 (or (window-in-direction 'above (minibuffer-window))
220 (minibuffer-selected-window)
221 (get-largest-window)))
222 (unless (and (listp mode-line-format)
223 (assq 'eldoc-mode-line-string mode-line-format))
224 (setq mode-line-format
225 (list "" '(eldoc-mode-line-string
226 (" " eldoc-mode-line-string " "))
227 mode-line-format))))
228 (add-hook 'minibuffer-exit-hook
229 (lambda () (setq eldoc-mode-line-string nil))
230 nil t)
231 (cond
232 ((null format-string)
233 (setq eldoc-mode-line-string nil))
234 ((stringp format-string)
235 (setq eldoc-mode-line-string
236 (apply 'format format-string args))))
237 (force-mode-line-update))
238 (apply 'message format-string args)))
239
191(defun eldoc-message (&rest args) 240(defun eldoc-message (&rest args)
192 (let ((omessage eldoc-last-message)) 241 (let ((omessage eldoc-last-message))
193 (setq eldoc-last-message 242 (setq eldoc-last-message
@@ -203,8 +252,9 @@ expression point is on."
203 ;; they are Legion. 252 ;; they are Legion.
204 ;; Emacs way of preventing log messages. 253 ;; Emacs way of preventing log messages.
205 (let ((message-log-max nil)) 254 (let ((message-log-max nil))
206 (cond (eldoc-last-message (message "%s" eldoc-last-message)) 255 (cond (eldoc-last-message
207 (omessage (message nil))))) 256 (funcall eldoc-message-function "%s" eldoc-last-message))
257 (omessage (funcall eldoc-message-function nil)))))
208 eldoc-last-message) 258 eldoc-last-message)
209 259
210;; This function goes on pre-command-hook for XEmacs or when using idle 260;; This function goes on pre-command-hook for XEmacs or when using idle
@@ -222,25 +272,23 @@ expression point is on."
222;; Decide whether now is a good time to display a message. 272;; Decide whether now is a good time to display a message.
223(defun eldoc-display-message-p () 273(defun eldoc-display-message-p ()
224 (and (eldoc-display-message-no-interference-p) 274 (and (eldoc-display-message-no-interference-p)
225 ;; If this-command is non-nil while running via an idle 275 ;; `eldoc-post-insert-mode' uses no timers.
226 ;; timer, we're still in the middle of executing a command, 276 (or (not eldoc-mode)
227 ;; e.g. a query-replace where it would be annoying to 277 ;; If this-command is non-nil while running via an idle
228 ;; overwrite the echo area. 278 ;; timer, we're still in the middle of executing a command,
229 (and (not this-command) 279 ;; e.g. a query-replace where it would be annoying to
230 (symbolp last-command) 280 ;; overwrite the echo area.
231 (intern-soft (symbol-name last-command) 281 (and (not this-command)
232 eldoc-message-commands)))) 282 (symbolp last-command)
283 (intern-soft (symbol-name last-command)
284 eldoc-message-commands)))))
233 285
234;; Check various conditions about the current environment that might make 286;; Check various conditions about the current environment that might make
235;; it undesirable to print eldoc messages right this instant. 287;; it undesirable to print eldoc messages right this instant.
236(defun eldoc-display-message-no-interference-p () 288(defun eldoc-display-message-no-interference-p ()
237 (and eldoc-mode 289 (and (or eldoc-mode eldoc-post-insert-mode)
238 (not executing-kbd-macro) 290 (not executing-kbd-macro)
239 (not (and (boundp 'edebug-active) edebug-active)) 291 (not (and (boundp 'edebug-active) edebug-active))))
240 ;; Having this mode operate in an active minibuffer/echo area causes
241 ;; interference with what's going on there.
242 (not cursor-in-echo-area)
243 (not (eq (selected-window) (minibuffer-window)))))
244 292
245 293
246;;;###autoload 294;;;###autoload
diff --git a/lisp/simple.el b/lisp/simple.el
index 3ef700a6058..9baa1b7c884 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1291,6 +1291,9 @@ display the result of expression evaluation."
1291 (format " (#o%o, #x%x, %s)" value value char-string) 1291 (format " (#o%o, #x%x, %s)" value value char-string)
1292 (format " (#o%o, #x%x)" value value))))) 1292 (format " (#o%o, #x%x)" value value)))))
1293 1293
1294(defvar eval-expression-minibuffer-setup-hook nil
1295 "Hook run by `eval-expression' when entering the minibuffer.")
1296
1294;; We define this, rather than making `eval' interactive, 1297;; We define this, rather than making `eval' interactive,
1295;; for the sake of completion of names like eval-region, eval-buffer. 1298;; for the sake of completion of names like eval-region, eval-buffer.
1296(defun eval-expression (exp &optional insert-value) 1299(defun eval-expression (exp &optional insert-value)
@@ -1308,9 +1311,11 @@ If `eval-expression-debug-on-error' is non-nil, which is the default,
1308this command arranges for all errors to enter the debugger." 1311this command arranges for all errors to enter the debugger."
1309 (interactive 1312 (interactive
1310 (list (let ((minibuffer-completing-symbol t)) 1313 (list (let ((minibuffer-completing-symbol t))
1311 (read-from-minibuffer "Eval: " 1314 (minibuffer-with-setup-hook
1312 nil read-expression-map t 1315 (lambda () (run-hooks 'eval-expression-minibuffer-setup-hook))
1313 'read-expression-history)) 1316 (read-from-minibuffer "Eval: "
1317 nil read-expression-map t
1318 'read-expression-history)))
1314 current-prefix-arg)) 1319 current-prefix-arg))
1315 1320
1316 (if (null eval-expression-debug-on-error) 1321 (if (null eval-expression-debug-on-error)