annotate lisp/emacs-lisp/eldoc.el @ 16891:989845750a4d

(init_display): Check for overflow in screen size.
author Richard M. Stallman <rms@gnu.org>
date Mon, 20 Jan 1997 01:21:07 +0000
parents 2b768a1e4f5f
children 436fd36233d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
1 ;;; eldoc.el --- show function arglist or variable docstring in echo area
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
2
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
3 ;; Copyright (C) 1995 Noah S. Friedman
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
4
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
5 ;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
6 ;; Maintainer: friedman@prep.ai.mit.edu
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
7 ;; Keywords: extensions
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
8 ;; Status: Works in Emacs 19 and XEmacs.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
9 ;; Created: 1995-10-06
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
10
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
11 ;; LCD Archive Entry:
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
12 ;; eldoc|Noah Friedman|friedman@prep.ai.mit.edu|
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
13 ;; show function arglist or variable docstring in echo area|
16385
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
14 ;; $Date: 1996/07/14 16:46:25 $|$Revision: 1.6 $|~/misc/eldoc.el.gz|
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
15
16385
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
16 ;; $Id: eldoc.el,v 1.6 1996/07/14 16:46:25 friedman Exp friedman $
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
17
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
18 ;; This program is free software; you can redistribute it and/or modify
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
19 ;; it under the terms of the GNU General Public License as published by
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
20 ;; the Free Software Foundation; either version 2, or (at your option)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
21 ;; any later version.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
22 ;;
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
23 ;; This program is distributed in the hope that it will be useful,
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
26 ;; GNU General Public License for more details.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
27 ;;
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
28 ;; You should have received a copy of the GNU General Public License
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
29 ;; along with this program; if not, you can either send email to this
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
30 ;; program's maintainer or write to: The Free Software Foundation,
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
31 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
32
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
33 ;;; Commentary:
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
34
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
35 ;; This program was inspired by the behavior of the Lisp Machine "mouse
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
36 ;; documentation window"; as you type a function's symbol name as part of a
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
37 ;; sexp, it will print the argument list for that function. However, this
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
38 ;; program's behavior is different in a couple of significant ways. For
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
39 ;; one, you need not actually type the function name; you need only move
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
40 ;; point around in a sexp that calls it. However, if point is over a
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
41 ;; documented variable, it will print the one-line documentation for that
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
42 ;; variable instead, to remind you of that variable's purpose.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
43
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
44 ;; One useful way to enable this minor mode is to put the following in your
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
45 ;; .emacs:
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
46 ;;
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
47 ;; (autoload 'turn-on-eldoc-mode "eldoc" nil t)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
48 ;; (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
49 ;; (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
50
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
51 ;;; Code:
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
52
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
53 ;;;###autoload
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
54 (defvar eldoc-mode nil
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
55 "*If non-nil, show the defined parameters for the elisp function near point.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
56
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
57 For the emacs lisp function at the beginning of the sexp which point is
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
58 within, show the defined parameters for the function in the echo area.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
59 This information is extracted directly from the function or macro if it is
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
60 in pure lisp.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
61
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
62 If the emacs function is a subr, the parameters are obtained from the
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
63 documentation string if possible.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
64
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
65 If point is over a documented variable, print that variable's docstring
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
66 instead; see function `eldoc-print-var-docstring'.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
67
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
68 This variable is buffer-local.")
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
69 (make-variable-buffer-local 'eldoc-mode)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
70
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
71 (defvar eldoc-idle-delay 0.50
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
72 "*Number of seconds of idle time to wait before printing.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
73 If user input arrives before this interval of time has elapsed after the
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
74 last input, no documentation will be printed.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
75
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
76 If this variable is set to 0, no idle time is required.")
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
77
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
78 (defvar eldoc-argument-case 'upcase
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
79 "Case to display argument names of functions, as a symbol.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
80 This has two preferred values: `upcase' or `downcase'.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
81 Actually, any name of a function which takes a string as an argument and
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
82 returns another string is acceptable.")
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
83
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
84 (defvar eldoc-mode-message-commands nil
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
85 "*Obarray of command names where it is appropriate to print in the echo area.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
86
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
87 This is not done for all commands since some print their own
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
88 messages in the echo area, and these functions would instantly overwrite
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
89 them. But self-insert-command as well as most motion commands are good
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
90 candidates.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
91
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
92 It is probably best to manipulate this data structure with the commands
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
93 `eldoc-add-command' and `eldoc-remove-command'.")
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
94
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
95 (cond ((null eldoc-mode-message-commands)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
96 ;; If you increase the number of buckets, keep it a prime number.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
97 (setq eldoc-mode-message-commands (make-vector 31 0))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
98 (let ((list '("self-insert-command"
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
99 "next-" "previous-"
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
100 "forward-" "backward-"
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
101 "beginning-of-" "end-of-"
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
102 "goto-"
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
103 "recenter"
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
104 "scroll-"))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
105 (syms nil))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
106 (while list
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
107 (setq syms (all-completions (car list) obarray 'fboundp))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
108 (setq list (cdr list))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
109 (while syms
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
110 (set (intern (car syms) eldoc-mode-message-commands) t)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
111 (setq syms (cdr syms)))))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
112
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
113 ;; Bookkeeping; the car contains the last symbol read from the buffer.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
114 ;; The cdr contains the string last displayed in the echo area, so it can
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
115 ;; be printed again if necessary without reconsing.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
116 (defvar eldoc-last-data '(nil . nil))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
117
13591
b2fb0109006d (eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents: 13532
diff changeset
118 (defvar eldoc-minor-mode-string " ElDoc"
b2fb0109006d (eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents: 13532
diff changeset
119 "*String to display in mode line when Eldoc Mode is enabled.")
b2fb0109006d (eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents: 13532
diff changeset
120
13532
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
121 ;; Put this minor mode on the global minor-mode-alist.
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
122 (or (assq 'eldoc-mode (default-value 'minor-mode-alist))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
123 (setq-default minor-mode-alist
13532
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
124 (append (default-value 'minor-mode-alist)
13591
b2fb0109006d (eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents: 13532
diff changeset
125 '((eldoc-mode eldoc-minor-mode-string)))))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
126
13647
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
127 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages are
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
128 ;; recorded in a log. Do not put eldoc messages in that log since
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
129 ;; they are Legion.
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
130 (defmacro eldoc-message (&rest args)
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
131 (if (fboundp 'display-message)
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
132 ;; XEmacs 19.13 way of preventing log messages.
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
133 (list 'display-message '(quote no-log) (apply 'list 'format args))
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
134 (list 'let (list (list 'message-log-max 'nil))
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
135 (apply 'list 'message args))))
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
136
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
137
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
138 ;;;###autoload
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
139 (defun eldoc-mode (&optional prefix)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
140 "*If non-nil, then enable eldoc-mode (see variable docstring)."
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
141 (interactive "P")
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
142
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
143 ;; Make sure it's on the post-command-idle-hook if defined, otherwise put
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
144 ;; it on post-command-hook. The former first appeared in Emacs 19.30.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
145 (add-hook (if (boundp 'post-command-idle-hook)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
146 'post-command-idle-hook
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
147 'post-command-hook)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
148 'eldoc-mode-print-current-symbol-info)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
149
15671
27e6b6f4f1b6 (eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents: 13647
diff changeset
150 (setq eldoc-mode (if prefix
27e6b6f4f1b6 (eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents: 13647
diff changeset
151 (>= (prefix-numeric-value prefix) 0)
27e6b6f4f1b6 (eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents: 13647
diff changeset
152 (not eldoc-mode)))
27e6b6f4f1b6 (eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents: 13647
diff changeset
153
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
154 (and (interactive-p)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
155 (if eldoc-mode
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
156 (message "eldoc-mode is enabled")
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
157 (message "eldoc-mode is disabled")))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
158 eldoc-mode)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
159
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
160 ;;;###autoload
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
161 (defun turn-on-eldoc-mode ()
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
162 "Unequivocally turn on eldoc-mode (see variable documentation)."
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
163 (interactive)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
164 (eldoc-mode 1))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
165
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
166 (defun eldoc-add-command (cmd)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
167 "Add COMMAND to the list of commands which causes function arg display.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
168 If called interactively, completion matches any bound function.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
169
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
170 When point is in a sexp, the function args are not reprinted in the echo
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
171 area after every possible interactive command because some of them print
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
172 their own messages in the echo area; the eldoc functions would instantly
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
173 overwrite them unless it is more restrained."
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
174 (interactive "aAdd function to eldoc message commands list: ")
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
175 (and (fboundp cmd)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
176 (set (intern (symbol-name cmd) eldoc-mode-message-commands) t)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
177
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
178 (defun eldoc-remove-command (cmd)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
179 "Remove COMMAND from the list of commands which causes function arg display.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
180 If called interactively, completion matches only those functions currently
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
181 in the list.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
182
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
183 When point is in a sexp, the function args are not reprinted in the echo
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
184 area after every possible interactive command because some of them print
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
185 their own messages in the echo area; the eldoc functions would instantly
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
186 overwrite them unless it is more restrained."
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
187 (interactive (list (completing-read
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
188 "Remove function from eldoc message commands list: "
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
189 eldoc-mode-message-commands 'boundp t)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
190 (and (symbolp cmd)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
191 (setq cmd (symbol-name cmd)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
192 (if (fboundp 'unintern)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
193 (unintern cmd eldoc-mode-message-commands)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
194 (let ((s (intern-soft cmd eldoc-mode-message-commands)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
195 (and s
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
196 (makunbound s)))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
197
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
198 (defun eldoc-mode-print-current-symbol-info ()
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
199 (and eldoc-mode
13614
de978cbb25d2 (eldoc-mode-print-current-symbol-info): Do nothing if executing-macro.
Noah Friedman <friedman@splode.com>
parents: 13591
diff changeset
200 (not executing-macro)
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
201 ;; Having this mode operate in the minibuffer makes it impossible to
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
202 ;; see what you're doing.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
203 (not (eq (selected-window) (minibuffer-window)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
204 (sit-for eldoc-idle-delay)
13532
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
205 (symbolp this-command)
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
206 (intern-soft (symbol-name this-command) eldoc-mode-message-commands)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
207 (let ((current-symbol (eldoc-current-symbol))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
208 (current-fnsym (eldoc-fnsym-in-current-sexp)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
209 (cond ((eq current-symbol current-fnsym)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
210 (eldoc-print-fnsym-args current-fnsym))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
211 (t
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
212 (or (eldoc-print-var-docstring current-symbol)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
213 (eldoc-print-fnsym-args current-fnsym)))))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
214
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
215
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
216 (defun eldoc-print-var-docstring (&optional sym)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
217 "Print the brief (one-line) documentation string for the variable at point.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
218 If called with no argument, print the first line of the variable
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
219 documentation string for the symbol at point in the echo area.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
220 If called with a symbol, print the line for that symbol.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
221
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
222 If the entire line cannot fit in the echo area, the variable name may be
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
223 truncated or eliminated entirely from the output to make room.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
224 Any leading `*' in the docstring (which indicates the variable is a user
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
225 option) is not printed."
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
226 (interactive)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
227 (let* ((s (or sym (eldoc-current-symbol)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
228 (name (symbol-name s))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
229 (doc (and s (documentation-property s 'variable-documentation t))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
230 (and doc
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
231 (save-match-data
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
232 (and (string-match "\n" doc)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
233 (setq doc (substring doc 0 (match-beginning 0))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
234 (and (string-match "^\\*" doc)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
235 (setq doc (substring doc 1)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
236 (let* ((doclen (+ (length name) (length ": ") (length doc)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
237 ;; Subtract 1 from window width since emacs seems not to
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
238 ;; write any chars to the last column, at least for some
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
239 ;; terminal types.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
240 (strip (- doclen (1- (window-width (minibuffer-window))))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
241 (cond ((> strip 0)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
242 (let* ((len (length name)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
243 (cond ((>= strip len)
13647
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
244 (eldoc-message "%s" doc))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
245 (t
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
246 (setq name (substring name 0 (- len strip)))
13647
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
247 (eldoc-message "%s: %s" name doc)))))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
248 (t
13647
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
249 (eldoc-message "%s: %s" s doc))))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
250 t))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
251
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
252
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
253 ;;;###autoload
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
254 (defun eldoc-print-fnsym-args (&optional symbol)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
255 "*Show the defined parameters for the function near point.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
256 For the function at the beginning of the sexp which point is within, show
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
257 the defined parameters for the function in the echo area.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
258 This information is extracted directly from the function or macro if it is
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
259 in pure lisp.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
260 If the emacs function is a subr, the parameters are obtained from the
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
261 documentation string if possible."
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
262 (interactive)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
263 (let ((sym (or symbol (eldoc-fnsym-in-current-sexp)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
264 (printit t)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
265 (args nil))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
266 (cond ((not (and (symbolp sym)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
267 (fboundp sym))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
268 ((eq sym (car eldoc-last-data))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
269 (setq printit nil)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
270 (setq args (cdr eldoc-last-data)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
271 ((subrp (eldoc-symbol-function sym))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
272 (setq args (eldoc-function-argstring-from-docstring sym))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
273 (setcdr eldoc-last-data args))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
274 (t
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
275 (setq args (eldoc-function-argstring sym))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
276 (setcdr eldoc-last-data args)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
277 (and args
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
278 printit
13647
40e469e13255 (eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents: 13614
diff changeset
279 (eldoc-message "%s: %s" sym args))))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
280
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
281 (defun eldoc-fnsym-in-current-sexp ()
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
282 (let* ((p (point))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
283 (sym (progn
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
284 (while (and (eldoc-forward-sexp-safe -1)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
285 (> (point) (point-min))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
286 (cond ((or (= (point) (point-min))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
287 (memq (or (char-after (point)) 0)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
288 '(?\( ?\"))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
289 ;; If we hit a quotation mark before a paren, we
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
290 ;; are inside a specific string, not a list of
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
291 ;; symbols.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
292 (eq (or (char-after (1- (point))) 0) ?\"))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
293 nil)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
294 (t (condition-case nil
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
295 (read (current-buffer))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
296 (error nil)))))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
297 (goto-char p)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
298 (and (symbolp sym)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
299 sym)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
300
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
301 (defun eldoc-function-argstring (fn)
13532
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
302 (let* ((prelim-def (eldoc-symbol-function fn))
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
303 (def (if (eq (car-safe prelim-def) 'macro)
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
304 (cdr prelim-def)
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
305 prelim-def))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
306 (arglist (cond ((null def) nil)
13532
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
307 ((byte-code-function-p def)
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
308 (if (fboundp 'compiled-function-arglist)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
309 (funcall 'compiled-function-arglist def)
13532
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
310 (aref def 0)))
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
311 ((eq (car-safe def) 'lambda)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
312 (nth 1 def))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
313 (t t))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
314 (eldoc-function-argstring-format arglist)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
315
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
316 (defun eldoc-function-argstring-from-docstring (fn)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
317 (let ((docstring (documentation fn 'raw))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
318 (doc nil)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
319 (doclist nil)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
320 (end nil))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
321 (save-match-data
16385
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
322 ;; TODO: Move these into a separate table that is iterated over until
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
323 ;; a match is found.
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
324 (cond
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
325 ;; Try first searching for args starting with symbol name.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
326 ;; This is to avoid matching parenthetical remarks in e.g. sit-for.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
327 ((string-match (format "^(%s[^\n)]*)$" fn) docstring)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
328 ;; end does not include trailing ")" sequence.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
329 (setq end (- (match-end 0) 1))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
330 (if (string-match " +" docstring (match-beginning 0))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
331 (setq doc (substring docstring (match-end 0) end))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
332 (setq doc "")))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
333
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
334 ;; Try again not requiring this symbol name in the docstring.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
335 ;; This will be the case when looking up aliases.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
336 ((string-match (format "^([^\n)]+)$" fn) docstring)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
337 ;; end does not include trailing ")" sequence.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
338 (setq end (- (match-end 0) 1))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
339 (if (string-match " +" docstring (match-beginning 0))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
340 (setq doc (substring docstring (match-end 0) end))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
341 (setq doc "")))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
342
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
343 ;; Emacs subr docstring style:
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
344 ;; (fn arg1 arg2 ...): description...
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
345 ((string-match "^([^\n)]+):" docstring)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
346 ;; end does not include trailing "):" sequence.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
347 (setq end (- (match-end 0) 2))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
348 (if (string-match " +" docstring (match-beginning 0))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
349 (setq doc (substring docstring (match-end 0) end))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
350 (setq doc "")))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
351
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
352 ;; XEmacs subr docstring style:
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
353 ;; "arguments: (arg1 arg2 ...)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
354 ((string-match "^arguments: (\\([^\n)]+\\))" docstring)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
355 ;; Also, skip leading paren, but the first word is actually an
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
356 ;; argument, not the function name.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
357 (setq doc (substring docstring
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
358 (match-beginning 1)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
359 (match-end 1))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
360
13532
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
361 ;; This finds the argstring for `condition-case'.
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
362 ;; I don't know if there are any others with the same pattern.
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
363 ((string-match (format "^Usage looks like \\((%s[^\n)]*)\\)\\.$" fn)
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
364 docstring)
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
365 ;; end does not include trailing ")" sequence.
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
366 (setq end (- (match-end 1) 1))
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
367 (if (string-match " +" docstring (match-beginning 1))
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
368 (setq doc (substring docstring (match-end 0) end))
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
369 (setq doc "")))
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
370
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
371 ;; This finds the argstring for `setq-default'.
37fdd3664658 (top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents: 13530
diff changeset
372 ;; I don't know if there are any others with the same pattern.
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
373 ((string-match (format "^[ \t]+\\((%s[^\n)]*)\\)$" fn) docstring)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
374 ;; end does not include trailing ")" sequence.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
375 (setq end (- (match-end 1) 1))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
376 (if (string-match " +" docstring (match-beginning 1))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
377 (setq doc (substring docstring (match-end 0) end))
16385
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
378 (setq doc "")))
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
379
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
380 ;; This finds the argstring for `start-process'.
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
381 ;; I don't know if there are any others with the same pattern.
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
382 ((string-match "^Args are +\\([^\n]+\\)$" docstring)
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
383 (setq doc (substring docstring (match-beginning 1) (match-end 1))))
2b768a1e4f5f (eldoc-function-argstring-from-docstring): Add search that finds arglist
Noah Friedman <friedman@splode.com>
parents: 15671
diff changeset
384 )
13530
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
385
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
386 (cond ((not (stringp doc))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
387 nil)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
388 ((string-match "&" doc)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
389 (let ((p 0)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
390 (l (length doc)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
391 (while (< p l)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
392 (cond ((string-match "[ \t\n]+" doc p)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
393 (setq doclist
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
394 (cons (substring doc p (match-beginning 0))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
395 doclist))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
396 (setq p (match-end 0)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
397 (t
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
398 (setq doclist (cons (substring doc p) doclist))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
399 (setq p l))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
400 (eldoc-function-argstring-format (nreverse doclist))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
401 (t
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
402 (concat "(" (funcall eldoc-argument-case doc) ")"))))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
403
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
404 (defun eldoc-function-argstring-format (arglist)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
405 (cond ((not (listp arglist))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
406 (setq arglist nil))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
407 ((symbolp (car arglist))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
408 (setq arglist
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
409 (mapcar (function (lambda (s)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
410 (if (memq s '(&optional &rest))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
411 (symbol-name s)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
412 (funcall eldoc-argument-case
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
413 (symbol-name s)))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
414 arglist)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
415 ((stringp (car arglist))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
416 (setq arglist
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
417 (mapcar (function (lambda (s)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
418 (if (member s '("&optional" "&rest"))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
419 s
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
420 (funcall eldoc-argument-case s))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
421 arglist))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
422 (concat "(" (mapconcat 'identity arglist " ") ")"))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
423
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
424
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
425 ;; forward-sexp calls scan-sexps, which returns an error if it hits the
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
426 ;; beginning or end of the sexp. This returns nil instead.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
427 (defun eldoc-forward-sexp-safe (&optional count)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
428 "Move forward across one balanced expression (sexp).
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
429 With argument, do it that many times. Negative arg -COUNT means
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
430 move backward across COUNT balanced expressions.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
431 Return distance in buffer moved, or nil."
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
432 (or count (setq count 1))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
433 (condition-case err
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
434 (- (- (point) (progn
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
435 (let ((parse-sexp-ignore-comments t))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
436 (forward-sexp count))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
437 (point))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
438 (error nil)))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
439
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
440 ;; Do indirect function resolution if possible.
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
441 (defun eldoc-symbol-function (fsym)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
442 (let ((defn (and (fboundp fsym)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
443 (symbol-function fsym))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
444 (and (symbolp defn)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
445 (condition-case err
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
446 (setq defn (indirect-function fsym))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
447 (error (setq defn nil))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
448 defn))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
449
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
450 (defun eldoc-current-symbol ()
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
451 (let ((c (char-after (point))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
452 (and c
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
453 (memq (char-syntax c) '(?w ?_))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
454 (intern-soft (current-word)))))
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
455
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
456 (provide 'eldoc)
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
457
625e90e74d83 Initial revision
Noah Friedman <friedman@splode.com>
parents:
diff changeset
458 ;;; eldoc.el ends here