1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-06 11:50:51 -08:00

Re-implement the feature of showing eldoc info after editing.

* emacs-lisp/eldoc.el (eldoc-post-insert-mode): Remove.
(eldoc-edit-message-commands): New function.
(eldoc-print-after-edit): New variable.
(eldoc-pre-command-refresh-echo-area): Emit message only by
eldoc-message-commands.
(eldoc-mode): Restrict eldoc-message-commands to editing commands
if eldoc-print-after-edit is set. 

* progmodes/octave.el (octave-mode-menu): Adapt to change in
eldoc.

Fixes: debbugs:16346
This commit is contained in:
Leo Liu 2014-01-12 12:00:03 +08:00
parent 4efa3f1e0e
commit 9b335362d0
4 changed files with 45 additions and 30 deletions

View file

@ -1,3 +1,17 @@
2014-01-12 Leo Liu <sdl.web@gmail.com>
Re-implement the feature of showing eldoc info after editing.
* emacs-lisp/eldoc.el (eldoc-post-insert-mode): Remove.
(eldoc-edit-message-commands): New function.
(eldoc-print-after-edit): New variable.
(eldoc-pre-command-refresh-echo-area): Emit message only by
eldoc-message-commands.
(eldoc-mode): Restrict eldoc-message-commands to editing commands
if eldoc-print-after-edit is set. (Bug#16346)
* progmodes/octave.el (octave-mode-menu): Adapt to change in
eldoc.
2014-01-11 Eric S. Raymond <esr@thyrsus.com> 2014-01-11 Eric S. Raymond <esr@thyrsus.com>
* version.el (emacs-repository-get-version): Enhancee so the * version.el (emacs-repository-get-version): Enhancee so the

View file

@ -1,4 +1,4 @@
;;; eldoc.el --- show function arglist or variable docstring in echo area ;;; eldoc.el --- show function arglist or variable docstring in echo area -*- lexical-binding: t; -*-
;; Copyright (C) 1996-2014 Free Software Foundation, Inc. ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
@ -62,6 +62,12 @@ If this variable is set to 0, no idle time is required."
:type 'number :type 'number
:group 'eldoc) :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 ;;;###autoload
(defcustom eldoc-minor-mode-string (purecopy " ElDoc") (defcustom eldoc-minor-mode-string (purecopy " ElDoc")
"String to display in mode line when ElDoc Mode is enabled; nil for none." "String to display in mode line when ElDoc Mode is enabled; nil for none."
@ -150,6 +156,16 @@ This is used to determine if `eldoc-idle-delay' is changed by the user.")
"The function used by `eldoc-message' to display messages. "The function used by `eldoc-message' to display messages.
It should receive the same arguments as `message'.") 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-p re (symbol-name s))
(intern (symbol-name s) cmds)))
obarray)
cmds))
;;;###autoload ;;;###autoload
(define-minor-mode eldoc-mode (define-minor-mode eldoc-mode
@ -168,25 +184,13 @@ expression point is on."
(setq eldoc-last-message nil) (setq eldoc-last-message nil)
(if eldoc-mode (if eldoc-mode
(progn (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 'post-command-hook 'eldoc-schedule-timer nil t)
(add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t)) (add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t))
(remove-hook 'post-command-hook 'eldoc-schedule-timer) (kill-local-variable 'eldoc-message-commands)
(remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area))) (remove-hook 'post-command-hook 'eldoc-schedule-timer t)
(remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t)))
;;;###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)
;;;###autoload ;;;###autoload
(defun turn-on-eldoc-mode () (defun turn-on-eldoc-mode ()
@ -264,8 +268,10 @@ Otherwise work like `message'."
;; This doesn't seem to be required for Emacs 19.28 and earlier. ;; This doesn't seem to be required for Emacs 19.28 and earlier.
(defun eldoc-pre-command-refresh-echo-area () (defun eldoc-pre-command-refresh-echo-area ()
(and eldoc-last-message (and eldoc-last-message
(if (eldoc-display-message-no-interference-p) (if (and (eldoc-display-message-no-interference-p)
(eldoc-message eldoc-last-message) (symbolp this-command)
(intern-soft (symbol-name this-command) eldoc-message-commands))
(eldoc-message eldoc-last-message)
(setq eldoc-last-message nil)))) (setq eldoc-last-message nil))))
;; Decide whether now is a good time to display a message. ;; Decide whether now is a good time to display a message.
@ -283,9 +289,7 @@ Otherwise work like `message'."
;; Check various conditions about the current environment that might make ;; Check various conditions about the current environment that might make
;; it undesirable to print eldoc messages right this instant. ;; it undesirable to print eldoc messages right this instant.
(defun eldoc-display-message-no-interference-p () (defun eldoc-display-message-no-interference-p ()
(and eldoc-mode (not (or executing-kbd-macro (bound-and-true-p edebug-active))))
(not executing-kbd-macro)
(not (and (boundp 'edebug-active) edebug-active))))
;;;###autoload ;;;###autoload
@ -309,7 +313,7 @@ Emacs Lisp mode) that support ElDoc.")
;; This is run from post-command-hook or some idle timer thing, ;; This is run from post-command-hook or some idle timer thing,
;; so we need to be careful that errors aren't ignored. ;; so we need to be careful that errors aren't ignored.
(with-demoted-errors "eldoc error: %s" (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 (if eldoc-documentation-function
(eldoc-message (funcall eldoc-documentation-function)) (eldoc-message (funcall eldoc-documentation-function))
(let* ((current-symbol (eldoc-current-symbol)) (let* ((current-symbol (eldoc-current-symbol))

View file

@ -154,12 +154,8 @@ parenthetical grouping.")
["Insert Function" octave-insert-defun t] ["Insert Function" octave-insert-defun t]
["Update Function File Comment" octave-update-function-file-comment t] ["Update Function File Comment" octave-update-function-file-comment t]
"---" "---"
["Function Syntax Hints" (call-interactively ["Function Syntax Hints" (eldoc-mode 'toggle)
(if (fboundp 'eldoc-post-insert-mode) :style toggle :selected (bound-and-true-p eldoc-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))
:help "Display function signatures after typing `SPC' or `('"] :help "Display function signatures after typing `SPC' or `('"]
["Delimiter Matching" show-paren-mode ["Delimiter Matching" show-paren-mode
:style toggle :selected show-paren-mode :style toggle :selected show-paren-mode

View file

@ -1387,6 +1387,7 @@ display the result of expression evaluation."
(lambda () (lambda ()
(add-hook 'completion-at-point-functions (add-hook 'completion-at-point-functions
#'lisp-completion-at-point nil t) #'lisp-completion-at-point nil t)
(eldoc-mode 1)
(run-hooks 'eval-expression-minibuffer-setup-hook)) (run-hooks 'eval-expression-minibuffer-setup-hook))
(read-from-minibuffer prompt initial-contents (read-from-minibuffer prompt initial-contents
read-expression-map t read-expression-map t