1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-30 19:53:09 +00:00

(eldoc-minor-mode-string): Add autoload cookie; otherwise autoloaded

add-minor-mode call complains in Emacs 21.
Use add-minor-mode to set minor-mode-alist, if available.

(eldoc-echo-area-use-multiline-p): New user option.
(eldoc-echo-area-multiline-supported-p): New variable.
(eldoc-docstring-format-sym-doc): Use them.
(eldoc-mode): If not using idle timers, append to local post and
pre command hooks.  Suggested by David Byers <davby@ida.liu.se>.

(eldoc-display-message-no-interference-p): Don't interfere with edebug.
Add autoload cookie for eldoc-mode minor-mode-alist initialization.

(eldoc-function-arglist): New function.
(eldoc-function-argstring): Use it.
This commit is contained in:
Noah Friedman 2000-07-24 00:38:34 +00:00
parent db3ca487f6
commit 03a9c6d06a
2 changed files with 101 additions and 41 deletions

View File

@ -1,5 +1,19 @@
2000-07-23 Noah Friedman <friedman@splode.com> 2000-07-23 Noah Friedman <friedman@splode.com>
* emacs-lisp/eldoc.el (eldoc-minor-mode-string): Add autoload
cookie.
Use add-minor-mode to set minor-mode-alist, if available.
(eldoc-echo-area-use-multiline-p): New user option.
(eldoc-echo-area-multiline-supported-p): New variable.
(eldoc-docstring-format-sym-doc): Use them.
(eldoc-mode): If not using idle timers, append to local post and
pre command hooks. Suggested by David Byers <davby@ida.liu.se>.
(eldoc-display-message-no-interference-p): Don't interfere with
edebug.
Add autoload cookie for eldoc-mode minor-mode-alist initialization.
(eldoc-function-arglist): New function.
(eldoc-function-argstring): Use it.
* menu-bar.el (menu-bar-files-menu [recover-session]): Make sure * menu-bar.el (menu-bar-files-menu [recover-session]): Make sure
auto save directory exists before calling directory-files. auto save directory exists before calling directory-files.

View File

