Mercurial > emacs
annotate lisp/emacs-lisp/checkdoc.el @ 22134:29c2db002dd5
(which-func-modes): Fix custom type.
(which-func-non-auto-modes): Likewise.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 19 May 1998 00:38:20 +0000 |
parents | 38f78542051a |
children | bab34c7c16fb |
rev | line source |
---|---|
20085 | 1 ;;; checkdoc --- Check documentation strings for style requirements |
2 | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
3 ;;; Copyright (C) 1997, 1998 Free Software Foundation |
21181 | 4 |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
5 ;; Author: Eric M. Ludlam <zappo@gnu.org> |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
6 ;; Version: 0.5.1 |
20085 | 7 ;; Keywords: docs, maint, lisp |
21181 | 8 |
20085 | 9 ;; This file is part of GNU Emacs. |
21181 | 10 |
20085 | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
21181 | 15 |
20085 | 16 ;; GNU Emacs is distributed in the hope that it will be useful, |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
21181 | 20 |
20085 | 21 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 ;; | |
28 ;; The emacs lisp manual has a nice chapter on how to write | |
29 ;; documentation strings. Many stylistic suggestions are fairly | |
30 ;; deterministic and easy to check for syntactically, but also easy | |
31 ;; to forget. The main checkdoc engine will perform the stylistic | |
32 ;; checks needed to make sure these styles are remembered. | |
33 ;; | |
34 ;; There are two ways to use checkdoc: | |
35 ;; 1) Periodically use `checkdoc'. `checkdoc-current-buffer' and | |
36 ;; `checkdoc-defun' to check your documentation. | |
37 ;; 2) Use `checkdoc-minor-mode' to automatically check your | |
38 ;; documentation whenever you evaluate lisp code with C-M-x | |
39 ;; or [menu-bar emacs-lisp eval-buffer]. Additional key-bindings | |
40 ;; are also provided under C-c ? KEY | |
41 ;; (require 'checkdoc) | |
42 ;; (add-hook 'emacs-lisp-mode-hook | |
43 ;; '(lambda () (checkdoc-minor-mode 1))) | |
44 ;; | |
45 ;; Auto-fixing: | |
46 ;; | |
47 ;; There are four classifications of style errors in terms of how | |
48 ;; easy they are to fix. They are simple, complex, really complex, | |
49 ;; and impossible. (Impossible really means that checkdoc does not | |
50 ;; have a fixing routine yet.) Typically white-space errors are | |
51 ;; classified as simple, and are auto-fixed by default. Typographic | |
52 ;; changes are considered complex, and the user is asked if they want | |
53 ;; the problem fixed before checkdoc makes the change. These changes | |
54 ;; can be done without asking if `checkdoc-autofix-flag' is properly | |
55 ;; set. Potentially redundant changes are considered really complex, | |
56 ;; and the user is always asked before a change is inserted. The | |
57 ;; variable `checkdoc-autofix-flag' controls how these types of errors | |
58 ;; are fixed. | |
59 ;; | |
60 ;; Spell checking doc-strings: | |
61 ;; | |
62 ;; The variable `checkdoc-spellcheck-documentation-flag' can be set | |
63 ;; to customize how spell checking is to be done. Since spell | |
64 ;; checking can be quite slow, you can optimize how best you want your | |
65 ;; checking done. The default is 'defun, which spell checks each time | |
66 ;; `checkdoc-defun' or `checkdoc-eval-defun' is used. Setting to nil | |
67 ;; prevents spell checking during normal usage. | |
68 ;; Setting this variable to nil does not mean you cannot take | |
69 ;; advantage of the spell checking. You can instead use the | |
70 ;; interactive functions `checkdoc-ispell-*' to check the spelling of | |
71 ;; your documentation. | |
72 ;; There is a list of lisp-specific words which checkdoc will | |
73 ;; install into ispell on the fly, but only if ispell is not already | |
74 ;; running. Use `ispell-kill-ispell' to make checkdoc restart it with | |
75 ;; these words enabled. | |
76 ;; | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
77 ;; Checking parameters |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
78 ;; |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
79 ;; You might not always want a function to have it's parameters listed |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
80 ;; in order. When this is the case, put the following comment just in |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
81 ;; front of the documentation string: "; checkdoc-order: nil" This |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
82 ;; overrides the value of `checkdoc-arguments-in-order-flag'. |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
83 ;; |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
84 ;; If you specifically wish to avoid mentioning a parameter of a |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
85 ;; function in the doc string (such as a hidden parameter, or a |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
86 ;; parameter which is very obvious like events), you can have checkdoc |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
87 ;; skip looking for it by putting the following comment just in front |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
88 ;; of the documentation string: "; checkdoc-params: (args go here)" |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
89 ;; |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
90 ;; Checking message strings |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
91 ;; |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
92 ;; The text that follows the `error', and `y-or-n-p' commands is |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
93 ;; also checked. The documentation for `error' clearly states some |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
94 ;; simple style rules to follow which checkdoc will auto-fix for you. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
95 ;; `y-or-n-p' also states that it should end in a space. I added that |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
96 ;; it should end in "? " since that is almost always used. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
97 ;; |
20085 | 98 ;; Adding your own checks: |
99 ;; | |
100 ;; You can experiment with adding your own checks by setting the | |
101 ;; hooks `checkdoc-style-hooks' and `checkdoc-comment-style-hooks'. | |
102 ;; Return a string which is the error you wish to report. The cursor | |
103 ;; position should be preserved. | |
104 ;; | |
105 ;; This file requires lisp-mnt (lisp maintenance routines) for the | |
106 ;; comment checkers. | |
107 ;; | |
108 ;; Requires custom for emacs v20. | |
109 | |
110 ;;; Change log: | |
111 ;; 0.1 Initial revision | |
112 ;; 0.2 Fixed comments in this file to match the emacs lisp standards. | |
113 ;; Added new doc checks for: variable-flags, function arguments | |
114 ;; Added autofix functionality for white-space, and quoted variables. | |
115 ;; Unquoted symbols are allowed after ( character. (Sample code) | |
116 ;; Check for use of `? ' at end of line and warn. | |
117 ;; Check for spaces at end of lines for whole file, or one defun. | |
118 ;; Check for comments standards, including headinds like Code: | |
119 ;; and use of triple semicolons versus double semicolons | |
120 ;; Check that interactive functions have a doc-string. Optionally | |
121 ;; set `checkdoc-force-docstrings-flag' to non-nil to make all | |
122 ;; definitions have a doc-string. | |
123 ;; 0.3 Regexp changse for accuracy on var checking and param checking. | |
124 ;; lm-verify check expanded to each sub-call w/ more descriptive | |
125 ;; messages, and two autofix-options. | |
126 ;; Suggestions/patches from Christoph Wedler <wedler@fmi.uni-passau.de> | |
127 ;; XEmacs support w/ extents/overlays. | |
128 ;; Better Whitespace finding regexps | |
129 ;; Added `checkdoc-arguments-in-order-flag' to optionally turn off | |
130 ;; warnings of arguments that do not appear in order in doc | |
131 ;; strings. | |
132 ;; 0.4 New fix routine when two lines can be joined to make the | |
133 ;; first line a comlete sentence. | |
134 ;; Added ispell code. Use `checkdoc-spellcheck-documentation-flag' | |
135 ;; to enable or disable this test in certain contexts. | |
136 ;; Added ispell interface functions `checkdoc-ispell', | |
137 ;; `checkdoc-ispell-continue', `checkdoc-ispell-defun' | |
138 ;; `checkdoc-ispell-interactive', `checkdoc-ispell-current-buffer'. | |
139 ;; Loop through all potential unquoted symbols. | |
140 ;; Auto-fixing no longer screws up the "end" of the doc-string. | |
141 ;; Maintain a different syntax table when examining arguments. | |
142 ;; Autofix enabled for parameters which are not uppercase iff they | |
143 ;; occur in lower case in the doc-string. | |
144 ;; Autofix enable if there is no Code: label. | |
145 ;; The comment text ";; checkdoc-order: nil|t" inside a defun to | |
146 ;; enable or disable the checking of argument order for one defun. | |
147 ;; The comment text ";; checkdoc-params: (arg1 arg2)" inside a defun | |
148 ;; (Such as just before the doc string) will list ARG1 and ARG2 as | |
149 ;; being paramters that need not show up in the doc string. | |
150 ;; Brought in suggestions from Jari Aalto <jaalto@tre.tele.nokia.fi> | |
151 ;; More robustness (comments in/around doc-strings/ arg lists) | |
152 ;; Don't offer to `quote'afy symbols or keystroke representations | |
153 ;; that are in lists (sample code) This added new fn | |
154 ;; `checkdoc-in-sample-code-p' | |
155 ;; Added more comments near the ;;; comment check about why it | |
156 ;; is being done. ;;; Are also now allowed inside a defun. | |
157 ;; This added the function `checkdoc-outside-major-sexp' | |
158 ;; Added `checkdoc-interactive' which permits interactive | |
159 ;; perusal of document warnings, and editing of strings. | |
160 ;; Fixed `checkdoc-defun-info' to be more robust when creating | |
161 ;; the paramter list. | |
162 ;; Added list of verbs in the wrong tense, and their fixes. | |
163 ;; Added defconst/subst/advice to checked items. | |
164 ;; Added `checkdoc-style-hooks' and `checkdoc-comment-style-hooks' | |
165 ;; for adding in user tests. | |
166 ;; Added `checkdoc-continue', a version of checkdoc that continues | |
167 ;; from point. | |
168 ;; [X]Emacs 20 support for extended characters. | |
169 ;; Only check comments on real files. | |
170 ;; Put `checkdoc' and `checkdoc-continue' into keymap/menu | |
171 ;; 0.4.1 Made `custom' friendly. | |
172 ;; C-m in warning buffer also goes to error. | |
173 ;; Shrink error buffer to size of text. | |
174 ;; Added `checkdoc-tripple-semi-comment-check-flag'. | |
175 ;; `checkdoc-spellcheck-documentation-flag' off by default. | |
176 ;; Re-sorted check order so white space is removed before adding a . | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
177 ;; 0.4.2 Added some more comments in the commentary. |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
178 ;; You can now `quote' symbols that look like keystrokes |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
179 ;; When spell checking, meta variables can end in `th' or `s'. |
21181 | 180 ;; 0.4.3 Fixed bug where multi-function checking skips defuns that |
181 ;; have comments before the doc-string. | |
182 ;; Fixed bug where keystrokes were identified from a variable name | |
183 ;; like ASSOC-P. | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
184 ;; 0.5 Added checks for basics in messages using `error'. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
185 ;; Added check for symbols that are both functions and symbols. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
186 ;; These references are ambiguous and should be prefixed with |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
187 ;; "function", or "variable". Added auto-fix for this also. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
188 ;; Added auto fix for args that do not occur in the doc string. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
189 ;; 0.5.1 Fixed question about putting a symbol in `quotes'. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
190 ;; Added spaces to the end of all y/n questions. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
191 ;; Added checks for y/n question endings to require "? " |
20085 | 192 |
193 ;;; TO DO: | |
194 ;; Hook into the byte compiler on a defun/defver level to generate | |
195 ;; warnings in the byte-compiler's warning/error buffer. | |
196 ;; Better ways to override more typical `eval' functions. Advice | |
197 ;; might be good but hard to turn on/off as a minor mode. | |
198 ;; | |
199 ;;; Maybe Do: | |
200 ;; Code sweep checks for "forbidden functions", proper use of hooks, | |
201 ;; proper keybindings, and other items from the manual that are | |
202 ;; not specifically docstring related. Would this even be useful? | |
203 | |
204 ;;; Code: | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
205 (defvar checkdoc-version "0.5.1" |
20085 | 206 "Release version of checkdoc you are currently running.") |
207 | |
208 ;; From custom web page for compatibility between versions of custom: | |
209 (eval-and-compile | |
210 (condition-case () | |
211 (require 'custom) | |
212 (error nil)) | |
213 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
214 nil ;; We've got what we needed | |
215 ;; We have the old custom-library, hack around it! | |
216 (defmacro defgroup (&rest args) | |
217 nil) | |
218 (defmacro custom-add-option (&rest args) | |
219 nil) | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
220 (defmacro defcustom (var value doc &rest args) |
20085 | 221 (` (defvar (, var) (, value) (, doc)))))) |
222 | |
223 (defcustom checkdoc-autofix-flag 'semiautomatic | |
224 "*Non-nil means attempt auto-fixing of doc-strings. | |
225 If this value is the symbol 'query, then the user is queried before | |
226 any change is made. If the value is 'automatic, then all changes are | |
227 made without asking unless the change is very-complex. If the value | |
228 is 'semiautomatic, or any other value, then simple fixes are made | |
229 without asking, and complex changes are made by asking the user first. | |
230 The value 'never is the same as nil, never ask or change anything." | |
231 :group 'checkdoc | |
232 :type '(choice (const automatic) | |
233 (const semiautomatic) | |
234 (const query) | |
235 (const never))) | |
236 | |
237 (defcustom checkdoc-bouncy-flag t | |
238 "*Non-nil means to 'bounce' to auto-fix locations. | |
239 Setting this to nil will silently make fixes that require no user | |
240 interaction. See `checkdoc-autofix-flag' for auto-fixing details." | |
241 :group 'checkdoc | |
242 :type 'boolean) | |
243 | |
244 (defcustom checkdoc-force-docstrings-flag t | |
245 "*Non-nil means that all checkable definitions should have documentation. | |
246 Style guide dictates that interactive functions MUST have documentation, | |
247 and that its good but not required practice to make non user visible items | |
248 have doc-strings." | |
249 :group 'checkdoc | |
250 :type 'boolean) | |
251 | |
252 (defcustom checkdoc-tripple-semi-comment-check-flag t | |
253 "*Non-nil means to check for multiple adjacent occurrences of ;;; comments. | |
254 According to the style of emacs code in the lisp libraries, a block | |
255 comment can look like this: | |
256 ;;; Title | |
257 ;; text | |
258 ;; text | |
259 But when inside a function, code can be commented out using the ;;; | |
260 construct for all lines. When this variable is nil, the ;;; construct | |
261 is ignored regardless of it's location in the code." | |
262 :group 'checkdoc | |
263 :type 'boolean) | |
264 | |
265 (defcustom checkdoc-spellcheck-documentation-flag nil | |
266 "*Non-nil means run ispell on doc-strings based on value. | |
267 This will be automatically set to nil if ispell does not exist on your | |
268 system. Possible values are: | |
269 | |
270 nil - Don't spell-check during basic style checks. | |
271 'defun - Spell-check when style checking a single defun | |
272 'buffer - Spell-check only when style checking the whole buffer | |
273 'interactive - Spell-check only during `checkdoc-interactive' | |
274 t - Always spell-check" | |
275 :group 'checkdoc | |
276 :type '(choice (const nil) | |
277 (const defun) | |
278 (const buffer) | |
279 (const interactive) | |
280 (const t))) | |
281 | |
282 (defvar checkdoc-ispell-lisp-words | |
283 '("alist" "etags" "iff" "keymap" "paren" "regexp" "sexp" "xemacs") | |
284 "List of words that are correct when spell-checking lisp documentation.") | |
285 | |
286 (defcustom checkdoc-max-keyref-before-warn 10 | |
287 "*The number of \\ [command-to-keystroke] tokens allowed in a doc-string. | |
288 Any more than this and a warning is generated suggesting that the construct | |
289 \\ {keymap} be used instead." | |
290 :group 'checkdoc | |
291 :type 'integer) | |
292 | |
293 (defcustom checkdoc-arguments-in-order-flag t | |
294 "*Non-nil means warn if arguments appear out of order. | |
295 Setting this to nil will mean only checking that all the arguments | |
296 appear in the proper form in the documentation, not that they are in | |
297 the same order as they appear in the argument list. No mention is | |
298 made in the style guide relating to order." | |
299 :group 'checkdoc | |
300 :type 'boolean) | |
301 | |
302 (defvar checkdoc-style-hooks nil | |
303 "Hooks called after the standard style check is completed. | |
304 All hooks must return nil or a string representing the error found. | |
305 Useful for adding new user implemented commands. | |
306 | |
307 Each hook is called with two parameters, (DEFUNINFO ENDPOINT). | |
308 DEFUNINFO is the return value of `checkdoc-defun-info'. ENDPOINT is the | |
309 location of end of the documentation string.") | |
310 | |
311 (defvar checkdoc-comment-style-hooks nil | |
312 "Hooks called after the standard comment style check is completed. | |
313 Must return nil if no errors are found, or a string describing the | |
314 problem discovered. This is useful for adding additional checks.") | |
315 | |
316 (defvar checkdoc-diagnostic-buffer "*Style Warnings*" | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
317 "Name of warning message buffer.") |
20085 | 318 |
319 (defvar checkdoc-defun-regexp | |
320 "^(def\\(un\\|var\\|custom\\|macro\\|const\\|subst\\|advice\\)\ | |
321 \\s-+\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]+" | |
322 "Regular expression used to identify a defun. | |
323 A search leaves the cursor in front of the parameter list.") | |
324 | |
325 (defcustom checkdoc-verb-check-experimental-flag t | |
326 "*Non-nil means to attempt to check the voice of the doc-string. | |
327 This check keys off some words which are commonly misused. See the | |
328 variable `checkdoc-common-verbs-wrong-voice' if you wish to add your | |
329 own." | |
330 :group 'checkdoc | |
331 :type 'boolean) | |
332 | |
333 (defvar checkdoc-common-verbs-regexp nil | |
334 "Regular expression derived from `checkdoc-common-verbs-regexp'.") | |
335 | |
336 (defvar checkdoc-common-verbs-wrong-voice | |
337 '(("adds" . "add") | |
338 ("allows" . "allow") | |
339 ("appends" . "append") | |
340 ("applies" "apply") | |
341 ("arranges" "arrange") | |
342 ("brings" . "bring") | |
343 ("calls" . "call") | |
344 ("catches" . "catch") | |
345 ("changes" . "change") | |
346 ("checks" . "check") | |
347 ("contains" . "contain") | |
348 ("creates" . "create") | |
349 ("destroys" . "destroy") | |
350 ("disables" . "disable") | |
351 ("executes" . "execute") | |
352 ("evals" . "evaluate") | |
353 ("evaluates" . "evaluate") | |
354 ("finds" . "find") | |
355 ("forces" . "force") | |
356 ("gathers" . "gather") | |
357 ("generates" . "generate") | |
358 ("goes" . "go") | |
359 ("guesses" . "guess") | |
360 ("highlights" . "highlight") | |
361 ("holds" . "hold") | |
362 ("ignores" . "ignore") | |
363 ("indents" . "indent") | |
364 ("initializes" . "initialize") | |
365 ("inserts" . "insert") | |
366 ("installs" . "install") | |
367 ("investigates" . "investigate") | |
368 ("keeps" . "keep") | |
369 ("kills" . "kill") | |
370 ("leaves" . "leave") | |
371 ("lets" . "let") | |
372 ("loads" . "load") | |
373 ("looks" . "look") | |
374 ("makes" . "make") | |
375 ("marks" . "mark") | |
376 ("matches" . "match") | |
377 ("notifies" . "notify") | |
378 ("offers" . "offer") | |
379 ("parses" . "parse") | |
380 ("performs" . "perform") | |
381 ("prepares" . "prepare") | |
382 ("prepends" . "prepend") | |
383 ("reads" . "read") | |
384 ("raises" . "raise") | |
385 ("removes" . "remove") | |
386 ("replaces" . "replace") | |
387 ("resets" . "reset") | |
388 ("restores" . "restore") | |
389 ("returns" . "return") | |
390 ("runs" . "run") | |
391 ("saves" . "save") | |
392 ("says" . "say") | |
393 ("searches" . "search") | |
394 ("selects" . "select") | |
395 ("sets" . "set") | |
396 ("sex" . "s*x") | |
397 ("shows" . "show") | |
398 ("signifies" . "signify") | |
399 ("sorts" . "sort") | |
400 ("starts" . "start") | |
401 ("stores" . "store") | |
402 ("switches" . "switch") | |
403 ("tells" . "tell") | |
404 ("tests" . "test") | |
405 ("toggles" . "toggle") | |
406 ("tries" . "try") | |
407 ("turns" . "turn") | |
408 ("undoes" . "undo") | |
409 ("unloads" . "unload") | |
410 ("unmarks" . "unmark") | |
411 ("updates" . "update") | |
412 ("uses" . "use") | |
413 ("yanks" . "yank") | |
414 ) | |
415 "Alist of common words in the wrong voice and what should be used instead. | |
416 Set `checkdoc-verb-check-experimental-flag' to nil to avoid this costly | |
417 and experimental check. Do not modify this list without setting | |
418 the value of `checkdoc-common-verbs-regexp' to nil which cause it to | |
419 be re-created.") | |
420 | |
421 (defvar checkdoc-syntax-table nil | |
422 "Syntax table used by checkdoc in document strings.") | |
423 | |
424 (if checkdoc-syntax-table | |
425 nil | |
426 (setq checkdoc-syntax-table (copy-syntax-table emacs-lisp-mode-syntax-table)) | |
427 ;; When dealing with syntax in doc-strings, make sure that - are encompased | |
428 ;; in words so we can use cheap \\> to get the end of a symbol, not the | |
429 ;; end of a word in a conglomerate. | |
430 (modify-syntax-entry ?- "w" checkdoc-syntax-table) | |
431 ) | |
432 | |
433 | |
434 ;;; Compatibility | |
435 ;; | |
436 (if (string-match "X[Ee]macs" emacs-version) | |
437 (progn | |
438 (defalias 'checkdoc-make-overlay 'make-extent) | |
439 (defalias 'checkdoc-overlay-put 'set-extent-property) | |
440 (defalias 'checkdoc-delete-overlay 'delete-extent) | |
441 (defalias 'checkdoc-overlay-start 'extent-start) | |
442 (defalias 'checkdoc-overlay-end 'extent-end) | |
443 (defalias 'checkdoc-mode-line-update 'redraw-modeline) | |
444 (defalias 'checkdoc-call-eval-buffer 'eval-buffer) | |
445 ) | |
446 (defalias 'checkdoc-make-overlay 'make-overlay) | |
447 (defalias 'checkdoc-overlay-put 'overlay-put) | |
448 (defalias 'checkdoc-delete-overlay 'delete-overlay) | |
449 (defalias 'checkdoc-overlay-start 'overlay-start) | |
450 (defalias 'checkdoc-overlay-end 'overlay-end) | |
451 (defalias 'checkdoc-mode-line-update 'force-mode-line-update) | |
452 (defalias 'checkdoc-call-eval-buffer 'eval-current-buffer) | |
453 ) | |
454 | |
455 ;; Emacs 20s have MULE characters which dont equate to numbers. | |
456 (if (fboundp 'char=) | |
457 (defalias 'checkdoc-char= 'char=) | |
458 (defalias 'checkdoc-char= '=)) | |
459 | |
460 ;; Emacs 19.28 and earlier don't have the handy 'add-to-list function | |
461 (if (fboundp 'add-to-list) | |
462 | |
463 (defalias 'checkdoc-add-to-list 'add-to-list) | |
464 | |
465 (defun checkdoc-add-to-list (list-var element) | |
466 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet." | |
467 (if (not (member element (symbol-value list-var))) | |
468 (set list-var (cons element (symbol-value list-var))))) | |
469 ) | |
470 | |
471 ;; To be safe in new emacsen, we want to read events, not characters | |
472 (if (fboundp 'read-event) | |
473 (defalias 'checkdoc-read-event 'read-event) | |
474 (defalias 'checkdoc-read-event 'read-char)) | |
475 | |
476 ;;; User level commands | |
477 ;; | |
478 ;;;###autoload | |
479 (defun checkdoc-eval-current-buffer () | |
480 "Evaluate and check documentation for the current buffer. | |
481 Evaluation is done first because good documentation for something that | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
482 doesn't work is just not useful. Comments, doc-strings, and rogue |
20085 | 483 spacing are all verified." |
484 (interactive) | |
485 (checkdoc-call-eval-buffer nil) | |
486 (checkdoc-current-buffer t)) | |
487 | |
488 ;;;###autoload | |
489 (defun checkdoc-current-buffer (&optional take-notes) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
490 "Check current buffer for document, comment, error style, and rogue spaces. |
20085 | 491 Optional argument TAKE-NOTES non-nil will store all found errors in a |
492 warnings buffer, otherwise it stops after the first error." | |
493 (interactive "P") | |
494 (if (interactive-p) (message "Checking buffer for style...")) | |
495 ;; Assign a flag to spellcheck flag | |
496 (let ((checkdoc-spellcheck-documentation-flag | |
497 (memq checkdoc-spellcheck-documentation-flag '(buffer t)))) | |
498 ;; every test is responsible for returning the cursor. | |
499 (or (and buffer-file-name ;; only check comments in a file | |
500 (checkdoc-comments take-notes)) | |
501 (checkdoc take-notes) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
502 (checkdoc-message-text take-notes) |
20085 | 503 (checkdoc-rogue-spaces take-notes) |
504 (not (interactive-p)) | |
505 (message "Checking buffer for style...Done.")))) | |
506 | |
507 ;;;###autoload | |
508 (defun checkdoc-interactive (&optional start-here) | |
509 "Interactively check the current buffers for errors. | |
510 Prefix argument START-HERE will start the checking from the current | |
511 point, otherwise the check starts at the beginning of the current | |
512 buffer. Allows navigation forward and backwards through document | |
513 errors. Does not check for comment or space warnings." | |
514 (interactive "P") | |
515 ;; Determine where to start the test | |
516 (let* ((begin (prog1 (point) | |
517 (if (not start-here) (goto-char (point-min))))) | |
518 ;; Assign a flag to spellcheck flag | |
519 (checkdoc-spellcheck-documentation-flag | |
520 (member checkdoc-spellcheck-documentation-flag | |
521 '(buffer interactive t))) | |
522 ;; Fetch the error list | |
523 (err-list (list (checkdoc-next-error)))) | |
524 (if (not (car err-list)) (setq err-list nil)) | |
525 ;; Include whatever function point is in for good measure. | |
526 (beginning-of-defun) | |
527 (while err-list | |
528 (goto-char (cdr (car err-list))) | |
529 ;; The cursor should be just in front of the offending doc-string | |
530 (let ((cdo (save-excursion | |
531 (checkdoc-make-overlay (point) | |
532 (progn (forward-sexp 1) | |
533 (point))))) | |
534 c) | |
535 (unwind-protect | |
536 (progn | |
537 (checkdoc-overlay-put cdo 'face 'highlight) | |
538 ;; Make sure the whole doc-string is visible if possible. | |
539 (sit-for 0) | |
540 (if (not (pos-visible-in-window-p | |
541 (save-excursion (forward-sexp 1) (point)) | |
542 (selected-window))) | |
543 (recenter)) | |
544 (message "%s(? e n p q)" (car (car err-list))) | |
545 (setq c (checkdoc-read-event)) | |
546 (if (not (integerp c)) (setq c ??)) | |
547 (cond ((or (checkdoc-char= c ?n) (checkdoc-char= c ?\ )) | |
548 (let ((ne (checkdoc-next-error))) | |
549 (if (not ne) | |
550 (progn | |
551 (message "No More Stylistic Errors.") | |
552 (sit-for 2)) | |
553 (setq err-list (cons ne err-list))))) | |
554 ((or (checkdoc-char= c ?p) (checkdoc-char= c ?\C-?)) | |
555 (if (/= (length err-list) 1) | |
556 (progn | |
557 (setq err-list (cdr err-list)) | |
558 ;; This will just re-ask fixup questions if | |
559 ;; it was skipped the last time. | |
560 (checkdoc-next-error)) | |
561 (message "No Previous Errors.") | |
562 (sit-for 2))) | |
563 ((checkdoc-char= c ?e) | |
564 (message "Edit the docstring, and press C-M-c to exit.") | |
565 (recursive-edit) | |
566 (checkdoc-delete-overlay cdo) | |
567 (setq err-list (cdr err-list)) ;back up the error found. | |
568 (beginning-of-defun) | |
569 (let ((ne (checkdoc-next-error))) | |
570 (if (not ne) | |
571 (progn | |
572 (message "No More Stylistic Errors.") | |
573 (sit-for 2)) | |
574 (setq err-list (cons ne err-list))))) | |
575 ((checkdoc-char= c ?q) | |
576 (setq err-list nil | |
577 begin (point))) | |
578 (t | |
579 (message "[E]dit [SPC|n] next error [DEL|p] prev error\ | |
580 [q]uit [?] help: ") | |
581 (sit-for 5)))) | |
582 (checkdoc-delete-overlay cdo)))) | |
583 (goto-char begin) | |
584 (message "Checkdoc: Done."))) | |
585 | |
586 (defun checkdoc-next-error () | |
587 "Find and return the next checkdoc error list, or nil. | |
588 Add error vector is of the form (WARNING . POSITION) where WARNING | |
589 is the warning text, and POSITION is the point in the buffer where the | |
590 error was found. We can use points and not markers because we promise | |
591 not to edit the buffer before point without re-executing this check." | |
592 (let ((msg nil) (p (point))) | |
593 (condition-case nil | |
594 (while (and (not msg) (checkdoc-next-docstring)) | |
595 (message "Searching for doc-string error...%d%%" | |
596 (/ (* 100 (point)) (point-max))) | |
597 (if (setq msg (checkdoc-this-string-valid)) | |
598 (setq msg (cons msg (point))))) | |
599 ;; Quit.. restore position, Other errors, leave alone | |
600 (quit (goto-char p))) | |
601 msg)) | |
602 | |
603 ;;;###autoload | |
604 (defun checkdoc (&optional take-notes) | |
605 "Use `checkdoc-continue' starting at the beginning of the current buffer. | |
606 Prefix argument TAKE-NOTES means to collect all the warning messages into | |
607 a separate buffer." | |
608 (interactive "P") | |
609 (let ((p (point))) | |
610 (goto-char (point-min)) | |
611 (checkdoc-continue take-notes) | |
612 ;; Go back since we can't be here without success above. | |
613 (goto-char p) | |
614 nil)) | |
615 | |
616 ;;;###autoload | |
617 (defun checkdoc-continue (&optional take-notes) | |
618 "Find the next doc-string in the current buffer which is stylisticly poor. | |
619 Prefix argument TAKE-NOTES means to continue through the whole buffer and | |
620 save warnings in a separate buffer. Second optional argument START-POINT | |
621 is the starting location. If this is nil, `point-min' is used instead." | |
622 (interactive "P") | |
623 (let ((wrong nil) (msg nil) (errors nil) | |
624 ;; Assign a flag to spellcheck flag | |
625 (checkdoc-spellcheck-documentation-flag | |
626 (member checkdoc-spellcheck-documentation-flag | |
627 '(buffer t)))) | |
628 (save-excursion | |
629 ;; If we are taking notes, encompass the whole buffer, otherwise | |
630 ;; the user is navigating down through the buffer. | |
631 (if take-notes (checkdoc-start-section "checkdoc")) | |
632 (while (and (not wrong) (checkdoc-next-docstring)) | |
21181 | 633 ;; OK, lets look at the doc-string. |
634 (setq msg (checkdoc-this-string-valid)) | |
635 (if msg | |
636 ;; Oops | |
637 (if take-notes | |
638 (progn | |
639 (checkdoc-error (point) msg) | |
640 (setq errors t)) | |
641 (setq wrong (point)))))) | |
20085 | 642 (if wrong |
643 (progn | |
644 (goto-char wrong) | |
645 (error msg))) | |
646 (if (and take-notes errors) | |
647 (checkdoc-show-diagnostics) | |
648 (if (interactive-p) | |
649 (message "No style warnings."))))) | |
650 | |
651 (defun checkdoc-next-docstring () | |
652 "Find the next doc-string after point and return t. | |
653 Return nil if there are no more doc-strings." | |
654 (if (not (re-search-forward checkdoc-defun-regexp nil t)) | |
655 nil | |
656 ;; search drops us after the identifier. The next sexp is either | |
657 ;; the argument list or the value of the variable. skip it. | |
658 (forward-sexp 1) | |
659 (skip-chars-forward " \n\t") | |
660 t)) | |
661 | |
662 ;;; ###autoload | |
663 (defun checkdoc-comments (&optional take-notes) | |
664 "Find missing comment sections in the current emacs lisp file. | |
665 Prefix argument TAKE-NOTES non-nil means to save warnings in a | |
666 separate buffer. Otherwise print a message. This returns the error | |
667 if there is one." | |
668 (interactive "P") | |
669 (if take-notes (checkdoc-start-section "checkdoc-comments")) | |
670 (if (not buffer-file-name) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
671 (error "Can only check comments for a file buffer")) |
20085 | 672 (let* ((checkdoc-spellcheck-documentation-flag |
673 (member checkdoc-spellcheck-documentation-flag | |
674 '(buffer t))) | |
675 (e (checkdoc-file-comments-engine))) | |
676 (if e | |
677 (if take-notes | |
678 (checkdoc-error nil e) | |
679 (error e))) | |
680 (if (and e take-notes) | |
681 (checkdoc-show-diagnostics)) | |
682 e)) | |
683 | |
684 ;;;###autoload | |
685 (defun checkdoc-rogue-spaces (&optional take-notes) | |
686 "Find extra spaces at the end of lines in the current file. | |
687 Prefix argument TAKE-NOTES non-nil means to save warnings in a | |
688 separate buffer. Otherwise print a message. This returns the error | |
689 if there is one." | |
690 (interactive "P") | |
691 (if take-notes (checkdoc-start-section "checkdoc-rogue-spaces")) | |
692 (let ((e (checkdoc-rogue-space-check-engine))) | |
693 (if e | |
694 (if take-notes | |
695 (checkdoc-error nil e) | |
696 (message e))) | |
697 (if (and e take-notes) | |
698 (checkdoc-show-diagnostics)) | |
699 (if (not (interactive-p)) | |
700 e | |
701 (if e (message e) (message "Space Check: done."))))) | |
702 | |
703 | |
704 ;;;###autoload | |
705 (defun checkdoc-eval-defun () | |
706 "Evaluate the current form with `eval-defun' and check it's documentation. | |
707 Evaluation is done first so the form will be read before the | |
708 documentation is checked. If there is a documentation error, then the display | |
709 of what was evaluated will be overwritten by the diagnostic message." | |
710 (interactive) | |
711 (eval-defun nil) | |
712 (checkdoc-defun)) | |
713 | |
714 ;;;###autoload | |
715 (defun checkdoc-defun (&optional no-error) | |
716 "Examine the doc-string of the function or variable under point. | |
717 Calls `error' if the doc-string produces diagnostics. If NO-ERROR is | |
718 non-nil, then do not call error, but call `message' instead. | |
719 If the document check passes, then check the function for rogue white | |
720 space at the end of each line." | |
721 (interactive) | |
722 (save-excursion | |
723 (beginning-of-defun) | |
724 (if (not (looking-at checkdoc-defun-regexp)) | |
725 ;; I found this more annoying than useful. | |
726 ;;(if (not no-error) | |
727 ;; (message "Cannot check this sexp's doc-string.")) | |
728 nil | |
729 ;; search drops us after the identifier. The next sexp is either | |
730 ;; the argument list or the value of the variable. skip it. | |
731 (goto-char (match-end 0)) | |
732 (forward-sexp 1) | |
733 (skip-chars-forward " \n\t") | |
734 (let* ((checkdoc-spellcheck-documentation-flag | |
735 (member checkdoc-spellcheck-documentation-flag | |
736 '(defun t))) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
737 (beg (save-excursion (beginning-of-defun) (point))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
738 (end (save-excursion (end-of-defun) (point))) |
20085 | 739 (msg (checkdoc-this-string-valid))) |
740 (if msg (if no-error (message msg) (error msg)) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
741 (setq msg (checkdoc-message-text-search beg end)) |
20085 | 742 (if msg (if no-error (message msg) (error msg)) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
743 (setq msg (checkdoc-rogue-space-check-engine beg end)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
744 (if msg (if no-error (message msg) (error msg))))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
745 (if (interactive-p) (message "Checkdoc: done.")))))) |
20085 | 746 |
747 ;;; Ispell interface for forcing a spell check | |
748 ;; | |
749 | |
750 ;;;###autoload | |
751 (defun checkdoc-ispell-current-buffer (&optional take-notes) | |
752 "Check the style and spelling of the current buffer interactively. | |
753 Calls `checkdoc-current-buffer' with spell-checking turned on. | |
754 Prefix argument TAKE-NOTES is the same as for `checkdoc-current-buffer'" | |
755 (interactive) | |
756 (let ((checkdoc-spellcheck-documentation-flag t)) | |
757 (call-interactively 'checkdoc-current-buffer nil current-prefix-arg))) | |
758 | |
759 ;;;###autoload | |
760 (defun checkdoc-ispell-interactive (&optional take-notes) | |
761 "Check the style and spelling of the current buffer interactively. | |
762 Calls `checkdoc-interactive' with spell-checking turned on. | |
763 Prefix argument TAKE-NOTES is the same as for `checkdoc-interacitve'" | |
764 (interactive) | |
765 (let ((checkdoc-spellcheck-documentation-flag t)) | |
766 (call-interactively 'checkdoc-interactive nil current-prefix-arg))) | |
767 | |
768 ;;;###autoload | |
769 (defun checkdoc-ispell (&optional take-notes) | |
770 "Check the style and spelling of the current buffer. | |
771 Calls `checkdoc' with spell-checking turned on. | |
772 Prefix argument TAKE-NOTES is the same as for `checkdoc'" | |
773 (interactive) | |
774 (let ((checkdoc-spellcheck-documentation-flag t)) | |
775 (call-interactively 'checkdoc nil current-prefix-arg))) | |
776 | |
777 ;;;###autoload | |
778 (defun checkdoc-ispell-continue (&optional take-notes) | |
779 "Check the style and spelling of the current buffer after point. | |
780 Calls `checkdoc-continue' with spell-checking turned on. | |
781 Prefix argument TAKE-NOTES is the same as for `checkdoc-continue'" | |
782 (interactive) | |
783 (let ((checkdoc-spellcheck-documentation-flag t)) | |
784 (call-interactively 'checkdoc-continue nil current-prefix-arg))) | |
785 | |
786 ;;;###autoload | |
787 (defun checkdoc-ispell-comments (&optional take-notes) | |
788 "Check the style and spelling of the current buffer's comments. | |
789 Calls `checkdoc-comments' with spell-checking turned on. | |
790 Prefix argument TAKE-NOTES is the same as for `checkdoc-comments'" | |
791 (interactive) | |
792 (let ((checkdoc-spellcheck-documentation-flag t)) | |
793 (call-interactively 'checkdoc-comments nil current-prefix-arg))) | |
794 | |
795 ;;;###autoload | |
796 (defun checkdoc-ispell-defun (&optional take-notes) | |
797 "Check the style and spelling of the current defun with ispell. | |
798 Calls `checkdoc-defun' with spell-checking turned on. | |
799 Prefix argument TAKE-NOTES is the same as for `checkdoc-defun'" | |
800 (interactive) | |
801 (let ((checkdoc-spellcheck-documentation-flag t)) | |
802 (call-interactively 'checkdoc-defun nil current-prefix-arg))) | |
803 | |
804 ;;; Minor Mode specification | |
805 ;; | |
806 (defvar checkdoc-minor-mode nil | |
807 "Non-nil in `emacs-lisp-mode' for automatic documentation checking.") | |
808 (make-variable-buffer-local 'checkdoc-minor-mode) | |
809 | |
810 (checkdoc-add-to-list 'minor-mode-alist '(checkdoc-minor-mode " CDoc")) | |
811 | |
812 (defvar checkdoc-minor-keymap | |
813 (let ((map (make-sparse-keymap)) | |
814 (pmap (make-sparse-keymap))) | |
815 ;; Override some bindings | |
816 (define-key map "\C-\M-x" 'checkdoc-eval-defun) | |
817 (if (not (string-match "XEmacs" emacs-version)) | |
818 (define-key map [menu-bar emacs-lisp eval-buffer] | |
819 'checkdoc-eval-current-buffer)) | |
820 (define-key pmap "x" 'checkdoc-defun) | |
821 (define-key pmap "X" 'checkdoc-ispell-defun) | |
822 (define-key pmap "`" 'checkdoc-continue) | |
823 (define-key pmap "~" 'checkdoc-ispell-continue) | |
824 (define-key pmap "d" 'checkdoc) | |
825 (define-key pmap "D" 'checkdoc-ispell) | |
826 (define-key pmap "i" 'checkdoc-interactive) | |
827 (define-key pmap "I" 'checkdoc-ispell-interactive) | |
828 (define-key pmap "b" 'checkdoc-current-buffer) | |
829 (define-key pmap "B" 'checkdoc-ispell-current-buffer) | |
830 (define-key pmap "e" 'checkdoc-eval-current-buffer) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
831 (define-key pmap "m" 'checkdoc-message-text) |
20085 | 832 (define-key pmap "c" 'checkdoc-comments) |
833 (define-key pmap "C" 'checkdoc-ispell-comments) | |
834 (define-key pmap " " 'checkdoc-rogue-spaces) | |
835 | |
836 ;; bind our submap into map | |
837 (define-key map "\C-c?" pmap) | |
838 map) | |
839 "Keymap used to override evaluation key-bindings for documentation checking.") | |
840 | |
841 ;; Add in a menubar with easy-menu | |
842 | |
843 (if checkdoc-minor-keymap | |
844 (easy-menu-define | |
845 checkdoc-minor-menu checkdoc-minor-keymap "Checkdoc Minor Mode Menu" | |
846 '("CheckDoc" | |
847 ["First Style Error" checkdoc t] | |
848 ["First Style or Spelling Error " checkdoc-ispell t] | |
849 ["Next Style Error" checkdoc-continue t] | |
850 ["Next Style or Spelling Error" checkdoc-ispell-continue t] | |
851 ["Interactive Style Check" checkdoc-interactive t] | |
852 ["Interactive Style and Spelling Check" checkdoc-ispell-interactive t] | |
853 ["Check Defun" checkdoc-defun t] | |
854 ["Check and Spell Defun" checkdoc-ispell-defun t] | |
855 ["Check and Evaluate Defun" checkdoc-eval-defun t] | |
856 ["Check Buffer" checkdoc-current-buffer t] | |
857 ["Check and Spell Buffer" checkdoc-ispell-current-buffer t] | |
858 ["Check and Evaluate Buffer" checkdoc-eval-current-buffer t] | |
859 ["Check Comment Style" checkdoc-comments buffer-file-name] | |
860 ["Check Comment Style and Spelling" checkdoc-ispell-comments | |
861 buffer-file-name] | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
862 ["Check message text" checkdoc-message-text t] |
20085 | 863 ["Check for Rogue Spaces" checkdoc-rogue-spaces t] |
864 ))) | |
865 ;; XEmacs requires some weird stuff to add this menu in a minor mode. | |
866 ;; What is it? | |
867 | |
868 ;; Allow re-insertion of a new keymap | |
869 (let ((a (assoc 'checkdoc-minor-mode minor-mode-map-alist))) | |
870 (if a | |
871 (setcdr a checkdoc-minor-keymap) | |
872 (checkdoc-add-to-list 'minor-mode-map-alist (cons 'checkdoc-minor-mode | |
873 checkdoc-minor-keymap)))) | |
874 | |
875 ;;;###autoload | |
876 (defun checkdoc-minor-mode (&optional arg) | |
877 "Toggle checkdoc minor mode. A mode for checking lisp doc-strings. | |
878 With prefix ARG, turn checkdoc minor mode on iff ARG is positive. | |
879 | |
880 In checkdoc minor mode, the usual bindings for `eval-defun' which is | |
881 bound to \\<checkdoc-minor-keymap> \\[checkdoc-eval-defun] and `checkdoc-eval-current-buffer' are overridden to include | |
882 checking of documentation strings. | |
883 | |
884 \\{checkdoc-minor-keymap}" | |
885 (interactive "P") | |
886 (setq checkdoc-minor-mode | |
887 (not (or (and (null arg) checkdoc-minor-mode) | |
888 (<= (prefix-numeric-value arg) 0)))) | |
889 (checkdoc-mode-line-update)) | |
890 | |
891 ;;; Subst utils | |
892 ;; | |
893 (defsubst checkdoc-run-hooks (hookvar &rest args) | |
894 "Run hooks in HOOKVAR with ARGS." | |
895 (if (fboundp 'run-hook-with-args-until-success) | |
896 (apply 'run-hook-with-args-until-success hookvar args) | |
897 ;; This method was similar to above. We ignore the warning | |
898 ;; since we will use the above for future emacs versions | |
899 (apply 'run-hook-with-args hookvar args))) | |
900 | |
901 (defsubst checkdoc-create-common-verbs-regexp () | |
902 "Rebuild the contents of `checkdoc-common-verbs-regexp'." | |
903 (or checkdoc-common-verbs-regexp | |
904 (setq checkdoc-common-verbs-regexp | |
905 (concat "\\<\\(" | |
906 (mapconcat (lambda (e) (concat (car e))) | |
907 checkdoc-common-verbs-wrong-voice "\\|") | |
908 "\\)\\>")))) | |
909 | |
910 ;; Profiler says this is not yet faster than just calling assoc | |
911 ;;(defun checkdoc-word-in-alist-vector (word vector) | |
912 ;; "Check to see if WORD is in the car of an element of VECTOR. | |
913 ;;VECTOR must be sorted. The CDR should be a replacement. Since the | |
914 ;;word list is getting bigger, it is time for a quick bisecting search." | |
915 ;; (let ((max (length vector)) (min 0) i | |
916 ;; (found nil) (fw nil)) | |
917 ;; (setq i (/ max 2)) | |
918 ;; (while (and (not found) (/= min max)) | |
919 ;; (setq fw (car (aref vector i))) | |
920 ;; (cond ((string= word fw) (setq found (cdr (aref vector i)))) | |
921 ;; ((string< word fw) (setq max i)) | |
922 ;; (t (setq min i))) | |
923 ;; (setq i (/ (+ max min) 2)) | |
924 ;; ) | |
925 ;; found)) | |
926 | |
927 ;;; Checking engines | |
928 ;; | |
929 (defun checkdoc-this-string-valid () | |
930 "Return a message string if the current doc-string is invalid. | |
931 Check for style only, such as the first line always being a complete | |
932 sentence, whitespace restrictions, and making sure there are no | |
933 hard-coded key-codes such as C-[char] or mouse-[number] in the comment. | |
934 See the style guide in the Emacs Lisp manual for more details." | |
935 | |
936 ;; Jump over comments between the last object and the doc-string | |
937 (while (looking-at "[ \t\n]*;") | |
938 (forward-line 1) | |
939 (beginning-of-line) | |
940 (skip-chars-forward " \n\t")) | |
941 | |
942 (if (not (looking-at "[ \t\n]*\"")) | |
943 nil | |
944 (let ((old-syntax-table (syntax-table))) | |
945 (unwind-protect | |
946 (progn | |
947 (set-syntax-table checkdoc-syntax-table) | |
948 (checkdoc-this-string-valid-engine)) | |
949 (set-syntax-table old-syntax-table))))) | |
950 | |
951 (defun checkdoc-this-string-valid-engine () | |
952 "Return a message string if the current doc-string is invalid. | |
953 Depends on `checkdoc-this-string-valid' to reset the syntax table so that | |
954 regexp short cuts work." | |
955 (let ((case-fold-search nil) | |
956 ;; Use a marker so if an early check modifies the text, | |
957 ;; we won't accidentally loose our place. This could cause | |
958 ;; end-of doc-string whitespace to also delete the " char. | |
959 (e (save-excursion (forward-sexp 1) (point-marker))) | |
960 (fp (checkdoc-defun-info))) | |
961 (or | |
962 ;; * *Do not* indent subsequent lines of a documentation string so that | |
963 ;; the text is lined up in the source code with the text of the first | |
964 ;; line. This looks nice in the source code, but looks bizarre when | |
965 ;; users view the documentation. Remember that the indentation | |
966 ;; before the starting double-quote is not part of the string! | |
967 (save-excursion | |
968 (forward-line 1) | |
969 (beginning-of-line) | |
970 (if (and (< (point) e) | |
971 (looking-at "\\([ \t]+\\)[^ \t\n]")) | |
972 (if (checkdoc-autofix-ask-replace (match-beginning 1) | |
973 (match-end 1) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
974 "Remove this whitespace? " |
20085 | 975 "") |
976 nil | |
977 "Second line should not have indentation"))) | |
978 ;; * Do not start or end a documentation string with whitespace. | |
979 (let (start end) | |
980 (if (or (if (looking-at "\"\\([ \t\n]+\\)") | |
981 (setq start (match-beginning 1) | |
982 end (match-end 1))) | |
983 (save-excursion | |
984 (forward-sexp 1) | |
985 (forward-char -1) | |
986 (if (/= (skip-chars-backward " \t\n") 0) | |
987 (setq start (point) | |
988 end (1- e))))) | |
989 (if (checkdoc-autofix-ask-replace | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
990 start end "Remove this whitespace? " "") |
20085 | 991 nil |
992 "Documentation strings should not start or end with whitespace"))) | |
993 ;; * Every command, function, or variable intended for users to know | |
994 ;; about should have a documentation string. | |
995 ;; | |
996 ;; * An internal variable or subroutine of a Lisp program might as well | |
997 ;; have a documentation string. In earlier Emacs versions, you could | |
998 ;; save space by using a comment instead of a documentation string, | |
999 ;; but that is no longer the case. | |
1000 (if (and (not (nth 1 fp)) ; not a variable | |
1001 (or (nth 2 fp) ; is interactive | |
1002 checkdoc-force-docstrings-flag) ;or we always complain | |
1003 (not (checkdoc-char= (following-char) ?\"))) ; no doc-string | |
1004 (if (nth 2 fp) | |
1005 "All interactive functions should have documentation" | |
1006 "All variables and subroutines might as well have a \ | |
1007 documentation string")) | |
1008 ;; * The first line of the documentation string should consist of one | |
1009 ;; or two complete sentences that stand on their own as a summary. | |
1010 ;; `M-x apropos' displays just the first line, and if it doesn't | |
1011 ;; stand on its own, the result looks bad. In particular, start the | |
1012 ;; first line with a capital letter and end with a period. | |
1013 (save-excursion | |
1014 (end-of-line) | |
1015 (skip-chars-backward " \t\n") | |
1016 (if (> (point) e) (goto-char e)) ;of the form (defun n () "doc" nil) | |
1017 (forward-char -1) | |
1018 (cond | |
1019 ((and (checkdoc-char= (following-char) ?\") | |
1020 ;; A backslashed double quote at the end of a sentence | |
1021 (not (checkdoc-char= (preceding-char) ?\\))) | |
1022 ;; We might have to add a period in this case | |
1023 (forward-char -1) | |
1024 (if (looking-at "[.!]") | |
1025 nil | |
1026 (forward-char 1) | |
1027 (if (checkdoc-autofix-ask-replace | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1028 (point) (1+ (point)) "Add period to sentence? " |
20085 | 1029 ".\"" t) |
1030 nil | |
1031 "First sentence should end with punctuation."))) | |
1032 ((looking-at "[\\!;:.)]") | |
1033 ;; These are ok | |
1034 nil) | |
1035 (t | |
1036 ;; If it is not a complete sentence, lets see if we can | |
1037 ;; predict a clever way to make it one. | |
1038 (let ((msg "First line is not a complete sentence") | |
1039 (e (point))) | |
1040 (beginning-of-line) | |
1041 (if (re-search-forward "\\. +" e t) | |
1042 ;; Here we have found a complete sentence, but no break. | |
1043 (if (checkdoc-autofix-ask-replace | |
1044 (1+ (match-beginning 0)) (match-end 0) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1045 "First line not a complete sentence. Add RET here? " |
20085 | 1046 "\n" t) |
1047 (let (l1 l2) | |
1048 (forward-line 1) | |
1049 (end-of-line) | |
1050 (setq l1 (current-column) | |
1051 l2 (save-excursion | |
1052 (forward-line 1) | |
1053 (end-of-line) | |
1054 (current-column))) | |
1055 (if (> (+ l1 l2 1) 80) | |
1056 (setq msg "Incomplete auto-fix. Doc-string \ | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1057 may require more formatting") |
20085 | 1058 ;; We can merge these lines! Replace this CR |
1059 ;; with a space. | |
1060 (delete-char 1) (insert " ") | |
1061 (setq msg nil)))) | |
1062 ;; Lets see if there is enough room to draw the next | |
1063 ;; line's sentence up here. I often get hit w/ | |
1064 ;; auto-fill moving my words around. | |
1065 (let ((numc (progn (end-of-line) (- 80 (current-column)))) | |
1066 (p (point))) | |
1067 (forward-line 1) | |
1068 (beginning-of-line) | |
1069 (if (and (re-search-forward "[.!:\"][ \n\"]" (save-excursion | |
1070 (end-of-line) | |
1071 (point)) | |
1072 t) | |
1073 (< (current-column) numc)) | |
1074 (if (checkdoc-autofix-ask-replace | |
1075 p (1+ p) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1076 "1st line not a complete sentence. Join these lines? " |
20085 | 1077 " " t) |
1078 (progn | |
1079 ;; They said yes. We have more fill work to do... | |
1080 (delete-char 1) | |
1081 (insert "\n") | |
1082 (setq msg nil)))))) | |
1083 msg)))) | |
1084 ;; Continuation of above. Make sure our sentence is capitalized. | |
1085 (save-excursion | |
1086 (skip-chars-forward "\"\\*") | |
1087 (if (looking-at "[a-z]") | |
1088 (if (checkdoc-autofix-ask-replace | |
1089 (match-beginning 0) (match-end 0) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1090 "Capitalize your sentence? " (upcase (match-string 0)) |
20085 | 1091 t) |
1092 nil | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1093 "First line should be capitalized") |
20085 | 1094 nil)) |
1095 ;; * For consistency, phrase the verb in the first sentence of a | |
1096 ;; documentation string as an infinitive with "to" omitted. For | |
1097 ;; instance, use "Return the cons of A and B." in preference to | |
1098 ;; "Returns the cons of A and B." Usually it looks good to do | |
1099 ;; likewise for the rest of the first paragraph. Subsequent | |
1100 ;; paragraphs usually look better if they have proper subjects. | |
1101 ;; | |
1102 ;; For our purposes, just check to first sentence. A more robust | |
1103 ;; grammar checker would be preferred for the rest of the | |
1104 ;; documentation string. | |
1105 (and checkdoc-verb-check-experimental-flag | |
1106 (save-excursion | |
1107 ;; Maybe rebuild the monster-regex | |
1108 (checkdoc-create-common-verbs-regexp) | |
1109 (let ((lim (save-excursion | |
1110 (end-of-line) | |
1111 ;; check string-continuation | |
1112 (if (checkdoc-char= (preceding-char) ?\\) | |
1113 (progn (forward-line 1) | |
1114 (end-of-line))) | |
1115 (point))) | |
1116 (rs nil) replace original (case-fold-search t)) | |
1117 (while (and (not rs) | |
1118 (re-search-forward checkdoc-common-verbs-regexp | |
1119 lim t)) | |
1120 (setq original (buffer-substring-no-properties | |
1121 (match-beginning 1) (match-end 1)) | |
1122 rs (assoc (downcase original) | |
1123 checkdoc-common-verbs-wrong-voice)) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1124 (if (not rs) (error "Verb voice alist corrupted")) |
20085 | 1125 (setq replace (let ((case-fold-search nil)) |
1126 (save-match-data | |
1127 (if (string-match "^[A-Z]" original) | |
1128 (capitalize (cdr rs)) | |
1129 (cdr rs))))) | |
1130 (if (checkdoc-autofix-ask-replace | |
1131 (match-beginning 1) (match-end 1) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1132 (format "Wrong voice for verb `%s'. Replace with `%s'? " |
20085 | 1133 original replace) |
1134 replace t) | |
1135 (setq rs nil))) | |
1136 (if rs | |
1137 ;; there was a match, but no replace | |
1138 (format | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1139 "Incorrect voice in sentence. Use `%s' instead of `%s'" |
20085 | 1140 replace original))))) |
1141 ;; * Don't write key sequences directly in documentation strings. | |
1142 ;; Instead, use the `\\[...]' construct to stand for them. | |
1143 (save-excursion | |
1144 (let ((f nil) (m nil) (start (point)) | |
21181 | 1145 (re "[^`A-Za-z0-9_]\\([CMA]-[a-zA-Z]\\|\\(\\([CMA]-\\)?\ |
20085 | 1146 mouse-[0-3]\\)\\)\\>")) |
1147 ;; Find the first key sequence not in a sample | |
1148 (while (and (not f) (setq m (re-search-forward re e t))) | |
1149 (setq f (not (checkdoc-in-sample-code-p start e)))) | |
1150 (if m | |
1151 (concat | |
1152 "Keycode " (match-string 1) | |
1153 " embedded in doc-string. Use \\\\<keymap> & \\\\[function] " | |
1154 "instead")))) | |
1155 ;; It is not practical to use `\\[...]' very many times, because | |
1156 ;; display of the documentation string will become slow. So use this | |
1157 ;; to describe the most important commands in your major mode, and | |
1158 ;; then use `\\{...}' to display the rest of the mode's keymap. | |
1159 (save-excursion | |
1160 (if (re-search-forward "\\\\\\\\\\[\\w+" e t | |
1161 (1+ checkdoc-max-keyref-before-warn)) | |
1162 "Too many occurrences of \\[function]. Use \\{keymap} instead")) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1163 ;; Ambiguous quoted symbol. When a symbol is both bound and fbound, |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1164 ;; and is referred to in documentation, it should be prefixed with |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1165 ;; something to disambiguate it. This check must be before the |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1166 ;; 80 column check because it will probably break that. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1167 (save-excursion |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1168 (let ((case-fold-search t) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1169 (ret nil)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1170 (while (and |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1171 (re-search-forward |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1172 "\\(\\<\\(variable\\|option\\|function\\|command\\|symbol\\)\ |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1173 \\s-+\\)?`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'" e t) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1174 (not ret)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1175 (let ((sym (intern-soft (match-string 3))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1176 (mb (match-beginning 3))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1177 (if (and sym (boundp sym) (fboundp sym) (not (match-string 1))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1178 (if (checkdoc-autofix-ask-replace |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1179 mb (match-end 3) "Prefix this ambiguous symbol? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1180 (match-string 3) t) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1181 ;; We didn't actuall replace anything. Here we find |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1182 ;; out what special word form they wish to use as |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1183 ;; a prefix. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1184 (let ((disambiguate |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1185 (completing-read |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1186 "Disambiguating Keyword (default: variable): " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1187 '(("function") ("command") ("variable") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1188 ("option") ("symbol")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1189 nil t nil nil "variable"))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1190 (goto-char (1- mb)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1191 (insert disambiguate " ") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1192 (forward-word 1)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1193 (setq ret |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1194 (format "Disambiguate %s by preceeding w/ \ |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1195 function,command,variable,option or symbol." (match-string 3))))))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1196 ret)) |
20085 | 1197 ;; * Format the documentation string so that it fits in an |
1198 ;; Emacs window on an 80-column screen. It is a good idea | |
1199 ;; for most lines to be no wider than 60 characters. The | |
1200 ;; first line can be wider if necessary to fit the | |
1201 ;; information that ought to be there. | |
1202 (save-excursion | |
1203 (let ((start (point))) | |
1204 (while (and (< (point) e) | |
1205 (or (progn (end-of-line) (< (current-column) 80)) | |
1206 (progn (beginning-of-line) | |
1207 (re-search-forward "\\\\\\\\[[<{]" | |
1208 (save-excursion | |
1209 (end-of-line) | |
1210 (point)) t)) | |
1211 (checkdoc-in-sample-code-p start e))) | |
1212 (forward-line 1)) | |
1213 (end-of-line) | |
1214 (if (and (< (point) e) (> (current-column) 80)) | |
1215 "Some lines are over 80 columns wide"))) | |
1216 ;;* When a documentation string refers to a Lisp symbol, write it as | |
1217 ;; it would be printed (which usually means in lower case), with | |
1218 ;; single-quotes around it. For example: `lambda'. There are two | |
1219 ;; exceptions: write t and nil without single-quotes. (In this | |
1220 ;; manual, we normally do use single-quotes for those symbols.) | |
1221 (save-excursion | |
1222 (let ((found nil) (start (point)) (msg nil) (ms nil)) | |
1223 (while (and (not msg) | |
1224 (re-search-forward | |
1225 "[^([`':]\\(\\w\+[:-]\\(\\w\\|\\s_\\)+\\)[^]']" | |
1226 e t)) | |
1227 (setq ms (match-string 1)) | |
1228 (save-match-data | |
1229 ;; A . is a \s_ char, so we must remove periods from | |
1230 ;; sentences more carefully. | |
1231 (if (string-match "\\.$" ms) | |
1232 (setq ms (substring ms 0 (1- (length ms)))))) | |
1233 (if (and (not (checkdoc-in-sample-code-p start e)) | |
1234 (setq found (intern-soft ms)) | |
1235 (or (boundp found) (fboundp found))) | |
1236 (progn | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1237 (setq msg (format "Add quotes around lisp symbol `%s'? " |
20085 | 1238 ms)) |
1239 (if (checkdoc-autofix-ask-replace | |
1240 (match-beginning 1) (+ (match-beginning 1) | |
1241 (length ms)) | |
1242 msg (concat "`" ms "'") t) | |
1243 (setq msg nil))))) | |
1244 msg)) | |
1245 ;; t and nil case | |
1246 (save-excursion | |
1247 (if (re-search-forward "\\(`\\(t\\|nil\\)'\\)" e t) | |
1248 (if (checkdoc-autofix-ask-replace | |
1249 (match-beginning 1) (match-end 1) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1250 (format "%s should not appear in quotes. Remove? " |
20085 | 1251 (match-string 2)) |
1252 (match-string 2) t) | |
1253 nil | |
1254 "Symbols t and nil should not appear in `quotes'"))) | |
1255 ;; Here we deviate to tests based on a variable or function. | |
1256 (cond ((eq (nth 1 fp) t) | |
1257 ;; This is if we are in a variable | |
1258 (or | |
1259 ;; * The documentation string for a variable that is a | |
1260 ;; yes-or-no flag should start with words such as "Non-nil | |
1261 ;; means...", to make it clear that all non-`nil' values are | |
1262 ;; equivalent and indicate explicitly what `nil' and non-`nil' | |
1263 ;; mean. | |
1264 ;; * If a user option variable records a true-or-false | |
1265 ;; condition, give it a name that ends in `-flag'. | |
1266 | |
1267 ;; If the variable has -flag in the name, make sure | |
1268 (if (and (string-match "-flag$" (car fp)) | |
1269 (not (looking-at "\"\\*?Non-nil\\s-+means\\s-+"))) | |
1270 "Flag variable doc-strings should start: Non-nil means") | |
1271 ;; If the doc-string starts with "Non-nil means" | |
1272 (if (and (looking-at "\"\\*?Non-nil\\s-+means\\s-+") | |
1273 (not (string-match "-flag$" (car fp)))) | |
1274 "Flag variables should end in: -flag") | |
1275 ;; Done with variables | |
1276 )) | |
1277 (t | |
1278 ;; This if we are in a function definition | |
1279 (or | |
1280 ;; * When a function's documentation string mentions the value | |
1281 ;; of an argument of the function, use the argument name in | |
1282 ;; capital letters as if it were a name for that value. Thus, | |
1283 ;; the documentation string of the function `/' refers to its | |
1284 ;; second argument as `DIVISOR', because the actual argument | |
1285 ;; name is `divisor'. | |
1286 | |
1287 ;; Addendum: Make sure they appear in the doc in the same | |
1288 ;; order that they are found in the arg list. | |
1289 (let ((args (cdr (cdr (cdr (cdr fp))))) | |
1290 (last-pos 0) | |
1291 (found 1) | |
1292 (order (and (nth 3 fp) (car (nth 3 fp)))) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1293 (nocheck (append '("&optional" "&rest") (nth 3 fp))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1294 (inopts nil)) |
20085 | 1295 (while (and args found (> found last-pos)) |
1296 (if (member (car args) nocheck) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1297 (setq args (cdr args) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1298 inopts t) |
20085 | 1299 (setq last-pos found |
1300 found (save-excursion | |
1301 (re-search-forward | |
1302 (concat "\\<" (upcase (car args)) | |
1303 ;; Require whitespace OR | |
1304 ;; ITEMth<space> OR | |
1305 ;; ITEMs<space> | |
1306 "\\(\\>\\|th\\>\\|s\\>\\)") | |
1307 e t))) | |
1308 (if (not found) | |
1309 (let ((case-fold-search t)) | |
1310 ;; If the symbol was not found, lets see if we | |
1311 ;; can find it with a different capitalization | |
1312 ;; and see if the user wants to capitalize it. | |
1313 (if (save-excursion | |
1314 (re-search-forward | |
1315 (concat "\\<\\(" (car args) | |
1316 ;; Require whitespace OR | |
1317 ;; ITEMth<space> OR | |
1318 ;; ITEMs<space> | |
1319 "\\)\\(\\>\\|th\\>\\|s\\>\\)") | |
1320 e t)) | |
1321 (if (checkdoc-autofix-ask-replace | |
1322 (match-beginning 1) (match-end 1) | |
1323 (format | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1324 "Argument `%s' should appear as `%s'. Fix? " |
20085 | 1325 (car args) (upcase (car args))) |
1326 (upcase (car args)) t) | |
1327 (setq found (match-beginning 1)))))) | |
1328 (if found (setq args (cdr args))))) | |
1329 (if (not found) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1330 ;; It wasn't found at all! Offer to attach this new symbol |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1331 ;; to the end of the documentation string. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1332 (if (y-or-n-p |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1333 (format "Add %s documentation to end of doc-string?" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1334 (upcase (car args)))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1335 ;; No do some majic an invent a doc string. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1336 (save-excursion |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1337 (goto-char e) (forward-char -1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1338 (insert "\n" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1339 (if inopts "Optional a" "A") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1340 "rgument " (upcase (car args)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1341 " ") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1342 (insert (read-string "Describe: ")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1343 (if (not (save-excursion (forward-char -1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1344 (looking-at "[.?!]"))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1345 (insert ".")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1346 nil) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1347 (format |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1348 "Argument `%s' should appear as `%s' in the doc-string" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1349 (car args) (upcase (car args)))) |
20085 | 1350 (if (or (and order (eq order 'yes)) |
1351 (and (not order) checkdoc-arguments-in-order-flag)) | |
1352 (if (< found last-pos) | |
1353 "Arguments occur in the doc-string out of order")))) | |
1354 ;; Done with functions | |
1355 ))) | |
1356 ;; Make sure the doc-string has correctly spelled english words | |
1357 ;; in it. This functions is extracted due to it's complexity, | |
1358 ;; and reliance on the ispell program. | |
1359 (checkdoc-ispell-docstring-engine e) | |
1360 ;; User supplied checks | |
1361 (save-excursion (checkdoc-run-hooks 'checkdoc-style-hooks fp e)) | |
1362 ;; Done! | |
1363 ))) | |
1364 | |
1365 (defun checkdoc-defun-info nil | |
1366 "Return a list of details about the current sexp. | |
1367 It is a list of the form: | |
1368 '( NAME VARIABLE INTERACTIVE NODOCPARAMS PARAMETERS ... ) | |
1369 where NAME is the name, VARIABLE is t if this is a `defvar', | |
1370 INTERACTIVE is nil if this is not an interactive function, otherwise | |
1371 it is the position of the `interactive' call, and PARAMETERS is a | |
1372 string which is the name of each variable in the function's argument | |
1373 list. The NODOCPARAMS is a sublist of parameters specified by a checkdoc | |
1374 comment for a given defun. If the first element is not a string, then | |
1375 the token checkdoc-order: <TOKEN> exists, and TOKEN is a symbol read | |
1376 from the comment." | |
1377 (save-excursion | |
1378 (beginning-of-defun) | |
1379 (let ((defun (looking-at "(def\\(un\\|macro\\|subst\\|advice\\)")) | |
1380 (is-advice (looking-at "(defadvice")) | |
1381 (lst nil) | |
1382 (ret nil) | |
1383 (oo (make-vector 3 0))) ;substitute obarray for `read' | |
1384 (forward-char 1) | |
1385 (forward-sexp 1) | |
1386 (skip-chars-forward " \n\t") | |
1387 (setq ret | |
1388 (list (buffer-substring-no-properties | |
1389 (point) (progn (forward-sexp 1) (point))))) | |
1390 (if (not defun) | |
1391 (setq ret (cons t ret)) | |
1392 ;; The variable spot | |
1393 (setq ret (cons nil ret)) | |
1394 ;; Interactive | |
1395 (save-excursion | |
1396 (setq ret (cons | |
1397 (re-search-forward "(interactive" | |
1398 (save-excursion (end-of-defun) (point)) | |
1399 t) | |
1400 ret))) | |
1401 (skip-chars-forward " \t\n") | |
1402 (let ((bss (buffer-substring (point) (save-excursion (forward-sexp 1) | |
1403 (point)))) | |
1404 ;; Overload th main obarray so read doesn't intern the | |
1405 ;; local symbols of the function we are checking. | |
1406 ;; Without this we end up cluttering the symbol space w/ | |
1407 ;; useless symbols. | |
1408 (obarray oo)) | |
1409 ;; Ok, check for checkdoc parameter comment here | |
1410 (save-excursion | |
1411 (setq ret | |
1412 (cons | |
1413 (let ((sl1 nil)) | |
1414 (if (re-search-forward ";\\s-+checkdoc-order:\\s-+" | |
1415 (save-excursion (end-of-defun) | |
1416 (point)) | |
1417 t) | |
1418 (setq sl1 (list (cond ((looking-at "nil") 'no) | |
1419 ((looking-at "t") 'yes))))) | |
1420 (if (re-search-forward ";\\s-+checkdoc-params:\\s-+" | |
1421 (save-excursion (end-of-defun) | |
1422 (point)) | |
1423 t) | |
1424 (let ((sl nil)) | |
1425 (goto-char (match-end 0)) | |
1426 (setq lst (read (current-buffer))) | |
1427 (while lst | |
1428 (setq sl (cons (symbol-name (car lst)) sl) | |
1429 lst (cdr lst))) | |
1430 (setq sl1 (append sl1 sl)))) | |
1431 sl1) | |
1432 ret))) | |
1433 ;; Read the list of paramters, but do not put the symbols in | |
1434 ;; the standard obarray. | |
1435 (setq lst (read bss))) | |
1436 ;; This is because read will intern nil if it doesn't into the | |
1437 ;; new obarray. | |
1438 (if (not (listp lst)) (setq lst nil)) | |
1439 (if is-advice nil | |
1440 (while lst | |
1441 (setq ret (cons (symbol-name (car lst)) ret) | |
1442 lst (cdr lst))))) | |
1443 (nreverse ret)))) | |
1444 | |
1445 (defun checkdoc-in-sample-code-p (start limit) | |
1446 "Return Non-nil if the current point is in a code-fragment. | |
1447 A code fragment is identified by an open parenthesis followed by a | |
1448 symbol which is a valid function, or a parenthesis that is quoted with the ' | |
1449 character. Only the region from START to LIMIT is is allowed while | |
1450 searching for the bounding parenthesis." | |
1451 (save-match-data | |
1452 (save-restriction | |
1453 (narrow-to-region start limit) | |
1454 (save-excursion | |
1455 (and (condition-case nil (progn (up-list 1) t) (error nil)) | |
1456 (condition-case nil (progn (forward-list -1) t) (error nil)) | |
1457 (or (save-excursion (forward-char -1) (looking-at "'(")) | |
1458 (and (looking-at "(\\(\\(\\w\\|[-:_]\\)+\\)[ \t\n;]") | |
1459 (let ((ms (buffer-substring-no-properties | |
1460 (match-beginning 1) (match-end 1)))) | |
1461 ;; if this string is function bound, we are in | |
1462 ;; sample code. If it has a - or : character in | |
1463 ;; the name, then it is probably supposed to be bound | |
1464 ;; but isn't yet. | |
1465 (or (fboundp (intern-soft ms)) | |
1466 (string-match "\\w[-:_]+\\w" ms)))))))))) | |
1467 | |
1468 ;;; Ispell engine | |
1469 ;; | |
1470 (eval-when-compile (require 'ispell)) | |
1471 | |
1472 (defun checkdoc-ispell-init () | |
1473 "Initialize ispell process (default version) with lisp words. | |
1474 The words used are from `checkdoc-ispell-lisp-words'. If `ispell' | |
1475 cannot be loaded, then set `checkdoc-spellcheck-documentation-flag' to | |
1476 nil." | |
1477 (require 'ispell) | |
1478 (if (not (symbol-value 'ispell-process)) ;Silence byteCompiler | |
1479 (condition-case nil | |
1480 (progn | |
1481 (ispell-buffer-local-words) | |
1482 ;; This code copied in part from ispell.el emacs 19.34 | |
1483 (let ((w checkdoc-ispell-lisp-words)) | |
1484 (while w | |
1485 (process-send-string | |
1486 ;; Silence byte compiler | |
1487 (symbol-value 'ispell-process) | |
1488 (concat "@" (car w) "\n")) | |
1489 (setq w (cdr w))))) | |
1490 (error (setq checkdoc-spellcheck-documentation-flag nil))))) | |
1491 | |
1492 (defun checkdoc-ispell-docstring-engine (end) | |
1493 "Run the ispell tools on the doc-string between point and END. | |
1494 Since ispell isn't lisp smart, we must pre-process the doc-string | |
1495 before using the ispell engine on it." | |
1496 (if (not checkdoc-spellcheck-documentation-flag) | |
1497 nil | |
1498 (checkdoc-ispell-init) | |
1499 (save-excursion | |
1500 (skip-chars-forward "^a-zA-Z") | |
1501 (let ((word nil) (sym nil) (case-fold-search nil) (err nil)) | |
1502 (while (and (not err) (< (point) end)) | |
1503 (if (save-excursion (forward-char -1) (looking-at "[('`]")) | |
1504 ;; Skip lists describing meta-syntax, or bound variables | |
1505 (forward-sexp 1) | |
1506 (setq word (buffer-substring-no-properties | |
1507 (point) (progn | |
1508 (skip-chars-forward "a-zA-Z-") | |
1509 (point))) | |
1510 sym (intern-soft word)) | |
1511 (if (and sym (or (boundp sym) (fboundp sym))) | |
1512 ;; This is probably repetative in most cases, but not always. | |
1513 nil | |
1514 ;; Find out how we spell-check this word. | |
1515 (if (or | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
1516 ;; All caps w/ option th, or s tacked on the end |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
1517 ;; for pluralization or nuberthness. |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
1518 (string-match "^[A-Z][A-Z]+\\(s\\|th\\)?$" word) |
20085 | 1519 (looking-at "}") ; a keymap expression |
1520 ) | |
1521 nil | |
1522 (save-excursion | |
1523 (if (not (eq checkdoc-autofix-flag 'never)) | |
1524 (let ((lk last-input-event)) | |
1525 (ispell-word nil t) | |
1526 (if (not (equal last-input-event lk)) | |
1527 (progn | |
1528 (sit-for 0) | |
1529 (message "Continuing...")))) | |
1530 ;; Nothing here. | |
1531 ))))) | |
1532 (skip-chars-forward "^a-zA-Z")) | |
1533 err)))) | |
1534 | |
1535 ;;; Rogue space checking engine | |
1536 ;; | |
1537 (defun checkdoc-rogue-space-check-engine (&optional start end) | |
1538 "Return a message string if there is a line with white space at the end. | |
1539 If `checkdoc-autofix-flag' permits, delete that whitespace instead. | |
1540 If optional arguments START and END are non nil, bound the check to | |
1541 this region." | |
1542 (let ((p (point)) | |
1543 (msg nil)) | |
1544 (if (not start) (setq start (point-min))) | |
1545 ;; If end is nil, it means end of buffer to search anyway | |
1546 (or | |
1547 ;; Checkfor and error if `? ' or `?\ ' is used at the end of a line. | |
1548 ;; (It's dangerous) | |
1549 (progn | |
1550 (goto-char start) | |
1551 (if (re-search-forward "\\?\\\\?[ \t][ \t]*$" end t) | |
1552 (setq msg | |
1553 "Don't use `? ' at the end of a line. \ | |
1554 Some editors & news agents may remove it"))) | |
1555 ;; Check for, and pottentially remove whitespace appearing at the | |
1556 ;; end of different lines. | |
1557 (progn | |
1558 (goto-char start) | |
1559 ;; There is no documentation in the elisp manual about this check, | |
1560 ;; it is intended to help clean up messy code and reduce the file size. | |
1561 (while (and (not msg) (re-search-forward "[^ \t\n]\\([ \t]+\\)$" end t)) | |
1562 ;; This is not a complex activity | |
1563 (if (checkdoc-autofix-ask-replace | |
1564 (match-beginning 1) (match-end 1) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1565 "White space at end of line. Remove? " "") |
20085 | 1566 nil |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1567 (setq msg "White space found at end of line"))))) |
20085 | 1568 ;; Return an error and leave the cursor at that spot, or restore |
1569 ;; the cursor. | |
1570 (if msg | |
1571 msg | |
1572 (goto-char p) | |
1573 nil))) | |
1574 | |
1575 ;;; Comment checking engine | |
1576 ;; | |
1577 (eval-when-compile | |
1578 ;; We must load this to: | |
1579 ;; a) get symbols for comple and | |
1580 ;; b) determine if we have lm-history symbol which doesn't always exist | |
1581 (require 'lisp-mnt)) | |
1582 | |
1583 (defun checkdoc-file-comments-engine () | |
1584 "Return a message string if this file does not match the emacs standard. | |
1585 This checks for style only, such as the first line, Commentary:, | |
1586 Code:, and others referenced in the style guide." | |
1587 (if (featurep 'lisp-mnt) | |
1588 nil | |
1589 (require 'lisp-mnt) | |
1590 ;; Old Xemacs don't have `lm-commentary-mark' | |
1591 (if (and (not (fboundp 'lm-commentary-mark)) (boundp 'lm-commentary)) | |
1592 (defalias 'lm-commentary-mark 'lm-commentary))) | |
1593 (save-excursion | |
1594 (let* ((f1 (file-name-nondirectory (buffer-file-name))) | |
1595 (fn (file-name-sans-extension f1)) | |
1596 (fe (substring f1 (length fn)))) | |
1597 (goto-char (point-min)) | |
1598 (or | |
1599 ;; Lisp Maintenance checks first | |
1600 ;; Was: (lm-verify) -> not flexible enough for some people | |
1601 ;; * Summary at the beginning of the file: | |
1602 (if (not (lm-summary)) | |
1603 ;; This certifies as very complex so always ask unless | |
1604 ;; it's set to never | |
1605 (if (and checkdoc-autofix-flag | |
1606 (not (eq checkdoc-autofix-flag 'never)) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1607 (y-or-n-p "There is no first line summary! Add one? ")) |
20085 | 1608 (progn |
1609 (goto-char (point-min)) | |
1610 (insert ";;; " fn fe " --- " (read-string "Summary: ") "\n")) | |
1611 "The first line should be of the form: \";;; package --- Summary\"") | |
1612 nil) | |
1613 ;; * Commentary Section | |
1614 (if (not (lm-commentary-mark)) | |
1615 "You should have a section marked \";;; Commentary:\"" | |
1616 nil) | |
1617 ;; * History section. Say nothing if there is a file ChangeLog | |
1618 (if (or (file-exists-p "ChangeLog") | |
1619 (let ((fn 'lm-history-mark)) ;bestill byte-compiler | |
1620 (and (fboundp fn) (funcall fn)))) | |
1621 nil | |
1622 "You should have a section marked \";;; History:\" or use a ChangeLog") | |
1623 ;; * Code section | |
1624 (if (not (lm-code-mark)) | |
1625 (let ((cont t)) | |
1626 (goto-char (point-min)) | |
1627 (while (and cont (re-search-forward "^(" nil t)) | |
1628 (setq cont (looking-at "require\\s-+"))) | |
1629 (if (and (not cont) | |
1630 checkdoc-autofix-flag | |
1631 (not (eq checkdoc-autofix-flag 'never)) | |
1632 (y-or-n-p "There is no ;;; Code: marker. Insert one? ")) | |
1633 (progn (beginning-of-line) | |
1634 (insert ";;; Code:\n") | |
1635 nil) | |
1636 "You should have a section marked \";;; Code:\"")) | |
1637 nil) | |
1638 ;; * A footer. Not compartamentalized from lm-verify: too bad. | |
1639 ;; The following is partially clipped from lm-verify | |
1640 (save-excursion | |
1641 (goto-char (point-max)) | |
1642 (if (not (re-search-backward | |
1643 (concat "^;;;[ \t]+" fn "\\(" (regexp-quote fe) | |
1644 "\\)?[ \t]+ends here[ \t]*$" | |
1645 "\\|^;;;[ \t]+ End of file[ \t]+" | |
1646 fn "\\(" (regexp-quote fe) "\\)?") | |
1647 nil t)) | |
1648 (if (and checkdoc-autofix-flag | |
1649 (not (eq checkdoc-autofix-flag 'never)) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1650 (y-or-n-p "No identifiable footer! Add one? ")) |
20085 | 1651 (progn |
1652 (goto-char (point-max)) | |
1653 (insert "\n(provide '" fn ")\n;;; " fn fe " ends here\n")) | |
1654 (format "The footer should be (provide '%s)\\n;;; %s%s ends here" | |
1655 fn fn fe)))) | |
1656 ;; Ok, now lets look for multiple occurances of ;;;, and offer | |
1657 ;; to remove the extra ";" if applicable. This pre-supposes | |
1658 ;; that the user has semiautomatic fixing on to be useful. | |
1659 | |
1660 ;; In the info node (elisp)Library Headers a header is three ; | |
1661 ;; (the header) followed by text of only two ; | |
1662 ;; In (elisp)Comment Tips, however it says this: | |
1663 ;; * Another use for triple-semicolon comments is for commenting out | |
1664 ;; lines within a function. We use triple-semicolons for this | |
1665 ;; precisely so that they remain at the left margin. | |
1666 (let ((msg nil)) | |
1667 (goto-char (point-min)) | |
1668 (while (and checkdoc-tripple-semi-comment-check-flag | |
1669 (not msg) (re-search-forward "^;;;[^;]" nil t)) | |
1670 ;; We found a triple, lets check all following lines. | |
1671 (if (not (bolp)) (progn (beginning-of-line) (forward-line 1))) | |
1672 (let ((complex-replace t)) | |
1673 (while (looking-at ";;\\(;\\)[^;]") | |
1674 (if (and (checkdoc-outside-major-sexp) ;in code is ok. | |
1675 (checkdoc-autofix-ask-replace | |
1676 (match-beginning 1) (match-end 1) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1677 "Multiple occurances of ;;; found. Use ;; instead? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1678 "" complex-replace)) |
20085 | 1679 ;; Learn that, yea, the user did want to do this a |
1680 ;; whole bunch of times. | |
1681 (setq complex-replace nil)) | |
1682 (beginning-of-line) | |
1683 (forward-line 1))))) | |
1684 ;; Lets spellcheck the commentary section. This is the only | |
1685 ;; section that is easy to pick out, and it is also the most | |
1686 ;; visible section (with the finder) | |
1687 (save-excursion | |
1688 (goto-char (lm-commentary-mark)) | |
1689 ;; Spellcheck between the commentary, and the first | |
1690 ;; non-comment line. We could use lm-commentary, but that | |
1691 ;; returns a string, and ispell wants to talk to a buffer. | |
1692 ;; Since the comments talk about lisp, use the specialized | |
1693 ;; spell-checker we also used for doc-strings. | |
1694 (checkdoc-ispell-docstring-engine (save-excursion | |
1695 (re-search-forward "^[^;]" nil t) | |
1696 (point)))) | |
1697 ;;; test comment out code | |
1698 ;;; (foo 1 3) | |
1699 ;;; (bar 5 7) | |
1700 ;; Generic Full-file checks (should be comment related) | |
1701 (checkdoc-run-hooks 'checkdoc-comment-style-hooks) | |
1702 ;; Done with full file comment checks | |
1703 )))) | |
1704 | |
1705 (defun checkdoc-outside-major-sexp () | |
1706 "Return t if point is outside the bounds of a valid sexp." | |
1707 (save-match-data | |
1708 (save-excursion | |
1709 (let ((p (point))) | |
1710 (or (progn (beginning-of-defun) (bobp)) | |
1711 (progn (end-of-defun) (< (point) p))))))) | |
1712 | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1713 ;;; `error' and `message' text verifier. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1714 ;; |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1715 (defun checkdoc-message-text (&optional take-notes) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1716 "Scan the buffer for occurrences of the error function, and verify text. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1717 Optional argument TAKE-NOTES causes all errors to be logged." |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1718 (interactive "P") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1719 (if take-notes (checkdoc-start-section "checkdoc-message-text")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1720 (let ((p (point)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1721 (e (checkdoc-message-text-search))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1722 (if e (if take-notes (checkdoc-error (point) e) (error e))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1723 (if (and take-notes e) (checkdoc-show-diagnostics)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1724 (goto-char p)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1725 (if (interactive-p) (message "Checking error message text...done."))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1726 |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1727 (defun checkdoc-message-text-search (&optional beg end) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1728 "Search between BEG and END for an error with `error'. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1729 Optional arguments BEG and END represent the boundary of the check. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1730 The default boundary is the entire buffer." |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1731 (let ((e nil)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1732 (if (not (or beg end)) (setq beg (point-min) end (point-max))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1733 (goto-char beg) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1734 (while (and (not e) (re-search-forward "(\\s-*error[ \t\n]" end t)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1735 (if (looking-at "\"") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1736 (setq e (checkdoc-message-text-engine 'error)))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1737 (goto-char beg) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1738 (while (and (not e) (re-search-forward |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1739 "\\<y-or-n-p\\(-with-timeout\\)?[ \t\n]" end t)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1740 ;; Format is common as a first arg.. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1741 (if (looking-at "(format[ \t\n]") (goto-char (match-end 0))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1742 (if (looking-at "\"") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1743 (setq e (checkdoc-message-text-engine 'y-or-n-p)))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1744 (goto-char beg) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1745 ;; this is cheating for checkdoc only. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1746 (while (and (not e) (re-search-forward |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1747 "(checkdoc-autofix-ask-replace[ \t\n]" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1748 end t)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1749 (forward-sexp 2) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1750 (skip-chars-forward " \t\n") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1751 (if (looking-at "(format[ \t\n]") (goto-char (match-end 0))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1752 (if (looking-at "\"") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1753 (setq e (checkdoc-message-text-engine 'y-or-n-p)))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1754 ;; Is it worth adding checks for read commands too? That would |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1755 ;; require fixing up `interactive' which could be unpleasant. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1756 ;; Most people get that right by accident anyway. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1757 e)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1758 |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1759 (defun checkdoc-message-text-engine (type) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1760 "Return or fix errors found in strings passed to a message display function. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1761 According to the documentation for the function `error', the error string |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1762 should not end with a period, and should start with a capitol letter. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1763 The function `y-or-n-p' has similar constraints. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1764 Argument TYPE specifies the type of question, such as `error or `y-or-n-p." |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1765 (let ((case-fold-search nil)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1766 (or |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1767 ;; From the documentation of the symbol `error': |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1768 ;; In Emacs, the convention is that error messages start with a capital |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1769 ;; letter but *do not* end with a period. Please follow this convention |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1770 ;; for the sake of consistency. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1771 (if (and (save-excursion (forward-char 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1772 (looking-at "[a-z]\\w+")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1773 (not (checkdoc-autofix-ask-replace |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1774 (match-beginning 0) (match-end 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1775 "Capitalize your message text? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1776 (capitalize (match-string 0)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1777 t))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1778 "Messages should start with a capitol letter" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1779 nil) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1780 (if (and (eq type 'error) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1781 (save-excursion (forward-sexp 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1782 (forward-char -2) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1783 (looking-at "\\.")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1784 (not (checkdoc-autofix-ask-replace (match-beginning 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1785 (match-end 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1786 "Remove period from error? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1787 "" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1788 t))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1789 "Error messages should *not* end with a period" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1790 nil) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1791 ;; `y-or-n-p' documentation explicitly says: |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1792 ;; It should end in a space; `y-or-n-p' adds `(y or n) ' to it. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1793 ;; I added the ? requirement. Without it, it is unclear that we |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1794 ;; ask a question and it appears to be an undocumented style. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1795 (if (and (eq type 'y-or-n-p) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1796 (save-excursion (forward-sexp 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1797 (forward-char -3) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1798 (not (looking-at "\\? "))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1799 (if (save-excursion (forward-sexp 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1800 (forward-char -2) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1801 (looking-at "\\?")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1802 ;; If we see a ?, then replace with "? ". |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1803 (if (checkdoc-autofix-ask-replace |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1804 (match-beginning 0) (match-end 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1805 "y-or-n-p text should endwith \"? \". Fix? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1806 "? " t) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1807 nil |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1808 "y-or-n-p text should endwith \"? \".") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1809 (if (save-excursion (forward-sexp 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1810 (forward-char -2) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1811 (looking-at " ")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1812 (if (checkdoc-autofix-ask-replace |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1813 (match-beginning 0) (match-end 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1814 "y-or-n-p text should endwith \"? \". Fix? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1815 "? " t) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1816 nil |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1817 "y-or-n-p text should endwith \"? \".") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1818 (if (and ;; if this isn't true, we have a problem. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1819 (save-excursion (forward-sexp 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1820 (forward-char -1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1821 (looking-at "\"")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1822 (checkdoc-autofix-ask-replace |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1823 (match-beginning 0) (match-end 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1824 "y-or-n-p text should endwith \"? \". Fix? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1825 "? \"" t)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1826 nil |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1827 "y-or-n-p text should endwith \"? \".")))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1828 nil) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1829 ))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1830 |
20085 | 1831 ;;; Auto-fix helper functions |
1832 ;; | |
1833 (defun checkdoc-autofix-ask-replace (start end question replacewith | |
1834 &optional complex) | |
1835 "Highlight between START and END and queries the user with QUESTION. | |
1836 If the user says yes, or if `checkdoc-autofix-flag' permits, replace | |
1837 the region marked by START and END with REPLACEWITH. If optional flag | |
1838 COMPLEX is non-nil, then we may ask the user a question. See the | |
1839 documentation for `checkdoc-autofix-flag' for details. | |
1840 | |
1841 If a section is auto-replaced without asking the user, this function | |
1842 will pause near the fixed code so the user will briefly see what | |
1843 happened. | |
1844 | |
1845 This function returns non-nil if the text was replaced." | |
1846 (if checkdoc-autofix-flag | |
1847 (let ((o (checkdoc-make-overlay start end)) | |
1848 (ret nil)) | |
1849 (unwind-protect | |
1850 (progn | |
1851 (checkdoc-overlay-put o 'face 'highlight) | |
1852 (if (or (eq checkdoc-autofix-flag 'automatic) | |
1853 (and (eq checkdoc-autofix-flag 'semiautomatic) | |
1854 (not complex)) | |
1855 (and (or (eq checkdoc-autofix-flag 'query) complex) | |
1856 (y-or-n-p question))) | |
1857 (save-excursion | |
1858 (goto-char start) | |
1859 ;; On the off chance this is automatic, display | |
1860 ;; the question anyway so the user knows whats | |
1861 ;; going on. | |
1862 (if checkdoc-bouncy-flag (message "%s -> done" question)) | |
1863 (delete-region start end) | |
1864 (insert replacewith) | |
1865 (if checkdoc-bouncy-flag (sit-for 0)) | |
1866 (setq ret t))) | |
1867 (checkdoc-delete-overlay o)) | |
1868 (checkdoc-delete-overlay o)) | |
1869 ret))) | |
1870 | |
1871 ;;; Warning management | |
1872 ;; | |
1873 (defvar checkdoc-output-font-lock-keywords | |
1874 '(("\\(\\w+\\.el\\):" 1 font-lock-function-name-face) | |
1875 ("style check: \\(\\w+\\)" 1 font-lock-comment-face) | |
20953
f3f9df46d008
Changed font-lock-reference-face to font-lock-constant-face.
Simon Marshall <simon@gnu.org>
parents:
20603
diff
changeset
|
1876 ("^\\([0-9]+\\):" 1 font-lock-constant-face)) |
20085 | 1877 "Keywords used to highlight a checkdoc diagnostic buffer.") |
1878 | |
1879 (defvar checkdoc-output-mode-map nil | |
1880 "Keymap used in `checkdoc-output-mode'.") | |
1881 | |
1882 (if checkdoc-output-mode-map | |
1883 nil | |
1884 (setq checkdoc-output-mode-map (make-sparse-keymap)) | |
1885 (if (not (string-match "XEmacs" emacs-version)) | |
1886 (define-key checkdoc-output-mode-map [mouse-2] | |
1887 'checkdoc-find-error-mouse)) | |
1888 (define-key checkdoc-output-mode-map "\C-c\C-c" 'checkdoc-find-error) | |
1889 (define-key checkdoc-output-mode-map "\C-m" 'checkdoc-find-error)) | |
1890 | |
1891 (defun checkdoc-output-mode () | |
1892 "Create and setup the buffer used to maintain checkdoc warnings. | |
1893 \\<checkdoc-output-mode-map>\\[checkdoc-find-error] - Go to this error location | |
1894 \\[checkdoc-find-error-mouse] - Goto the error clicked on." | |
1895 (if (get-buffer checkdoc-diagnostic-buffer) | |
1896 (get-buffer checkdoc-diagnostic-buffer) | |
1897 (save-excursion | |
1898 (set-buffer (get-buffer-create checkdoc-diagnostic-buffer)) | |
1899 (kill-all-local-variables) | |
1900 (setq mode-name "Checkdoc" | |
1901 major-mode 'checkdoc-output-mode) | |
1902 (set (make-local-variable 'font-lock-defaults) | |
1903 '((checkdoc-output-font-lock-keywords) t t ((?- . "w") (?_ . "w")))) | |
1904 (use-local-map checkdoc-output-mode-map) | |
1905 (run-hooks 'checkdoc-output-mode-hook) | |
1906 (current-buffer)))) | |
1907 | |
1908 (defun checkdoc-find-error-mouse (e) | |
1909 ;; checkdoc-params: (e) | |
1910 "Call `checkdoc-find-error' where the user clicks the mouse." | |
1911 (interactive "e") | |
1912 (mouse-set-point e) | |
1913 (checkdoc-find-error)) | |
1914 | |
1915 (defun checkdoc-find-error () | |
1916 "In a checkdoc diagnostic buffer, find the error under point." | |
1917 (interactive) | |
1918 (beginning-of-line) | |
1919 (if (looking-at "[0-9]+") | |
1920 (let ((l (string-to-int (match-string 0))) | |
1921 (f (save-excursion | |
1922 (re-search-backward " \\(\\(\\w+\\|\\s_\\)+\\.el\\):") | |
1923 (match-string 1)))) | |
1924 (if (not (get-buffer f)) | |
1925 (error "Can't find buffer %s" f)) | |
1926 (switch-to-buffer-other-window (get-buffer f)) | |
1927 (goto-line l)))) | |
1928 | |
1929 (defun checkdoc-start-section (check-type) | |
1930 "Initialize the checkdoc diagnostic buffer for a pass. | |
1931 Create the header so that the string CHECK-TYPE is displayed as the | |
1932 function called to create the messages." | |
1933 (checkdoc-output-to-error-buffer | |
1934 "\n\n*** " (current-time-string) " " | |
1935 (file-name-nondirectory (buffer-file-name)) ": style check: " check-type | |
1936 " V " checkdoc-version)) | |
1937 | |
1938 (defun checkdoc-error (point msg) | |
1939 "Store POINT and MSG as errors in the checkdoc diagnostic buffer." | |
1940 (checkdoc-output-to-error-buffer | |
1941 "\n" (int-to-string (count-lines (point-min) (or point 1))) ": " | |
1942 msg)) | |
1943 | |
1944 (defun checkdoc-output-to-error-buffer (&rest text) | |
1945 "Place TEXT into the checkdoc diagnostic buffer." | |
1946 (save-excursion | |
1947 (set-buffer (checkdoc-output-mode)) | |
1948 (goto-char (point-max)) | |
1949 (apply 'insert text))) | |
1950 | |
1951 (defun checkdoc-show-diagnostics () | |
1952 "Display the checkdoc diagnostic buffer in a temporary window." | |
1953 (let ((b (get-buffer checkdoc-diagnostic-buffer))) | |
1954 (if b (progn (pop-to-buffer b) | |
1955 (beginning-of-line))) | |
1956 (other-window -1) | |
1957 (shrink-window-if-larger-than-buffer))) | |
1958 | |
1959 (defgroup checkdoc nil | |
1960 "Support for doc-string checking in emacs lisp." | |
1961 :prefix "checkdoc" | |
21651
86fcccceba7b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21181
diff
changeset
|
1962 :group 'lisp |
86fcccceba7b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21181
diff
changeset
|
1963 :version "20.3") |
20085 | 1964 |
1965 (custom-add-option 'emacs-lisp-mode-hook | |
1966 (lambda () (checkdoc-minor-mode 1))) | |
1967 | |
1968 (provide 'checkdoc) | |
1969 ;;; checkdoc.el ends here |