Mercurial > emacs
comparison lisp/emacs-lisp/checkdoc.el @ 22195:bab34c7c16fb
Many doc fixes.
Put two spaces between sentences.
(checkdoc-this-string-valid-engine): Fix message.
(checkdoc-ispell-lisp-words): Add "emacs".
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 23 May 1998 00:51:44 +0000 |
parents | 38f78542051a |
children | dee11277c07d |
comparison
equal
deleted
inserted
replaced
22194:376bd8ec20f1 | 22195:bab34c7c16fb |
---|---|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02111-1307, USA. |
25 | 25 |
26 ;;; Commentary: | 26 ;;; Commentary: |
27 ;; | 27 ;; |
28 ;; The emacs lisp manual has a nice chapter on how to write | 28 ;; The Emacs Lisp manual has a nice chapter on how to write |
29 ;; documentation strings. Many stylistic suggestions are fairly | 29 ;; documentation strings. Many stylistic suggestions are fairly |
30 ;; deterministic and easy to check for syntactically, but also easy | 30 ;; deterministic and easy to check for syntactically, but also easy |
31 ;; to forget. The main checkdoc engine will perform the stylistic | 31 ;; to forget. The main checkdoc engine will perform the stylistic |
32 ;; checks needed to make sure these styles are remembered. | 32 ;; checks needed to make sure these styles are remembered. |
33 ;; | 33 ;; |
34 ;; There are two ways to use checkdoc: | 34 ;; There are two ways to use checkdoc: |
35 ;; 1) Periodically use `checkdoc'. `checkdoc-current-buffer' and | 35 ;; 1) Periodically use `checkdoc'. `checkdoc-current-buffer' and |
36 ;; `checkdoc-defun' to check your documentation. | 36 ;; `checkdoc-defun' to check your documentation. |
37 ;; 2) Use `checkdoc-minor-mode' to automatically check your | 37 ;; 2) Use `checkdoc-minor-mode' to automatically check your |
38 ;; documentation whenever you evaluate lisp code with C-M-x | 38 ;; documentation whenever you evaluate Lisp code with C-M-x |
39 ;; or [menu-bar emacs-lisp eval-buffer]. Additional key-bindings | 39 ;; or [menu-bar emacs-lisp eval-buffer]. Additional key-bindings |
40 ;; are also provided under C-c ? KEY | 40 ;; are also provided under C-c ? KEY |
41 ;; (require 'checkdoc) | 41 ;; (require 'checkdoc) |
42 ;; (add-hook 'emacs-lisp-mode-hook | 42 ;; (add-hook 'emacs-lisp-mode-hook |
43 ;; '(lambda () (checkdoc-minor-mode 1))) | 43 ;; '(lambda () (checkdoc-minor-mode 1))) |
55 ;; set. Potentially redundant changes are considered really complex, | 55 ;; set. Potentially redundant changes are considered really complex, |
56 ;; and the user is always asked before a change is inserted. The | 56 ;; and the user is always asked before a change is inserted. The |
57 ;; variable `checkdoc-autofix-flag' controls how these types of errors | 57 ;; variable `checkdoc-autofix-flag' controls how these types of errors |
58 ;; are fixed. | 58 ;; are fixed. |
59 ;; | 59 ;; |
60 ;; Spell checking doc-strings: | 60 ;; Spell checking doc strings: |
61 ;; | 61 ;; |
62 ;; The variable `checkdoc-spellcheck-documentation-flag' can be set | 62 ;; The variable `checkdoc-spellcheck-documentation-flag' can be set |
63 ;; to customize how spell checking is to be done. Since spell | 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 | 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 | 65 ;; checking done. The default is 'defun, which spell checks each time |
67 ;; prevents spell checking during normal usage. | 67 ;; prevents spell checking during normal usage. |
68 ;; Setting this variable to nil does not mean you cannot take | 68 ;; Setting this variable to nil does not mean you cannot take |
69 ;; advantage of the spell checking. You can instead use the | 69 ;; advantage of the spell checking. You can instead use the |
70 ;; interactive functions `checkdoc-ispell-*' to check the spelling of | 70 ;; interactive functions `checkdoc-ispell-*' to check the spelling of |
71 ;; your documentation. | 71 ;; your documentation. |
72 ;; There is a list of lisp-specific words which checkdoc will | 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 | 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 | 74 ;; running. Use `ispell-kill-ispell' to make checkdoc restart it with |
75 ;; these words enabled. | 75 ;; these words enabled. |
76 ;; | 76 ;; |
77 ;; Checking parameters | 77 ;; Checking parameters |
78 ;; | 78 ;; |
100 ;; You can experiment with adding your own checks by setting the | 100 ;; You can experiment with adding your own checks by setting the |
101 ;; hooks `checkdoc-style-hooks' and `checkdoc-comment-style-hooks'. | 101 ;; hooks `checkdoc-style-hooks' and `checkdoc-comment-style-hooks'. |
102 ;; Return a string which is the error you wish to report. The cursor | 102 ;; Return a string which is the error you wish to report. The cursor |
103 ;; position should be preserved. | 103 ;; position should be preserved. |
104 ;; | 104 ;; |
105 ;; This file requires lisp-mnt (lisp maintenance routines) for the | 105 ;; This file requires lisp-mnt (Lisp maintenance routines) for the |
106 ;; comment checkers. | 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 . | |
177 ;; 0.4.2 Added some more comments in the commentary. | |
178 ;; You can now `quote' symbols that look like keystrokes | |
179 ;; When spell checking, meta variables can end in `th' or `s'. | |
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. | |
184 ;; 0.5 Added checks for basics in messages using `error'. | |
185 ;; Added check for symbols that are both functions and symbols. | |
186 ;; These references are ambiguous and should be prefixed with | |
187 ;; "function", or "variable". Added auto-fix for this also. | |
188 ;; Added auto fix for args that do not occur in the doc string. | |
189 ;; 0.5.1 Fixed question about putting a symbol in `quotes'. | |
190 ;; Added spaces to the end of all y/n questions. | |
191 ;; Added checks for y/n question endings to require "? " | |
192 | 107 |
193 ;;; TO DO: | 108 ;;; TO DO: |
194 ;; Hook into the byte compiler on a defun/defver level to generate | 109 ;; Hook into the byte compiler on a defun/defver level to generate |
195 ;; warnings in the byte-compiler's warning/error buffer. | 110 ;; warnings in the byte-compiler's warning/error buffer. |
196 ;; Better ways to override more typical `eval' functions. Advice | 111 ;; Better ways to override more typical `eval' functions. Advice |
219 nil) | 134 nil) |
220 (defmacro defcustom (var value doc &rest args) | 135 (defmacro defcustom (var value doc &rest args) |
221 (` (defvar (, var) (, value) (, doc)))))) | 136 (` (defvar (, var) (, value) (, doc)))))) |
222 | 137 |
223 (defcustom checkdoc-autofix-flag 'semiautomatic | 138 (defcustom checkdoc-autofix-flag 'semiautomatic |
224 "*Non-nil means attempt auto-fixing of doc-strings. | 139 "*Non-nil means attempt auto-fixing of doc strings. |
225 If this value is the symbol 'query, then the user is queried before | 140 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 | 141 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 | 142 made without asking unless the change is very-complex. If the value |
228 is 'semiautomatic, or any other value, then simple fixes are made | 143 is `semiautomatic', or any other value, then simple fixes are made |
229 without asking, and complex changes are made by asking the user first. | 144 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." | 145 The value `never' is the same as nil, never ask or change anything." |
231 :group 'checkdoc | 146 :group 'checkdoc |
232 :type '(choice (const automatic) | 147 :type '(choice (const automatic) |
233 (const semiautomatic) | 148 (const semiautomatic) |
234 (const query) | 149 (const query) |
235 (const never))) | 150 (const never))) |
236 | 151 |
237 (defcustom checkdoc-bouncy-flag t | 152 (defcustom checkdoc-bouncy-flag t |
238 "*Non-nil means to 'bounce' to auto-fix locations. | 153 "*Non-nil means to \"bounce\" to auto-fix locations. |
239 Setting this to nil will silently make fixes that require no user | 154 Setting this to nil will silently make fixes that require no user |
240 interaction. See `checkdoc-autofix-flag' for auto-fixing details." | 155 interaction. See `checkdoc-autofix-flag' for auto-fixing details." |
241 :group 'checkdoc | 156 :group 'checkdoc |
242 :type 'boolean) | 157 :type 'boolean) |
243 | 158 |
244 (defcustom checkdoc-force-docstrings-flag t | 159 (defcustom checkdoc-force-docstrings-flag t |
245 "*Non-nil means that all checkable definitions should have documentation. | 160 "*Non-nil means that all checkable definitions should have documentation. |
246 Style guide dictates that interactive functions MUST have documentation, | 161 Style guide dictates that interactive functions MUST have documentation, |
247 and that its good but not required practice to make non user visible items | 162 and that its good but not required practice to make non user visible items |
248 have doc-strings." | 163 have doc strings." |
249 :group 'checkdoc | 164 :group 'checkdoc |
250 :type 'boolean) | 165 :type 'boolean) |
251 | 166 |
252 (defcustom checkdoc-tripple-semi-comment-check-flag t | 167 (defcustom checkdoc-tripple-semi-comment-check-flag t |
253 "*Non-nil means to check for multiple adjacent occurrences of ;;; comments. | 168 "*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 | 169 According to the style of Emacs code in the Lisp libraries, a block |
255 comment can look like this: | 170 comment can look like this: |
256 ;;; Title | 171 ;;; Title |
257 ;; text | 172 ;; text |
258 ;; text | 173 ;; text |
259 But when inside a function, code can be commented out using the ;;; | 174 But when inside a function, code can be commented out using the ;;; |
261 is ignored regardless of it's location in the code." | 176 is ignored regardless of it's location in the code." |
262 :group 'checkdoc | 177 :group 'checkdoc |
263 :type 'boolean) | 178 :type 'boolean) |
264 | 179 |
265 (defcustom checkdoc-spellcheck-documentation-flag nil | 180 (defcustom checkdoc-spellcheck-documentation-flag nil |
266 "*Non-nil means run ispell on doc-strings based on value. | 181 "*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 | 182 This is automatically set to nil if Ispell does not exist on your |
268 system. Possible values are: | 183 system. Possible values are: |
269 | 184 |
270 nil - Don't spell-check during basic style checks. | 185 nil - Don't spell-check during basic style checks. |
271 'defun - Spell-check when style checking a single defun | 186 defun - Spell-check when style checking a single defun |
272 'buffer - Spell-check only when style checking the whole buffer | 187 buffer - Spell-check only when style checking the whole buffer |
273 'interactive - Spell-check only during `checkdoc-interactive' | 188 interactive - Spell-check only during `checkdoc-interactive' |
274 t - Always spell-check" | 189 t - Always spell-check" |
275 :group 'checkdoc | 190 :group 'checkdoc |
276 :type '(choice (const nil) | 191 :type '(choice (const nil) |
277 (const defun) | 192 (const defun) |
278 (const buffer) | 193 (const buffer) |
279 (const interactive) | 194 (const interactive) |
280 (const t))) | 195 (const t))) |
281 | 196 |
282 (defvar checkdoc-ispell-lisp-words | 197 (defvar checkdoc-ispell-lisp-words |
283 '("alist" "etags" "iff" "keymap" "paren" "regexp" "sexp" "xemacs") | 198 '("alist" "etags" "iff" "keymap" "paren" "regexp" "sexp" "emacs" "xemacs") |
284 "List of words that are correct when spell-checking lisp documentation.") | 199 "List of words that are correct when spell-checking Lisp documentation.") |
285 | 200 |
286 (defcustom checkdoc-max-keyref-before-warn 10 | 201 (defcustom checkdoc-max-keyref-before-warn 10 |
287 "*The number of \\ [command-to-keystroke] tokens allowed in a doc-string. | 202 "*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 | 203 Any more than this and a warning is generated suggesting that the construct |
289 \\ {keymap} be used instead." | 204 \\ {keymap} be used instead." |
290 :group 'checkdoc | 205 :group 'checkdoc |
291 :type 'integer) | 206 :type 'integer) |
292 | 207 |
321 \\s-+\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]+" | 236 \\s-+\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]+" |
322 "Regular expression used to identify a defun. | 237 "Regular expression used to identify a defun. |
323 A search leaves the cursor in front of the parameter list.") | 238 A search leaves the cursor in front of the parameter list.") |
324 | 239 |
325 (defcustom checkdoc-verb-check-experimental-flag t | 240 (defcustom checkdoc-verb-check-experimental-flag t |
326 "*Non-nil means to attempt to check the voice of the doc-string. | 241 "*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 | 242 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 | 243 variable `checkdoc-common-verbs-wrong-voice' if you wish to add your own." |
329 own." | |
330 :group 'checkdoc | 244 :group 'checkdoc |
331 :type 'boolean) | 245 :type 'boolean) |
332 | 246 |
333 (defvar checkdoc-common-verbs-regexp nil | 247 (defvar checkdoc-common-verbs-regexp nil |
334 "Regular expression derived from `checkdoc-common-verbs-regexp'.") | 248 "Regular expression derived from `checkdoc-common-verbs-regexp'.") |
422 "Syntax table used by checkdoc in document strings.") | 336 "Syntax table used by checkdoc in document strings.") |
423 | 337 |
424 (if checkdoc-syntax-table | 338 (if checkdoc-syntax-table |
425 nil | 339 nil |
426 (setq checkdoc-syntax-table (copy-syntax-table emacs-lisp-mode-syntax-table)) | 340 (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 | 341 ;; 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 | 342 ;; in words so we can use cheap \\> to get the end of a symbol, not the |
429 ;; end of a word in a conglomerate. | 343 ;; end of a word in a conglomerate. |
430 (modify-syntax-entry ?- "w" checkdoc-syntax-table) | 344 (modify-syntax-entry ?- "w" checkdoc-syntax-table) |
431 ) | 345 ) |
432 | 346 |
466 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet." | 380 "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))) | 381 (if (not (member element (symbol-value list-var))) |
468 (set list-var (cons element (symbol-value list-var))))) | 382 (set list-var (cons element (symbol-value list-var))))) |
469 ) | 383 ) |
470 | 384 |
471 ;; To be safe in new emacsen, we want to read events, not characters | 385 ;; To be safe in new Emacsen, we want to read events, not characters |
472 (if (fboundp 'read-event) | 386 (if (fboundp 'read-event) |
473 (defalias 'checkdoc-read-event 'read-event) | 387 (defalias 'checkdoc-read-event 'read-event) |
474 (defalias 'checkdoc-read-event 'read-char)) | 388 (defalias 'checkdoc-read-event 'read-char)) |
475 | 389 |
476 ;;; User level commands | 390 ;;; User level commands |
477 ;; | 391 ;; |
478 ;;;###autoload | 392 ;;;###autoload |
479 (defun checkdoc-eval-current-buffer () | 393 (defun checkdoc-eval-current-buffer () |
480 "Evaluate and check documentation for the current buffer. | 394 "Evaluate and check documentation for the current buffer. |
481 Evaluation is done first because good documentation for something that | 395 Evaluation is done first because good documentation for something that |
482 doesn't work is just not useful. Comments, doc-strings, and rogue | 396 doesn't work is just not useful. Comments, doc strings, and rogue |
483 spacing are all verified." | 397 spacing are all verified." |
484 (interactive) | 398 (interactive) |
485 (checkdoc-call-eval-buffer nil) | 399 (checkdoc-call-eval-buffer nil) |
486 (checkdoc-current-buffer t)) | 400 (checkdoc-current-buffer t)) |
487 | 401 |
488 ;;;###autoload | 402 ;;;###autoload |
489 (defun checkdoc-current-buffer (&optional take-notes) | 403 (defun checkdoc-current-buffer (&optional take-notes) |
490 "Check current buffer for document, comment, error style, and rogue spaces. | 404 "Check current buffer for document, comment, error style, and rogue spaces. |
491 Optional argument TAKE-NOTES non-nil will store all found errors in a | 405 With a prefix argument (in Lisp, the argument TAKE-NOTES), |
492 warnings buffer, otherwise it stops after the first error." | 406 store all errors found in a warnings buffer, |
407 otherwise stop after the first error." | |
493 (interactive "P") | 408 (interactive "P") |
494 (if (interactive-p) (message "Checking buffer for style...")) | 409 (if (interactive-p) (message "Checking buffer for style...")) |
495 ;; Assign a flag to spellcheck flag | 410 ;; Assign a flag to spellcheck flag |
496 (let ((checkdoc-spellcheck-documentation-flag | 411 (let ((checkdoc-spellcheck-documentation-flag |
497 (memq checkdoc-spellcheck-documentation-flag '(buffer t)))) | 412 (memq checkdoc-spellcheck-documentation-flag '(buffer t)))) |
524 (if (not (car err-list)) (setq err-list nil)) | 439 (if (not (car err-list)) (setq err-list nil)) |
525 ;; Include whatever function point is in for good measure. | 440 ;; Include whatever function point is in for good measure. |
526 (beginning-of-defun) | 441 (beginning-of-defun) |
527 (while err-list | 442 (while err-list |
528 (goto-char (cdr (car err-list))) | 443 (goto-char (cdr (car err-list))) |
529 ;; The cursor should be just in front of the offending doc-string | 444 ;; The cursor should be just in front of the offending doc string |
530 (let ((cdo (save-excursion | 445 (let ((cdo (save-excursion |
531 (checkdoc-make-overlay (point) | 446 (checkdoc-make-overlay (point) |
532 (progn (forward-sexp 1) | 447 (progn (forward-sexp 1) |
533 (point))))) | 448 (point))))) |
534 c) | 449 c) |
535 (unwind-protect | 450 (unwind-protect |
536 (progn | 451 (progn |
537 (checkdoc-overlay-put cdo 'face 'highlight) | 452 (checkdoc-overlay-put cdo 'face 'highlight) |
538 ;; Make sure the whole doc-string is visible if possible. | 453 ;; Make sure the whole doc string is visible if possible. |
539 (sit-for 0) | 454 (sit-for 0) |
540 (if (not (pos-visible-in-window-p | 455 (if (not (pos-visible-in-window-p |
541 (save-excursion (forward-sexp 1) (point)) | 456 (save-excursion (forward-sexp 1) (point)) |
542 (selected-window))) | 457 (selected-window))) |
543 (recenter)) | 458 (recenter)) |
590 error was found. We can use points and not markers because we promise | 505 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." | 506 not to edit the buffer before point without re-executing this check." |
592 (let ((msg nil) (p (point))) | 507 (let ((msg nil) (p (point))) |
593 (condition-case nil | 508 (condition-case nil |
594 (while (and (not msg) (checkdoc-next-docstring)) | 509 (while (and (not msg) (checkdoc-next-docstring)) |
595 (message "Searching for doc-string error...%d%%" | 510 (message "Searching for doc string error...%d%%" |
596 (/ (* 100 (point)) (point-max))) | 511 (/ (* 100 (point)) (point-max))) |
597 (if (setq msg (checkdoc-this-string-valid)) | 512 (if (setq msg (checkdoc-this-string-valid)) |
598 (setq msg (cons msg (point))))) | 513 (setq msg (cons msg (point))))) |
599 ;; Quit.. restore position, Other errors, leave alone | 514 ;; Quit.. restore position, Other errors, leave alone |
600 (quit (goto-char p))) | 515 (quit (goto-char p))) |
613 (goto-char p) | 528 (goto-char p) |
614 nil)) | 529 nil)) |
615 | 530 |
616 ;;;###autoload | 531 ;;;###autoload |
617 (defun checkdoc-continue (&optional take-notes) | 532 (defun checkdoc-continue (&optional take-notes) |
618 "Find the next doc-string in the current buffer which is stylisticly poor. | 533 "Find the next docstring in the current buffer which is stylisticly poor. |
619 Prefix argument TAKE-NOTES means to continue through the whole buffer and | 534 Prefix argument TAKE-NOTES means to continue through the whole buffer and |
620 save warnings in a separate buffer. Second optional argument START-POINT | 535 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." | 536 is the starting location. If this is nil, `point-min' is used instead." |
622 (interactive "P") | 537 (interactive "P") |
623 (let ((wrong nil) (msg nil) (errors nil) | 538 (let ((wrong nil) (msg nil) (errors nil) |
628 (save-excursion | 543 (save-excursion |
629 ;; If we are taking notes, encompass the whole buffer, otherwise | 544 ;; If we are taking notes, encompass the whole buffer, otherwise |
630 ;; the user is navigating down through the buffer. | 545 ;; the user is navigating down through the buffer. |
631 (if take-notes (checkdoc-start-section "checkdoc")) | 546 (if take-notes (checkdoc-start-section "checkdoc")) |
632 (while (and (not wrong) (checkdoc-next-docstring)) | 547 (while (and (not wrong) (checkdoc-next-docstring)) |
633 ;; OK, lets look at the doc-string. | 548 ;; OK, lets look at the doc string. |
634 (setq msg (checkdoc-this-string-valid)) | 549 (setq msg (checkdoc-this-string-valid)) |
635 (if msg | 550 (if msg |
636 ;; Oops | 551 ;; Oops |
637 (if take-notes | 552 (if take-notes |
638 (progn | 553 (progn |
647 (checkdoc-show-diagnostics) | 562 (checkdoc-show-diagnostics) |
648 (if (interactive-p) | 563 (if (interactive-p) |
649 (message "No style warnings."))))) | 564 (message "No style warnings."))))) |
650 | 565 |
651 (defun checkdoc-next-docstring () | 566 (defun checkdoc-next-docstring () |
652 "Find the next doc-string after point and return t. | 567 "Move to the next doc string after point, and return t. |
653 Return nil if there are no more doc-strings." | 568 Return nil if there are no more doc strings." |
654 (if (not (re-search-forward checkdoc-defun-regexp nil t)) | 569 (if (not (re-search-forward checkdoc-defun-regexp nil t)) |
655 nil | 570 nil |
656 ;; search drops us after the identifier. The next sexp is either | 571 ;; search drops us after the identifier. The next sexp is either |
657 ;; the argument list or the value of the variable. skip it. | 572 ;; the argument list or the value of the variable. skip it. |
658 (forward-sexp 1) | 573 (forward-sexp 1) |
659 (skip-chars-forward " \n\t") | 574 (skip-chars-forward " \n\t") |
660 t)) | 575 t)) |
661 | 576 |
662 ;;; ###autoload | 577 ;;; ###autoload |
663 (defun checkdoc-comments (&optional take-notes) | 578 (defun checkdoc-comments (&optional take-notes) |
664 "Find missing comment sections in the current emacs lisp file. | 579 "Find missing comment sections in the current Emacs Lisp file. |
665 Prefix argument TAKE-NOTES non-nil means to save warnings in a | 580 Prefix argument TAKE-NOTES non-nil means to save warnings in a |
666 separate buffer. Otherwise print a message. This returns the error | 581 separate buffer. Otherwise print a message. This returns the error |
667 if there is one." | 582 if there is one." |
668 (interactive "P") | 583 (interactive "P") |
669 (if take-notes (checkdoc-start-section "checkdoc-comments")) | 584 (if take-notes (checkdoc-start-section "checkdoc-comments")) |
711 (eval-defun nil) | 626 (eval-defun nil) |
712 (checkdoc-defun)) | 627 (checkdoc-defun)) |
713 | 628 |
714 ;;;###autoload | 629 ;;;###autoload |
715 (defun checkdoc-defun (&optional no-error) | 630 (defun checkdoc-defun (&optional no-error) |
716 "Examine the doc-string of the function or variable under point. | 631 "Examine the doc string of the function or variable under point. |
717 Calls `error' if the doc-string produces diagnostics. If NO-ERROR is | 632 Call `error' if the doc string has problems. If NO-ERROR is |
718 non-nil, then do not call error, but call `message' instead. | 633 non-nil, then do not call error, but call `message' instead. |
719 If the document check passes, then check the function for rogue white | 634 If the doc string passes the test, then check the function for rogue white |
720 space at the end of each line." | 635 space at the end of each line." |
721 (interactive) | 636 (interactive) |
722 (save-excursion | 637 (save-excursion |
723 (beginning-of-defun) | 638 (beginning-of-defun) |
724 (if (not (looking-at checkdoc-defun-regexp)) | 639 (if (not (looking-at checkdoc-defun-regexp)) |
725 ;; I found this more annoying than useful. | 640 ;; I found this more annoying than useful. |
726 ;;(if (not no-error) | 641 ;;(if (not no-error) |
727 ;; (message "Cannot check this sexp's doc-string.")) | 642 ;; (message "Cannot check this sexp's docstring.")) |
728 nil | 643 nil |
729 ;; search drops us after the identifier. The next sexp is either | 644 ;; search drops us after the identifier. The next sexp is either |
730 ;; the argument list or the value of the variable. skip it. | 645 ;; the argument list or the value of the variable. skip it. |
731 (goto-char (match-end 0)) | 646 (goto-char (match-end 0)) |
732 (forward-sexp 1) | 647 (forward-sexp 1) |
792 (let ((checkdoc-spellcheck-documentation-flag t)) | 707 (let ((checkdoc-spellcheck-documentation-flag t)) |
793 (call-interactively 'checkdoc-comments nil current-prefix-arg))) | 708 (call-interactively 'checkdoc-comments nil current-prefix-arg))) |
794 | 709 |
795 ;;;###autoload | 710 ;;;###autoload |
796 (defun checkdoc-ispell-defun (&optional take-notes) | 711 (defun checkdoc-ispell-defun (&optional take-notes) |
797 "Check the style and spelling of the current defun with ispell. | 712 "Check the style and spelling of the current defun with Ispell. |
798 Calls `checkdoc-defun' with spell-checking turned on. | 713 Calls `checkdoc-defun' with spell-checking turned on. |
799 Prefix argument TAKE-NOTES is the same as for `checkdoc-defun'" | 714 Prefix argument TAKE-NOTES is the same as for `checkdoc-defun'" |
800 (interactive) | 715 (interactive) |
801 (let ((checkdoc-spellcheck-documentation-flag t)) | 716 (let ((checkdoc-spellcheck-documentation-flag t)) |
802 (call-interactively 'checkdoc-defun nil current-prefix-arg))) | 717 (call-interactively 'checkdoc-defun nil current-prefix-arg))) |
872 (checkdoc-add-to-list 'minor-mode-map-alist (cons 'checkdoc-minor-mode | 787 (checkdoc-add-to-list 'minor-mode-map-alist (cons 'checkdoc-minor-mode |
873 checkdoc-minor-keymap)))) | 788 checkdoc-minor-keymap)))) |
874 | 789 |
875 ;;;###autoload | 790 ;;;###autoload |
876 (defun checkdoc-minor-mode (&optional arg) | 791 (defun checkdoc-minor-mode (&optional arg) |
877 "Toggle checkdoc minor mode. A mode for checking lisp doc-strings. | 792 "Toggle Checkdoc minor mode, a mode for checking Lisp doc strings. |
878 With prefix ARG, turn checkdoc minor mode on iff ARG is positive. | 793 With prefix ARG, turn Checkdoc minor mode on iff ARG is positive. |
879 | 794 |
880 In checkdoc minor mode, the usual bindings for `eval-defun' which is | 795 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 | 796 bound to \\<checkdoc-minor-keymap> \\[checkdoc-eval-defun] and `checkdoc-eval-current-buffer' are overridden to include |
882 checking of documentation strings. | 797 checking of documentation strings. |
883 | 798 |
884 \\{checkdoc-minor-keymap}" | 799 \\{checkdoc-minor-keymap}" |
885 (interactive "P") | 800 (interactive "P") |
893 (defsubst checkdoc-run-hooks (hookvar &rest args) | 808 (defsubst checkdoc-run-hooks (hookvar &rest args) |
894 "Run hooks in HOOKVAR with ARGS." | 809 "Run hooks in HOOKVAR with ARGS." |
895 (if (fboundp 'run-hook-with-args-until-success) | 810 (if (fboundp 'run-hook-with-args-until-success) |
896 (apply 'run-hook-with-args-until-success hookvar args) | 811 (apply 'run-hook-with-args-until-success hookvar args) |
897 ;; This method was similar to above. We ignore the warning | 812 ;; This method was similar to above. We ignore the warning |
898 ;; since we will use the above for future emacs versions | 813 ;; since we will use the above for future Emacs versions |
899 (apply 'run-hook-with-args hookvar args))) | 814 (apply 'run-hook-with-args hookvar args))) |
900 | 815 |
901 (defsubst checkdoc-create-common-verbs-regexp () | 816 (defsubst checkdoc-create-common-verbs-regexp () |
902 "Rebuild the contents of `checkdoc-common-verbs-regexp'." | 817 "Rebuild the contents of `checkdoc-common-verbs-regexp'." |
903 (or checkdoc-common-verbs-regexp | 818 (or checkdoc-common-verbs-regexp |
925 ;; found)) | 840 ;; found)) |
926 | 841 |
927 ;;; Checking engines | 842 ;;; Checking engines |
928 ;; | 843 ;; |
929 (defun checkdoc-this-string-valid () | 844 (defun checkdoc-this-string-valid () |
930 "Return a message string if the current doc-string is invalid. | 845 "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 | 846 Check for style only, such as the first line always being a complete |
932 sentence, whitespace restrictions, and making sure there are no | 847 sentence, whitespace restrictions, and making sure there are no |
933 hard-coded key-codes such as C-[char] or mouse-[number] in the comment. | 848 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." | 849 See the style guide in the Emacs Lisp manual for more details." |
935 | 850 |
936 ;; Jump over comments between the last object and the doc-string | 851 ;; Jump over comments between the last object and the doc string |
937 (while (looking-at "[ \t\n]*;") | 852 (while (looking-at "[ \t\n]*;") |
938 (forward-line 1) | 853 (forward-line 1) |
939 (beginning-of-line) | 854 (beginning-of-line) |
940 (skip-chars-forward " \n\t")) | 855 (skip-chars-forward " \n\t")) |
941 | 856 |
947 (set-syntax-table checkdoc-syntax-table) | 862 (set-syntax-table checkdoc-syntax-table) |
948 (checkdoc-this-string-valid-engine)) | 863 (checkdoc-this-string-valid-engine)) |
949 (set-syntax-table old-syntax-table))))) | 864 (set-syntax-table old-syntax-table))))) |
950 | 865 |
951 (defun checkdoc-this-string-valid-engine () | 866 (defun checkdoc-this-string-valid-engine () |
952 "Return a message string if the current doc-string is invalid. | 867 "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 | 868 Depends on `checkdoc-this-string-valid' to reset the syntax table so that |
954 regexp short cuts work." | 869 regexp short cuts work." |
955 (let ((case-fold-search nil) | 870 (let ((case-fold-search nil) |
956 ;; Use a marker so if an early check modifies the text, | 871 ;; Use a marker so if an early check modifies the text, |
957 ;; we won't accidentally loose our place. This could cause | 872 ;; we won't accidentally loose our place. This could cause |
958 ;; end-of doc-string whitespace to also delete the " char. | 873 ;; end-of doc string whitespace to also delete the " char. |
959 (e (save-excursion (forward-sexp 1) (point-marker))) | 874 (e (save-excursion (forward-sexp 1) (point-marker))) |
960 (fp (checkdoc-defun-info))) | 875 (fp (checkdoc-defun-info))) |
961 (or | 876 (or |
962 ;; * *Do not* indent subsequent lines of a documentation string so that | 877 ;; * *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 | 878 ;; the text is lined up in the source code with the text of the first |
998 ;; save space by using a comment instead of a documentation string, | 913 ;; save space by using a comment instead of a documentation string, |
999 ;; but that is no longer the case. | 914 ;; but that is no longer the case. |
1000 (if (and (not (nth 1 fp)) ; not a variable | 915 (if (and (not (nth 1 fp)) ; not a variable |
1001 (or (nth 2 fp) ; is interactive | 916 (or (nth 2 fp) ; is interactive |
1002 checkdoc-force-docstrings-flag) ;or we always complain | 917 checkdoc-force-docstrings-flag) ;or we always complain |
1003 (not (checkdoc-char= (following-char) ?\"))) ; no doc-string | 918 (not (checkdoc-char= (following-char) ?\"))) ; no doc string |
1004 (if (nth 2 fp) | 919 (if (nth 2 fp) |
1005 "All interactive functions should have documentation" | 920 "All interactive functions should have documentation" |
1006 "All variables and subroutines might as well have a \ | 921 "All variables and subroutines might as well have a \ |
1007 documentation string")) | 922 documentation string")) |
1008 ;; * The first line of the documentation string should consist of one | 923 ;; * The first line of the documentation string should consist of one |
1051 l2 (save-excursion | 966 l2 (save-excursion |
1052 (forward-line 1) | 967 (forward-line 1) |
1053 (end-of-line) | 968 (end-of-line) |
1054 (current-column))) | 969 (current-column))) |
1055 (if (> (+ l1 l2 1) 80) | 970 (if (> (+ l1 l2 1) 80) |
1056 (setq msg "Incomplete auto-fix. Doc-string \ | 971 (setq msg "Incomplete auto-fix; doc string \ |
1057 may require more formatting") | 972 may require more formatting") |
1058 ;; We can merge these lines! Replace this CR | 973 ;; We can merge these lines! Replace this CR |
1059 ;; with a space. | 974 ;; with a space. |
1060 (delete-char 1) (insert " ") | 975 (delete-char 1) (insert " ") |
1061 (setq msg nil)))) | 976 (setq msg nil)))) |
1071 (point)) | 986 (point)) |
1072 t) | 987 t) |
1073 (< (current-column) numc)) | 988 (< (current-column) numc)) |
1074 (if (checkdoc-autofix-ask-replace | 989 (if (checkdoc-autofix-ask-replace |
1075 p (1+ p) | 990 p (1+ p) |
1076 "1st line not a complete sentence. Join these lines? " | 991 "1st line not a complete sentence. Join these lines? " |
1077 " " t) | 992 " " t) |
1078 (progn | 993 (progn |
1079 ;; They said yes. We have more fill work to do... | 994 ;; They said yes. We have more fill work to do... |
1080 (delete-char 1) | 995 (delete-char 1) |
1081 (insert "\n") | 996 (insert "\n") |
1148 (while (and (not f) (setq m (re-search-forward re e t))) | 1063 (while (and (not f) (setq m (re-search-forward re e t))) |
1149 (setq f (not (checkdoc-in-sample-code-p start e)))) | 1064 (setq f (not (checkdoc-in-sample-code-p start e)))) |
1150 (if m | 1065 (if m |
1151 (concat | 1066 (concat |
1152 "Keycode " (match-string 1) | 1067 "Keycode " (match-string 1) |
1153 " embedded in doc-string. Use \\\\<keymap> & \\\\[function] " | 1068 " embedded in doc string. Use \\\\<keymap> & \\\\[function] " |
1154 "instead")))) | 1069 "instead")))) |
1155 ;; It is not practical to use `\\[...]' very many times, because | 1070 ;; It is not practical to use `\\[...]' very many times, because |
1156 ;; display of the documentation string will become slow. So use this | 1071 ;; display of the documentation string will become slow. So use this |
1157 ;; to describe the most important commands in your major mode, and | 1072 ;; to describe the most important commands in your major mode, and |
1158 ;; then use `\\{...}' to display the rest of the mode's keymap. | 1073 ;; then use `\\{...}' to display the rest of the mode's keymap. |
1159 (save-excursion | 1074 (save-excursion |
1160 (if (re-search-forward "\\\\\\\\\\[\\w+" e t | 1075 (if (re-search-forward "\\\\\\\\\\[\\w+" e t |
1161 (1+ checkdoc-max-keyref-before-warn)) | 1076 (1+ checkdoc-max-keyref-before-warn)) |
1162 "Too many occurrences of \\[function]. Use \\{keymap} instead")) | 1077 "Too many occurrences of \\[function]. Use \\{keymap} instead")) |
1163 ;; Ambiguous quoted symbol. When a symbol is both bound and fbound, | 1078 ;; Ambiguous quoted symbol. When a symbol is both bound and fbound, |
1164 ;; and is referred to in documentation, it should be prefixed with | 1079 ;; and is referred to in documentation, it should be prefixed with |
1165 ;; something to disambiguate it. This check must be before the | 1080 ;; something to disambiguate it. This check must be before the |
1166 ;; 80 column check because it will probably break that. | 1081 ;; 80 column check because it will probably break that. |
1167 (save-excursion | 1082 (save-excursion |
1168 (let ((case-fold-search t) | 1083 (let ((case-fold-search t) |
1232 (setq ms (substring ms 0 (1- (length ms)))))) | 1147 (setq ms (substring ms 0 (1- (length ms)))))) |
1233 (if (and (not (checkdoc-in-sample-code-p start e)) | 1148 (if (and (not (checkdoc-in-sample-code-p start e)) |
1234 (setq found (intern-soft ms)) | 1149 (setq found (intern-soft ms)) |
1235 (or (boundp found) (fboundp found))) | 1150 (or (boundp found) (fboundp found))) |
1236 (progn | 1151 (progn |
1237 (setq msg (format "Add quotes around lisp symbol `%s'? " | 1152 (setq msg (format "Add quotes around Lisp symbol `%s'? " |
1238 ms)) | 1153 ms)) |
1239 (if (checkdoc-autofix-ask-replace | 1154 (if (checkdoc-autofix-ask-replace |
1240 (match-beginning 1) (+ (match-beginning 1) | 1155 (match-beginning 1) (+ (match-beginning 1) |
1241 (length ms)) | 1156 (length ms)) |
1242 msg (concat "`" ms "'") t) | 1157 msg (concat "`" ms "'") t) |
1245 ;; t and nil case | 1160 ;; t and nil case |
1246 (save-excursion | 1161 (save-excursion |
1247 (if (re-search-forward "\\(`\\(t\\|nil\\)'\\)" e t) | 1162 (if (re-search-forward "\\(`\\(t\\|nil\\)'\\)" e t) |
1248 (if (checkdoc-autofix-ask-replace | 1163 (if (checkdoc-autofix-ask-replace |
1249 (match-beginning 1) (match-end 1) | 1164 (match-beginning 1) (match-end 1) |
1250 (format "%s should not appear in quotes. Remove? " | 1165 (format "%s should not appear in quotes. Remove? " |
1251 (match-string 2)) | 1166 (match-string 2)) |
1252 (match-string 2) t) | 1167 (match-string 2) t) |
1253 nil | 1168 nil |
1254 "Symbols t and nil should not appear in `quotes'"))) | 1169 "Symbols t and nil should not appear in `quotes'"))) |
1255 ;; Here we deviate to tests based on a variable or function. | 1170 ;; Here we deviate to tests based on a variable or function. |
1265 ;; condition, give it a name that ends in `-flag'. | 1180 ;; condition, give it a name that ends in `-flag'. |
1266 | 1181 |
1267 ;; If the variable has -flag in the name, make sure | 1182 ;; If the variable has -flag in the name, make sure |
1268 (if (and (string-match "-flag$" (car fp)) | 1183 (if (and (string-match "-flag$" (car fp)) |
1269 (not (looking-at "\"\\*?Non-nil\\s-+means\\s-+"))) | 1184 (not (looking-at "\"\\*?Non-nil\\s-+means\\s-+"))) |
1270 "Flag variable doc-strings should start: Non-nil means") | 1185 "Flag variable doc strings should start: Non-nil means") |
1271 ;; If the doc-string starts with "Non-nil means" | 1186 ;; If the doc string starts with "Non-nil means" |
1272 (if (and (looking-at "\"\\*?Non-nil\\s-+means\\s-+") | 1187 (if (and (looking-at "\"\\*?Non-nil\\s-+means\\s-+") |
1273 (not (string-match "-flag$" (car fp)))) | 1188 (not (string-match "-flag$" (car fp)))) |
1274 "Flag variables should end in: -flag") | 1189 "Flag variables should end in `-flag'") |
1275 ;; Done with variables | 1190 ;; Done with variables |
1276 )) | 1191 )) |
1277 (t | 1192 (t |
1278 ;; This if we are in a function definition | 1193 ;; This if we are in a function definition |
1279 (or | 1194 (or |
1319 "\\)\\(\\>\\|th\\>\\|s\\>\\)") | 1234 "\\)\\(\\>\\|th\\>\\|s\\>\\)") |
1320 e t)) | 1235 e t)) |
1321 (if (checkdoc-autofix-ask-replace | 1236 (if (checkdoc-autofix-ask-replace |
1322 (match-beginning 1) (match-end 1) | 1237 (match-beginning 1) (match-end 1) |
1323 (format | 1238 (format |
1324 "Argument `%s' should appear as `%s'. Fix? " | 1239 "Argument `%s' should appear as `%s'. Fix? " |
1325 (car args) (upcase (car args))) | 1240 (car args) (upcase (car args))) |
1326 (upcase (car args)) t) | 1241 (upcase (car args)) t) |
1327 (setq found (match-beginning 1)))))) | 1242 (setq found (match-beginning 1)))))) |
1328 (if found (setq args (cdr args))))) | 1243 (if found (setq args (cdr args))))) |
1329 (if (not found) | 1244 (if (not found) |
1330 ;; It wasn't found at all! Offer to attach this new symbol | 1245 ;; It wasn't found at all! Offer to attach this new symbol |
1331 ;; to the end of the documentation string. | 1246 ;; to the end of the documentation string. |
1332 (if (y-or-n-p | 1247 (if (y-or-n-p |
1333 (format "Add %s documentation to end of doc-string?" | 1248 (format "Add %s documentation to end of doc string?" |
1334 (upcase (car args)))) | 1249 (upcase (car args)))) |
1335 ;; No do some majic an invent a doc string. | 1250 ;; Now do some magic and invent a doc string. |
1336 (save-excursion | 1251 (save-excursion |
1337 (goto-char e) (forward-char -1) | 1252 (goto-char e) (forward-char -1) |
1338 (insert "\n" | 1253 (insert "\n" |
1339 (if inopts "Optional a" "A") | 1254 (if inopts "Optional a" "A") |
1340 "rgument " (upcase (car args)) | 1255 "rgument " (upcase (car args)) |
1343 (if (not (save-excursion (forward-char -1) | 1258 (if (not (save-excursion (forward-char -1) |
1344 (looking-at "[.?!]"))) | 1259 (looking-at "[.?!]"))) |
1345 (insert ".")) | 1260 (insert ".")) |
1346 nil) | 1261 nil) |
1347 (format | 1262 (format |
1348 "Argument `%s' should appear as `%s' in the doc-string" | 1263 "Argument `%s' should appear as `%s' in the doc string" |
1349 (car args) (upcase (car args)))) | 1264 (car args) (upcase (car args)))) |
1350 (if (or (and order (eq order 'yes)) | 1265 (if (or (and order (eq order 'yes)) |
1351 (and (not order) checkdoc-arguments-in-order-flag)) | 1266 (and (not order) checkdoc-arguments-in-order-flag)) |
1352 (if (< found last-pos) | 1267 (if (< found last-pos) |
1353 "Arguments occur in the doc-string out of order")))) | 1268 "Arguments occur in the doc string out of order")))) |
1354 ;; Done with functions | 1269 ;; Done with functions |
1355 ))) | 1270 ))) |
1356 ;; Make sure the doc-string has correctly spelled english words | 1271 ;; Make sure the doc string has correctly spelled english words |
1357 ;; in it. This functions is extracted due to it's complexity, | 1272 ;; in it. This functions is extracted due to its complexity, |
1358 ;; and reliance on the ispell program. | 1273 ;; and reliance on the Ispell program. |
1359 (checkdoc-ispell-docstring-engine e) | 1274 (checkdoc-ispell-docstring-engine e) |
1360 ;; User supplied checks | 1275 ;; User supplied checks |
1361 (save-excursion (checkdoc-run-hooks 'checkdoc-style-hooks fp e)) | 1276 (save-excursion (checkdoc-run-hooks 'checkdoc-style-hooks fp e)) |
1362 ;; Done! | 1277 ;; Done! |
1363 ))) | 1278 ))) |
1364 | 1279 |
1365 (defun checkdoc-defun-info nil | 1280 (defun checkdoc-defun-info nil |
1366 "Return a list of details about the current sexp. | 1281 "Return a list of details about the current sexp. |
1367 It is a list of the form: | 1282 It is a list of the form: |
1368 '( NAME VARIABLE INTERACTIVE NODOCPARAMS PARAMETERS ... ) | 1283 (NAME VARIABLE INTERACTIVE NODOCPARAMS PARAMETERS ...) |
1369 where NAME is the name, VARIABLE is t if this is a `defvar', | 1284 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 | 1285 INTERACTIVE is nil if this is not an interactive function, otherwise |
1371 it is the position of the `interactive' call, and PARAMETERS is a | 1286 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 | 1287 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 | 1288 list. The NODOCPARAMS is a sublist of parameters specified by a checkdoc |
1441 (setq ret (cons (symbol-name (car lst)) ret) | 1356 (setq ret (cons (symbol-name (car lst)) ret) |
1442 lst (cdr lst))))) | 1357 lst (cdr lst))))) |
1443 (nreverse ret)))) | 1358 (nreverse ret)))) |
1444 | 1359 |
1445 (defun checkdoc-in-sample-code-p (start limit) | 1360 (defun checkdoc-in-sample-code-p (start limit) |
1446 "Return Non-nil if the current point is in a code-fragment. | 1361 "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 | 1362 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 ' | 1363 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 | 1364 character. Only the region from START to LIMIT is is allowed while |
1450 searching for the bounding parenthesis." | 1365 searching for the bounding parenthesis." |
1451 (save-match-data | 1366 (save-match-data |
1468 ;;; Ispell engine | 1383 ;;; Ispell engine |
1469 ;; | 1384 ;; |
1470 (eval-when-compile (require 'ispell)) | 1385 (eval-when-compile (require 'ispell)) |
1471 | 1386 |
1472 (defun checkdoc-ispell-init () | 1387 (defun checkdoc-ispell-init () |
1473 "Initialize ispell process (default version) with lisp words. | 1388 "Initialize Ispell process (default version) with Lisp words. |
1474 The words used are from `checkdoc-ispell-lisp-words'. If `ispell' | 1389 The words used are from `checkdoc-ispell-lisp-words'. If `ispell' |
1475 cannot be loaded, then set `checkdoc-spellcheck-documentation-flag' to | 1390 cannot be loaded, then set `checkdoc-spellcheck-documentation-flag' to |
1476 nil." | 1391 nil." |
1477 (require 'ispell) | 1392 (require 'ispell) |
1478 (if (not (symbol-value 'ispell-process)) ;Silence byteCompiler | 1393 (if (not (symbol-value 'ispell-process)) ;Silence byteCompiler |
1479 (condition-case nil | 1394 (condition-case nil |
1480 (progn | 1395 (progn |
1481 (ispell-buffer-local-words) | 1396 (ispell-buffer-local-words) |
1482 ;; This code copied in part from ispell.el emacs 19.34 | 1397 ;; This code copied in part from ispell.el Emacs 19.34 |
1483 (let ((w checkdoc-ispell-lisp-words)) | 1398 (let ((w checkdoc-ispell-lisp-words)) |
1484 (while w | 1399 (while w |
1485 (process-send-string | 1400 (process-send-string |
1486 ;; Silence byte compiler | 1401 ;; Silence byte compiler |
1487 (symbol-value 'ispell-process) | 1402 (symbol-value 'ispell-process) |
1488 (concat "@" (car w) "\n")) | 1403 (concat "@" (car w) "\n")) |
1489 (setq w (cdr w))))) | 1404 (setq w (cdr w))))) |
1490 (error (setq checkdoc-spellcheck-documentation-flag nil))))) | 1405 (error (setq checkdoc-spellcheck-documentation-flag nil))))) |
1491 | 1406 |
1492 (defun checkdoc-ispell-docstring-engine (end) | 1407 (defun checkdoc-ispell-docstring-engine (end) |
1493 "Run the ispell tools on the doc-string between point and END. | 1408 "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 | 1409 Since Ispell isn't Lisp-smart, we must pre-process the doc string |
1495 before using the ispell engine on it." | 1410 before using the Ispell engine on it." |
1496 (if (not checkdoc-spellcheck-documentation-flag) | 1411 (if (not checkdoc-spellcheck-documentation-flag) |
1497 nil | 1412 nil |
1498 (checkdoc-ispell-init) | 1413 (checkdoc-ispell-init) |
1499 (save-excursion | 1414 (save-excursion |
1500 (skip-chars-forward "^a-zA-Z") | 1415 (skip-chars-forward "^a-zA-Z") |
1554 Some editors & news agents may remove it"))) | 1469 Some editors & news agents may remove it"))) |
1555 ;; Check for, and pottentially remove whitespace appearing at the | 1470 ;; Check for, and pottentially remove whitespace appearing at the |
1556 ;; end of different lines. | 1471 ;; end of different lines. |
1557 (progn | 1472 (progn |
1558 (goto-char start) | 1473 (goto-char start) |
1559 ;; There is no documentation in the elisp manual about this check, | 1474 ;; There is no documentation in the Emacs Lisp manual about this check, |
1560 ;; it is intended to help clean up messy code and reduce the file size. | 1475 ;; 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)) | 1476 (while (and (not msg) (re-search-forward "[^ \t\n]\\([ \t]+\\)$" end t)) |
1562 ;; This is not a complex activity | 1477 ;; This is not a complex activity |
1563 (if (checkdoc-autofix-ask-replace | 1478 (if (checkdoc-autofix-ask-replace |
1564 (match-beginning 1) (match-end 1) | 1479 (match-beginning 1) (match-end 1) |
1565 "White space at end of line. Remove? " "") | 1480 "White space at end of line. Remove? " "") |
1566 nil | 1481 nil |
1567 (setq msg "White space found at end of line"))))) | 1482 (setq msg "White space found at end of line"))))) |
1568 ;; Return an error and leave the cursor at that spot, or restore | 1483 ;; Return an error and leave the cursor at that spot, or restore |
1569 ;; the cursor. | 1484 ;; the cursor. |
1570 (if msg | 1485 (if msg |
1579 ;; a) get symbols for comple and | 1494 ;; a) get symbols for comple and |
1580 ;; b) determine if we have lm-history symbol which doesn't always exist | 1495 ;; b) determine if we have lm-history symbol which doesn't always exist |
1581 (require 'lisp-mnt)) | 1496 (require 'lisp-mnt)) |
1582 | 1497 |
1583 (defun checkdoc-file-comments-engine () | 1498 (defun checkdoc-file-comments-engine () |
1584 "Return a message string if this file does not match the emacs standard. | 1499 "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:, | 1500 This checks for style only, such as the first line, Commentary:, |
1586 Code:, and others referenced in the style guide." | 1501 Code:, and others referenced in the style guide." |
1587 (if (featurep 'lisp-mnt) | 1502 (if (featurep 'lisp-mnt) |
1588 nil | 1503 nil |
1589 (require 'lisp-mnt) | 1504 (require 'lisp-mnt) |
1672 (let ((complex-replace t)) | 1587 (let ((complex-replace t)) |
1673 (while (looking-at ";;\\(;\\)[^;]") | 1588 (while (looking-at ";;\\(;\\)[^;]") |
1674 (if (and (checkdoc-outside-major-sexp) ;in code is ok. | 1589 (if (and (checkdoc-outside-major-sexp) ;in code is ok. |
1675 (checkdoc-autofix-ask-replace | 1590 (checkdoc-autofix-ask-replace |
1676 (match-beginning 1) (match-end 1) | 1591 (match-beginning 1) (match-end 1) |
1677 "Multiple occurances of ;;; found. Use ;; instead? " | 1592 "Multiple occurances of ;;; found. Use ;; instead? " |
1678 "" complex-replace)) | 1593 "" complex-replace)) |
1679 ;; Learn that, yea, the user did want to do this a | 1594 ;; Learn that, yea, the user did want to do this a |
1680 ;; whole bunch of times. | 1595 ;; whole bunch of times. |
1681 (setq complex-replace nil)) | 1596 (setq complex-replace nil)) |
1682 (beginning-of-line) | 1597 (beginning-of-line) |
1686 ;; visible section (with the finder) | 1601 ;; visible section (with the finder) |
1687 (save-excursion | 1602 (save-excursion |
1688 (goto-char (lm-commentary-mark)) | 1603 (goto-char (lm-commentary-mark)) |
1689 ;; Spellcheck between the commentary, and the first | 1604 ;; Spellcheck between the commentary, and the first |
1690 ;; non-comment line. We could use lm-commentary, but that | 1605 ;; non-comment line. We could use lm-commentary, but that |
1691 ;; returns a string, and ispell wants to talk to a buffer. | 1606 ;; returns a string, and Ispell wants to talk to a buffer. |
1692 ;; Since the comments talk about lisp, use the specialized | 1607 ;; Since the comments talk about Lisp, use the specialized |
1693 ;; spell-checker we also used for doc-strings. | 1608 ;; spell-checker we also used for doc strings. |
1694 (checkdoc-ispell-docstring-engine (save-excursion | 1609 (checkdoc-ispell-docstring-engine (save-excursion |
1695 (re-search-forward "^[^;]" nil t) | 1610 (re-search-forward "^[^;]" nil t) |
1696 (point)))) | 1611 (point)))) |
1697 ;;; test comment out code | 1612 ;;; test comment out code |
1698 ;;; (foo 1 3) | 1613 ;;; (foo 1 3) |
1955 (beginning-of-line))) | 1870 (beginning-of-line))) |
1956 (other-window -1) | 1871 (other-window -1) |
1957 (shrink-window-if-larger-than-buffer))) | 1872 (shrink-window-if-larger-than-buffer))) |
1958 | 1873 |
1959 (defgroup checkdoc nil | 1874 (defgroup checkdoc nil |
1960 "Support for doc-string checking in emacs lisp." | 1875 "Support for doc string checking in Emacs Lisp." |
1961 :prefix "checkdoc" | 1876 :prefix "checkdoc" |
1962 :group 'lisp | 1877 :group 'lisp |
1963 :version "20.3") | 1878 :version "20.3") |
1964 | 1879 |
1965 (custom-add-option 'emacs-lisp-mode-hook | 1880 (custom-add-option 'emacs-lisp-mode-hook |
1966 (lambda () (checkdoc-minor-mode 1))) | 1881 (lambda () (checkdoc-minor-mode 1))) |
1967 | 1882 |
1968 (provide 'checkdoc) | 1883 (provide 'checkdoc) |
1884 | |
1969 ;;; checkdoc.el ends here | 1885 ;;; checkdoc.el ends here |