annotate lisp/emacs-lisp/check-declare.el @ 86244:d6eda104caa6

(check-declare-verify): Tweak regexp for end of function-name. Handle define-derived-mode.
author Glenn Morris <rgm@gnu.org>
date Tue, 20 Nov 2007 03:53:23 +0000
parents 1244ab609a99
children 2f50908378c9
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
86220
1244ab609a99 (check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents: 86178
diff changeset
33 ;;; TODO:
1244ab609a99 (check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents: 86178
diff changeset
34
1244ab609a99 (check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents: 86178
diff changeset
35 ;; 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
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
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 (defun check-declare-scan (file)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 "Scan FILE for `declare-function' calls.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 Return a list with elements of the form (FNFILE FN ARGLIST), where
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 ARGLIST may be absent. This claims that FNFILE defines FN, with ARGLIST."
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 (let ((m (format "Scanning %s..." file))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 alist fnfile fn)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 (message "%s" m)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 (with-temp-buffer
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 (insert-file-contents file)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 (while (re-search-forward
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 "^[ \t]*(declare-function[ \t]+\\(\\S-+\\)[ \t]+\
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 \"\\(\\S-+\\)\"" nil t)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 (setq fn (match-string 1)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 fnfile (match-string 2))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 (or (file-name-absolute-p fnfile)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 (setq fnfile (expand-file-name fnfile (file-name-directory file))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 (setq alist (cons
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 (list fnfile fn
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 (progn
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 (skip-chars-forward " \t\n")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 ;; Use `t' to distinguish no arglist
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 ;; specified from an empty one.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 (if (looking-at "\\((\\|nil\\)")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 (read (current-buffer))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 t)))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 alist))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 (message "%sdone" m)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 alist))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 (autoload 'byte-compile-arglist-signature "bytecomp")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (defun check-declare-verify (fnfile fnlist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 "Check that FNFILE contains function definitions matching FNLIST.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 Each element of FNLIST has the form (FILE FN ARGLIST), where
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 ARGLIST is optional. This means FILE claimed FN was defined in
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 FNFILE with the specified ARGLIST. Returns nil if all claims are
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 found to be true, otherwise a list of errors with elements of the form
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 \(FILE FN TYPE), where TYPE is a string giving details of the error."
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 (let ((m (format "Checking %s..." fnfile))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 re fn sig siglist arglist type errlist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 (message "%s" m)
86220
1244ab609a99 (check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents: 86178
diff changeset
83 (or (file-exists-p fnfile)
1244ab609a99 (check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents: 86178
diff changeset
84 (setq fnfile (concat fnfile ".el")))
86178
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 (if (file-exists-p fnfile)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 (with-temp-buffer
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 (insert-file-contents fnfile)
86220
1244ab609a99 (check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents: 86178
diff changeset
88 ;; defsubst's don't _have_ to be known at compile time.
86244
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
89 (setq re (format "^[ \t]*(\\(def\\(?:un\\|subst\\|\
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
90 ine-derived-mode\\)\\)\[ \t]+%s\\([ \t;]+\\|$\\)"
86178
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 (regexp-opt (mapcar 'cadr fnlist) t)))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 (while (re-search-forward re nil t)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 (skip-chars-forward " \t\n")
86220
1244ab609a99 (check-declare-verify): If fnfile does not exist, try adding `.el'
Glenn Morris <rgm@gnu.org>
parents: 86178
diff changeset
94 (setq fn (match-string 2)
86244
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
95 sig (if (string-equal "define-derived-mode"
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
96 (match-string 1))
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
97 '(0 . 0)
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
98 (if (looking-at "\\((\\|nil\\)")
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
99 (byte-compile-arglist-signature
d6eda104caa6 (check-declare-verify): Tweak regexp for end of function-name. Handle
Glenn Morris <rgm@gnu.org>
parents: 86220
diff changeset
100 (read (current-buffer)))))
86178
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 ;; alist of functions and arglist signatures.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 siglist (cons (cons fn sig) siglist)))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 (dolist (e fnlist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 (setq arglist (nth 2 e)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 type
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 (if re ; re non-nil means found a file
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 (if (setq sig (assoc (cadr e) siglist))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 ;; Recall we use t to mean no arglist specified,
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 ;; to distinguish from an empty arglist.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 (unless (eq arglist t)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 (unless (equal (byte-compile-arglist-signature arglist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 (cdr sig))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 "arglist mismatch"))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 "function not found")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 "file not found"))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 (when type
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 (setq errlist (cons (list (car e) (cadr e) type) errlist))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 (message "%s%s" m (if errlist "problems found" "OK"))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 errlist))
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-sort (alist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 "Sort a list with elements FILE (FNFILE ...).
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 Returned list has elements FNFILE (FILE ...)."
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 (let (file fnfile rest sort a)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 (dolist (e alist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 (setq file (car e))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 (dolist (f (cdr e))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 (setq fnfile (car f)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 rest (cdr f))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 (if (setq a (assoc fnfile sort))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 (setcdr a (append (cdr a) (list (cons file rest))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 (setq sort (cons (list fnfile (cons file rest)) sort)))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 sort))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 (defun check-declare-warn (file fn fnfile type)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 "Warn that FILE made a false claim about FN in FNFILE.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 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
138 `check-declare-warning-buffer'."
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 (display-warning 'check-declare
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 (format "%s said `%s' was defined in %s: %s"
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 (file-name-nondirectory file) fn
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 (file-name-nondirectory fnfile)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 type)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 nil check-declare-warning-buffer))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 (defun check-declare-files (&rest files)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 "Check veracity of all `declare-function' statements in FILES.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 Return a list of any errors found."
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 (let (alist err errlist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 (dolist (file files)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 (setq alist (cons (cons file (check-declare-scan file)) alist)))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 ;; Sort so that things are ordered by the files supposed to
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 ;; contain the defuns.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 (dolist (e (check-declare-sort alist))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 (if (setq err (check-declare-verify (car e) (cdr e)))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 (setq errlist (cons (cons (car e) err) errlist))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 (if (get-buffer check-declare-warning-buffer)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 (kill-buffer check-declare-warning-buffer))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 ;; Sort back again so that errors are ordered by the files
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 ;; containing the declare-function statements.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 (dolist (e (check-declare-sort errlist))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 (dolist (f (cdr e))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 (check-declare-warn (car e) (cadr f) (car f) (nth 2 f))))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 errlist))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 ;;;###autoload
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 (defun check-declare-file (file)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 "Check veracity of all `declare-function' statements in FILE.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 See `check-declare-directory' for more information."
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 (interactive "fFile to check: ")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 (or (file-exists-p file)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 (error "File `%s' not found" file))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 (let ((m (format "Checking %s..." file))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 errlist)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 (message "%s" m)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 (setq errlist (check-declare-files file))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 (message "%s%s" m (if errlist "problems found" "OK"))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 errlist))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 ;;;###autoload
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181 (defun check-declare-directory (root)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 "Check veracity of all `declare-function' statements under directory ROOT.
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 Returns non-nil if any false statements are found. For this to
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 work correctly, the statements must adhere to the format
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 described in the documentation of `declare-function'."
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 (interactive "DDirectory to check: ")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 (or (file-directory-p (setq root (expand-file-name root)))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 (error "Directory `%s' not found" root))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 (let ((m "Checking `declare-function' statements...")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 (m2 "Finding files with declarations...")
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 errlist files)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 (message "%s" m)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 (message "%s" m2)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 (setq files (process-lines "find" root "-name" "*.el"
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 "-exec" "grep" "-l"
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 "^[ ]*(declare-function" "{}" ";"))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 (message "%s%d found" m2 (length files))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198 (when files
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 (setq errlist (apply 'check-declare-files files))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 (message "%s%s" m (if errlist "problems found" "OK"))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 errlist)))
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 (provide 'check-declare)
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 ;; arch-tag: a4d6cdc4-deb7-4502-b327-0e4ef3d82d96
d5707b4c3b0f New file.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 ;;; check-declare.el ends here.