Mercurial > emacs
annotate lisp/emacs-lisp/check-declare.el @ 86632:1fc61f150bae
Move to etc/nxml
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 28 Nov 2007 05:03:43 +0000 |
parents | db04d9e790f1 |
children | bf4a9f989c37 |
rev | line source |
---|---|
86178 | 1 ;;; check-declare.el --- Check declare-function statements |
2 | |
3 ;; Copyright (C) 2007 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Glenn Morris <rgm@gnu.org> | |
6 ;; Keywords: lisp, tools, maint | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 3, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
23 ;; Boston, MA 02110-1301, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; The byte-compiler often warns about undefined functions that you | |
28 ;; know will actually be defined when it matters. The `declare-function' | |
29 ;; statement allows you to suppress these warnings. This package | |
30 ;; checks that all such statements in a file or directory are accurate. | |
31 ;; The entry points are `check-declare-file' and `check-declare-directory'. | |
32 | |
86388 | 33 ;; For more information, see Info node `elisp(Declaring Functions)'. |
34 | |
86220
1244ab609a99
(check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents:
86178
diff
changeset
|
35 ;;; TODO: |
1244ab609a99
(check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents:
86178
diff
changeset
|
36 |
1244ab609a99
(check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents:
86178
diff
changeset
|
37 ;; 1. Handle defstructs (eg uniquify-item-base in desktop.el). |
1244ab609a99
(check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents:
86178
diff
changeset
|
38 |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
39 ;; 2. Handle fset (eg dired-omit-old-add-entry in dired-x.el). |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
40 |
86178 | 41 ;;; Code: |
42 | |
43 (defconst check-declare-warning-buffer "*Check Declarations Warnings*" | |
44 "Name of buffer used to display any `check-declare' warnings.") | |
45 | |
86342
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
46 (defun check-declare-locate (file basefile) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
47 "Return the full path of FILE. |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
48 Expands files with a \".c\" extension relative to the Emacs |
86528
db04d9e790f1
(check-declare-locate): Reflow doc.
Glenn Morris <rgm@gnu.org>
parents:
86457
diff
changeset
|
49 \"src/\" directory. Otherwise, `locate-library' searches for FILE. |
db04d9e790f1
(check-declare-locate): Reflow doc.
Glenn Morris <rgm@gnu.org>
parents:
86457
diff
changeset
|
50 If that fails, expands FILE relative to BASEFILE's directory part. |
db04d9e790f1
(check-declare-locate): Reflow doc.
Glenn Morris <rgm@gnu.org>
parents:
86457
diff
changeset
|
51 The returned file might not exist." |
86342
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
52 (if (string-equal "c" (file-name-extension file)) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
53 (expand-file-name file (expand-file-name "src" source-directory)) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
54 (let ((tfile (locate-library (file-name-nondirectory file)))) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
55 (if tfile |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
56 (progn |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
57 (setq tfile (replace-regexp-in-string "\\.elc\\'" ".el" tfile)) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
58 (if (and (not (file-exists-p tfile)) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
59 (file-exists-p (concat tfile ".gz"))) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
60 (concat tfile ".gz") |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
61 tfile)) |
86342
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
62 (setq tfile (expand-file-name file (file-name-directory basefile))) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
63 (if (or (file-exists-p tfile) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
64 (string-match "\\.el\\'" tfile)) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
65 tfile |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
66 (concat tfile ".el")))))) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
67 |
86178 | 68 (defun check-declare-scan (file) |
69 "Scan FILE for `declare-function' calls. | |
70 Return a list with elements of the form (FNFILE FN ARGLIST), where | |
71 ARGLIST may be absent. This claims that FNFILE defines FN, with ARGLIST." | |
72 (let ((m (format "Scanning %s..." file)) | |
73 alist fnfile fn) | |
74 (message "%s" m) | |
75 (with-temp-buffer | |
76 (insert-file-contents file) | |
77 (while (re-search-forward | |
78 "^[ \t]*(declare-function[ \t]+\\(\\S-+\\)[ \t]+\ | |
79 \"\\(\\S-+\\)\"" nil t) | |
80 (setq fn (match-string 1) | |
86342
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
81 fnfile (match-string 2) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
82 fnfile (check-declare-locate fnfile (expand-file-name file)) |
79a4d6e44352
(check-declare-locate): New function.
Glenn Morris <rgm@gnu.org>
parents:
86302
diff
changeset
|
83 alist (cons |
86178 | 84 (list fnfile fn |
85 (progn | |
86 (skip-chars-forward " \t\n") | |
87 ;; Use `t' to distinguish no arglist | |
88 ;; specified from an empty one. | |
89 (if (looking-at "\\((\\|nil\\)") | |
90 (read (current-buffer)) | |
91 t))) | |
92 alist)))) | |
93 (message "%sdone" m) | |
94 alist)) | |
95 | |
96 (autoload 'byte-compile-arglist-signature "bytecomp") | |
97 | |
98 (defun check-declare-verify (fnfile fnlist) | |
99 "Check that FNFILE contains function definitions matching FNLIST. | |
100 Each element of FNLIST has the form (FILE FN ARGLIST), where | |
101 ARGLIST is optional. This means FILE claimed FN was defined in | |
102 FNFILE with the specified ARGLIST. Returns nil if all claims are | |
103 found to be true, otherwise a list of errors with elements of the form | |
104 \(FILE FN TYPE), where TYPE is a string giving details of the error." | |
105 (let ((m (format "Checking %s..." fnfile)) | |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
106 (cflag (string-equal "c" (file-name-extension fnfile))) |
86300
96fee69c65a2
(check-declare-verify): Implement arglist checking for C files.
Glenn Morris <rgm@gnu.org>
parents:
86297
diff
changeset
|
107 re fn sig siglist arglist type errlist minargs maxargs) |
86178 | 108 (message "%s" m) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
109 (if (file-exists-p fnfile) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
110 (with-temp-buffer |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
111 (insert-file-contents fnfile) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
112 ;; defsubst's don't _have_ to be known at compile time. |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
113 (setq re (format (if cflag |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
114 "^[ \t]*\\(DEFUN\\)[ \t]*([ \t]*\"%s\"" |
86528
db04d9e790f1
(check-declare-locate): Reflow doc.
Glenn Morris <rgm@gnu.org>
parents:
86457
diff
changeset
|
115 "^[ \t]*(\\(fset[ \t]+'\\|def\\(?:un\\|subst\\|\ |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
116 ine-\\(?:derived\\|generic\\|\\(?:global\\(?:ized\\)?-\\)?minor\\)-mode\ |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
117 \\|\\(?:ine-obsolete-function-\\)?alias[ \t]+'\\)\\)\ |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
118 \[ \t]*%s\\([ \t;]+\\|$\\)") |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
119 (regexp-opt (mapcar 'cadr fnlist) t))) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
120 (while (re-search-forward re nil t) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
121 (skip-chars-forward " \t\n") |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
122 (setq fn (match-string 2) |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
123 type (match-string 1) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
124 ;; (min . max) for a fixed number of arguments, or |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
125 ;; arglists with optional elements. |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
126 ;; (min) for arglists with &rest. |
86302
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
127 ;; sig = 'err means we could not find an arglist. |
86300
96fee69c65a2
(check-declare-verify): Implement arglist checking for C files.
Glenn Morris <rgm@gnu.org>
parents:
86297
diff
changeset
|
128 sig (cond (cflag |
86302
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
129 (or |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
130 (when (re-search-forward "," nil t 3) |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
131 (skip-chars-forward " \t\n") |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
132 ;; Assuming minargs and maxargs on same line. |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
133 (when (looking-at "\\([0-9]+\\)[ \t]*,[ \t]*\ |
86300
96fee69c65a2
(check-declare-verify): Implement arglist checking for C files.
Glenn Morris <rgm@gnu.org>
parents:
86297
diff
changeset
|
134 \\([0-9]+\\|MANY\\|UNEVALLED\\)") |
86302
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
135 (setq minargs (string-to-number |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
136 (match-string 1)) |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
137 maxargs (match-string 2)) |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
138 (cons minargs (unless (string-match "[^0-9]" |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
139 maxargs) |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
140 (string-to-number |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
141 maxargs))))) |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
142 'err)) |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
143 ((string-match |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
144 "\\`define-\\(derived\\|generic\\)-mode\\'" |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
145 type) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
146 '(0 . 0)) |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
147 ((string-match |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
148 "\\`define\\(-global\\(ized\\)?\\)?-minor-mode\\'" |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
149 type) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
150 '(0 . 1)) |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
151 ;; Prompt to update. |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
152 ((string-match |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
153 "\\`define-obsolete-function-alias\\>" |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
154 type) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
155 'obsolete) |
86528
db04d9e790f1
(check-declare-locate): Reflow doc.
Glenn Morris <rgm@gnu.org>
parents:
86457
diff
changeset
|
156 ;; Can't easily check arguments in these cases. |
db04d9e790f1
(check-declare-locate): Reflow doc.
Glenn Morris <rgm@gnu.org>
parents:
86457
diff
changeset
|
157 ((string-match "\\`\\(defalias\\|fset\\)\\>" type) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
158 t) |
86302
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
159 ((looking-at "\\((\\|nil\\)") |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
160 (byte-compile-arglist-signature |
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
161 (read (current-buffer)))) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
162 (t |
86302
9525bd421fdb
(check-declare-verify): Fix previous change. Warn if could not find
Glenn Morris <rgm@gnu.org>
parents:
86300
diff
changeset
|
163 'err)) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
164 ;; alist of functions and arglist signatures. |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
165 siglist (cons (cons fn sig) siglist))))) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
166 (dolist (e fnlist) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
167 (setq arglist (nth 2 e) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
168 type |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
169 (if (not re) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
170 "file not found" |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
171 (if (not (setq sig (assoc (cadr e) siglist))) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
172 "function not found" |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
173 (setq sig (cdr sig)) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
174 (cond ((eq sig 'obsolete) ; check even when no arglist specified |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
175 "obsolete alias") |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
176 ;; arglist t means no arglist specified, as |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
177 ;; opposed to an empty arglist. |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
178 ((eq arglist t) nil) |
86528
db04d9e790f1
(check-declare-locate): Reflow doc.
Glenn Morris <rgm@gnu.org>
parents:
86457
diff
changeset
|
179 ((eq sig t) nil) ; eg defalias - can't check arguments |
86457
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
180 ((eq sig 'err) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
181 "arglist not found") ; internal error |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
182 ((not (equal (byte-compile-arglist-signature |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
183 arglist) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
184 sig)) |
47fc5bc30170
(check-declare-locate): Handle compressed files.
Glenn Morris <rgm@gnu.org>
parents:
86388
diff
changeset
|
185 "arglist mismatch"))))) |
86297
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
186 (when type |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
187 (setq errlist (cons (list (car e) (cadr e) type) errlist)))) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
188 (message "%s%s" m (if errlist "problems found" "OK")) |
a80b13d94c3c
(check-declare-scan): Expand .c files relative to src/ directory.
Glenn Morris <rgm@gnu.org>
parents:
86278
diff
changeset
|
189 errlist)) |
86178 | 190 |
191 (defun check-declare-sort (alist) | |
192 "Sort a list with elements FILE (FNFILE ...). | |
193 Returned list has elements FNFILE (FILE ...)." | |
194 (let (file fnfile rest sort a) | |
195 (dolist (e alist) | |
196 (setq file (car e)) | |
197 (dolist (f (cdr e)) | |
198 (setq fnfile (car f) | |
199 rest (cdr f)) | |
200 (if (setq a (assoc fnfile sort)) | |
201 (setcdr a (append (cdr a) (list (cons file rest)))) | |
202 (setq sort (cons (list fnfile (cons file rest)) sort))))) | |
203 sort)) | |
204 | |
205 (defun check-declare-warn (file fn fnfile type) | |
206 "Warn that FILE made a false claim about FN in FNFILE. | |
207 TYPE is a string giving the nature of the error. Warning is displayed in | |
208 `check-declare-warning-buffer'." | |
209 (display-warning 'check-declare | |
210 (format "%s said `%s' was defined in %s: %s" | |
211 (file-name-nondirectory file) fn | |
212 (file-name-nondirectory fnfile) | |
213 type) | |
214 nil check-declare-warning-buffer)) | |
215 | |
216 (defun check-declare-files (&rest files) | |
217 "Check veracity of all `declare-function' statements in FILES. | |
218 Return a list of any errors found." | |
219 (let (alist err errlist) | |
220 (dolist (file files) | |
221 (setq alist (cons (cons file (check-declare-scan file)) alist))) | |
222 ;; Sort so that things are ordered by the files supposed to | |
223 ;; contain the defuns. | |
224 (dolist (e (check-declare-sort alist)) | |
225 (if (setq err (check-declare-verify (car e) (cdr e))) | |
226 (setq errlist (cons (cons (car e) err) errlist)))) | |
227 (if (get-buffer check-declare-warning-buffer) | |
228 (kill-buffer check-declare-warning-buffer)) | |
229 ;; Sort back again so that errors are ordered by the files | |
230 ;; containing the declare-function statements. | |
231 (dolist (e (check-declare-sort errlist)) | |
232 (dolist (f (cdr e)) | |
233 (check-declare-warn (car e) (cadr f) (car f) (nth 2 f)))) | |
234 errlist)) | |
235 | |
236 ;;;###autoload | |
237 (defun check-declare-file (file) | |
238 "Check veracity of all `declare-function' statements in FILE. | |
239 See `check-declare-directory' for more information." | |
240 (interactive "fFile to check: ") | |
241 (or (file-exists-p file) | |
242 (error "File `%s' not found" file)) | |
243 (let ((m (format "Checking %s..." file)) | |
244 errlist) | |
245 (message "%s" m) | |
246 (setq errlist (check-declare-files file)) | |
247 (message "%s%s" m (if errlist "problems found" "OK")) | |
248 errlist)) | |
249 | |
250 ;;;###autoload | |
251 (defun check-declare-directory (root) | |
252 "Check veracity of all `declare-function' statements under directory ROOT. | |
253 Returns non-nil if any false statements are found. For this to | |
254 work correctly, the statements must adhere to the format | |
255 described in the documentation of `declare-function'." | |
256 (interactive "DDirectory to check: ") | |
257 (or (file-directory-p (setq root (expand-file-name root))) | |
258 (error "Directory `%s' not found" root)) | |
259 (let ((m "Checking `declare-function' statements...") | |
260 (m2 "Finding files with declarations...") | |
261 errlist files) | |
262 (message "%s" m) | |
263 (message "%s" m2) | |
264 (setq files (process-lines "find" root "-name" "*.el" | |
265 "-exec" "grep" "-l" | |
266 "^[ ]*(declare-function" "{}" ";")) | |
267 (message "%s%d found" m2 (length files)) | |
268 (when files | |
269 (setq errlist (apply 'check-declare-files files)) | |
270 (message "%s%s" m (if errlist "problems found" "OK")) | |
271 errlist))) | |
272 | |
273 (provide 'check-declare) | |
274 | |
275 ;; arch-tag: a4d6cdc4-deb7-4502-b327-0e4ef3d82d96 | |
276 ;;; check-declare.el ends here. |