annotate lisp/emacs-lisp/check-declare.el @ 86862:b98c748aa4bf

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