@ -1,13 +1,13 @@
;;; eldoc.el --- show function arglist or variable docstring in echo area ;;; eldoc.el --- show function arglist or variable docstring in echo area
;; Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. ;; Copyright (C) 1996, 97, 98, 99, 2000 Free Software Foundation, Inc.
;; Author: Noah Friedman <friedman@splode.com> ;; Author: Noah Friedman <friedman@splode.com>
;; Maintainer: friedman@splode.com ;; Maintainer: friedman@splode.com
;; Keywords: extensions ;; Keywords: extensions
;; Created: 1995-10-06 ;; Created: 1995-10-06
;; $Id: eldoc.el,v 1.15 1998/09/19 02:15:26 friedman Exp $ ;; $Id: eldoc.el,v 1.20 2000/06/03 19:50:18 friedman Exp $
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
@ -48,14 +48,16 @@
;;; Code: ;;; Code:
;; Use idle timers if available in the version of emacs running. ;; Use idle timers if available in the version of emacs running.
;; Please don't change this to use `require'; this package works as-is in ;; Please don't change this to use `require'; this package works
;; XEmacs (which doesn't have timer.el as of 19.14), and I would like to ;; as-is in XEmacs 19.14 and later and I am striving to maintain
;; maintain compatibility with that since I must use it sometimes. --Noah ;; compatibility between emacs variants.
(or (featurep 'timer) (or (featurep 'timer)
(load "timer" t)) (load "timer" t))
(defgroup eldoc nil (defgroup eldoc nil
"Show function arglist or variable docstring in echo area." "Show function arglist or variable docstring in echo area."
:group 'eldoc
:group 'lisp
:group 'extensions) :group 'extensions)
;;;###autoload ;;;###autoload
@ -85,28 +87,52 @@ If this variable is set to 0, no idle time is required."
:type 'number :type 'number
:group 'eldoc) :group 'eldoc)
;;;###autoload
(defcustom eldoc-minor-mode-string " ElDoc" (defcustom eldoc-minor-mode-string " ElDoc"
"*String to display in mode line when Eldoc Mode is enabled." "*String to display in mode line when Eldoc Mode is enabled."
:type 'string :type 'string
:group 'eldoc) :group 'eldoc)
;; Put this minor mode on the global minor-mode-alist.
(or (assq 'eldoc-mode (default-value 'minor-mode-alist))
(setq-default minor-mode-alist
(append (default-value 'minor-mode-alist)
'((eldoc-mode eldoc-minor-mode-string)))))
(defcustom eldoc-argument-case 'upcase (defcustom eldoc-argument-case 'upcase
"Case to display argument names of functions, as a symbol. "Case to display argument names of functions, as a symbol.
This has two preferred values: `upcase' or `downcase'. This has two preferred values: `upcase' or `downcase'.
Actually, any name of a function which takes a string as an argument and Actually, any name of a function which takes a string as an argument and
returns another string is acceptable." returns another string is acceptable."
:type '(radio function :type '(radio (function-item upcase)
(function-item upcase) (function-item downcase)
(function-item downcase)) function)
:group 'eldoc) :group 'eldoc)
;; No user options below here. (defcustom eldoc-echo-area-use-multiline-p 'truncate-sym-name-if-fit
"*Allow long eldoc messages to resize echo area display.
If value is `t', never attempt to truncate messages; complete symbol name
and function arglist or 1-line variable documentation will be displayed
even if echo area must be resized to fit.
If value is any non-nil value other than `t', symbol name may be truncated
if it will enable the function arglist or documentation string to fit on a
single line without resizing window. Otherwise, behavior is just like
former case.
If value is nil, messages are always truncated to fit in a single line of
display in the echo area. Function or variable symbol name may be
truncated to make more of the arglist or documentation string visible.
Non-nil values for this variable have no effect unless
`eldoc-echo-area-multiline-supported-p' is non-nil."
:type '(radio (const :tag "Always" t)
(const :tag "Never" nil)
(const :tag "Yes, but truncate symbol names if it will\
enable argument list to fit on one line" truncate-sym-name-if-fit))
:group 'eldoc)
;;; No user options below here.
;; Non-nil if this version of emacs supports dynamically resizable echo areas.
(defvar eldoc-echo-area-multiline-supported-p
(and (string-lessp "21" emacs-version)
(save-match-data
(numberp (string-match "^GNU Emacs" (emacs-version))))))
;; Commands after which it is appropriate to print in the echo area. ;; Commands after which it is appropriate to print in the echo area.
;; Eldoc does not try to print function arglists, etc. after just any command, ;; Eldoc does not try to print function arglists, etc. after just any command,
@ -143,6 +169,16 @@ returns another string is acceptable."
;; This is used to determine if eldoc-idle-delay is changed by the user. ;; This is used to determine if eldoc-idle-delay is changed by the user.
(defvar eldoc-current-idle-delay eldoc-idle-delay) (defvar eldoc-current-idle-delay eldoc-idle-delay)
;; Put minor mode string on the global minor-mode-alist.
;;;###autoload
(cond ((fboundp 'add-minor-mode)
(add-minor-mode 'eldoc-mode 'eldoc-minor-mode-string))
((assq 'eldoc-mode (default-value 'minor-mode-alist)))
(t
(setq-default minor-mode-alist
(append (default-value 'minor-mode-alist)
'((eldoc-mode eldoc-minor-mode-string))))))
;;;###autoload ;;;###autoload
(defun eldoc-mode (&optional prefix) (defun eldoc-mode (&optional prefix)
@ -164,13 +200,13 @@ the mode, respectively."
;; 19.30; that is the first version in which it appeared, but it ;; 19.30; that is the first version in which it appeared, but it
;; was obsolesced by idle timers in Emacs 19.31. ;; was obsolesced by idle timers in Emacs 19.31.
(add-hook (if (boundp 'post-command-idle-hook) (add-hook (if (boundp 'post-command-idle-hook)
'post-command-idle-hook 'post-command-idle-hook
'post-command-hook) 'post-command-hook)
'eldoc-print-current-symbol-info) 'eldoc-print-current-symbol-info t t)
;; quick and dirty hack for seeing if this is XEmacs ;; quick and dirty hack for seeing if this is XEmacs
(and (fboundp 'display-message) (and (fboundp 'display-message)
(add-hook 'pre-command-hook (add-hook 'pre-command-hook
'eldoc-pre-command-refresh-echo-area)))) 'eldoc-pre-command-refresh-echo-area t t))))
(setq eldoc-mode (if prefix (setq eldoc-mode (if prefix
(>= (prefix-numeric-value prefix) 0) (>= (prefix-numeric-value prefix) 0)
(not eldoc-mode))) (not eldoc-mode)))
@ -265,9 +301,12 @@ the mode, respectively."
eldoc-message-commands) eldoc-message-commands)
(sit-for eldoc-idle-delay)))))) (sit-for eldoc-idle-delay))))))
;; 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 () (defun eldoc-display-message-no-interference-p ()
(and eldoc-mode (and eldoc-mode
(not executing-kbd-macro) (not executing-kbd-macro)
(not (and (boundp 'edebug-active) edebug-active))
;; Having this mode operate in an active minibuffer/echo area causes ;; Having this mode operate in an active minibuffer/echo area causes
;; interference with what's going on there. ;; interference with what's going on there.
(not cursor-in-echo-area) (not cursor-in-echo-area)
@ -345,24 +384,27 @@ the mode, respectively."
(defun eldoc-docstring-format-sym-doc (sym doc) (defun eldoc-docstring-format-sym-doc (sym doc)
(save-match-data (save-match-data
(let* ((name (symbol-name sym)) (let* ((name (symbol-name sym))
(doclen (+ (length name) (length ": ") (length doc))) (ea-multi (and eldoc-echo-area-multiline-supported-p
;; Subtract 1 from window width since emacs seems not to write eldoc-echo-area-use-multiline-p))
;; any chars to the last column, at least for some terminal types. ;; Subtract 1 from window width since emacs will not write
(strip (- doclen (1- (window-width (minibuffer-window)))))) ;; any chars to the last column, or in later versions, will
(cond ((> strip 0) ;; cause a wraparound and resize of the echo area.
(let* ((len (length name))) (ea-width (1- (window-width (minibuffer-window))))
(cond ((>= strip len) (strip (- (+ (length name) (length ": ") (length doc)) ea-width)))
(format "%s" doc)) (cond ((or (<= strip 0)
(t (eq ea-multi t)
;;(setq name (substring name 0 (- len strip))) (and ea-multi (> (length doc) ea-width)))
;; (format "%s: %s" sym doc))
;; Show the end of the partial symbol name, rather ((> (length doc) ea-width)
;; than the beginning, since the former is more likely (substring (format "%s" doc) 0 ea-width))
;; to be unique given package namespace conventions. ((>= strip (length name))
(setq name (substring name strip)) (format "%s" doc))
(format "%s: %s" name doc)))))
(t (t
(format "%s: %s" sym doc)))))) ;; Show the end of the partial symbol name, rather
;; than the beginning, since the former is more likely
;; to be unique given package namespace conventions.
(setq name (substring name strip))
(format "%s: %s" name doc))))))
(defun eldoc-fnsym-in-current-sexp () (defun eldoc-fnsym-in-current-sexp ()
@ -401,20 +443,24 @@ the mode, respectively."
(error (setq defn nil)))) (error (setq defn nil))))
defn)) defn))
(defun eldoc-function-argstring (fn) (defun eldoc-function-arglist (fn)
(let* ((prelim-def (eldoc-symbol-function fn)) (let* ((prelim-def (eldoc-symbol-function fn))
(def (if (eq (car-safe prelim-def) 'macro) (def (if (eq (car-safe prelim-def) 'macro)
(cdr prelim-def) (cdr prelim-def)
prelim-def)) prelim-def))
(arglist (cond ((null def) nil) (arglist (cond ((null def) nil)
((byte-code-function-p def) ((byte-code-function-p def)
(if (fboundp 'compiled-function-arglist) (cond ((fboundp 'compiled-function-arglist)
(funcall 'compiled-function-arglist def) (funcall 'compiled-function-arglist def))
(aref def 0))) (t
(aref def 0))))
((eq (car-safe def) 'lambda) ((eq (car-safe def) 'lambda)
(nth 1 def)) (nth 1 def))
(t t)))) (t t))))
(eldoc-function-argstring-format arglist))) arglist))
(defun eldoc-function-argstring (fn)
(eldoc-function-argstring-format (eldoc-function-arglist fn)))
(defun eldoc-function-argstring-format (arglist) (defun eldoc-function-argstring-format (arglist)
(cond ((not (listp arglist)) (cond ((not (listp arglist))