annotate lisp/emacs-lisp/elint.el @ 105643:062d17ee6c05

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