1 ;;; checkdoc.el --- check documentation strings for style requirements
3 ;; Copyright (C) 1997-1998, 2001-2012 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: docs, maint, lisp
9 ;; This file is part of GNU Emacs.
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 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; The Emacs Lisp manual has a nice chapter on how to write
27 ;; documentation strings. Many stylistic suggestions are fairly
28 ;; deterministic and easy to check for syntactically, but also easy
29 ;; to forget. The main checkdoc engine will perform the stylistic
30 ;; checks needed to make sure these styles are remembered.
32 ;; There are two ways to use checkdoc:
33 ;; 1) Periodically use `checkdoc' or `checkdoc-current-buffer'.
34 ;; `checkdoc' is a more interactive version of
35 ;; `checkdoc-current-buffer'
36 ;; 2) Use `checkdoc-minor-mode' to automatically check your
37 ;; documentation whenever you evaluate Lisp code with C-M-x
38 ;; or [menu-bar emacs-lisp eval-buffer]. Additional key-bindings
39 ;; are also provided under C-c ? KEY
40 ;; (require 'checkdoc)
41 ;; (add-hook 'emacs-lisp-mode-hook 'checkdoc-minor-mode)
45 ;; The commands `checkdoc' and `checkdoc-ispell' are the top-level
46 ;; entry points to all of the different checks that are available. It
47 ;; breaks examination of your Lisp file into four sections (comments,
48 ;; documentation, messages, and spacing) and indicates its current
49 ;; state in a status buffer.
51 ;; The Comments check examines your headers, footers, and
52 ;; various tags (such as "Code:") to make sure that your code is ready
53 ;; for easy integration into existing systems.
55 ;; The Documentation check deals with documentation strings
56 ;; and their elements that help make Emacs easier to use.
58 ;; The Messages check ensures that the strings displayed in the
59 ;; minibuffer by some commands (such as `error' and `y-or-n-p')
60 ;; are consistent with the Emacs environment.
62 ;; The Spacing check cleans up white-space at the end of lines.
64 ;; The interface while working with documentation and messages is
65 ;; slightly different when being run in the interactive mode. The
66 ;; interface offers several options, including the ability to skip to
67 ;; the next error, or back up to previous errors. Auto-fixing is
68 ;; turned off at this stage, but you can use the `f' or `F' key to fix
69 ;; a given error (if the fix is available.)
73 ;; There are four classifications of style errors in terms of how
74 ;; easy they are to fix. They are simple, complex, really complex,
75 ;; and impossible. (Impossible really means that checkdoc does not
76 ;; have a fixing routine yet.) Typically white-space errors are
77 ;; classified as simple, and are auto-fixed by default. Typographic
78 ;; changes are considered complex, and the user is asked if they want
79 ;; the problem fixed before checkdoc makes the change. These changes
80 ;; can be done without asking if `checkdoc-autofix-flag' is properly
81 ;; set. Potentially redundant changes are considered really complex,
82 ;; and the user is always asked before a change is inserted. The
83 ;; variable `checkdoc-autofix-flag' controls how these types of errors
86 ;; Spell checking text:
88 ;; The variable `checkdoc-spellcheck-documentation-flag' can be set
89 ;; to customize how spell checking is to be done. Since spell
90 ;; checking can be quite slow, you can optimize how best you want your
91 ;; checking done. The default is `defun', which spell checks each time
92 ;; `checkdoc-defun' or `checkdoc-eval-defun' is used. Setting to nil
93 ;; prevents spell checking during normal usage.
94 ;; Setting this variable to nil does not mean you cannot take
95 ;; advantage of the spell checking. You can instead use the
96 ;; interactive functions `checkdoc-ispell-*' to check the spelling of
97 ;; your documentation.
98 ;; There is a list of Lisp-specific words which checkdoc will
99 ;; install into Ispell on the fly, but only if Ispell is not already
100 ;; running. Use `ispell-kill-ispell' to make checkdoc restart it with
101 ;; these words enabled.
103 ;; Checking parameters:
105 ;; You might not always want a function to have its parameters listed
106 ;; in order. When this is the case, put the following comment just in
107 ;; front of the documentation string: "; checkdoc-order: nil" This
108 ;; overrides the value of `checkdoc-arguments-in-order-flag'.
110 ;; If you specifically wish to avoid mentioning a parameter of a
111 ;; function in the doc string (such as a hidden parameter, or a
112 ;; parameter which is very obvious like events), you can have checkdoc
113 ;; skip looking for it by putting the following comment just in front
114 ;; of the documentation string: "; checkdoc-params: (args go here)"
116 ;; Checking message strings:
118 ;; The text that follows the `error' and `y-or-n-p' commands is
119 ;; also checked. The documentation for `error' clearly states some
120 ;; simple style rules to follow which checkdoc will auto-fix for you.
121 ;; `y-or-n-p' also states that it should end in a space. I added that
122 ;; it should end in "? " since that is almost always used.
124 ;; Adding your own checks:
126 ;; You can experiment with adding your own checks by setting the
127 ;; hooks `checkdoc-style-hooks' and `checkdoc-comment-style-hooks'.
128 ;; Return a string which is the error you wish to report. The cursor
129 ;; position should be preserved.
133 ;; Checkdoc does not always flag errors correctly. There are a
134 ;; couple ways you can coax your file into passing all of checkdoc's
135 ;; tests through buffer local variables.
137 ;; The variable `checkdoc-verb-check-experimental-flag' can be used
138 ;; to turn off the check for verb-voice in case you use words that are
139 ;; not semantically verbs, but are still in the incomplete list.
141 ;; The variable `checkdoc-symbol-words' can be a list of words that
142 ;; happen to also be symbols. This is not a problem for one-word
143 ;; symbols, but if you use a hyphenated word that is also a symbol,
144 ;; then you may need this.
146 ;; The symbol `checkdoc-force-docstrings-flag' can be set to nil if
147 ;; you have many undocumented functions you don't wish to document.
149 ;; See the above section "Checking Parameters" for details about
150 ;; parameter checking.
154 ;; This file requires lisp-mnt (Lisp maintenance routines) for the
157 ;; Requires custom for Emacs v20.
160 ;; Hook into the byte compiler on a defun/defvar level to generate
161 ;; warnings in the byte-compiler's warning/error buffer.
162 ;; Better ways to override more typical `eval' functions. Advice
163 ;; might be good but hard to turn on/off as a minor mode.
166 ;; Code sweep checks for "forbidden functions", proper use of hooks,
167 ;; proper keybindings, and other items from the manual that are
168 ;; not specifically docstring related. Would this even be useful?
171 (defvar checkdoc-version
"0.6.1"
172 "Release version of checkdoc you are currently running.")
174 (require 'help-mode
) ;; for help-xref-info-regexp
175 (require 'thingatpt
) ;; for handy thing-at-point-looking-at
177 (defvar compilation-error-regexp-alist
)
178 (defvar compilation-mode-font-lock-keywords
)
180 (defgroup checkdoc nil
181 "Support for doc string checking in Emacs Lisp."
186 (defcustom checkdoc-minor-mode-string
" CDoc"
187 "String to display in mode line when Checkdoc mode is enabled; nil for none."
188 :type
'(choice string
(const :tag
"None" nil
))
192 (defcustom checkdoc-autofix-flag
'semiautomatic
193 "Non-nil means attempt auto-fixing of doc strings.
194 If this value is the symbol `query', then the user is queried before
195 any change is made. If the value is `automatic', then all changes are
196 made without asking unless the change is very-complex. If the value
197 is `semiautomatic' or any other value, then simple fixes are made
198 without asking, and complex changes are made by asking the user first.
199 The value `never' is the same as nil, never ask or change anything."
201 :type
'(choice (const automatic
)
204 (other :tag
"semiautomatic" semiautomatic
)))
206 (defcustom checkdoc-bouncy-flag t
207 "Non-nil means to \"bounce\" to auto-fix locations.
208 Setting this to nil will silently make fixes that require no user
209 interaction. See `checkdoc-autofix-flag' for auto-fixing details."
213 (defcustom checkdoc-force-docstrings-flag t
214 "Non-nil means that all checkable definitions should have documentation.
215 Style guide dictates that interactive functions MUST have documentation,
216 and that it's good but not required practice to make non user visible items
220 ;;;###autoload(put 'checkdoc-force-docstrings-flag 'safe-local-variable 'booleanp)
222 (defcustom checkdoc-force-history-flag nil
223 "Non-nil means that files should have a History section or ChangeLog file.
224 This helps document the evolution of, and recent changes to, the package."
227 ;;;###autoload(put 'checkdoc-force-history-flag 'safe-local-variable 'booleanp)
229 (defcustom checkdoc-permit-comma-termination-flag nil
230 "Non-nil means the first line of a docstring may end with a comma.
231 Ordinarily, a full sentence is required. This may be misleading when
232 there is a substantial caveat to the one-line description -- the comma
233 should be used when the first part could stand alone as a sentence, but
234 it indicates that a modifying clause follows."
237 ;;;###autoload(put 'checkdoc-permit-comma-termination-flag 'safe-local-variable 'booleanp)
239 (defcustom checkdoc-spellcheck-documentation-flag nil
240 "Non-nil means run Ispell on text based on value.
241 This is automatically set to nil if Ispell does not exist on your
242 system. Possible values are:
244 nil - Don't spell-check during basic style checks.
245 defun - Spell-check when style checking a single defun
246 buffer - Spell-check when style checking the whole buffer
247 interactive - Spell-check during any interactive check.
248 t - Always spell-check"
250 :type
'(choice (const nil
)
256 (defvar checkdoc-ispell-lisp-words
257 '("alist" "emacs" "etags" "keymap" "paren" "regexp" "sexp" "xemacs")
258 "List of words that are correct when spell-checking Lisp documentation.")
260 (defcustom checkdoc-max-keyref-before-warn
10
261 "The number of \\ [command-to-keystroke] tokens allowed in a doc string.
262 Any more than this and a warning is generated suggesting that the construct
263 \\ {keymap} be used instead."
267 (defcustom checkdoc-arguments-in-order-flag t
268 "Non-nil means warn if arguments appear out of order.
269 Setting this to nil will mean only checking that all the arguments
270 appear in the proper form in the documentation, not that they are in
271 the same order as they appear in the argument list. No mention is
272 made in the style guide relating to order."
275 ;;;###autoload(put 'checkdoc-arguments-in-order-flag 'safe-local-variable 'booleanp)
277 (defvar checkdoc-style-hooks nil
278 "Hooks called after the standard style check is completed.
279 All hooks must return nil or a string representing the error found.
280 Useful for adding new user implemented commands.
282 Each hook is called with two parameters, (DEFUNINFO ENDPOINT).
283 DEFUNINFO is the return value of `checkdoc-defun-info'. ENDPOINT is the
284 location of end of the documentation string.")
286 (defvar checkdoc-comment-style-hooks nil
287 "Hooks called after the standard comment style check is completed.
288 Must return nil if no errors are found, or a string describing the
289 problem discovered. This is useful for adding additional checks.")
291 (defvar checkdoc-diagnostic-buffer
"*Style Warnings*"
292 "Name of warning message buffer.")
294 (defvar checkdoc-defun-regexp
295 "^(def\\(un\\|var\\|custom\\|macro\\|const\\|subst\\|advice\\)\
296 \\s-+\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]+"
297 "Regular expression used to identify a defun.
298 A search leaves the cursor in front of the parameter list.")
300 (defcustom checkdoc-verb-check-experimental-flag t
301 "Non-nil means to attempt to check the voice of the doc string.
302 This check keys off some words which are commonly misused. See the
303 variable `checkdoc-common-verbs-wrong-voice' if you wish to add your own."
307 (defvar checkdoc-generate-compile-warnings-flag nil
308 "Non-nil means generate warnings in a buffer for browsing.
309 Do not set this by hand, use a function like `checkdoc-current-buffer'
310 with a universal argument.")
312 (defcustom checkdoc-symbol-words nil
313 "A list of symbol names (strings) which also happen to make good words.
314 These words are ignored when unquoted symbols are searched for.
315 This should be set in an Emacs Lisp file's local variables."
317 :type
'(repeat (symbol :tag
"Word")))
318 ;;;###autoload(put 'checkdoc-symbol-words 'safe-local-variable 'checkdoc-list-of-strings-p)
321 (defun checkdoc-list-of-strings-p (obj)
322 ;; this is a function so it might be shared by checkdoc-proper-noun-list
323 ;; and/or checkdoc-ispell-lisp-words in the future
325 (not (memq nil
(mapcar 'stringp obj
)))))
327 (defvar checkdoc-proper-noun-list
328 '("ispell" "xemacs" "emacs" "lisp")
329 "List of words (not capitalized) which should be capitalized.")
331 (defvar checkdoc-proper-noun-regexp
332 ;; "[.!?]" is for noun at end of a sentence, since those chars
333 ;; are symbol syntax in emacs-lisp-mode and so don't match \\_>.
334 ;; The \" allows it to be the last sentence in a docstring too.
336 (regexp-opt checkdoc-proper-noun-list t
)
337 "\\(\\_>\\|[.!?][ \t\n\"]\\)")
338 "Regular expression derived from `checkdoc-proper-noun-regexp'.")
340 (defvar checkdoc-common-verbs-regexp nil
341 "Regular expression derived from `checkdoc-common-verbs-regexp'.")
343 (defvar checkdoc-common-verbs-wrong-voice
346 ("appends" .
"append")
347 ("applies" .
"apply")
348 ("arranges" .
"arrange")
351 ("catches" .
"catch")
352 ("changes" .
"change")
354 ("contains" .
"contain")
355 ("converts" .
"convert")
356 ("creates" .
"create")
357 ("destroys" .
"destroy")
358 ("disables" .
"disable")
359 ("executes" .
"execute")
360 ("evals" .
"evaluate")
361 ("evaluates" .
"evaluate")
364 ("gathers" .
"gather")
365 ("generates" .
"generate")
367 ("guesses" .
"guess")
368 ("highlights" .
"highlight")
370 ("ignores" .
"ignore")
371 ("indents" .
"indent")
372 ("initializes" .
"initialize")
373 ("inserts" .
"insert")
374 ("installs" .
"install")
375 ("investigates" .
"investigate")
384 ("matches" .
"match")
386 ("notifies" .
"notify")
389 ("performs" .
"perform")
390 ("prepares" .
"prepare")
391 ("prepends" .
"prepend")
394 ("removes" .
"remove")
395 ("replaces" .
"replace")
397 ("restores" .
"restore")
398 ("returns" .
"return")
402 ("searches" .
"search")
403 ("selects" .
"select")
407 ("signifies" .
"signify")
411 ("switches" .
"switch")
414 ("toggles" .
"toggle")
418 ("unloads" .
"unload")
419 ("unmarks" .
"unmark")
420 ("updates" .
"update")
424 "Alist of common words in the wrong voice and what should be used instead.
425 Set `checkdoc-verb-check-experimental-flag' to nil to avoid this costly
426 and experimental check. Do not modify this list without setting
427 the value of `checkdoc-common-verbs-regexp' to nil which cause it to
430 (defvar checkdoc-syntax-table
431 (let ((st (make-syntax-table emacs-lisp-mode-syntax-table
)))
432 ;; When dealing with syntax in doc strings, make sure that - are
433 ;; encompassed in words so we can use cheap \\> to get the end of a symbol,
434 ;; not the end of a word in a conglomerate.
435 (modify-syntax-entry ?-
"w" st
)
437 "Syntax table used by checkdoc in document strings.")
441 (defalias 'checkdoc-make-overlay
442 (if (featurep 'xemacs
) 'make-extent
'make-overlay
))
443 (defalias 'checkdoc-overlay-put
444 (if (featurep 'xemacs
) 'set-extent-property
'overlay-put
))
445 (defalias 'checkdoc-delete-overlay
446 (if (featurep 'xemacs
) 'delete-extent
'delete-overlay
))
447 (defalias 'checkdoc-overlay-start
448 (if (featurep 'xemacs
) 'extent-start
'overlay-start
))
449 (defalias 'checkdoc-overlay-end
450 (if (featurep 'xemacs
) 'extent-end
'overlay-end
))
451 (defalias 'checkdoc-mode-line-update
452 (if (featurep 'xemacs
) 'redraw-modeline
'force-mode-line-update
))
453 (defalias 'checkdoc-char
=
454 (if (featurep 'xemacs
) 'char
= '=))
456 ;;; User level commands
460 "Interactively check the entire buffer for style errors.
461 The current status of the check will be displayed in a buffer which
462 the users will view as each check is completed."
464 (let ((status (list "Checking..." "-" "-" "-"))
465 (checkdoc-spellcheck-documentation-flag
466 (car (memq checkdoc-spellcheck-documentation-flag
467 '(buffer interactive t
))))
468 ;; if the user set autofix to never, then that breaks the
469 ;; obviously requested asking implied by using this function.
470 ;; Set it to paranoia level.
471 (checkdoc-autofix-flag (if (or (not checkdoc-autofix-flag
)
472 (eq checkdoc-autofix-flag
'never
))
474 checkdoc-autofix-flag
))
476 (checkdoc-display-status-buffer status
)
477 ;; check the comments
478 (if (not buffer-file-name
)
479 (setcar status
"Not checked")
480 (if (checkdoc-file-comments-engine)
481 (setcar status
"Errors")
482 (setcar status
"Ok")))
483 (setcar (cdr status
) "Checking...")
484 (checkdoc-display-status-buffer status
)
485 ;; Check the documentation
486 (setq tmp
(checkdoc-interactive nil t
))
488 (setcar (cdr status
) (format "%d Errors" (length tmp
)))
489 (setcar (cdr status
) "Ok"))
490 (setcar (cdr (cdr status
)) "Checking...")
491 (checkdoc-display-status-buffer status
)
492 ;; Check the message text
493 (if (setq tmp
(checkdoc-message-interactive nil t
))
494 (setcar (cdr (cdr status
)) (format "%d Errors" (length tmp
)))
495 (setcar (cdr (cdr status
)) "Ok"))
496 (setcar (cdr (cdr (cdr status
))) "Checking...")
497 (checkdoc-display-status-buffer status
)
499 (if (condition-case nil
500 (checkdoc-rogue-spaces nil t
)
502 (setcar (cdr (cdr (cdr status
))) "Errors")
503 (setcar (cdr (cdr (cdr status
))) "Ok"))
504 (checkdoc-display-status-buffer status
)))
506 (defun checkdoc-display-status-buffer (check)
507 "Display and update the status buffer for the current checkdoc mode.
508 CHECK is a list of four strings stating the current status of each
509 test; the nth string describes the status of the nth test."
510 (let (temp-buffer-setup-hook)
511 (with-output-to-temp-buffer "*Checkdoc Status*"
513 (list "Buffer comments and tags: " (nth 0 check
)
514 "\nDocumentation style: " (nth 1 check
)
515 "\nMessage/Query text style: " (nth 2 check
)
516 "\nUnwanted Spaces: " (nth 3 check
)))))
517 (shrink-window-if-larger-than-buffer
518 (get-buffer-window "*Checkdoc Status*"))
523 (defun checkdoc-interactive (&optional start-here showstatus
)
524 "Interactively check the current buffer for doc string errors.
525 Prefix argument START-HERE will start the checking from the current
526 point, otherwise the check starts at the beginning of the current
527 buffer. Allows navigation forward and backwards through document
528 errors. Does not check for comment or space warnings.
529 Optional argument SHOWSTATUS indicates that we should update the
530 checkdoc status window instead of the usual behavior."
532 (let ((checkdoc-spellcheck-documentation-flag
533 (car (memq checkdoc-spellcheck-documentation-flag
536 ;; Due to a design flaw, this will never spell check
538 (checkdoc-interactive-loop start-here showstatus
539 'checkdoc-next-error
)
540 ;; This is a workaround to perform spell checking.
541 (checkdoc-interactive-ispell-loop start-here
))))
544 (defun checkdoc-message-interactive (&optional start-here showstatus
)
545 "Interactively check the current buffer for message string errors.
546 Prefix argument START-HERE will start the checking from the current
547 point, otherwise the check starts at the beginning of the current
548 buffer. Allows navigation forward and backwards through document
549 errors. Does not check for comment or space warnings.
550 Optional argument SHOWSTATUS indicates that we should update the
551 checkdoc status window instead of the usual behavior."
553 (let ((checkdoc-spellcheck-documentation-flag
554 (car (memq checkdoc-spellcheck-documentation-flag
557 ;; Due to a design flaw, this will never spell check messages.
558 (checkdoc-interactive-loop start-here showstatus
559 'checkdoc-next-message-error
)
560 ;; This is a workaround to perform spell checking.
561 (checkdoc-message-interactive-ispell-loop start-here
))))
563 (defun checkdoc-interactive-loop (start-here showstatus findfunc
)
564 "Interactively loop over all errors that can be found by a given method.
566 If START-HERE is nil, searching starts at the beginning of the current
567 buffer, otherwise searching starts at START-HERE. SHOWSTATUS
568 expresses the verbosity of the search, and whether ending the search
569 will auto-exit this function.
571 FINDFUNC is a symbol representing a function that will position the
572 cursor, and return error message text to present to the user. It is
573 assumed that the cursor will stop just before a major sexp, which will
574 be highlighted to present the user with feedback as to the offending
576 ;; Determine where to start the test
577 (let* ((begin (prog1 (point)
578 (if (not start-here
) (goto-char (point-min)))))
579 ;; Assign a flag to spellcheck flag
580 (checkdoc-spellcheck-documentation-flag
581 (car (memq checkdoc-spellcheck-documentation-flag
582 '(buffer interactive t
))))
583 ;; Fetch the error list
584 (err-list (list (funcall findfunc nil
)))
588 (save-window-excursion
589 (if (not (car err-list
)) (setq err-list nil
))
590 ;; Include whatever function point is in for good measure.
593 (goto-char (cdr (car err-list
)))
594 ;; The cursor should be just in front of the offending doc string
595 (if (stringp (car (car err-list
)))
596 (setq cdo
(save-excursion (checkdoc-make-overlay
597 (point) (progn (forward-sexp 1)
599 (setq cdo
(checkdoc-make-overlay
600 (checkdoc-error-start (car (car err-list
)))
601 (checkdoc-error-end (car (car err-list
))))))
604 (checkdoc-overlay-put cdo
'face
'highlight
)
605 ;; Make sure the whole doc string is visible if possible.
607 (if (and (looking-at "\"")
608 (not (pos-visible-in-window-p
609 (save-excursion (forward-sexp 1) (point))
611 (let ((l (count-lines (point)
613 (forward-sexp 1) (point)))))
614 (if (> l
(window-height))
616 (recenter (/ (- (window-height) l
) 2))))
618 (message "%s (C-h,%se,n,p,q)" (checkdoc-error-text
619 (car (car err-list
)))
620 (if (checkdoc-error-unfixable (car (car err-list
)))
623 (goto-char (checkdoc-error-start (car (car err-list
))))
624 (if (not (pos-visible-in-window-p))
625 (recenter (- (window-height) 2)))
626 (setq c
(read-event)))
627 (if (not (integerp c
)) (setq c ??
))
630 ((checkdoc-char= c ?\C-g
) (signal 'quit nil
))
631 ;; Request an auto-fix
632 ((or (checkdoc-char= c ?y
) (checkdoc-char= c ?f
))
633 (checkdoc-delete-overlay cdo
)
635 (goto-char (cdr (car err-list
)))
636 ;; `automatic-then-never' tells the autofix function
637 ;; to only allow one fix to be automatic. The autofix
638 ;; function will then set the flag to 'never, allowing
639 ;; the checker to return a different error.
640 (let ((checkdoc-autofix-flag 'automatic-then-never
)
643 (setq fixed
(not (eq checkdoc-autofix-flag
644 'automatic-then-never
)))
647 (message "A Fix was not available.")
649 (setq err-list
(cdr err-list
))))
651 (let ((ne (funcall findfunc nil
)))
653 (setq err-list
(cons ne err-list
))
654 (cond ((not err-list
)
655 (message "No More Stylistic Errors.")
659 "No Additional style errors. Continuing...")
661 ;; Move to the next error (if available)
662 ((or (checkdoc-char= c ?n
) (checkdoc-char= c ?\s
))
663 (let ((ne (funcall findfunc nil
)))
666 (setq returnme err-list
669 (message "No More Stylistic Errors.")
670 (message "No Additional style errors. Continuing..."))
672 (setq err-list
(cons ne err-list
)))))
673 ;; Go backwards in the list of errors
674 ((or (checkdoc-char= c ?p
) (checkdoc-char= c ?\C-?
))
675 (if (/= (length err-list
) 1)
677 (setq err-list
(cdr err-list
))
678 (goto-char (cdr (car err-list
)))
679 (beginning-of-defun))
680 (message "No Previous Errors.")
682 ;; Edit the buffer recursively.
683 ((checkdoc-char= c ?e
)
684 (checkdoc-recursive-edit
685 (checkdoc-error-text (car (car err-list
))))
686 (checkdoc-delete-overlay cdo
)
687 (setq err-list
(cdr err-list
)) ;back up the error found.
689 (let ((ne (funcall findfunc nil
)))
692 (setq returnme err-list
694 (message "No More Stylistic Errors.")
696 (setq err-list
(cons ne err-list
)))))
698 ((checkdoc-char= c ?q
)
699 (setq returnme err-list
704 (if (get-buffer-window "*Checkdoc Help*")
706 (delete-window (get-buffer-window "*Checkdoc Help*"))
707 (kill-buffer "*Checkdoc Help*"))
708 (with-output-to-temp-buffer "*Checkdoc Help*"
709 (with-current-buffer standard-output
711 "Checkdoc Keyboard Summary:\n"
712 (if (checkdoc-error-unfixable (car (car err-list
)))
715 "f, y - auto Fix this warning without asking (if\
717 " Very complex operations will still query.\n")
719 "e - Enter recursive Edit. Press C-M-c to exit.\n"
720 "SPC, n - skip to the Next error.\n"
721 "DEL, p - skip to the Previous error.\n"
722 "q - Quit checkdoc.\n"
723 "C-h - Toggle this help buffer.")))
724 (shrink-window-if-larger-than-buffer
725 (get-buffer-window "*Checkdoc Help*"))))))
726 (if cdo
(checkdoc-delete-overlay cdo
)))))
728 (if (get-buffer "*Checkdoc Help*") (kill-buffer "*Checkdoc Help*"))
729 (message "Checkdoc: Done.")
732 (defun checkdoc-interactive-ispell-loop (start-here)
733 "Interactively spell check doc strings in the current buffer.
734 If START-HERE is nil, searching starts at the beginning of the current
735 buffer, otherwise searching starts at START-HERE."
736 (when checkdoc-spellcheck-documentation-flag
738 ;; Move point to where we need to start.
740 ;; Include whatever function point is in for good measure.
742 (goto-char (point-min)))
743 ;; Loop over docstrings.
744 (while (checkdoc-next-docstring)
745 (message "Searching for doc string spell error...%d%%"
746 (/ (* 100 (point)) (point-max)))
747 (if (looking-at "\"")
748 (checkdoc-ispell-docstring-engine
749 (save-excursion (forward-sexp 1) (point-marker)))))
750 (message "Checkdoc: Done."))))
752 (defun checkdoc-message-interactive-ispell-loop (start-here)
753 "Interactively spell check messages in the current buffer.
754 If START-HERE is nil, searching starts at the beginning of the current
755 buffer, otherwise searching starts at START-HERE."
756 (when checkdoc-spellcheck-documentation-flag
758 ;; Move point to where we need to start.
760 ;; Include whatever function point is in for good measure.
762 (goto-char (point-min)))
763 ;; Loop over message strings.
764 (while (checkdoc-message-text-next-string (point-max))
765 (message "Searching for message string spell error...%d%%"
766 (/ (* 100 (point)) (point-max)))
767 (if (looking-at "\"")
768 (checkdoc-ispell-docstring-engine
769 (save-excursion (forward-sexp 1) (point-marker)))))
770 (message "Checkdoc: Done."))))
773 (defun checkdoc-next-error (enable-fix)
774 "Find and return the next checkdoc error list, or nil.
775 Only documentation strings are checked.
776 An error list is of the form (WARNING . POSITION) where WARNING is the
777 warning text, and POSITION is the point in the buffer where the error
778 was found. We can use points and not markers because we promise not
779 to edit the buffer before point without re-executing this check.
780 Argument ENABLE-FIX will enable auto-fixing while looking for the next
781 error. This argument assumes that the cursor is already positioned to
784 (checkdoc-this-string-valid)
785 (let ((msg nil
) (p (point))
786 (checkdoc-autofix-flag nil
))
788 (while (and (not msg
) (checkdoc-next-docstring))
789 (message "Searching for doc string error...%d%%"
790 (/ (* 100 (point)) (point-max)))
791 (if (setq msg
(checkdoc-this-string-valid))
792 (setq msg
(cons msg
(point)))))
793 ;; Quit.. restore position, Other errors, leave alone
794 (quit (goto-char p
)))
797 (defun checkdoc-next-message-error (enable-fix)
798 "Find and return the next checkdoc message related error list, or nil.
799 Only text for error and `y-or-n-p' strings are checked. See
800 `checkdoc-next-error' for details on the return value.
801 Argument ENABLE-FIX turns on the auto-fix feature. This argument
802 assumes that the cursor is already positioned to perform the fix."
804 (checkdoc-message-text-engine)
805 (let ((msg nil
) (p (point)) (type nil
)
806 (checkdoc-autofix-flag nil
))
808 (while (and (not msg
)
810 (checkdoc-message-text-next-string (point-max))))
811 (message "Searching for message string error...%d%%"
812 (/ (* 100 (point)) (point-max)))
813 (if (setq msg
(checkdoc-message-text-engine type
))
814 (setq msg
(cons msg
(point)))))
815 ;; Quit.. restore position, Other errors, leave alone
816 (quit (goto-char p
)))
819 (defun checkdoc-recursive-edit (msg)
820 "Enter recursive edit to permit a user to fix some error checkdoc has found.
821 MSG is the error that was found, which is displayed in a help buffer."
822 (with-output-to-temp-buffer "*Checkdoc Help*"
824 (list "Error message:\n " msg
825 "\n\nEdit to fix this problem, and press C-M-c to continue.")))
826 (shrink-window-if-larger-than-buffer
827 (get-buffer-window "*Checkdoc Help*"))
828 (message "When you're done editing press C-M-c to continue.")
831 (if (get-buffer-window "*Checkdoc Help*")
833 (delete-window (get-buffer-window "*Checkdoc Help*"))
834 (kill-buffer "*Checkdoc Help*")))))
837 (defun checkdoc-eval-current-buffer ()
838 "Evaluate and check documentation for the current buffer.
839 Evaluation is done first because good documentation for something that
840 doesn't work is just not useful. Comments, doc strings, and rogue
841 spacing are all verified."
844 (checkdoc-current-buffer t
))
847 (defun checkdoc-current-buffer (&optional take-notes
)
848 "Check current buffer for document, comment, error style, and rogue spaces.
849 With a prefix argument (in Lisp, the argument TAKE-NOTES),
850 store all errors found in a warnings buffer,
851 otherwise stop after the first error."
853 (if (called-interactively-p 'interactive
)
854 (message "Checking buffer for style..."))
855 ;; Assign a flag to spellcheck flag
856 (let ((checkdoc-spellcheck-documentation-flag
857 (car (memq checkdoc-spellcheck-documentation-flag
859 (checkdoc-autofix-flag (if take-notes
'never
860 checkdoc-autofix-flag
))
861 (checkdoc-generate-compile-warnings-flag
862 (or take-notes checkdoc-generate-compile-warnings-flag
)))
864 (checkdoc-start-section "checkdoc-current-buffer"))
865 ;; every test is responsible for returning the cursor.
866 (or (and buffer-file-name
;; only check comments in a file
869 (checkdoc-message-text)
870 (checkdoc-rogue-spaces)
871 (not (called-interactively-p 'interactive
))
872 (if take-notes
(checkdoc-show-diagnostics))
873 (message "Checking buffer for style...Done."))))
876 (defun checkdoc-start (&optional take-notes
)
877 "Start scanning the current buffer for documentation string style errors.
878 Only documentation strings are checked.
879 Use `checkdoc-continue' to continue checking if an error cannot be fixed.
880 Prefix argument TAKE-NOTES means to collect all the warning messages into
884 (goto-char (point-min))
885 (if (and take-notes
(called-interactively-p 'interactive
))
886 (checkdoc-start-section "checkdoc-start"))
887 (checkdoc-continue take-notes
)
888 ;; Go back since we can't be here without success above.
893 (defun checkdoc-continue (&optional take-notes
)
894 "Find the next doc string in the current buffer which has a style error.
895 Prefix argument TAKE-NOTES means to continue through the whole buffer and
896 save warnings in a separate buffer. Second optional argument START-POINT
897 is the starting location. If this is nil, `point-min' is used instead."
899 (let ((wrong nil
) (msg nil
)
900 ;; Assign a flag to spellcheck flag
901 (checkdoc-spellcheck-documentation-flag
902 (car (memq checkdoc-spellcheck-documentation-flag
904 (checkdoc-autofix-flag (if take-notes
'never
905 checkdoc-autofix-flag
))
906 (checkdoc-generate-compile-warnings-flag
907 (or take-notes checkdoc-generate-compile-warnings-flag
)))
909 ;; If we are taking notes, encompass the whole buffer, otherwise
910 ;; the user is navigating down through the buffer.
911 (while (and (not wrong
) (checkdoc-next-docstring))
912 ;; OK, let's look at the doc string.
913 (setq msg
(checkdoc-this-string-valid))
914 (if msg
(setq wrong
(point)))))
919 (error "%s" (checkdoc-error-text msg
)))))
920 (checkdoc-show-diagnostics)
921 (if (called-interactively-p 'interactive
)
922 (message "No style warnings."))))
924 (defun checkdoc-next-docstring ()
925 "Move to the next doc string after point, and return t.
926 Return nil if there are no more doc strings."
927 (if (not (re-search-forward checkdoc-defun-regexp nil t
))
929 ;; search drops us after the identifier. The next sexp is either
930 ;; the argument list or the value of the variable. skip it.
932 (skip-chars-forward " \n\t")
936 (defun checkdoc-comments (&optional take-notes
)
937 "Find missing comment sections in the current Emacs Lisp file.
938 Prefix argument TAKE-NOTES non-nil means to save warnings in a
939 separate buffer. Otherwise print a message. This returns the error
942 (if take-notes
(checkdoc-start-section "checkdoc-comments"))
943 (if (not buffer-file-name
)
944 (error "Can only check comments for a file buffer"))
945 (let* ((checkdoc-spellcheck-documentation-flag
946 (car (memq checkdoc-spellcheck-documentation-flag
948 (checkdoc-autofix-flag (if take-notes
'never checkdoc-autofix-flag
))
949 (e (checkdoc-file-comments-engine))
950 (checkdoc-generate-compile-warnings-flag
951 (or take-notes checkdoc-generate-compile-warnings-flag
)))
952 (if e
(error "%s" (checkdoc-error-text e
)))
953 (checkdoc-show-diagnostics)
957 (defun checkdoc-rogue-spaces (&optional take-notes interact
)
958 "Find extra spaces at the end of lines in the current file.
959 Prefix argument TAKE-NOTES non-nil means to save warnings in a
960 separate buffer. Otherwise print a message. This returns the error
962 Optional argument INTERACT permits more interactive fixing."
964 (if take-notes
(checkdoc-start-section "checkdoc-rogue-spaces"))
965 (let* ((checkdoc-autofix-flag (if take-notes
'never checkdoc-autofix-flag
))
966 (e (checkdoc-rogue-space-check-engine nil nil interact
))
967 (checkdoc-generate-compile-warnings-flag
968 (or take-notes checkdoc-generate-compile-warnings-flag
)))
969 (if (not (called-interactively-p 'interactive
))
972 (message "%s" (checkdoc-error-text e
))
973 (checkdoc-show-diagnostics)
974 (message "Space Check: done.")))))
977 (defun checkdoc-message-text (&optional take-notes
)
978 "Scan the buffer for occurrences of the error function, and verify text.
979 Optional argument TAKE-NOTES causes all errors to be logged."
981 (if take-notes
(checkdoc-start-section "checkdoc-message-text"))
983 (checkdoc-autofix-flag (if take-notes
'never checkdoc-autofix-flag
))
984 (checkdoc-generate-compile-warnings-flag
985 (or take-notes checkdoc-generate-compile-warnings-flag
)))
986 (setq e
(checkdoc-message-text-search))
987 (if (not (called-interactively-p 'interactive
))
990 (error "%s" (checkdoc-error-text e
))
991 (checkdoc-show-diagnostics)))
993 (if (called-interactively-p 'interactive
)
994 (message "Checking interactive message text...done.")))
997 (defun checkdoc-eval-defun ()
998 "Evaluate the current form with `eval-defun' and check its documentation.
999 Evaluation is done first so the form will be read before the
1000 documentation is checked. If there is a documentation error, then the display
1001 of what was evaluated will be overwritten by the diagnostic message."
1003 (call-interactively 'eval-defun
)
1007 (defun checkdoc-defun (&optional no-error
)
1008 "Examine the doc string of the function or variable under point.
1009 Call `error' if the doc string has problems. If NO-ERROR is
1010 non-nil, then do not call error, but call `message' instead.
1011 If the doc string passes the test, then check the function for rogue white
1012 space at the end of each line."
1015 (beginning-of-defun)
1016 (if (not (looking-at checkdoc-defun-regexp
))
1017 ;; I found this more annoying than useful.
1018 ;;(if (not no-error)
1019 ;; (message "Cannot check this sexp's doc string."))
1021 ;; search drops us after the identifier. The next sexp is either
1022 ;; the argument list or the value of the variable. skip it.
1023 (goto-char (match-end 0))
1025 (skip-chars-forward " \n\t")
1026 (let* ((checkdoc-spellcheck-documentation-flag
1027 (car (memq checkdoc-spellcheck-documentation-flag
1029 (beg (save-excursion (beginning-of-defun) (point)))
1030 (end (save-excursion (end-of-defun) (point)))
1031 (msg (checkdoc-this-string-valid)))
1032 (if msg
(if no-error
1033 (message "%s" (checkdoc-error-text msg
))
1034 (error "%s" (checkdoc-error-text msg
)))
1035 (setq msg
(checkdoc-message-text-search beg end
))
1036 (if msg
(if no-error
1037 (message "%s" (checkdoc-error-text msg
))
1038 (error "%s" (checkdoc-error-text msg
)))
1039 (setq msg
(checkdoc-rogue-space-check-engine beg end
))
1040 (if msg
(if no-error
1041 (message "%s" (checkdoc-error-text msg
))
1042 (error "%s" (checkdoc-error-text msg
))))))
1043 (if (called-interactively-p 'interactive
)
1044 (message "Checkdoc: done."))))))
1046 ;;; Ispell interface for forcing a spell check
1050 (defun checkdoc-ispell (&optional take-notes
)
1051 "Check the style and spelling of everything interactively.
1052 Calls `checkdoc' with spell-checking turned on.
1053 Prefix argument TAKE-NOTES is the same as for `checkdoc'"
1055 (let ((checkdoc-spellcheck-documentation-flag t
))
1056 (call-interactively 'checkdoc nil current-prefix-arg
)))
1059 (defun checkdoc-ispell-current-buffer (&optional take-notes
)
1060 "Check the style and spelling of the current buffer.
1061 Calls `checkdoc-current-buffer' with spell-checking turned on.
1062 Prefix argument TAKE-NOTES is the same as for `checkdoc-current-buffer'"
1064 (let ((checkdoc-spellcheck-documentation-flag t
))
1065 (call-interactively 'checkdoc-current-buffer nil current-prefix-arg
)))
1068 (defun checkdoc-ispell-interactive (&optional take-notes
)
1069 "Check the style and spelling of the current buffer interactively.
1070 Calls `checkdoc-interactive' with spell-checking turned on.
1071 Prefix argument TAKE-NOTES is the same as for `checkdoc-interactive'"
1073 (let ((checkdoc-spellcheck-documentation-flag t
))
1074 (call-interactively 'checkdoc-interactive nil current-prefix-arg
)))
1077 (defun checkdoc-ispell-message-interactive (&optional take-notes
)
1078 "Check the style and spelling of message text interactively.
1079 Calls `checkdoc-message-interactive' with spell-checking turned on.
1080 Prefix argument TAKE-NOTES is the same as for `checkdoc-message-interactive'"
1082 (let ((checkdoc-spellcheck-documentation-flag t
))
1083 (call-interactively 'checkdoc-message-interactive nil current-prefix-arg
)))
1086 (defun checkdoc-ispell-message-text (&optional take-notes
)
1087 "Check the style and spelling of message text interactively.
1088 Calls `checkdoc-message-text' with spell-checking turned on.
1089 Prefix argument TAKE-NOTES is the same as for `checkdoc-message-text'"
1091 (let ((checkdoc-spellcheck-documentation-flag t
))
1092 (call-interactively 'checkdoc-message-text nil current-prefix-arg
)))
1095 (defun checkdoc-ispell-start (&optional take-notes
)
1096 "Check the style and spelling of the current buffer.
1097 Calls `checkdoc-start' with spell-checking turned on.
1098 Prefix argument TAKE-NOTES is the same as for `checkdoc-start'"
1100 (let ((checkdoc-spellcheck-documentation-flag t
))
1101 (call-interactively 'checkdoc-start nil current-prefix-arg
)))
1104 (defun checkdoc-ispell-continue (&optional take-notes
)
1105 "Check the style and spelling of the current buffer after point.
1106 Calls `checkdoc-continue' with spell-checking turned on.
1107 Prefix argument TAKE-NOTES is the same as for `checkdoc-continue'"
1109 (let ((checkdoc-spellcheck-documentation-flag t
))
1110 (call-interactively 'checkdoc-continue nil current-prefix-arg
)))
1113 (defun checkdoc-ispell-comments (&optional take-notes
)
1114 "Check the style and spelling of the current buffer's comments.
1115 Calls `checkdoc-comments' with spell-checking turned on.
1116 Prefix argument TAKE-NOTES is the same as for `checkdoc-comments'"
1118 (let ((checkdoc-spellcheck-documentation-flag t
))
1119 (call-interactively 'checkdoc-comments nil current-prefix-arg
)))
1122 (defun checkdoc-ispell-defun (&optional take-notes
)
1123 "Check the style and spelling of the current defun with Ispell.
1124 Calls `checkdoc-defun' with spell-checking turned on.
1125 Prefix argument TAKE-NOTES is the same as for `checkdoc-defun'"
1127 (let ((checkdoc-spellcheck-documentation-flag t
))
1128 (call-interactively 'checkdoc-defun
nil current-prefix-arg
)))
1130 ;;; Error Management
1132 ;; Errors returned from checkdoc functions can have various
1133 ;; features and behaviors, so we need some ways of specifying
1134 ;; them, and making them easier to use in the wacked-out interfaces
1135 ;; people are requesting
1136 (defun checkdoc-create-error (text start end
&optional unfixable
)
1137 "Used to create the return error text returned from all engines.
1138 TEXT is the descriptive text of the error. START and END define the region
1139 it is sensible to highlight when describing the problem.
1140 Optional argument UNFIXABLE means that the error has no auto-fix available.
1142 A list of the form (TEXT START END UNFIXABLE) is returned if we are not
1143 generating a buffered list of errors."
1144 (if checkdoc-generate-compile-warnings-flag
1145 (progn (checkdoc-error start text
)
1147 (list text start end unfixable
)))
1149 (defun checkdoc-error-text (err)
1150 "Return the text specified in the checkdoc ERR."
1151 ;; string-p part is for backwards compatibility
1152 (if (stringp err
) err
(car err
)))
1154 (defun checkdoc-error-start (err)
1155 "Return the start point specified in the checkdoc ERR."
1156 ;; string-p part is for backwards compatibility
1157 (if (stringp err
) nil
(nth 1 err
)))
1159 (defun checkdoc-error-end (err)
1160 "Return the end point specified in the checkdoc ERR."
1161 ;; string-p part is for backwards compatibility
1162 (if (stringp err
) nil
(nth 2 err
)))
1164 (defun checkdoc-error-unfixable (err)
1165 "Return the t if we cannot autofix the error specified in the checkdoc ERR."
1166 ;; string-p part is for backwards compatibility
1167 (if (stringp err
) nil
(nth 3 err
)))
1169 ;;; Minor Mode specification
1172 (defvar checkdoc-minor-mode-map
1173 (let ((map (make-sparse-keymap))
1174 (pmap (make-sparse-keymap)))
1175 ;; Override some bindings
1176 (define-key map
"\C-\M-x" 'checkdoc-eval-defun
)
1177 (define-key map
"\C-x`" 'checkdoc-continue
)
1178 (if (not (featurep 'xemacs
))
1179 (define-key map
[menu-bar emacs-lisp eval-buffer
]
1180 'checkdoc-eval-current-buffer
))
1181 ;; Add some new bindings under C-c ?
1182 (define-key pmap
"x" 'checkdoc-defun
)
1183 (define-key pmap
"X" 'checkdoc-ispell-defun
)
1184 (define-key pmap
"`" 'checkdoc-continue
)
1185 (define-key pmap
"~" 'checkdoc-ispell-continue
)
1186 (define-key pmap
"s" 'checkdoc-start
)
1187 (define-key pmap
"S" 'checkdoc-ispell-start
)
1188 (define-key pmap
"d" 'checkdoc
)
1189 (define-key pmap
"D" 'checkdoc-ispell
)
1190 (define-key pmap
"b" 'checkdoc-current-buffer
)
1191 (define-key pmap
"B" 'checkdoc-ispell-current-buffer
)
1192 (define-key pmap
"e" 'checkdoc-eval-current-buffer
)
1193 (define-key pmap
"m" 'checkdoc-message-text
)
1194 (define-key pmap
"M" 'checkdoc-ispell-message-text
)
1195 (define-key pmap
"c" 'checkdoc-comments
)
1196 (define-key pmap
"C" 'checkdoc-ispell-comments
)
1197 (define-key pmap
" " 'checkdoc-rogue-spaces
)
1199 ;; bind our submap into map
1200 (define-key map
"\C-c?" pmap
)
1202 "Keymap used to override evaluation key-bindings for documentation checking.")
1204 ;; Add in a menubar with easy-menu
1207 nil checkdoc-minor-mode-map
"Checkdoc Minor Mode Menu"
1209 ["Interactive Buffer Style Check" checkdoc t
]
1210 ["Interactive Buffer Style and Spelling Check" checkdoc-ispell t
]
1211 ["Check Buffer" checkdoc-current-buffer t
]
1212 ["Check and Spell Buffer" checkdoc-ispell-current-buffer t
]
1214 ["Interactive Style Check" checkdoc-interactive t
]
1215 ["Interactive Style and Spelling Check" checkdoc-ispell-interactive t
]
1216 ["Find First Style Error" checkdoc-start t
]
1217 ["Find First Style or Spelling Error" checkdoc-ispell-start t
]
1218 ["Next Style Error" checkdoc-continue t
]
1219 ["Next Style or Spelling Error" checkdoc-ispell-continue t
]
1220 ["Interactive Message Text Style Check" checkdoc-message-interactive t
]
1221 ["Interactive Message Text Style and Spelling Check"
1222 checkdoc-ispell-message-interactive t
]
1223 ["Check Message Text" checkdoc-message-text t
]
1224 ["Check and Spell Message Text" checkdoc-ispell-message-text t
]
1225 ["Check Comment Style" checkdoc-comments buffer-file-name
]
1226 ["Check Comment Style and Spelling" checkdoc-ispell-comments
1228 ["Check for Rogue Spaces" checkdoc-rogue-spaces t
]
1230 ["Check Defun" checkdoc-defun
t]
1231 ["Check and Spell Defun" checkdoc-ispell-defun
t]
1232 ["Check and Evaluate Defun" checkdoc-eval-defun
t]
1233 ["Check and Evaluate Buffer" checkdoc-eval-current-buffer t
]
1235 ;; XEmacs requires some weird stuff to add this menu in a minor mode.
1239 (define-minor-mode checkdoc-minor-mode
1240 "Toggle automatic docstring checking (Checkdoc minor mode).
1241 With a prefix argument ARG, enable Checkdoc minor mode if ARG is
1242 positive, and disable it otherwise. If called from Lisp, enable
1243 the mode if ARG is omitted or nil.
1245 In Checkdoc minor mode, the usual bindings for `eval-defun' which is
1246 bound to \\<checkdoc-minor-mode-map>\\[checkdoc-eval-defun] and `checkdoc-eval-current-buffer' are overridden to include
1247 checking of documentation strings.
1249 \\{checkdoc-minor-mode-map}"
1250 nil checkdoc-minor-mode-string nil
1255 (defsubst checkdoc-run-hooks
(hookvar &rest args
)
1256 "Run hooks in HOOKVAR with ARGS."
1257 (if (fboundp 'run-hook-with-args-until-success
)
1258 (apply 'run-hook-with-args-until-success hookvar args
)
1259 ;; This method was similar to above. We ignore the warning
1260 ;; since we will use the above for future Emacs versions
1261 (apply 'run-hook-with-args hookvar args
)))
1263 (defsubst checkdoc-create-common-verbs-regexp
()
1264 "Rebuild the contents of `checkdoc-common-verbs-regexp'."
1265 (or checkdoc-common-verbs-regexp
1266 (setq checkdoc-common-verbs-regexp
1268 (mapconcat (lambda (e) (concat (car e
)))
1269 checkdoc-common-verbs-wrong-voice
"\\|")
1272 ;; Profiler says this is not yet faster than just calling assoc
1273 ;;(defun checkdoc-word-in-alist-vector (word vector)
1274 ;; "Check to see if WORD is in the car of an element of VECTOR.
1275 ;;VECTOR must be sorted. The CDR should be a replacement. Since the
1276 ;;word list is getting bigger, it is time for a quick bisecting search."
1277 ;; (let ((max (length vector)) (min 0) i
1278 ;; (found nil) (fw nil))
1279 ;; (setq i (/ max 2))
1280 ;; (while (and (not found) (/= min max))
1281 ;; (setq fw (car (aref vector i)))
1282 ;; (cond ((string= word fw) (setq found (cdr (aref vector i))))
1283 ;; ((string< word fw) (setq max i))
1284 ;; (t (setq min i)))
1285 ;; (setq i (/ (+ max min) 2))
1289 ;;; Checking engines
1291 (defun checkdoc-this-string-valid ()
1292 "Return a message string if the current doc string is invalid.
1293 Check for style only, such as the first line always being a complete
1294 sentence, whitespace restrictions, and making sure there are no
1295 hard-coded key-codes such as C-[char] or mouse-[number] in the comment.
1296 See the style guide in the Emacs Lisp manual for more details."
1298 ;; Jump over comments between the last object and the doc string
1299 (while (looking-at "[ \t\n]*;")
1302 (skip-chars-forward " \n\t"))
1304 (let ((fp (checkdoc-defun-info))
1308 ;; * Every command, function, or variable intended for users to know
1309 ;; about should have a documentation string.
1311 ;; * An internal variable or subroutine of a Lisp program might as well
1312 ;; have a documentation string. In earlier Emacs versions, you could
1313 ;; save space by using a comment instead of a documentation string,
1314 ;; but that is no longer the case.
1315 (if (and (not (nth 1 fp
)) ; not a variable
1316 (or (nth 2 fp
) ; is interactive
1317 checkdoc-force-docstrings-flag
) ;or we always complain
1318 (not (checkdoc-char= (following-char) ?
\"))) ; no doc string
1319 ;; Sometimes old code has comments where the documentation should
1320 ;; be. Let's see if we can find the comment, and offer to turn it
1321 ;; into documentation for them.
1322 (let ((have-comment nil
)
1323 (comment-start ";")) ; in case it's not default
1328 (skip-chars-forward "\n \t")
1329 (setq have-comment
(looking-at comment-start
)))
1332 (if (or (eq checkdoc-autofix-flag
1333 'automatic-then-never
)
1335 "Convert comment to documentation? "))
1337 ;; Our point is at the beginning of the comment!
1338 ;; Insert a quote, then remove the comment chars.
1340 (let ((docstring-start-point (point)))
1341 (while (looking-at comment-start
)
1342 (while (looking-at comment-start
)
1344 (if (looking-at "[ \t]+")
1345 (delete-region (match-beginning 0) (match-end 0)))
1348 (skip-chars-forward " \t")
1349 (if (looking-at comment-start
)
1352 (zap-to-char 1 ?\
;))))
1357 ;; quote any double-quote characters in the comment.
1358 (while (search-backward "\"" docstring-start-point t
)
1360 (if (eq checkdoc-autofix-flag
'automatic-then-never
)
1361 (setq checkdoc-autofix-flag
'never
))))
1362 (checkdoc-create-error
1363 "You should convert this comment to documentation"
1364 (point) (line-end-position)))
1365 (checkdoc-create-error
1367 "All interactive functions should have documentation"
1368 "All variables and subroutines might as well have a \
1369 documentation string")
1370 (point) (+ (point) 1) t
)))))
1371 (if (and (not err
) (looking-at "\""))
1372 (with-syntax-table checkdoc-syntax-table
1373 (checkdoc-this-string-valid-engine fp
))
1376 (defun checkdoc-this-string-valid-engine (fp)
1377 "Return an error list or string if the current doc string is invalid.
1378 Depends on `checkdoc-this-string-valid' to reset the syntax table so that
1379 regexp short cuts work. FP is the function defun information."
1380 (let ((case-fold-search nil
)
1381 ;; Use a marker so if an early check modifies the text,
1382 ;; we won't accidentally lose our place. This could cause
1383 ;; end-of doc string whitespace to also delete the " char.
1385 (e (if (looking-at "\"")
1386 (save-excursion (forward-sexp 1) (point-marker))
1389 ;; * *Do not* indent subsequent lines of a documentation string so that
1390 ;; the text is lined up in the source code with the text of the first
1391 ;; line. This looks nice in the source code, but looks bizarre when
1392 ;; users view the documentation. Remember that the indentation
1393 ;; before the starting double-quote is not part of the string!
1397 (if (and (< (point) e
)
1398 (looking-at "\\([ \t]+\\)[^ \t\n]"))
1399 (if (checkdoc-autofix-ask-replace (match-beginning 1)
1401 "Remove this whitespace? "
1404 (checkdoc-create-error
1405 "Second line should not have indentation"
1408 ;; * Check for '(' in column 0.
1410 (when (re-search-forward "^(" e t
)
1411 (if (checkdoc-autofix-ask-replace (match-beginning 0)
1416 (checkdoc-create-error
1417 "Open parenthesis in column 0 should be escaped"
1418 (match-beginning 0) (match-end 0)))))
1419 ;; * Do not start or end a documentation string with whitespace.
1421 (if (or (if (looking-at "\"\\([ \t\n]+\\)")
1422 (setq start
(match-beginning 1)
1427 (if (/= (skip-chars-backward " \t\n") 0)
1430 (if (checkdoc-autofix-ask-replace
1431 start end
"Remove this whitespace? " "")
1433 (checkdoc-create-error
1434 "Documentation strings should not start or end with whitespace"
1436 ;; * The first line of the documentation string should consist of one
1437 ;; or two complete sentences that stand on their own as a summary.
1438 ;; `M-x apropos' displays just the first line, and if it doesn't
1439 ;; stand on its own, the result looks bad. In particular, start the
1440 ;; first line with a capital letter and end with a period.
1443 (skip-chars-backward " \t\n")
1444 (if (> (point) e
) (goto-char e
)) ;of the form (defun n () "doc" nil)
1447 ((and (checkdoc-char= (following-char) ?
\")
1448 ;; A backslashed double quote at the end of a sentence
1449 (not (checkdoc-char= (preceding-char) ?
\\)))
1450 ;; We might have to add a period in this case
1452 (if (looking-at "[.!?]")
1455 (if (checkdoc-autofix-ask-replace
1456 (point) (1+ (point)) "Add period to sentence? "
1459 (checkdoc-create-error
1460 "First sentence should end with punctuation"
1461 (point) (1+ (point))))))
1462 ((looking-at "[\\!?;:.)]")
1465 ((and checkdoc-permit-comma-termination-flag
(looking-at ","))
1468 ;; If it is not a complete sentence, let's see if we can
1469 ;; predict a clever way to make it one.
1470 (let ((msg "First line is not a complete sentence")
1473 (if (re-search-forward "\\. +" e t
)
1474 ;; Here we have found a complete sentence, but no break.
1475 (if (checkdoc-autofix-ask-replace
1476 (1+ (match-beginning 0)) (match-end 0)
1477 "First line not a complete sentence. Add RET here? "
1481 (setq l1
(current-column)
1485 (if (> (+ l1 l2
1) 80)
1486 (setq msg
"Incomplete auto-fix; doc string \
1487 may require more formatting")
1488 ;; We can merge these lines! Replace this CR
1490 (delete-char 1) (insert " ")
1492 ;; Let's see if there is enough room to draw the next
1493 ;; line's sentence up here. I often get hit w/
1494 ;; auto-fill moving my words around.
1495 (let ((numc (progn (end-of-line) (- 80 (current-column))))
1499 (if (and (re-search-forward "[.!?:\"]\\([ \t\n]+\\|\"\\)"
1500 (line-end-position) t
)
1501 (< (current-column) numc
))
1502 (if (checkdoc-autofix-ask-replace
1504 "1st line not a complete sentence. Join these lines? "
1507 ;; They said yes. We have more fill work to do...
1508 (goto-char (match-beginning 1))
1509 (delete-region (point) (match-end 1))
1513 (checkdoc-create-error msg s
(save-excursion
1515 (line-end-position))))))))
1516 ;; Continuation of above. Make sure our sentence is capitalized.
1518 (skip-chars-forward "\"\\*")
1519 (if (looking-at "[a-z]")
1520 (if (checkdoc-autofix-ask-replace
1521 (match-beginning 0) (match-end 0)
1522 "Capitalize your sentence? " (upcase (match-string 0))
1525 (checkdoc-create-error
1526 "First line should be capitalized"
1527 (match-beginning 0) (match-end 0)))
1529 ;; * Don't write key sequences directly in documentation strings.
1530 ;; Instead, use the `\\[...]' construct to stand for them.
1532 (let ((f nil
) (m nil
) (start (point))
1533 (re "[^`A-Za-z0-9_]\\([CMA]-[a-zA-Z]\\|\\(\\([CMA]-\\)?\
1534 mouse-[0-3]\\)\\)\\>"))
1535 ;; Find the first key sequence not in a sample
1536 (while (and (not f
) (setq m
(re-search-forward re e t
)))
1537 (setq f
(not (checkdoc-in-sample-code-p start e
))))
1539 (checkdoc-create-error
1541 "Keycode " (match-string 1)
1542 " embedded in doc string. Use \\\\<keymap> & \\\\[function] "
1544 (match-beginning 1) (match-end 1) t
))))
1545 ;; It is not practical to use `\\[...]' very many times, because
1546 ;; display of the documentation string will become slow. So use this
1547 ;; to describe the most important commands in your major mode, and
1548 ;; then use `\\{...}' to display the rest of the mode's keymap.
1550 (if (and (re-search-forward "\\\\\\\\\\[\\w+" e t
1551 (1+ checkdoc-max-keyref-before-warn
))
1552 (not (re-search-forward "\\\\\\\\{\\w+}" e t
)))
1553 (checkdoc-create-error
1554 "Too many occurrences of \\[function]. Use \\{keymap} instead"
1555 s
(marker-position e
))))
1556 ;; Ambiguous quoted symbol. When a symbol is both bound and fbound,
1557 ;; and is referred to in documentation, it should be prefixed with
1558 ;; something to disambiguate it. This check must be before the
1559 ;; 80 column check because it will probably break that.
1561 (let ((case-fold-search t
)
1563 (while (and (re-search-forward "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'" e t
)
1565 (let* ((ms1 (match-string 1))
1566 (sym (intern-soft ms1
)))
1567 (setq mb
(match-beginning 1)
1569 (if (and sym
(boundp sym
) (fboundp sym
)
1574 "variable\\|option\\|function\\|command\\|symbol"))))
1575 (if (checkdoc-autofix-ask-replace
1576 mb me
"Prefix this ambiguous symbol? " ms1 t
)
1577 ;; We didn't actually replace anything. Here we find
1578 ;; out what special word form they wish to use as
1582 "Disambiguating Keyword (default variable): "
1583 '(("function") ("command") ("variable")
1584 ("option") ("symbol"))
1585 nil t nil nil
"variable")))
1587 (insert disambiguate
" ")
1590 (format "Disambiguate %s by preceding w/ \
1591 function,command,variable,option or symbol." ms1
))))))
1593 (checkdoc-create-error ret mb me
)
1595 ;; * Format the documentation string so that it fits in an
1596 ;; Emacs window on an 80-column screen. It is a good idea
1597 ;; for most lines to be no wider than 60 characters. The
1598 ;; first line can be wider if necessary to fit the
1599 ;; information that ought to be there.
1601 (let ((start (point))
1603 (while (and (< (point) e
)
1604 (or (progn (end-of-line) (setq eol
(point))
1605 (< (current-column) 80))
1606 (progn (beginning-of-line)
1607 (re-search-forward "\\\\\\\\[[<{]"
1609 (checkdoc-in-sample-code-p start e
)))
1612 (if (and (< (point) e
) (> (current-column) 80))
1613 (checkdoc-create-error
1614 "Some lines are over 80 columns wide"
1615 s
(save-excursion (goto-char s
) (line-end-position))))))
1616 ;; Here we deviate to tests based on a variable or function.
1617 ;; We must do this before checking for symbols in quotes because there
1618 ;; is a chance that just such a symbol might really be an argument.
1619 (cond ((eq (nth 1 fp
) t
)
1620 ;; This is if we are in a variable
1622 ;; * The documentation string for a variable that is a
1623 ;; yes-or-no flag should start with words such as Non-nil
1624 ;; means..., to make it clear that all non-`nil' values are
1625 ;; equivalent and indicate explicitly what `nil' and non-`nil'
1627 ;; * If a user option variable records a true-or-false
1628 ;; condition, give it a name that ends in `-flag'.
1630 ;; If the variable has -flag in the name, make sure
1631 (if (and (string-match "-flag$" (car fp
))
1632 (not (looking-at "\"\\*?Non-nil\\s-+means\\s-+")))
1633 (checkdoc-create-error
1634 "Flag variable doc strings should usually start: Non-nil means"
1635 s
(marker-position e
) t
))
1636 ;; Don't rename variable to "foo-flag". This is unnecessary
1637 ;; and such names often end up inconvenient when the variable
1638 ;; is later expanded to non-boolean values. --Stef
1639 ;; If the doc string starts with "Non-nil means"
1640 ;; (if (and (looking-at "\"\\*?Non-nil\\s-+means\\s-+")
1641 ;; (not (string-match "-flag$" (car fp))))
1643 ;; (if (string-match "-p$" (car fp))
1644 ;; (concat (substring (car fp) 0 -2) "-flag")
1645 ;; (concat (car fp) "-flag"))))
1646 ;; (if (checkdoc-y-or-n-p
1648 ;; "Rename to %s and Query-Replace all occurrences? "
1651 ;; (beginning-of-defun)
1652 ;; (query-replace-regexp
1653 ;; (concat "\\<" (regexp-quote (car fp)) "\\>")
1655 ;; (checkdoc-create-error
1656 ;; "Flag variable names should normally end in `-flag'" s
1657 ;; (marker-position e)))))
1658 ;; Done with variables
1661 ;; This if we are in a function definition
1663 ;; * When a function's documentation string mentions the value
1664 ;; of an argument of the function, use the argument name in
1665 ;; capital letters as if it were a name for that value. Thus,
1666 ;; the documentation string of the function `/' refers to its
1667 ;; second argument as `DIVISOR', because the actual argument
1668 ;; name is `divisor'.
1670 ;; Addendum: Make sure they appear in the doc in the same
1671 ;; order that they are found in the arg list.
1672 (let ((args (cdr (cdr (cdr (cdr fp
)))))
1675 (order (and (nth 3 fp
) (car (nth 3 fp
))))
1676 (nocheck (append '("&optional" "&rest") (nth 3 fp
)))
1678 (while (and args found
(> found last-pos
))
1679 (if (member (car args
) nocheck
)
1680 (setq args
(cdr args
)
1682 (setq last-pos found
1683 found
(save-excursion
1685 (concat "\\<" (upcase (car args
))
1686 ;; Require whitespace OR
1689 "\\(\\>\\|th\\>\\|s\\>\\|[.,;:]\\)")
1692 (let ((case-fold-search t
))
1693 ;; If the symbol was not found, let's see if we
1694 ;; can find it with a different capitalization
1695 ;; and see if the user wants to capitalize it.
1698 (concat "\\<\\(" (car args
)
1699 ;; Require whitespace OR
1702 "\\)\\(\\>\\|th\\>\\|s\\>\\)")
1704 (if (checkdoc-autofix-ask-replace
1705 (match-beginning 1) (match-end 1)
1707 "If this is the argument `%s', it should appear as %s. Fix? "
1708 (car args
) (upcase (car args
)))
1709 (upcase (car args
)) t
)
1710 (setq found
(match-beginning 1))))))
1711 (if found
(setq args
(cdr args
)))))
1713 ;; It wasn't found at all! Offer to attach this new symbol
1714 ;; to the end of the documentation string.
1715 (if (checkdoc-y-or-n-p
1717 "Add %s documentation to end of doc string? "
1718 (upcase (car args
))))
1719 ;; Now do some magic and invent a doc string.
1721 (goto-char e
) (forward-char -
1)
1723 (if inopts
"Optional a" "A")
1724 "rgument " (upcase (car args
))
1726 (insert (read-string "Describe: "))
1727 (if (not (save-excursion (forward-char -
1)
1728 (looking-at "[.?!]")))
1731 (checkdoc-create-error
1733 "Argument `%s' should appear (as %s) in the doc string"
1734 (car args
) (upcase (car args
)))
1735 s
(marker-position e
)))
1736 (if (or (and order
(eq order
'yes
))
1737 (and (not order
) checkdoc-arguments-in-order-flag
))
1738 (if (< found last-pos
)
1739 (checkdoc-create-error
1740 "Arguments occur in the doc string out of order"
1741 s
(marker-position e
) t
)))))
1742 ;; * For consistency, phrase the verb in the first sentence of a
1743 ;; documentation string for functions as an imperative.
1744 ;; For instance, use `Return the cons of A and
1745 ;; B.' in preference to `Returns the cons of A and B.'
1746 ;; Usually it looks good to do likewise for the rest of the
1747 ;; first paragraph. Subsequent paragraphs usually look better
1748 ;; if they have proper subjects.
1750 ;; This is the least important of the above tests. Make sure
1752 (and checkdoc-verb-check-experimental-flag
1754 ;; Maybe rebuild the monster-regexp
1755 (checkdoc-create-common-verbs-regexp)
1756 (let ((lim (save-excursion
1758 ;; check string-continuation
1759 (if (checkdoc-char= (preceding-char) ?
\\)
1760 (line-end-position 2)
1762 (rs nil
) replace original
(case-fold-search t
))
1763 (while (and (not rs
)
1765 checkdoc-common-verbs-regexp
1767 (setq original
(buffer-substring-no-properties
1768 (match-beginning 1) (match-end 1))
1769 rs
(assoc (downcase original
)
1770 checkdoc-common-verbs-wrong-voice
))
1771 (if (not rs
) (error "Verb voice alist corrupted"))
1772 (setq replace
(let ((case-fold-search nil
))
1773 (if (string-match-p "^[A-Z]" original
)
1774 (capitalize (cdr rs
))
1776 (if (checkdoc-autofix-ask-replace
1777 (match-beginning 1) (match-end 1)
1778 (format "Use the imperative for \"%s\". \
1779 Replace with \"%s\"? " original replace
)
1783 ;; there was a match, but no replace
1784 (checkdoc-create-error
1786 "Probably \"%s\" should be imperative \"%s\""
1788 (match-beginning 1) (match-end 1))))))
1789 ;; Done with functions
1791 ;;* When a documentation string refers to a Lisp symbol, write it as
1792 ;; it would be printed (which usually means in lower case), with
1793 ;; single-quotes around it. For example: `lambda'. There are two
1794 ;; exceptions: write t and nil without single-quotes. (In this
1795 ;; manual, we normally do use single-quotes for those symbols.)
1797 (let ((found nil
) (start (point)) (msg nil
) (ms nil
))
1798 (while (and (not msg
)
1800 ;; Ignore manual page references like
1802 "[^-([`':a-zA-Z]\\(\\w+[:-]\\(\\w\\|\\s_\\)+\\)[^](']"
1804 (setq ms
(match-string 1))
1805 ;; A . is a \s_ char, so we must remove periods from
1806 ;; sentences more carefully.
1807 (when (string-match-p "\\.$" ms
)
1808 (setq ms
(substring ms
0 (1- (length ms
)))))
1809 (if (and (not (checkdoc-in-sample-code-p start e
))
1810 (not (checkdoc-in-example-string-p start e
))
1811 (not (member ms checkdoc-symbol-words
))
1812 (setq found
(intern-soft ms
))
1813 (or (boundp found
) (fboundp found
)))
1815 (setq msg
(format "Add quotes around Lisp symbol `%s'? "
1817 (if (checkdoc-autofix-ask-replace
1818 (match-beginning 1) (+ (match-beginning 1)
1820 msg
(concat "`" ms
"'") t
)
1823 (format "Lisp symbol `%s' should appear in quotes"
1826 (checkdoc-create-error msg
(match-beginning 1)
1827 (+ (match-beginning 1)
1832 (if (re-search-forward "\\(`\\(t\\|nil\\)'\\)" e t
)
1833 (if (checkdoc-autofix-ask-replace
1834 (match-beginning 1) (match-end 1)
1835 (format "%s should not appear in quotes. Remove? "
1839 (checkdoc-create-error
1840 "Symbols t and nil should not appear in `...' quotes"
1841 (match-beginning 1) (match-end 1)))))
1842 ;; Here is some basic sentence formatting
1843 (checkdoc-sentencespace-region-engine (point) e
)
1844 ;; Here are common proper nouns that should always appear capitalized.
1845 (checkdoc-proper-noun-region-engine (point) e
)
1846 ;; Make sure the doc string has correctly spelled English words
1847 ;; in it. This function is extracted due to its complexity,
1848 ;; and reliance on the Ispell program.
1849 (checkdoc-ispell-docstring-engine e
)
1850 ;; User supplied checks
1851 (save-excursion (checkdoc-run-hooks 'checkdoc-style-hooks fp e
))
1855 (defun checkdoc-defun-info nil
1856 "Return a list of details about the current sexp.
1857 It is a list of the form:
1858 (NAME VARIABLE INTERACTIVE NODOCPARAMS PARAMETERS ...)
1859 where NAME is the name, VARIABLE is t if this is a `defvar',
1860 INTERACTIVE is nil if this is not an interactive function, otherwise
1861 it is the position of the `interactive' call, and PARAMETERS is a
1862 string which is the name of each variable in the function's argument
1863 list. The NODOCPARAMS is a sublist of parameters specified by a checkdoc
1864 comment for a given defun. If the first element is not a string, then
1865 the token checkdoc-order: <TOKEN> exists, and TOKEN is a symbol read
1868 (beginning-of-defun)
1869 (let ((defun (looking-at "(def\\(un\\|macro\\|subst\\|advice\\)"))
1870 (is-advice (looking-at "(defadvice"))
1873 (oo (make-vector 3 0))) ;substitute obarray for `read'
1876 (skip-chars-forward " \n\t")
1878 (list (buffer-substring-no-properties
1879 (point) (progn (forward-sexp 1) (point)))))
1881 (setq ret
(cons t ret
))
1882 ;; The variable spot
1883 (setq ret
(cons nil ret
))
1887 (re-search-forward "^\\s-*(interactive"
1888 (save-excursion (end-of-defun) (point))
1891 (skip-chars-forward " \t\n")
1892 (let ((bss (buffer-substring (point) (save-excursion (forward-sexp 1)
1894 ;; Overload th main obarray so read doesn't intern the
1895 ;; local symbols of the function we are checking.
1896 ;; Without this we end up cluttering the symbol space w/
1899 ;; Ok, check for checkdoc parameter comment here
1904 (if (re-search-forward ";\\s-+checkdoc-order:\\s-+"
1905 (save-excursion (end-of-defun)
1908 (setq sl1
(list (cond ((looking-at "nil") 'no
)
1909 ((looking-at "t") 'yes
)))))
1910 (if (re-search-forward ";\\s-+checkdoc-params:\\s-+"
1911 (save-excursion (end-of-defun)
1915 (goto-char (match-end 0))
1917 (setq lst
(read (current-buffer)))
1918 (error (setq lst nil
))) ; error in text
1919 (if (not (listp lst
)) ; not a list of args
1920 (setq lst
(list lst
)))
1921 (if (and lst
(not (symbolp (car lst
)))) ;weird arg
1924 (setq sl
(cons (symbol-name (car lst
)) sl
)
1926 (setq sl1
(append sl1 sl
))))
1929 ;; Read the list of parameters, but do not put the symbols in
1930 ;; the standard obarray.
1931 (setq lst
(read bss
)))
1932 ;; This is because read will intern nil if it doesn't into the
1934 (if (not (listp lst
)) (setq lst nil
))
1937 (setq ret
(cons (symbol-name (car lst
)) ret
)
1941 (defun checkdoc-in-sample-code-p (start limit
)
1942 "Return non-nil if the current point is in a code fragment.
1943 A code fragment is identified by an open parenthesis followed by a
1944 symbol which is a valid function or a word in all CAPS, or a parenthesis
1945 that is quoted with the ' character. Only the region from START to LIMIT
1946 is allowed while searching for the bounding parenthesis."
1949 (narrow-to-region start limit
)
1951 (and (condition-case nil
(progn (up-list 1) t
) (error nil
))
1952 (condition-case nil
(progn (forward-list -
1) t
) (error nil
))
1953 (or (save-excursion (forward-char -
1) (looking-at "'("))
1954 (and (looking-at "(\\(\\(\\w\\|[-:_]\\)+\\)[ \t\n;]")
1955 (let ((ms (buffer-substring-no-properties
1956 (match-beginning 1) (match-end 1))))
1957 ;; if this string is function bound, we are in
1958 ;; sample code. If it has a - or : character in
1959 ;; the name, then it is probably supposed to be bound
1961 (or (fboundp (intern-soft ms
))
1962 (let ((case-fold-search nil
))
1963 (string-match "^[A-Z-]+$" ms
))
1964 (string-match "\\w[-:_]+\\w" ms
))))))))))
1966 (defun checkdoc-in-example-string-p (start limit
)
1967 "Return non-nil if the current point is in an \"example string\".
1968 This string is identified by the characters \\\" surrounding the text.
1969 The text checked is between START and LIMIT."
1975 (while (and (< (point) p
) (re-search-forward "\\\\\"" limit t
))
1977 (and (< 0 c
) (= (% c
2) 0))))))
1979 (defun checkdoc-proper-noun-region-engine (begin end
)
1980 "Check all text between BEGIN and END for lower case proper nouns.
1981 These are Emacs centric proper nouns which should be capitalized for
1982 consistency. Return an error list if any are not fixed, but
1983 internally skip over no answers.
1984 If the offending word is in a piece of quoted text, then it is skipped."
1986 (let ((case-fold-search nil
)
1988 (with-syntax-table checkdoc-syntax-table
1990 (while (re-search-forward checkdoc-proper-noun-regexp end t
)
1991 (let ((text (match-string 1))
1992 (b (match-beginning 1))
1994 (if (and (not (save-excursion
1997 (looking-at "`\\|\"\\|\\.\\|\\\\")))
1998 ;; surrounded by /, as in a URL or filename: /emacs/
1999 (not (and (= ?
/ (char-after e
))
2000 (= ?
/ (char-before b
))))
2001 (not (checkdoc-in-example-string-p begin end
))
2002 ;; info or url links left alone
2003 (not (thing-at-point-looking-at
2004 help-xref-info-regexp
))
2005 (not (thing-at-point-looking-at
2006 help-xref-url-regexp
)))
2007 (if (checkdoc-autofix-ask-replace
2008 b e
(format "Text %s should be capitalized. Fix? "
2010 (capitalize text
) t
)
2013 ;; If there is already an error, then generate
2014 ;; the warning output if applicable
2015 (if checkdoc-generate-compile-warnings-flag
2016 (checkdoc-create-error
2018 "Name %s should appear capitalized as %s"
2019 text
(capitalize text
))
2023 "Name %s should appear capitalized as %s"
2024 text
(capitalize text
))
2026 (if errtxt
(checkdoc-create-error errtxt bb be
)))))
2028 (defun checkdoc-sentencespace-region-engine (begin end
)
2029 "Make sure all sentences have double spaces between BEGIN and END."
2030 (if sentence-end-double-space
2032 (let ((case-fold-search nil
)
2034 (with-syntax-table checkdoc-syntax-table
2036 (while (re-search-forward "[^ .0-9]\\(\\. \\)[^ \n]" end t
)
2037 (let ((b (match-beginning 1))
2039 (unless (or (checkdoc-in-sample-code-p begin end
)
2040 (checkdoc-in-example-string-p begin end
)
2046 ;; piece of an abbreviation
2049 "\\([a-zA-Z]\\|[iI]\\.?e\\|[eE]\\.?g\\)\\."))
2051 (if (checkdoc-autofix-ask-replace
2053 "There should be two spaces after a period. Fix? "
2057 ;; If there is already an error, then generate
2058 ;; the warning output if applicable
2059 (if checkdoc-generate-compile-warnings-flag
2060 (checkdoc-create-error
2061 "There should be two spaces after a period"
2064 "There should be two spaces after a period"
2066 (if errtxt
(checkdoc-create-error errtxt bb be
))))))
2070 (eval-when-compile (require 'ispell
))
2072 (defun checkdoc-ispell-init ()
2073 "Initialize Ispell process (default version) with Lisp words.
2074 The words used are from `checkdoc-ispell-lisp-words'. If `ispell'
2075 cannot be loaded, then set `checkdoc-spellcheck-documentation-flag' to
2078 (if (not (symbol-value 'ispell-process
)) ;Silence byteCompiler
2081 (ispell-buffer-local-words)
2082 ;; This code copied in part from ispell.el Emacs 19.34
2083 (let ((w checkdoc-ispell-lisp-words
))
2085 (process-send-string
2086 ;; Silence byte compiler
2087 (symbol-value 'ispell-process
)
2088 (concat "@" (car w
) "\n"))
2090 (error (setq checkdoc-spellcheck-documentation-flag nil
)))))
2092 (defun checkdoc-ispell-docstring-engine (end)
2093 "Run the Ispell tools on the doc string between point and END.
2094 Since Ispell isn't Lisp-smart, we must pre-process the doc string
2095 before using the Ispell engine on it."
2096 (if (or (not checkdoc-spellcheck-documentation-flag
)
2097 ;; If the user wants no questions or fixing, then we must
2098 ;; disable spell checking as not useful.
2099 (not checkdoc-autofix-flag
)
2100 (eq checkdoc-autofix-flag
'never
))
2102 (checkdoc-ispell-init)
2104 (skip-chars-forward "^a-zA-Z")
2105 (let ((word nil
) (sym nil
) (case-fold-search nil
) (err nil
))
2106 (while (and (not err
) (< (point) end
))
2107 (if (save-excursion (forward-char -
1) (looking-at "[('`]"))
2108 ;; Skip lists describing meta-syntax, or bound variables
2110 (setq word
(buffer-substring-no-properties
2112 (skip-chars-forward "a-zA-Z-")
2114 sym
(intern-soft word
))
2115 (if (and sym
(or (boundp sym
) (fboundp sym
)))
2116 ;; This is probably repetitive in most cases, but not always.
2118 ;; Find out how we spell-check this word.
2120 ;; All caps w/ option th, or s tacked on the end
2121 ;; for pluralization or number.
2122 (string-match "^[A-Z][A-Z]+\\(s\\|th\\)?$" word
)
2123 (looking-at "}") ; a keymap expression
2127 (if (not (eq checkdoc-autofix-flag
'never
))
2128 (let ((lk last-input-event
))
2130 (if (not (equal last-input-event lk
))
2133 (message "Continuing..."))))
2136 (skip-chars-forward "^a-zA-Z"))
2139 ;;; Rogue space checking engine
2141 (defun checkdoc-rogue-space-check-engine (&optional start end interact
)
2142 "Return a message list if there is a line with white space at the end.
2143 If `checkdoc-autofix-flag' permits, delete that whitespace instead.
2144 If optional arguments START and END are non-nil, bound the check to
2146 Optional argument INTERACT may permit the user to fix problems on the fly."
2148 (msg nil
) s e
(f nil
))
2149 (if (not start
) (setq start
(point-min)))
2150 ;; If end is nil, it means end of buffer to search anyway
2152 ;; Check for an error if `? ' or `?\ ' is used at the end of a line.
2156 (while (and (not msg
) (re-search-forward "\\?\\\\?[ \t][ \t]*$" end t
))
2158 "Don't use `? ' at the end of a line. \
2159 News agents may remove it"
2160 s
(match-beginning 0) e
(match-end 0) f t
)
2161 ;; If interactive is passed down, give them a chance to fix things.
2162 (if (and interact
(y-or-n-p (concat msg
". Fix? ")))
2164 (checkdoc-recursive-edit msg
)
2167 (beginning-of-line)))))
2168 ;; Check for, and potentially remove whitespace appearing at the
2169 ;; end of different lines.
2172 ;; There is no documentation in the Emacs Lisp manual about this check,
2173 ;; it is intended to help clean up messy code and reduce the file size.
2174 (while (and (not msg
) (re-search-forward "[^ \t\n;]\\([ \t]+\\)$" end t
))
2175 ;; This is not a complex activity
2176 (if (checkdoc-autofix-ask-replace
2177 (match-beginning 1) (match-end 1)
2178 "White space at end of line. Remove? " "")
2180 (setq msg
"White space found at end of line"
2181 s
(match-beginning 1) e
(match-end 1))))))
2182 ;; Return an error and leave the cursor at that spot, or restore
2185 (checkdoc-create-error msg s e f
)
2189 ;;; Comment checking engine
2192 ;; We must load this to:
2193 ;; a) get symbols for compile and
2194 ;; b) determine if we have lm-history symbol which doesn't always exist
2195 (require 'lisp-mnt
))
2197 (defvar generate-autoload-cookie
)
2199 (defun checkdoc-file-comments-engine ()
2200 "Return a message list if this file does not match the Emacs standard.
2201 This checks for style only, such as the first line, Commentary:,
2202 Code:, and others referenced in the style guide."
2203 (if (featurep 'lisp-mnt
)
2206 ;; Old XEmacs don't have `lm-commentary-mark'
2207 (if (and (not (fboundp 'lm-commentary-mark
)) (boundp 'lm-commentary
))
2208 (defalias 'lm-commentary-mark
'lm-commentary
)))
2210 (let* ((f1 (file-name-nondirectory (buffer-file-name)))
2211 (fn (file-name-sans-extension f1
))
2212 (fe (substring f1
(length fn
)))
2214 (goto-char (point-min))
2215 ;; This file has been set up where ERR is a variable. Each check is
2216 ;; asked, and the function will make sure that if the user does not
2217 ;; auto-fix some error, that we still move on to the next auto-fix,
2218 ;; AND we remember the past errors.
2221 ;; Lisp Maintenance checks first
2222 ;; Was: (lm-verify) -> not flexible enough for some people
2223 ;; * Summary at the beginning of the file:
2224 (if (not (lm-summary))
2225 ;; This certifies as very complex so always ask unless
2226 ;; it's set to never
2227 (if (checkdoc-y-or-n-p "There is no first line summary! Add one? ")
2229 (goto-char (point-min))
2230 (insert ";;; " fn fe
" --- " (read-string "Summary: ") "\n"))
2231 (checkdoc-create-error
2232 "The first line should be of the form: \";;; package --- Summary\""
2233 (point-min) (save-excursion (goto-char (point-min))
2234 (line-end-position))))
2239 ;; * Commentary Section
2240 (if (not (lm-commentary-mark))
2242 (goto-char (point-min))
2245 "write\\s-+to\\s-+the\\s-+Free Software Foundation, Inc."
2247 (re-search-forward "^;;\\s-*\n\\|^\n" nil t
))
2248 ((or (re-search-forward "^;;; History" nil t
)
2249 (re-search-forward "^;;; Code" nil t
)
2250 (re-search-forward "^(require" nil t
)
2251 (re-search-forward "^(" nil t
))
2252 (beginning-of-line))
2253 (t (re-search-forward ";;; .* --- .*\n")))
2254 (if (checkdoc-y-or-n-p
2255 "You should have a \";;; Commentary:\", add one? ")
2256 (insert "\n;;; Commentary:\n;; \n\n")
2257 (checkdoc-create-error
2258 "You should have a section marked \";;; Commentary:\""
2265 ;; * History section. Say nothing if there is a file ChangeLog
2266 (if (or (not checkdoc-force-history-flag
)
2267 (file-exists-p "ChangeLog")
2268 (file-exists-p "../ChangeLog")
2269 (let ((fn 'lm-history-mark
)) ;bestill byte-compiler
2270 (and (fboundp fn
) (funcall fn
))))
2273 (goto-char (or (lm-commentary-mark) (point-min)))
2276 "write\\s-+to\\s-+the\\s-+Free Software Foundation, Inc."
2278 (re-search-forward "^;;\\s-*\n\\|^\n" nil t
))
2279 ((or (re-search-forward "^;;; Code" nil t
)
2280 (re-search-forward "^(require" nil t
)
2281 (re-search-forward "^(" nil t
))
2282 (beginning-of-line)))
2283 (if (checkdoc-y-or-n-p
2284 "You should have a \";;; History:\", add one? ")
2285 (insert "\n;;; History:\n;; \n\n")
2286 (checkdoc-create-error
2287 "You should have a section marked \";;; History:\" or use a ChangeLog"
2294 (if (not (lm-code-mark))
2297 (goto-char (point-min))
2298 ;; match ";;;###autoload" cookie to keep it with the form
2300 (while (and cont
(re-search-forward
2302 (regexp-quote generate-autoload-cookie
)
2306 (setq pos
(match-beginning 0)
2307 cont
(looking-at "require\\s-+")))
2310 "There is no ;;; Code: marker. Insert one? "))
2311 (progn (goto-char pos
)
2312 (insert ";;; Code:\n\n")
2314 (checkdoc-create-error
2315 "You should have a section marked \";;; Code:\""
2322 ;; * A footer. Not compartmentalized from lm-verify: too bad.
2323 ;; The following is partially clipped from lm-verify
2325 (goto-char (point-max))
2326 (if (not (re-search-backward
2327 (concat "^;;;[ \t]+" (regexp-quote fn
) "\\(" (regexp-quote fe
)
2328 "\\)?[ \t]+ends here[ \t]*$"
2329 "\\|^;;;[ \t]+ End of file[ \t]+"
2330 (regexp-quote fn
) "\\(" (regexp-quote fe
) "\\)?")
2332 (if (checkdoc-y-or-n-p "No identifiable footer! Add one? ")
2334 (goto-char (point-max))
2335 (insert "\n(provide '" fn
")\n\n;;; " fn fe
" ends here\n"))
2336 (checkdoc-create-error
2337 (format "The footer should be: (provide '%s)\\n;;; %s%s ends here"
2339 (1- (point-max)) (point-max)))))
2341 ;; The below checks will not return errors if the user says NO
2343 ;; Let's spellcheck the commentary section. This is the only
2344 ;; section that is easy to pick out, and it is also the most
2345 ;; visible section (with the finder).
2346 (let ((cm (lm-commentary-mark)))
2350 (let ((e (copy-marker (lm-commentary-end))))
2351 ;; Since the comments talk about Lisp, use the
2352 ;; specialized spell-checker we also used for doc
2354 (checkdoc-sentencespace-region-engine (point) e
)
2355 (checkdoc-proper-noun-region-engine (point) e
)
2356 (checkdoc-ispell-docstring-engine e
)))))
2360 ;; Generic Full-file checks (should be comment related)
2361 (checkdoc-run-hooks 'checkdoc-comment-style-hooks
)
2363 ;; Done with full file comment checks
2366 (defun checkdoc-outside-major-sexp ()
2367 "Return t if point is outside the bounds of a valid sexp."
2371 (or (progn (beginning-of-defun) (bobp))
2372 (progn (end-of-defun) (< (point) p
)))))))
2374 ;;; `error' and `message' text verifier.
2376 (defun checkdoc-message-text-search (&optional beg end
)
2377 "Search between BEG and END for a style error with message text.
2378 Optional arguments BEG and END represent the boundary of the check.
2379 The default boundary is the entire buffer."
2382 (if (not (or beg end
)) (setq beg
(point-min) end
(point-max)))
2384 (while (setq type
(checkdoc-message-text-next-string end
))
2385 (setq e
(checkdoc-message-text-engine type
)))
2388 (defun checkdoc-message-text-next-string (end)
2389 "Move cursor to the next checkable message string after point.
2390 Return the message classification.
2391 Argument END is the maximum bounds to search in."
2393 (while (and (not return
)
2395 "(\\s-*\\(\\(\\w\\|\\s_\\)*error\\|\
2396 \\(\\w\\|\\s_\\)*y-or-n-p\\(-with-timeout\\)?\
2397 \\|checkdoc-autofix-ask-replace\\)[ \t\n]+" end t
))
2398 (let* ((fn (match-string 1))
2399 (type (cond ((string-match "error" fn
)
2402 (if (string-match "checkdoc-autofix-ask-replace" fn
)
2403 (progn (forward-sexp 2)
2404 (skip-chars-forward " \t\n")))
2405 (if (and (eq type
'y-or-n-p
)
2406 (looking-at "(format[ \t\n]+"))
2407 (goto-char (match-end 0)))
2408 (skip-chars-forward " \t\n")
2409 (if (not (looking-at "\""))
2411 (setq return type
))))
2414 (defun checkdoc-message-text-engine (&optional type
)
2415 "Return or fix errors found in strings passed to a message display function.
2416 According to the documentation for the function `error', the error list
2417 should not end with a period, and should start with a capital letter.
2418 The function `y-or-n-p' has similar constraints.
2419 Argument TYPE specifies the type of question, such as `error or `y-or-n-p."
2420 ;; If type is nil, then attempt to derive it.
2424 (if (looking-at "(format")
2427 (cond ((looking-at "(error")
2430 (let ((case-fold-search nil
))
2432 ;; From the documentation of the symbol `error':
2433 ;; In Emacs, the convention is that error messages start with a capital
2434 ;; letter but *do not* end with a period. Please follow this convention
2435 ;; for the sake of consistency.
2436 (if (and (save-excursion (forward-char 1)
2437 (looking-at "[a-z]\\w+"))
2438 (not (checkdoc-autofix-ask-replace
2439 (match-beginning 0) (match-end 0)
2440 "Capitalize your message text? "
2441 (capitalize (match-string 0))
2443 (checkdoc-create-error
2444 "Messages should start with a capital letter"
2445 (match-beginning 0) (match-end 0))
2447 ;; In general, sentences should have two spaces after the period.
2448 (checkdoc-sentencespace-region-engine (point)
2449 (save-excursion (forward-sexp 1)
2451 ;; Look for proper nouns in this region too.
2452 (checkdoc-proper-noun-region-engine (point)
2453 (save-excursion (forward-sexp 1)
2455 ;; Here are message type specific questions.
2456 (if (and (eq type
'error
)
2457 (save-excursion (forward-sexp 1)
2460 (not (checkdoc-autofix-ask-replace (match-beginning 0)
2462 "Remove period from error? "
2465 (checkdoc-create-error
2466 "Error messages should *not* end with a period"
2467 (match-beginning 0) (match-end 0))
2469 ;; `y-or-n-p' documentation explicitly says:
2470 ;; It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
2471 ;; I added the ? requirement. Without it, it is unclear that we
2472 ;; ask a question and it appears to be an undocumented style.
2473 (if (eq type
'y-or-n-p
)
2474 (if (not (save-excursion (forward-sexp 1)
2476 (not (looking-at "\\? "))))
2478 (if (save-excursion (forward-sexp 1)
2481 ;; If we see a ?, then replace with "? ".
2482 (if (checkdoc-autofix-ask-replace
2483 (match-beginning 0) (match-end 0)
2484 "`y-or-n-p' argument should end with \"? \". Fix? "
2487 (checkdoc-create-error
2488 "`y-or-n-p' argument should end with \"? \""
2489 (match-beginning 0) (match-end 0)))
2490 (if (save-excursion (forward-sexp 1)
2493 (if (checkdoc-autofix-ask-replace
2494 (match-beginning 0) (match-end 0)
2495 "`y-or-n-p' argument should end with \"? \". Fix? "
2498 (checkdoc-create-error
2499 "`y-or-n-p' argument should end with \"? \""
2500 (match-beginning 0) (match-end 0)))
2501 (if (and ;; if this isn't true, we have a problem.
2502 (save-excursion (forward-sexp 1)
2505 (checkdoc-autofix-ask-replace
2506 (match-beginning 0) (match-end 0)
2507 "`y-or-n-p' argument should end with \"? \". Fix? "
2510 (checkdoc-create-error
2511 "`y-or-n-p' argument should end with \"? \""
2512 (match-beginning 0) (match-end 0)))))))
2513 ;; Now, let's just run the spell checker on this guy.
2514 (checkdoc-ispell-docstring-engine (save-excursion (forward-sexp 1)
2518 ;;; Auto-fix helper functions
2520 (defun checkdoc-y-or-n-p (question)
2521 "Like `y-or-n-p', but pays attention to `checkdoc-autofix-flag'.
2522 Argument QUESTION is the prompt passed to `y-or-n-p'."
2524 (if (or (not checkdoc-autofix-flag
)
2525 (eq checkdoc-autofix-flag
'never
))
2527 (y-or-n-p question
))
2528 (if (eq checkdoc-autofix-flag
'automatic-then-never
)
2529 (setq checkdoc-autofix-flag
'never
))))
2531 (defun checkdoc-autofix-ask-replace (start end question replacewith
2533 "Highlight between START and END and queries the user with QUESTION.
2534 If the user says yes, or if `checkdoc-autofix-flag' permits, replace
2535 the region marked by START and END with REPLACEWITH. If optional flag
2536 COMPLEX is non-nil, then we may ask the user a question. See the
2537 documentation for `checkdoc-autofix-flag' for details.
2539 If a section is auto-replaced without asking the user, this function
2540 will pause near the fixed code so the user will briefly see what
2543 This function returns non-nil if the text was replaced.
2545 This function will not modify `match-data'."
2546 (if (and checkdoc-autofix-flag
2547 (not (eq checkdoc-autofix-flag
'never
)))
2548 (let ((o (checkdoc-make-overlay start end
))
2553 (checkdoc-overlay-put o
'face
'highlight
)
2554 (if (or (eq checkdoc-autofix-flag
'automatic
)
2555 (eq checkdoc-autofix-flag
'automatic-then-never
)
2556 (and (eq checkdoc-autofix-flag
'semiautomatic
)
2558 (and (or (eq checkdoc-autofix-flag
'query
) complex
)
2559 (y-or-n-p question
)))
2562 ;; On the off chance this is automatic, display
2563 ;; the question anyway so the user knows what's
2565 (if checkdoc-bouncy-flag
(message "%s -> done" question
))
2566 (delete-region start end
)
2567 (insert replacewith
)
2568 (if checkdoc-bouncy-flag
(sit-for 0))
2570 (checkdoc-delete-overlay o
)
2571 (set-match-data md
))
2572 (checkdoc-delete-overlay o
)
2573 (set-match-data md
))
2574 (if (eq checkdoc-autofix-flag
'automatic-then-never
)
2575 (setq checkdoc-autofix-flag
'never
))
2578 ;;; Warning management
2580 (defvar checkdoc-output-font-lock-keywords
2581 '(("^\\*\\*\\* \\(.+\\.el\\): \\([^ \n]+\\)"
2582 (1 font-lock-function-name-face
)
2583 (2 font-lock-comment-face
)))
2584 "Keywords used to highlight a checkdoc diagnostic buffer.")
2586 (defvar checkdoc-output-error-regex-alist
2587 '(("^\\(.+\\.el\\):\\([0-9]+\\): " 1 2)))
2589 (defvar checkdoc-pending-errors nil
2590 "Non-nil when there are errors that have not been displayed yet.")
2592 (define-derived-mode checkdoc-output-mode compilation-mode
"Checkdoc"
2593 "Set up the major mode for the buffer containing the list of errors."
2594 (set (make-local-variable 'compilation-error-regexp-alist
)
2595 checkdoc-output-error-regex-alist
)
2596 (set (make-local-variable 'compilation-mode-font-lock-keywords
)
2597 checkdoc-output-font-lock-keywords
))
2599 (defun checkdoc-buffer-label ()
2600 "The name to use for a checkdoc buffer in the error list."
2601 (if (buffer-file-name)
2602 (file-relative-name (buffer-file-name))
2603 (concat "#<buffer "(buffer-name) ">")))
2605 (defun checkdoc-start-section (check-type)
2606 "Initialize the checkdoc diagnostic buffer for a pass.
2607 Create the header so that the string CHECK-TYPE is displayed as the
2608 function called to create the messages."
2609 (let ((dir default-directory
)
2610 (label (checkdoc-buffer-label)))
2611 (with-current-buffer (get-buffer-create checkdoc-diagnostic-buffer
)
2612 (checkdoc-output-mode)
2613 (setq default-directory dir
)
2614 (goto-char (point-max))
2615 (let ((inhibit-read-only t
))
2616 (insert "\n\n\C-l\n*** " label
": "
2617 check-type
" V " checkdoc-version
)))))
2619 (defun checkdoc-error (point msg
)
2620 "Store POINT and MSG as errors in the checkdoc diagnostic buffer."
2621 (setq checkdoc-pending-errors t
)
2622 (let ((text (list "\n" (checkdoc-buffer-label) ":"
2624 (count-lines (point-min) (or point
(point-min))))
2626 (with-current-buffer (get-buffer checkdoc-diagnostic-buffer
)
2627 (goto-char (point-max))
2628 (let ((inhibit-read-only t
))
2629 (apply 'insert text
)))))
2631 (defun checkdoc-show-diagnostics ()
2632 "Display the checkdoc diagnostic buffer in a temporary window."
2633 (if checkdoc-pending-errors
2634 (let ((b (get-buffer checkdoc-diagnostic-buffer
)))
2635 (if b
(progn (pop-to-buffer b
)
2636 (goto-char (point-max))
2637 (re-search-backward "\C-l" nil t
)
2642 (setq checkdoc-pending-errors nil
)
2645 (custom-add-option 'emacs-lisp-mode-hook
'checkdoc-minor-mode
)
2647 (add-to-list 'debug-ignored-errors
2648 "Argument `.*' should appear (as .*) in the doc string")
2649 (add-to-list 'debug-ignored-errors
2650 "Lisp symbol `.*' should appear in quotes")
2651 (add-to-list 'debug-ignored-errors
"Disambiguate .* by preceding .*")
2655 ;;; checkdoc.el ends here