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