Mercurial > emacs
annotate lisp/emacs-lisp/elint.el @ 106451:ac7e866f2b51
* info-look.el: Add setup for apropos-mode to use emacs-lisp-mode
manuals, similar to existing setup for help-mode. (My bug#3913.)
author | Kevin Ryde <user42@zip.com.au> |
---|---|
date | Sun, 06 Dec 2009 00:42:19 +0000 |
parents | 85863d02e2db |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
20014
diff
changeset
|
1 ;;; elint.el --- Lint Emacs Lisp |
19210 | 2 |
102230
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
4 ;; 2009 Free Software Foundation, Inc. |
19210 | 5 |
6 ;; Author: Peter Liljenberg <petli@lysator.liu.se> | |
7 ;; Created: May 1997 | |
8 ;; Keywords: lisp | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
19210 | 13 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; (at your option) any later version. |
19210 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
19210 | 24 |
25 ;;; Commentary: | |
26 | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
27 ;; This is a linter for Emacs Lisp. Currently, it mainly catches |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
28 ;; misspellings and undefined variables, although it can also catch |
19210 | 29 ;; function calls with the wrong number of arguments. |
30 | |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
31 ;; To use, call elint-current-buffer or elint-defun to lint a buffer |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
32 ;; or defun. The first call runs `elint-initialize' to set up some |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
33 ;; argument data, which may take a while. |
19210 | 34 |
35 ;; The linter will try to "include" any require'd libraries to find | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
36 ;; the variables defined in those. There is a fair amount of voodoo |
19210 | 37 ;; involved in this, but it seems to work in normal situations. |
38 | |
39 ;;; To do: | |
40 | |
41 ;; * Adding type checking. (Stop that sniggering!) | |
105137 | 42 ;; * Make eval-when-compile be sensitive to the difference between |
43 ;; funcs and macros. | |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
44 ;; * Requires within function bodies. |
105137 | 45 ;; * Handle defstruct. |
46 ;; * Prevent recursive requires. | |
19210 | 47 |
48 ;;; Code: | |
49 | |
105137 | 50 (defgroup elint nil |
51 "Linting for Emacs Lisp." | |
52 :prefix "elint-" | |
53 :group 'maint) | |
54 | |
55 (defcustom elint-log-buffer "*Elint*" | |
56 "The buffer in which to log lint messages." | |
57 :type 'string | |
58 :safe 'stringp | |
59 :group 'elint) | |
60 | |
61 (defcustom elint-scan-preloaded t | |
62 "Non-nil means to scan `preloaded-file-list' when initializing. | |
63 Otherwise, just scan the DOC file for functions and variables. | |
64 This is faster, but less accurate, since it misses undocumented features. | |
65 This may result in spurious warnings about unknown functions, etc." | |
66 :type 'boolean | |
67 :safe 'booleanp | |
68 :group 'elint | |
69 :version "23.2") | |
70 | |
71 (defcustom elint-ignored-warnings nil | |
72 "If non-nil, a list of issue types that Elint should ignore. | |
73 This is useful if Elint has trouble understanding your code and | |
74 you need to suppress lots of spurious warnings. The valid list elements | |
75 are as follows, and suppress messages about the indicated features: | |
76 undefined-functions - calls to unknown functions | |
77 unbound-reference - reference to unknown variables | |
78 unbound-assignment - assignment to unknown variables | |
79 macro-expansions - failure to expand macros | |
80 empty-let - let-bindings with empty variable lists" | |
81 :type '(choice (const :tag "Don't suppress any warnings" nil) | |
82 (repeat :tag "List of issues to ignore" | |
83 (choice (const undefined-functions | |
84 :tag "Calls to unknown functions") | |
85 (const unbound-reference | |
86 :tag "Reference to unknown variables") | |
87 (const unbound-assignment | |
88 :tag "Assignment to unknown variables") | |
89 (const macro-expansion | |
90 :tag "Failure to expand macros") | |
91 (const empty-let | |
92 :tag "Let-binding with empty varlist")))) | |
93 :safe (lambda (value) (or (null value) | |
94 (and (listp value) | |
95 (equal value | |
96 (mapcar | |
97 (lambda (e) | |
98 (if (memq e | |
99 '(undefined-functions | |
100 unbound-reference | |
101 unbound-assignment | |
102 macro-expansion | |
103 empty-let)) | |
104 e)) | |
105 value))))) | |
106 :version "23.2" | |
107 :group 'elint) | |
108 | |
109 (defcustom elint-directory-skip-re "\\(ldefs-boot\\|loaddefs\\)\\.el\\'" | |
110 "If nil, a regexp matching files to skip when linting a directory." | |
111 :type '(choice (const :tag "Lint all files" nil) | |
112 (regexp :tag "Regexp to skip")) | |
113 :safe 'string-or-null-p | |
114 :group 'elint | |
115 :version "23.2") | |
19210 | 116 |
117 ;;; | |
58938
f3ac898990de
(elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents:
58740
diff
changeset
|
118 ;;; Data |
f3ac898990de
(elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents:
58740
diff
changeset
|
119 ;;; |
f3ac898990de
(elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents:
58740
diff
changeset
|
120 |
106016
042d5d78d053
Shigeru Fukaya <shigeru.fukaya at gmail.com>
Glenn Morris <rgm@gnu.org>
parents:
105305
diff
changeset
|
121 (defconst elint-standard-variables |
106017
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
122 ;; Most of these are defined in C with no documentation. |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
123 ;; FIXME I don't see why they shouldn't just get doc-strings. |
106016
042d5d78d053
Shigeru Fukaya <shigeru.fukaya at gmail.com>
Glenn Morris <rgm@gnu.org>
parents:
105305
diff
changeset
|
124 '(vc-mode local-write-file-hooks activate-menubar-hook buffer-name-history |
042d5d78d053
Shigeru Fukaya <shigeru.fukaya at gmail.com>
Glenn Morris <rgm@gnu.org>
parents:
105305
diff
changeset
|
125 coding-system-history extended-command-history |
042d5d78d053
Shigeru Fukaya <shigeru.fukaya at gmail.com>
Glenn Morris <rgm@gnu.org>
parents:
105305
diff
changeset
|
126 kbd-macro-termination-hook read-expression-history |
042d5d78d053
Shigeru Fukaya <shigeru.fukaya at gmail.com>
Glenn Morris <rgm@gnu.org>
parents:
105305
diff
changeset
|
127 yes-or-no-p-history) |
106017
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
128 "Standard variables, excluding `elint-builtin-variables'. |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
129 These are variables that we cannot detect automatically for some reason.") |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
130 |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
131 (defvar elint-builtin-variables nil |
105137 | 132 "List of built-in variables. Set by `elint-initialize'. |
133 This is actually all those documented in the DOC file, which includes | |
134 built-in variables and those from dumped Lisp files.") | |
58938
f3ac898990de
(elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents:
58740
diff
changeset
|
135 |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
136 (defvar elint-autoloaded-variables nil |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
137 "List of `loaddefs.el' variables. Set by `elint-initialize'.") |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
138 |
105137 | 139 (defvar elint-preloaded-env nil |
140 "Environment defined by the preloaded (dumped) Lisp files. | |
141 Set by `elint-initialize', if `elint-scan-preloaded' is non-nil.") | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
142 |
105137 | 143 (defconst elint-unknown-builtin-args |
144 ;; encode-time allows extra arguments for use with decode-time. | |
145 ;; For some reason, some people seem to like to use them in other cases. | |
146 '((encode-time second minute hour day month year &rest zone)) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
147 "Those built-ins for which we can't find arguments, if any.") |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
148 |
105137 | 149 (defvar elint-extra-errors '(file-locked file-supersession ftp-error) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
150 "Errors without error-message or error-confitions properties.") |
58938
f3ac898990de
(elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents:
58740
diff
changeset
|
151 |
105137 | 152 (defconst elint-preloaded-skip-re |
153 (regexp-opt '("loaddefs.el" "loadup.el" "cus-start" "language/" | |
154 "eucjp-ms" "mule-conf" "/characters" "/charprop" | |
155 "cp51932")) | |
156 "Regexp matching elements of `preloaded-file-list' to ignore. | |
157 We ignore them because they contain no definitions of use to Elint.") | |
158 | |
58938
f3ac898990de
(elint-standard-variables, elint-unknown-builtin-args): Move definitions up.
Richard M. Stallman <rms@gnu.org>
parents:
58740
diff
changeset
|
159 ;;; |
19210 | 160 ;;; ADT: top-form |
161 ;;; | |
162 | |
163 (defsubst elint-make-top-form (form pos) | |
164 "Create a top form. | |
165 FORM is the form, and POS is the point where it starts in the buffer." | |
166 (cons form pos)) | |
167 | |
168 (defsubst elint-top-form-form (top-form) | |
169 "Extract the form from a TOP-FORM." | |
170 (car top-form)) | |
171 | |
172 (defsubst elint-top-form-pos (top-form) | |
173 "Extract the position from a TOP-FORM." | |
174 (cdr top-form)) | |
175 | |
176 ;;; | |
177 ;;; ADT: env | |
178 ;;; | |
179 | |
180 (defsubst elint-make-env () | |
181 "Create an empty environment." | |
182 (list (list nil) nil nil)) | |
183 | |
184 (defsubst elint-env-add-env (env newenv) | |
185 "Augment ENV with NEWENV. | |
186 None of them is modified, and the new env is returned." | |
187 (list (append (car env) (car newenv)) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
188 (append (cadr env) (cadr newenv)) |
19210 | 189 (append (car (cdr (cdr env))) (car (cdr (cdr newenv)))))) |
190 | |
191 (defsubst elint-env-add-var (env var) | |
192 "Augment ENV with the variable VAR. | |
193 The new environment is returned, the old is unmodified." | |
194 (cons (cons (list var) (car env)) (cdr env))) | |
195 | |
196 (defsubst elint-env-add-global-var (env var) | |
197 "Augment ENV with the variable VAR. | |
198 ENV is modified so VAR is seen everywhere. | |
199 ENV is returned." | |
200 (nconc (car env) (list (list var))) | |
201 env) | |
202 | |
203 (defsubst elint-env-find-var (env var) | |
204 "Non-nil if ENV contains the variable VAR. | |
205 Actually, a list with VAR as a single element is returned." | |
206 (assq var (car env))) | |
207 | |
208 (defsubst elint-env-add-func (env func args) | |
209 "Augment ENV with the function FUNC, which has the arguments ARGS. | |
210 The new environment is returned, the old is unmodified." | |
211 (list (car env) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
212 (cons (list func args) (cadr env)) |
19210 | 213 (car (cdr (cdr env))))) |
214 | |
215 (defsubst elint-env-find-func (env func) | |
216 "Non-nil if ENV contains the function FUNC. | |
217 Actually, a list of (FUNC ARGS) is returned." | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
218 (assq func (cadr env))) |
19210 | 219 |
220 (defsubst elint-env-add-macro (env macro def) | |
221 "Augment ENV with the macro named MACRO. | |
222 DEF is the macro definition (a lambda expression or similar). | |
223 The new environment is returned, the old is unmodified." | |
224 (list (car env) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
225 (cadr env) |
19210 | 226 (cons (cons macro def) (car (cdr (cdr env)))))) |
227 | |
228 (defsubst elint-env-macro-env (env) | |
229 "Return the macro environment of ENV. | |
230 This environment can be passed to `macroexpand'." | |
231 (car (cdr (cdr env)))) | |
232 | |
233 (defsubst elint-env-macrop (env macro) | |
234 "Non-nil if ENV contains MACRO." | |
235 (assq macro (elint-env-macro-env env))) | |
236 | |
237 ;;; | |
238 ;;; User interface | |
239 ;;; | |
240 | |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
241 ;;;###autoload |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
242 (defun elint-file (file) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
243 "Lint the file FILE." |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
244 (interactive "fElint file: ") |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
245 (setq file (expand-file-name file)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
246 (or elint-builtin-variables |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
247 (elint-initialize)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
248 (let ((dir (file-name-directory file))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
249 (let ((default-directory dir)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
250 (elint-display-log)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
251 (elint-set-mode-line t) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
252 (with-current-buffer elint-log-buffer |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
253 (unless (string-equal default-directory dir) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
254 (elint-log-message (format "\nLeaving directory `%s'" |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
255 default-directory) t) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
256 (elint-log-message (format "Entering directory `%s'" dir) t) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
257 (setq default-directory dir)))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
258 (let ((str (format "Linting file %s" file))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
259 (message "%s..." str) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
260 (or noninteractive |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
261 (elint-log-message (format "\n%s at %s" str (current-time-string)) t)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
262 ;; elint-current-buffer clears log. |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
263 (with-temp-buffer |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
264 (insert-file-contents file) |
104985
25639b195258
(elint-file): Make max-lisp-eval-depth at least 1000.
Glenn Morris <rgm@gnu.org>
parents:
104974
diff
changeset
|
265 (let ((buffer-file-name file) |
25639b195258
(elint-file): Make max-lisp-eval-depth at least 1000.
Glenn Morris <rgm@gnu.org>
parents:
104974
diff
changeset
|
266 (max-lisp-eval-depth (max 1000 max-lisp-eval-depth))) |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
267 (with-syntax-table emacs-lisp-mode-syntax-table |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
268 (mapc 'elint-top-form (elint-update-env))))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
269 (elint-set-mode-line) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
270 (message "%s...done" str))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
271 |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
272 ;; cf byte-recompile-directory. |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
273 ;;;###autoload |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
274 (defun elint-directory (directory) |
105137 | 275 "Lint all the .el files in DIRECTORY. |
276 A complicated directory may require a lot of memory." | |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
277 (interactive "DElint directory: ") |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
278 (let ((elint-running t)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
279 (dolist (file (directory-files directory t)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
280 ;; Bytecomp has emacs-lisp-file-regexp. |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
281 (when (and (string-match "\\.el\\'" file) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
282 (file-readable-p file) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
283 (not (auto-save-file-name-p file))) |
105137 | 284 (if (string-match elint-directory-skip-re file) |
285 (message "Skipping file %s" file) | |
286 (elint-file file))))) | |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
287 (elint-set-mode-line)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
288 |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
289 ;;;###autoload |
19210 | 290 (defun elint-current-buffer () |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
291 "Lint the current buffer. |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
292 If necessary, this first calls `elint-initalize'." |
19210 | 293 (interactive) |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
294 (or elint-builtin-variables |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
295 (elint-initialize)) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
296 (elint-clear-log (format "Linting %s" (or (buffer-file-name) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
297 (buffer-name)))) |
19210 | 298 (elint-display-log) |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
299 (elint-set-mode-line t) |
84899
789f9201f375
(elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents:
78217
diff
changeset
|
300 (mapc 'elint-top-form (elint-update-env)) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
301 ;; Tell the user we're finished. This is terribly klugy: we set |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
302 ;; elint-top-form-logged so elint-log-message doesn't print the |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
303 ;; ** top form ** header... |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
304 (elint-set-mode-line) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
305 (elint-log-message "\nLinting finished.\n" t)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
306 |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
307 |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
308 ;;;###autoload |
19210 | 309 (defun elint-defun () |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
310 "Lint the function at point. |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
311 If necessary, this first calls `elint-initalize'." |
19210 | 312 (interactive) |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
313 (or elint-builtin-variables |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
314 (elint-initialize)) |
19210 | 315 (save-excursion |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
316 (or (beginning-of-defun) (error "Lint what?")) |
19210 | 317 (let ((pos (point)) |
318 (def (read (current-buffer)))) | |
319 (elint-display-log) | |
320 (elint-update-env) | |
321 (elint-top-form (elint-make-top-form def pos))))) | |
322 | |
323 ;;; | |
324 ;;; Top form functions | |
325 ;;; | |
326 | |
327 (defvar elint-buffer-env nil | |
328 "The environment of a elisp buffer. | |
329 Will be local in linted buffers.") | |
330 | |
331 (defvar elint-buffer-forms nil | |
332 "The top forms in a buffer. | |
333 Will be local in linted buffers.") | |
334 | |
335 (defvar elint-last-env-time nil | |
336 "The last time the buffers env was updated. | |
337 Is measured in buffer-modified-ticks and is local in linted buffers.") | |
338 | |
105137 | 339 ;; This is a minor optimization. It is local to every buffer, and so |
340 ;; does not prevent recursive requirs. It does not list the requires | |
341 ;; of requires. | |
342 (defvar elint-features nil | |
343 "List of all libraries this buffer has required, or that have been provided.") | |
344 | |
19210 | 345 (defun elint-update-env () |
346 "Update the elint environment in the current buffer. | |
347 Don't do anything if the buffer hasn't been changed since this | |
348 function was called the last time. | |
349 Returns the forms." | |
350 (if (and (local-variable-p 'elint-buffer-env (current-buffer)) | |
351 (local-variable-p 'elint-buffer-forms (current-buffer)) | |
352 (local-variable-p 'elint-last-env-time (current-buffer)) | |
353 (= (buffer-modified-tick) elint-last-env-time)) | |
354 ;; Env is up to date | |
355 elint-buffer-forms | |
356 ;; Remake env | |
357 (set (make-local-variable 'elint-buffer-forms) (elint-get-top-forms)) | |
105137 | 358 (set (make-local-variable 'elint-features) nil) |
19210 | 359 (set (make-local-variable 'elint-buffer-env) |
360 (elint-init-env elint-buffer-forms)) | |
105137 | 361 (if elint-preloaded-env |
362 (elint-env-add-env elint-preloaded-env elint-buffer-env)) | |
19210 | 363 (set (make-local-variable 'elint-last-env-time) (buffer-modified-tick)) |
364 elint-buffer-forms)) | |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
365 |
19210 | 366 (defun elint-get-top-forms () |
367 "Collect all the top forms in the current buffer." | |
368 (save-excursion | |
105137 | 369 (let (tops) |
19210 | 370 (goto-char (point-min)) |
371 (while (elint-find-next-top-form) | |
105137 | 372 (let ((elint-current-pos (point))) |
373 ;; non-list check could be here too. errors may be out of seq. | |
374 ;; quoted check cannot be elsewhere, since quotes skipped. | |
375 (if (looking-back "'") | |
376 ;; Eg cust-print.el uses ' as a comment syntax. | |
377 (elint-warning "Skipping quoted form `'%.20s...'" | |
378 (read (current-buffer))) | |
379 (condition-case nil | |
380 (setq tops (cons | |
381 (elint-make-top-form (read (current-buffer)) | |
382 elint-current-pos) | |
383 tops)) | |
384 (end-of-file | |
385 (goto-char elint-current-pos) | |
386 (error "Missing ')' in top form: %s" | |
387 (buffer-substring elint-current-pos | |
388 (line-end-position)))))))) | |
19210 | 389 (nreverse tops)))) |
390 | |
391 (defun elint-find-next-top-form () | |
392 "Find the next top form from point. | |
42206 | 393 Return nil if there are no more forms, t otherwise." |
19210 | 394 (parse-partial-sexp (point) (point-max) nil t) |
395 (not (eobp))) | |
396 | |
105137 | 397 (defvar env) ; from elint-init-env |
398 | |
399 (defun elint-init-form (form) | |
400 "Process FORM, adding to ENV if recognized." | |
401 (cond | |
402 ;; Eg nnmaildir seems to use [] as a form of comment syntax. | |
403 ((not (listp form)) | |
404 (elint-warning "Skipping non-list form `%s'" form)) | |
405 ;; Add defined variable | |
406 ((memq (car form) '(defvar defconst defcustom)) | |
407 (setq env (elint-env-add-var env (cadr form)))) | |
408 ;; Add function | |
409 ((memq (car form) '(defun defsubst)) | |
410 (setq env (elint-env-add-func env (cadr form) (nth 2 form)))) | |
411 ;; FIXME needs a handler to say second arg is not a variable when we come | |
412 ;; to scan the form. | |
413 ((eq (car form) 'define-derived-mode) | |
414 (setq env (elint-env-add-func env (cadr form) ()) | |
415 env (elint-env-add-var env (cadr form)) | |
416 env (elint-env-add-var env (intern (format "%s-map" (cadr form)))))) | |
417 ((eq (car form) 'define-minor-mode) | |
418 (setq env (elint-env-add-func env (cadr form) '(&optional arg)) | |
419 ;; FIXME mode map? | |
420 env (elint-env-add-var env (cadr form)))) | |
421 ((and (eq (car form) 'easy-menu-define) | |
422 (cadr form)) | |
423 (setq env (elint-env-add-func env (cadr form) '(event)) | |
424 env (elint-env-add-var env (cadr form)))) | |
425 ;; FIXME it would be nice to check the autoloads are correct. | |
426 ((eq (car form) 'autoload) | |
427 (setq env (elint-env-add-func env (cadr (cadr form)) 'unknown))) | |
428 ((eq (car form) 'declare-function) | |
105305
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
429 (setq env (elint-env-add-func |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
430 env (cadr form) |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
431 (if (or (< (length form) 4) |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
432 (eq (nth 3 form) t) |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
433 (unless (stringp (nth 2 form)) |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
434 (elint-error "Malformed declaration for `%s'" |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
435 (cadr form)) |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
436 t)) |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
437 'unknown |
76b69a033cf7
(elint-init-form): Report declarations where the filename is not a string.
Glenn Morris <rgm@gnu.org>
parents:
105137
diff
changeset
|
438 (nth 3 form))))) |
105137 | 439 ((and (eq (car form) 'defalias) (listp (nth 2 form))) |
440 ;; If the alias points to something already in the environment, | |
441 ;; add the alias to the environment with the same arguments. | |
442 ;; FIXME symbol-function, eg backquote.el? | |
443 (let ((def (elint-env-find-func env (cadr (nth 2 form))))) | |
444 (setq env (elint-env-add-func env (cadr (cadr form)) | |
445 (if def (cadr def) 'unknown))))) | |
446 ;; Add macro, both as a macro and as a function | |
447 ((eq (car form) 'defmacro) | |
448 (setq env (elint-env-add-macro env (cadr form) | |
449 (cons 'lambda (cddr form))) | |
450 env (elint-env-add-func env (cadr form) (nth 2 form)))) | |
451 ((and (eq (car form) 'put) | |
452 (= 4 (length form)) | |
453 (eq (car-safe (cadr form)) 'quote) | |
454 (equal (nth 2 form) '(quote error-conditions))) | |
455 (set (make-local-variable 'elint-extra-errors) | |
456 (cons (cadr (cadr form)) elint-extra-errors))) | |
457 ((eq (car form) 'provide) | |
458 (add-to-list 'elint-features (eval (cadr form)))) | |
459 ;; Import variable definitions | |
460 ((memq (car form) '(require cc-require cc-require-when-compile)) | |
461 (let ((name (eval (cadr form))) | |
462 (file (eval (nth 2 form))) | |
463 (elint-doing-cl (bound-and-true-p elint-doing-cl))) | |
464 (unless (memq name elint-features) | |
465 (add-to-list 'elint-features name) | |
466 ;; cl loads cl-macs in an opaque manner. | |
467 ;; Since cl-macs requires cl, we can just process cl-macs. | |
468 (and (eq name 'cl) (not elint-doing-cl) | |
469 ;; We need cl if elint-form is to be able to expand cl macros. | |
470 (require 'cl) | |
471 (setq name 'cl-macs | |
472 file nil | |
473 elint-doing-cl t)) ; blech | |
474 (setq env (elint-add-required-env env name file)))))) | |
475 env) | |
476 | |
19210 | 477 (defun elint-init-env (forms) |
63511
964ef053b1bc
(elint-init-env): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
59506
diff
changeset
|
478 "Initialize the environment from FORMS." |
19210 | 479 (let ((env (elint-make-env)) |
480 form) | |
481 (while forms | |
482 (setq form (elint-top-form-form (car forms)) | |
483 forms (cdr forms)) | |
105137 | 484 ;; FIXME eval-when-compile should be treated differently (macros). |
485 ;; Could bind something that makes elint-init-form only check | |
486 ;; defmacros. | |
487 (if (memq (car-safe form) | |
488 '(eval-and-compile eval-when-compile progn prog1 prog2 | |
489 with-no-warnings)) | |
490 (mapc 'elint-init-form (cdr form)) | |
491 (elint-init-form form))) | |
19210 | 492 env)) |
493 | |
494 (defun elint-add-required-env (env name file) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
495 "Augment ENV with the variables defined by feature NAME in FILE." |
106226
85863d02e2db
* emacs-lisp/elint.el (elint-add-required-env): Better error message
Kevin Ryde <user42@zip.com.au>
parents:
106017
diff
changeset
|
496 (condition-case err |
19210 | 497 (let* ((libname (if (stringp file) |
498 file | |
499 (symbol-name name))) | |
500 | |
501 ;; First try to find .el files, then the raw name | |
502 (lib1 (locate-library (concat libname ".el") t)) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
503 (lib (or lib1 (locate-library libname t)))) |
19210 | 504 ;; Clear the messages :-/ |
105137 | 505 ;; (Messes up the "Initializing elint..." message.) |
506 ;;; (message nil) | |
19210 | 507 (if lib |
508 (save-excursion | |
105008
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
509 ;; FIXME this doesn't use a temp buffer, because it |
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
510 ;; stores the result in buffer-local variables so that |
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
511 ;; it can be reused. |
105137 | 512 (set-buffer (find-file-noselect lib)) |
513 (elint-update-env) | |
514 (setq env (elint-env-add-env env elint-buffer-env))) | |
105008
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
515 ;;; (with-temp-buffer |
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
516 ;;; (insert-file-contents lib) |
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
517 ;;; (with-syntax-table emacs-lisp-mode-syntax-table |
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
518 ;;; (elint-update-env)) |
b9b9c3b2718d
(elint-add-required-env): Revert to not using temp-buffers (2009-09-12).
Glenn Morris <rgm@gnu.org>
parents:
104989
diff
changeset
|
519 ;;; (setq env (elint-env-add-env env elint-buffer-env)))) |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
520 ;;(message "Elint processed (require '%s)" name)) |
106226
85863d02e2db
* emacs-lisp/elint.el (elint-add-required-env): Better error message
Kevin Ryde <user42@zip.com.au>
parents:
106017
diff
changeset
|
521 (error "%s.el not found in load-path" libname))) |
19210 | 522 (error |
106226
85863d02e2db
* emacs-lisp/elint.el (elint-add-required-env): Better error message
Kevin Ryde <user42@zip.com.au>
parents:
106017
diff
changeset
|
523 (message "Can't get variables from require'd library %s: %s" |
85863d02e2db
* emacs-lisp/elint.el (elint-add-required-env): Better error message
Kevin Ryde <user42@zip.com.au>
parents:
106017
diff
changeset
|
524 name (error-message-string err)))) |
19210 | 525 env) |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
526 |
19210 | 527 (defvar elint-top-form nil |
528 "The currently linted top form, or nil.") | |
529 | |
530 (defvar elint-top-form-logged nil | |
531 "T if the currently linted top form has been mentioned in the log buffer.") | |
532 | |
533 (defun elint-top-form (form) | |
534 "Lint a top FORM." | |
535 (let ((elint-top-form form) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
536 (elint-top-form-logged nil) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
537 (elint-current-pos (elint-top-form-pos form))) |
19210 | 538 (elint-form (elint-top-form-form form) elint-buffer-env))) |
539 | |
540 ;;; | |
541 ;;; General form linting functions | |
542 ;;; | |
543 | |
544 (defconst elint-special-forms | |
545 '((let . elint-check-let-form) | |
546 (let* . elint-check-let-form) | |
547 (setq . elint-check-setq-form) | |
548 (quote . elint-check-quote-form) | |
105137 | 549 (function . elint-check-quote-form) |
19210 | 550 (cond . elint-check-cond-form) |
551 (lambda . elint-check-defun-form) | |
552 (function . elint-check-function-form) | |
553 (setq-default . elint-check-setq-form) | |
105137 | 554 (defalias . elint-check-defalias-form) |
19210 | 555 (defun . elint-check-defun-form) |
556 (defsubst . elint-check-defun-form) | |
557 (defmacro . elint-check-defun-form) | |
558 (defvar . elint-check-defvar-form) | |
559 (defconst . elint-check-defvar-form) | |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
560 (defcustom . elint-check-defcustom-form) |
19210 | 561 (macro . elint-check-macro-form) |
105137 | 562 (condition-case . elint-check-condition-case-form) |
563 (if . elint-check-conditional-form) | |
564 (when . elint-check-conditional-form) | |
565 (unless . elint-check-conditional-form) | |
566 (and . elint-check-conditional-form) | |
567 (or . elint-check-conditional-form)) | |
19210 | 568 "Functions to call when some special form should be linted.") |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
569 |
105137 | 570 (defun elint-form (form env &optional nohandler) |
19210 | 571 "Lint FORM in the environment ENV. |
105137 | 572 Optional argument NOHANDLER non-nil means ignore `elint-special-forms'. |
573 Returns the environment created by the form." | |
19210 | 574 (cond |
575 ((consp form) | |
576 (let ((func (cdr (assq (car form) elint-special-forms)))) | |
105137 | 577 (if (and func (not nohandler)) |
19210 | 578 ;; Special form |
579 (funcall func form env) | |
580 | |
581 (let* ((func (car form)) | |
582 (args (elint-get-args func env)) | |
583 (argsok t)) | |
584 (cond | |
585 ((eq args 'undefined) | |
586 (setq argsok nil) | |
105137 | 587 (or (memq 'undefined-functions elint-ignored-warnings) |
588 (elint-error "Call to undefined function: %s" func))) | |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
589 |
19210 | 590 ((eq args 'unknown) nil) |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
591 |
19210 | 592 (t (setq argsok (elint-match-args form args)))) |
593 | |
594 ;; Is this a macro? | |
595 (if (elint-env-macrop env func) | |
596 ;; Macro defined in buffer, expand it | |
597 (if argsok | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
598 ;; FIXME error if macro uses macro, eg bytecomp.el. |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
599 (condition-case nil |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
600 (elint-form |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
601 (macroexpand form (elint-env-macro-env env)) env) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
602 (error |
105137 | 603 (or (memq 'macro-expansion elint-ignored-warnings) |
604 (elint-error "Elint failed to expand macro: %s" func)) | |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
605 env)) |
19210 | 606 env) |
607 | |
608 (let ((fcode (if (symbolp func) | |
609 (if (fboundp func) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
610 (indirect-function func)) |
19210 | 611 func))) |
612 (if (and (listp fcode) (eq (car fcode) 'macro)) | |
613 ;; Macro defined outside buffer | |
614 (if argsok | |
615 (elint-form (macroexpand form) env) | |
616 env) | |
617 ;; Function, lint its parameters | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
618 (elint-forms (cdr form) env)))))))) |
19210 | 619 ((symbolp form) |
620 ;; :foo variables are quoted | |
105137 | 621 (and (/= (aref (symbol-name form) 0) ?:) |
622 (not (memq 'unbound-reference elint-ignored-warnings)) | |
623 (elint-unbound-variable form env) | |
624 (elint-warning "Reference to unbound symbol: %s" form)) | |
19210 | 625 env) |
626 | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
627 (t env))) |
19210 | 628 |
629 (defun elint-forms (forms env) | |
630 "Lint the FORMS, accumulating an environment, starting with ENV." | |
631 ;; grumblegrumbletailrecursiongrumblegrumble | |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
632 (if (listp forms) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
633 (dolist (f forms env) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
634 (setq env (elint-form f env))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
635 ;; Loop macro? |
104985
25639b195258
(elint-file): Make max-lisp-eval-depth at least 1000.
Glenn Morris <rgm@gnu.org>
parents:
104974
diff
changeset
|
636 (elint-error "Elint failed to parse form: %s" forms) |
25639b195258
(elint-file): Make max-lisp-eval-depth at least 1000.
Glenn Morris <rgm@gnu.org>
parents:
104974
diff
changeset
|
637 env)) |
19210 | 638 |
105137 | 639 (defvar elint-bound-variable nil |
640 "Name of a temporarily bound symbol.") | |
641 | |
19210 | 642 (defun elint-unbound-variable (var env) |
643 "T if VAR is unbound in ENV." | |
106017
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
644 ;; #1063 suggests adding (symbol-file var) here, but I don't think |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
645 ;; this is right, because it depends on what files you happen to have |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
646 ;; loaded at the time, which might not be the same when the code runs. |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
647 ;; It also suggests adding: |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
648 ;; (numberp (get var 'variable-documentation)) |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
649 ;; (numberp (cdr-safe (get var 'variable-documentation))) |
660fd54d2835
(elint-standard-variables): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
106016
diff
changeset
|
650 ;; but this is not needed now elint-scan-doc-file exists. |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
651 (not (or (memq var '(nil t)) |
105137 | 652 (eq var elint-bound-variable) |
19210 | 653 (elint-env-find-var env var) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
654 (memq var elint-builtin-variables) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
655 (memq var elint-autoloaded-variables) |
19210 | 656 (memq var elint-standard-variables)))) |
657 | |
658 ;;; | |
659 ;;; Function argument checking | |
660 ;;; | |
661 | |
662 (defun elint-match-args (arglist argpattern) | |
663 "Match ARGLIST against ARGPATTERN." | |
664 (let ((state 'all) | |
665 (al (cdr arglist)) | |
666 (ap argpattern) | |
667 (ok t)) | |
668 (while | |
669 (cond | |
670 ((and (null al) (null ap)) nil) | |
671 ((eq (car ap) '&optional) | |
672 (setq state 'optional) | |
673 (setq ap (cdr ap)) | |
674 t) | |
675 ((eq (car ap) '&rest) | |
676 nil) | |
677 ((or (and (eq state 'all) (or (null al) (null ap))) | |
678 (and (eq state 'optional) (and al (null ap)))) | |
679 (elint-error "Wrong number of args: %s, %s" arglist argpattern) | |
680 (setq ok nil) | |
681 nil) | |
682 ((and (eq state 'optional) (null al)) | |
683 nil) | |
684 (t (setq al (cdr al) | |
685 ap (cdr ap)) | |
686 t))) | |
687 ok)) | |
688 | |
105137 | 689 (defvar elint-bound-function nil |
690 "Name of a temporarily bound function symbol.") | |
691 | |
19210 | 692 (defun elint-get-args (func env) |
693 "Find the args of FUNC in ENV. | |
694 Returns `unknown' if we couldn't find arguments." | |
695 (let ((f (elint-env-find-func env func))) | |
696 (if f | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
697 (cadr f) |
19210 | 698 (if (symbolp func) |
105137 | 699 (if (eq func elint-bound-function) |
700 'unknown | |
701 (if (fboundp func) | |
702 (let ((fcode (indirect-function func))) | |
703 (if (subrp fcode) | |
704 ;; FIXME builtins with no args have args = nil. | |
705 (or (get func 'elint-args) 'unknown) | |
706 (elint-find-args-in-code fcode))) | |
707 'undefined)) | |
19210 | 708 (elint-find-args-in-code func))))) |
709 | |
710 (defun elint-find-args-in-code (code) | |
711 "Extract the arguments from CODE. | |
712 CODE can be a lambda expression, a macro, or byte-compiled code." | |
713 (cond | |
714 ((byte-code-function-p code) | |
715 (aref code 0)) | |
716 ((and (listp code) (eq (car code) 'lambda)) | |
717 (car (cdr code))) | |
718 ((and (listp code) (eq (car code) 'macro)) | |
719 (elint-find-args-in-code (cdr code))) | |
720 (t 'unknown))) | |
721 | |
722 ;;; | |
723 ;;; Functions to check some special forms | |
724 ;;; | |
725 | |
726 (defun elint-check-cond-form (form env) | |
727 "Lint a cond FORM in ENV." | |
105137 | 728 (dolist (f (cdr form)) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
729 (if (consp f) |
105137 | 730 (let ((test (car f))) |
731 (cond ((equal test '(featurep (quote xemacs)))) | |
732 ((equal test '(not (featurep (quote emacs))))) | |
733 ;; FIXME (and (boundp 'foo) | |
734 ((and (eq (car-safe test) 'fboundp) | |
735 (= 2 (length test)) | |
736 (eq (car-safe (cadr test)) 'quote)) | |
737 (let ((elint-bound-function (cadr (cadr test)))) | |
738 (elint-forms f env))) | |
739 ((and (eq (car-safe test) 'boundp) | |
740 (= 2 (length test)) | |
741 (eq (car-safe (cadr test)) 'quote)) | |
742 (let ((elint-bound-variable (cadr (cadr test)))) | |
743 (elint-forms f env))) | |
744 (t (elint-forms f env)))) | |
745 (elint-error "cond clause should be a list: %s" f))) | |
746 env) | |
19210 | 747 |
748 (defun elint-check-defun-form (form env) | |
749 "Lint a defun/defmacro/lambda FORM in ENV." | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
750 (setq form (if (eq (car form) 'lambda) (cdr form) (cddr form))) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
751 (mapc (lambda (p) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
752 (or (memq p '(&optional &rest)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
753 (setq env (elint-env-add-var env p)))) |
84899
789f9201f375
(elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents:
78217
diff
changeset
|
754 (car form)) |
19210 | 755 (elint-forms (cdr form) env)) |
756 | |
105137 | 757 (defun elint-check-defalias-form (form env) |
758 "Lint a defalias FORM in ENV." | |
759 (let ((alias (cadr form)) | |
760 (target (nth 2 form))) | |
761 (and (eq (car-safe alias) 'quote) | |
762 (eq (car-safe target) 'quote) | |
763 (eq (elint-get-args (cadr target) env) 'undefined) | |
764 (elint-warning "Alias `%s' has unknown target `%s'" | |
765 (cadr alias) (cadr target)))) | |
766 (elint-form form env t)) | |
767 | |
19210 | 768 (defun elint-check-let-form (form env) |
769 "Lint the let/let* FORM in ENV." | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
770 (let ((varlist (cadr form))) |
19210 | 771 (if (not varlist) |
105137 | 772 (if (> (length form) 2) |
773 ;; An empty varlist is not really an error. Eg some cl macros | |
774 ;; can expand to such a form. | |
775 (progn | |
776 (or (memq 'empty-let elint-ignored-warnings) | |
777 (elint-warning "Empty varlist in let: %s" form)) | |
778 ;; Lint the body forms | |
779 (elint-forms (cddr form) env)) | |
780 (elint-error "Malformed let: %s" form) | |
19210 | 781 env) |
782 ;; Check for (let (a (car b)) ...) type of error | |
783 (if (and (= (length varlist) 2) | |
784 (symbolp (car varlist)) | |
785 (listp (car (cdr varlist))) | |
786 (fboundp (car (car (cdr varlist))))) | |
787 (elint-warning "Suspect varlist: %s" form)) | |
788 ;; Add variables to environment, and check the init values | |
789 (let ((newenv env)) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
790 (mapc (lambda (s) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
791 (cond |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
792 ((symbolp s) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
793 (setq newenv (elint-env-add-var newenv s))) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
794 ((and (consp s) (<= (length s) 2)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
795 (elint-form (cadr s) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
796 (if (eq (car form) 'let) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
797 env |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
798 newenv)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
799 (setq newenv |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
800 (elint-env-add-var newenv (car s)))) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
801 (t (elint-error |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
802 "Malformed `let' declaration: %s" s)))) |
84899
789f9201f375
(elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents:
78217
diff
changeset
|
803 varlist) |
19210 | 804 |
805 ;; Lint the body forms | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
806 (elint-forms (cddr form) newenv))))) |
19210 | 807 |
808 (defun elint-check-setq-form (form env) | |
809 "Lint the setq FORM in ENV." | |
810 (or (= (mod (length form) 2) 1) | |
105137 | 811 ;; (setq foo) is valid and equivalent to (setq foo nil). |
812 (elint-warning "Missing value in setq: %s" form)) | |
19210 | 813 (let ((newenv env) |
814 sym val) | |
815 (setq form (cdr form)) | |
816 (while form | |
817 (setq sym (car form) | |
818 val (car (cdr form)) | |
819 form (cdr (cdr form))) | |
820 (if (symbolp sym) | |
105137 | 821 (and (not (memq 'unbound-assignment elint-ignored-warnings)) |
822 (elint-unbound-variable sym newenv) | |
823 (elint-warning "Setting previously unbound symbol: %s" sym)) | |
19210 | 824 (elint-error "Setting non-symbol in setq: %s" sym)) |
825 (elint-form val newenv) | |
826 (if (symbolp sym) | |
827 (setq newenv (elint-env-add-var newenv sym)))) | |
828 newenv)) | |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
829 |
19210 | 830 (defun elint-check-defvar-form (form env) |
831 "Lint the defvar/defconst FORM in ENV." | |
832 (if (or (= (length form) 2) | |
833 (= (length form) 3) | |
105137 | 834 ;; Eg the defcalcmodevar macro can expand with a nil doc-string. |
835 (and (= (length form) 4) (string-or-null-p (nth 3 form)))) | |
19210 | 836 (elint-env-add-global-var (elint-form (nth 2 form) env) |
837 (car (cdr form))) | |
838 (elint-error "Malformed variable declaration: %s" form) | |
839 env)) | |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
840 |
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
841 (defun elint-check-defcustom-form (form env) |
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
842 "Lint the defcustom FORM in ENV." |
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
843 (if (and (> (length form) 3) |
52880
9417a94488d3
(elint-check-defcustom-form): Don't use `evenp' so we don't implicitly
John Paul Wallington <jpw@pobox.com>
parents:
52401
diff
changeset
|
844 ;; even no. of keyword/value args ? |
9417a94488d3
(elint-check-defcustom-form): Don't use `evenp' so we don't implicitly
John Paul Wallington <jpw@pobox.com>
parents:
52401
diff
changeset
|
845 (zerop (logand (length form) 1))) |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
846 (elint-env-add-global-var (elint-form (nth 2 form) env) |
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
847 (car (cdr form))) |
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
848 (elint-error "Malformed variable declaration: %s" form) |
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
849 env)) |
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
850 |
19210 | 851 (defun elint-check-function-form (form env) |
852 "Lint the function FORM in ENV." | |
853 (let ((func (car (cdr-safe form)))) | |
854 (cond | |
855 ((symbolp func) | |
856 (or (elint-env-find-func env func) | |
105137 | 857 ;; FIXME potentially bogus, since it uses the current |
858 ;; environment rather than a clean one. | |
19210 | 859 (fboundp func) |
860 (elint-warning "Reference to undefined function: %s" form)) | |
861 env) | |
862 ((and (consp func) (memq (car func) '(lambda macro))) | |
863 (elint-form func env)) | |
864 ((stringp func) env) | |
865 (t (elint-error "Not a function object: %s" form) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
866 env)))) |
19210 | 867 |
868 (defun elint-check-quote-form (form env) | |
869 "Lint the quote FORM in ENV." | |
870 env) | |
871 | |
872 (defun elint-check-macro-form (form env) | |
873 "Check the macro FORM in ENV." | |
874 (elint-check-function-form (list (car form) (cdr form)) env)) | |
875 | |
876 (defun elint-check-condition-case-form (form env) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
877 "Check the `condition-case' FORM in ENV." |
19210 | 878 (let ((resenv env)) |
879 (if (< (length form) 3) | |
880 (elint-error "Malformed condition-case: %s" form) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
881 (or (symbolp (cadr form)) |
19210 | 882 (elint-warning "First parameter should be a symbol: %s" form)) |
883 (setq resenv (elint-form (nth 2 form) env)) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
884 (let ((newenv (elint-env-add-var env (cadr form))) |
19210 | 885 errlist) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
886 (dolist (err (nthcdr 3 form)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
887 (setq errlist (car err)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
888 (mapc (lambda (s) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
889 (or (get s 'error-conditions) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
890 (get s 'error-message) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
891 (memq s elint-extra-errors) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
892 (elint-warning |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
893 "Not an error symbol in error handler: %s" s))) |
84899
789f9201f375
(elint-current-buffer, elint-check-defun-form, elint-check-let-form,
Juanma Barranquero <lekktu@gmail.com>
parents:
78217
diff
changeset
|
894 (cond |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
895 ((symbolp errlist) (list errlist)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
896 ((listp errlist) errlist) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
897 (t (elint-error "Bad error list in error handler: %s" |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
898 errlist) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
899 nil))) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
900 (elint-forms (cdr err) newenv)))) |
19210 | 901 resenv)) |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
902 |
105137 | 903 ;; For the featurep parts, an alternative is to have |
904 ;; elint-get-top-forms skip the irrelevant branches. | |
905 (defun elint-check-conditional-form (form env) | |
906 "Check the when/unless/and/or FORM in ENV. | |
907 Does basic handling of `featurep' tests." | |
908 (let ((func (car form)) | |
909 (test (cadr form)) | |
910 sym) | |
911 ;; Misses things like (and t (featurep 'xemacs)) | |
912 ;; Check byte-compile-maybe-guarded. | |
913 (cond ((and (memq func '(when and)) | |
914 (eq (car-safe test) 'boundp) | |
915 (= 2 (length test)) | |
916 (eq (car-safe (cadr test)) 'quote)) | |
917 ;; Cf elint-check-let-form, which modifies the whole ENV. | |
918 (let ((elint-bound-variable (cadr (cadr test)))) | |
919 (elint-form form env t))) | |
920 ((and (memq func '(when and)) | |
921 (eq (car-safe test) 'fboundp) | |
922 (= 2 (length test)) | |
923 (eq (car-safe (cadr test)) 'quote)) | |
924 (let ((elint-bound-function (cadr (cadr test)))) | |
925 (elint-form form env t))) | |
926 ;; Let's not worry about (if (not (boundp... | |
927 ((and (eq func 'if) | |
928 (eq (car-safe test) 'boundp) | |
929 (= 2 (length test)) | |
930 (eq (car-safe (cadr test)) 'quote)) | |
931 (let ((elint-bound-variable (cadr (cadr test)))) | |
932 (elint-form (nth 2 form) env)) | |
933 (dolist (f (nthcdr 3 form)) | |
934 (elint-form f env))) | |
935 ((and (eq func 'if) | |
936 (eq (car-safe test) 'fboundp) | |
937 (= 2 (length test)) | |
938 (eq (car-safe (cadr test)) 'quote)) | |
939 (let ((elint-bound-function (cadr (cadr test)))) | |
940 (elint-form (nth 2 form) env)) | |
941 (dolist (f (nthcdr 3 form)) | |
942 (elint-form f env))) | |
943 ((and (memq func '(when and)) ; skip all | |
944 (or (null test) | |
945 (member test '((featurep (quote xemacs)) | |
946 (not (featurep (quote emacs))))) | |
947 (and (eq (car-safe test) 'and) | |
948 (equal (car-safe (cdr test)) | |
949 '(featurep (quote xemacs))))))) | |
950 ((and (memq func '(unless or)) | |
951 (equal test '(featurep (quote emacs))))) | |
952 ((and (eq func 'if) | |
953 (or (null test) ; eg custom-browse-insert-prefix | |
954 (member test '((featurep (quote xemacs)) | |
955 (not (featurep (quote emacs))))) | |
956 (and (eq (car-safe test) 'and) | |
957 (equal (car-safe (cdr test)) | |
958 '(featurep (quote xemacs)))))) | |
959 (dolist (f (nthcdr 3 form)) | |
960 (elint-form f env))) ; lint the else branch | |
961 ((and (eq func 'if) | |
962 (equal test '(featurep (quote emacs)))) | |
963 (elint-form (nth 2 form) env)) ; lint the if branch | |
964 ;; Process conditional as normal, without handler. | |
965 (t | |
966 (elint-form form env t)))) | |
967 env) | |
968 | |
19210 | 969 ;;; |
970 ;;; Message functions | |
971 ;;; | |
972 | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
973 (defvar elint-current-pos) ; dynamically bound in elint-top-form |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
974 |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
975 (defun elint-log (type string args) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
976 (elint-log-message (format "%s:%d:%s: %s" |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
977 (let ((f (buffer-file-name))) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
978 (if f |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
979 (file-name-nondirectory f) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
980 (buffer-name))) |
104989
bbe883d49650
(elint-init-env): Skip non-list forms.
Glenn Morris <rgm@gnu.org>
parents:
104985
diff
changeset
|
981 (if (boundp 'elint-current-pos) |
bbe883d49650
(elint-init-env): Skip non-list forms.
Glenn Morris <rgm@gnu.org>
parents:
104985
diff
changeset
|
982 (save-excursion |
bbe883d49650
(elint-init-env): Skip non-list forms.
Glenn Morris <rgm@gnu.org>
parents:
104985
diff
changeset
|
983 (goto-char elint-current-pos) |
bbe883d49650
(elint-init-env): Skip non-list forms.
Glenn Morris <rgm@gnu.org>
parents:
104985
diff
changeset
|
984 (1+ (count-lines (point-min) |
bbe883d49650
(elint-init-env): Skip non-list forms.
Glenn Morris <rgm@gnu.org>
parents:
104985
diff
changeset
|
985 (line-beginning-position)))) |
bbe883d49650
(elint-init-env): Skip non-list forms.
Glenn Morris <rgm@gnu.org>
parents:
104985
diff
changeset
|
986 0) ; unknown position |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
987 type |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
988 (apply 'format string args)))) |
19210 | 989 |
990 (defun elint-error (string &rest args) | |
47923
07d91c802db4
(elint-error, elint-warning): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
42268
diff
changeset
|
991 "Report a linting error. |
19210 | 992 STRING and ARGS are thrown on `format' to get the message." |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
993 (elint-log "Error" string args)) |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
994 |
19210 | 995 (defun elint-warning (string &rest args) |
47923
07d91c802db4
(elint-error, elint-warning): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
42268
diff
changeset
|
996 "Report a linting warning. |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
997 See `elint-error'." |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
998 (elint-log "Warning" string args)) |
19210 | 999 |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1000 (defun elint-output (string) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1001 "Print or insert STRING, depending on value of `noninteractive'." |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1002 (if noninteractive |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1003 (message "%s" string) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1004 (insert string "\n"))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1005 |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1006 (defun elint-log-message (errstr &optional top) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1007 "Insert ERRSTR last in the lint log buffer. |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1008 Optional argument TOP non-nil means pretend `elint-top-form-logged' is non-nil." |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1009 (with-current-buffer (elint-get-log-buffer) |
19210 | 1010 (goto-char (point-max)) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1011 (let ((inhibit-read-only t)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1012 (or (bolp) (newline)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1013 ;; Do we have to say where we are? |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1014 (unless (or elint-top-form-logged top) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1015 (let* ((form (elint-top-form-form elint-top-form)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1016 (top (car form))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1017 (elint-output (cond |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1018 ((memq top '(defun defsubst)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1019 (format "\nIn function %s:" (cadr form))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1020 ((eq top 'defmacro) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1021 (format "\nIn macro %s:" (cadr form))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1022 ((memq top '(defvar defconst)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1023 (format "\nIn variable %s:" (cadr form))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1024 (t "\nIn top level expression:")))) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1025 (setq elint-top-form-logged t)) |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1026 (elint-output errstr)))) |
19210 | 1027 |
1028 (defun elint-clear-log (&optional header) | |
1029 "Clear the lint log buffer. | |
1030 Insert HEADER followed by a blank line if non-nil." | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1031 (let ((dir default-directory)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1032 (with-current-buffer (elint-get-log-buffer) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1033 (setq default-directory dir) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1034 (let ((inhibit-read-only t)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1035 (erase-buffer) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1036 (if header (insert header "\n")))))) |
19210 | 1037 |
1038 (defun elint-display-log () | |
1039 "Display the lint log buffer." | |
1040 (let ((pop-up-windows t)) | |
1041 (display-buffer (elint-get-log-buffer)) | |
1042 (sit-for 0))) | |
1043 | |
104974
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1044 (defvar elint-running) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1045 |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1046 (defun elint-set-mode-line (&optional on) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1047 "Set the mode-line-process of the Elint log buffer." |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1048 (with-current-buffer (elint-get-log-buffer) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1049 (and (eq major-mode 'compilation-mode) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1050 (setq mode-line-process |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1051 (list (if (or on (bound-and-true-p elint-running)) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1052 (propertize ":run" 'face 'compilation-warning) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1053 (propertize ":finished" 'face 'compilation-info))))))) |
646ba543ede9
(elint-file, elint-directory): New autoloaded commands.
Glenn Morris <rgm@gnu.org>
parents:
104049
diff
changeset
|
1054 |
19210 | 1055 (defun elint-get-log-buffer () |
1056 "Return a log buffer for elint." | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1057 (or (get-buffer elint-log-buffer) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1058 (with-current-buffer (get-buffer-create elint-log-buffer) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1059 (or (eq major-mode 'compilation-mode) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1060 (compilation-mode)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1061 (setq buffer-undo-list t) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1062 (current-buffer)))) |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
1063 |
19210 | 1064 ;;; |
1065 ;;; Initializing code | |
1066 ;;; | |
20014
2ecea967337d
(elint-check-defcustom-form): New function.
Karl Heuer <kwzh@gnu.org>
parents:
19210
diff
changeset
|
1067 |
105137 | 1068 (defun elint-put-function-args (func args) |
1069 "Mark function FUNC as having argument list ARGS." | |
1070 (and (symbolp func) | |
1071 args | |
1072 (not (eq args 'unknown)) | |
1073 (put func 'elint-args args))) | |
1074 | |
19210 | 1075 ;;;###autoload |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1076 (defun elint-initialize (&optional reinit) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1077 "Initialize elint. |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1078 If elint is already initialized, this does nothing, unless |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1079 optional prefix argument REINIT is non-nil." |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1080 (interactive "P") |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1081 (if (and elint-builtin-variables (not reinit)) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1082 (message "Elint is already initialized") |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1083 (message "Initializing elint...") |
105137 | 1084 (setq elint-builtin-variables (elint-scan-doc-file) |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1085 elint-autoloaded-variables (elint-find-autoloaded-variables)) |
105137 | 1086 (mapc (lambda (x) (elint-put-function-args (car x) (cdr x))) |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1087 (elint-find-builtin-args)) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1088 (if elint-unknown-builtin-args |
105137 | 1089 (mapc (lambda (x) (elint-put-function-args (car x) (cdr x))) |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1090 elint-unknown-builtin-args)) |
105137 | 1091 (when elint-scan-preloaded |
1092 (dolist (lib preloaded-file-list) | |
1093 ;; Skip files that contain nothing of use to us. | |
1094 (unless (string-match elint-preloaded-skip-re lib) | |
1095 (setq elint-preloaded-env | |
1096 (elint-add-required-env elint-preloaded-env nil lib))))) | |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1097 (message "Initializing elint...done"))) |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1098 |
19210 | 1099 |
105137 | 1100 ;; This includes all the built-in and dumped things with documentation. |
1101 (defun elint-scan-doc-file () | |
1102 "Scan the DOC file for function and variables. | |
1103 Marks the function wih their arguments, and returns a list of variables." | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1104 ;; Cribbed from help-fns.el. |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1105 (let ((docbuf " *DOC*") |
105137 | 1106 vars sym args) |
104049
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1107 (save-excursion |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1108 (if (get-buffer docbuf) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1109 (progn |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1110 (set-buffer docbuf) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1111 (goto-char (point-min))) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1112 (set-buffer (get-buffer-create docbuf)) |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1113 (insert-file-contents-literally |
7fcfa9c429bd
(elint-current-buffer, elint-defun):
Glenn Morris <rgm@gnu.org>
parents:
104036
diff
changeset
|
1114 (expand-file-name internal-doc-file-name doc-directory))) |
105137 | 1115 (while (re-search-forward "\\([VF]\\)" nil t) |
1116 (when (setq sym (intern-soft (buffer-substring (point) | |
1117 (line-end-position)))) | |
1118 (if (string-equal (match-string 1) "V") | |
1119 ;; Excludes platform-specific stuff not relevant to the | |
1120 ;; running platform. | |
1121 (if (boundp sym) (setq vars (cons sym vars))) | |
1122 ;; Function. | |
1123 (when (fboundp sym) | |
1124 (when (re-search-forward "\\(^(fn.*)\\)?" nil t) | |
1125 (backward-char 1) | |
1126 ;; FIXME distinguish no args from not found. | |
1127 (and (setq args (match-string 1)) | |
1128 (setq args | |
1129 (ignore-errors | |
1130 (read | |
1131 (replace-regexp-in-string "^(fn ?" "(" args)))) | |
1132 (elint-put-function-args sym args)))))))) | |
1133 vars)) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1134 |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1135 (defun elint-find-autoloaded-variables () |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1136 "Return a list of all autoloaded variables." |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1137 (let (var vars) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1138 (with-temp-buffer |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1139 (insert-file-contents (locate-library "loaddefs.el")) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1140 (while (re-search-forward "^(defvar \\([[:alnum:]_-]+\\)" nil t) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1141 (and (setq var (intern-soft (match-string 1))) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1142 (boundp var) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1143 (setq vars (cons var vars))))) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1144 vars)) |
19210 | 1145 |
1146 (defun elint-find-builtins () | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1147 "Return a list of all built-in functions." |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1148 (let (subrs) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1149 (mapatoms (lambda (s) (and (fboundp s) (subrp (symbol-function s)) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1150 (setq subrs (cons s subrs))))) |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1151 subrs)) |
19210 | 1152 |
1153 (defun elint-find-builtin-args (&optional list) | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1154 "Return a list of the built-in functions and their arguments. |
19210 | 1155 If LIST is nil, call `elint-find-builtins' to get a list of all built-in |
1156 functions, otherwise use LIST. | |
1157 | |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1158 Each function is represented by a cons cell: |
19210 | 1159 \(function-symbol . args) |
1160 If no documentation could be found args will be `unknown'." | |
102230
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1161 (mapcar (lambda (f) |
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1162 (let ((doc (documentation f t))) |
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1163 (or (and doc |
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1164 (string-match "\n\n(fn\\(.*)\\)\\'" doc) |
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1165 (ignore-errors |
104036
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1166 ;; "BODY...)" -> "&rest BODY)". |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1167 (read (replace-regexp-in-string |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1168 "\\([^ ]+\\)\\.\\.\\.)\\'" "&rest \\1)" |
1a42628a650e
(elint-standard-variables): Remove most members,
Glenn Morris <rgm@gnu.org>
parents:
102230
diff
changeset
|
1169 (format "(%s %s" f (match-string 1 doc)) t)))) |
102230
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1170 (cons f 'unknown)))) |
5ae300b1d079
(elint-unknown-builtin-args): Fix encode-time spec. (Bug#2453)
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1171 (or list (elint-find-builtins)))) |
19210 | 1172 |
1173 (provide 'elint) | |
1174 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1175 ;; arch-tag: b2f061e2-af84-4ddc-8e39-f5e969ac228f |
19210 | 1176 ;;; elint.el ends here |