(defvar checkdoc-version "0.6.1"
"Release version of checkdoc you are currently running.")
(eval-and-compile
(condition-case ()
(require 'custom)
(error nil))
(if (and (featurep 'custom) (fboundp 'custom-declare-variable))
nil (defmacro defgroup (&rest args)
nil)
(defmacro custom-add-option (&rest args)
nil)
(defmacro defcustom (var value doc &rest args)
`(defvar ,var ,value ,doc))))
(defvar compilation-error-regexp-alist)
(defvar compilation-mode-font-lock-keywords)
(defgroup checkdoc nil
"Support for doc string checking in Emacs Lisp."
:prefix "checkdoc"
:group 'lisp
:version "20.3")
(defcustom checkdoc-autofix-flag 'semiautomatic
"Non-nil means attempt auto-fixing of doc strings.
If this value is the symbol `query', then the user is queried before
any change is made. If the value is `automatic', then all changes are
made without asking unless the change is very-complex. If the value
is `semiautomatic' or any other value, then simple fixes are made
without asking, and complex changes are made by asking the user first.
The value `never' is the same as nil, never ask or change anything."
:group 'checkdoc
:type '(choice (const automatic)
(const query)
(const never)
(other :tag "semiautomatic" semiautomatic)))
(defcustom checkdoc-bouncy-flag t
"Non-nil means to \"bounce\" to auto-fix locations.
Setting this to nil will silently make fixes that require no user
interaction. See `checkdoc-autofix-flag' for auto-fixing details."
:group 'checkdoc
:type 'boolean)
(defcustom checkdoc-force-docstrings-flag t
"Non-nil means that all checkable definitions should have documentation.
Style guide dictates that interactive functions MUST have documentation,
and that it's good but not required practice to make non user visible items
have doc strings."
:group 'checkdoc
:type 'boolean)
(put 'checkdoc-force-docstrings-flag 'safe-local-variable 'booleanp)
(defcustom checkdoc-force-history-flag t
"Non-nil means that files should have a History section or ChangeLog file.
This helps document the evolution of, and recent changes to, the package."
:group 'checkdoc
:type 'boolean)
(defcustom checkdoc-permit-comma-termination-flag nil
"Non-nil means the first line of a docstring may end with a comma.
Ordinarily, a full sentence is required. This may be misleading when
there is a substantial caveat to the one-line description -- the comma
should be used when the first part could stand alone as a sentence, but
it indicates that a modifying clause follows."
:group 'checkdoc
:type 'boolean)
(put 'checkdoc-permit-comma-termination-flag 'safe-local-variable 'booleanp)
(defcustom checkdoc-spellcheck-documentation-flag nil
"Non-nil means run Ispell on text based on value.
This is automatically set to nil if Ispell does not exist on your
system. Possible values are:
nil - Don't spell-check during basic style checks.
defun - Spell-check when style checking a single defun
buffer - Spell-check when style checking the whole buffer
interactive - Spell-check during any interactive check.
t - Always spell-check"
:group 'checkdoc
:type '(choice (const nil)
(const defun)
(const buffer)
(const interactive)
(const t)))
(defvar checkdoc-ispell-lisp-words
'("alist" "emacs" "etags" "iff" "keymap" "paren" "regexp" "sexp" "xemacs")
"List of words that are correct when spell-checking Lisp documentation.")
(defcustom checkdoc-max-keyref-before-warn 10
"The number of \\ [command-to-keystroke] tokens allowed in a doc string.
Any more than this and a warning is generated suggesting that the construct
\\ {keymap} be used instead."
:group 'checkdoc
:type 'integer)
(defcustom checkdoc-arguments-in-order-flag t
"Non-nil means warn if arguments appear out of order.
Setting this to nil will mean only checking that all the arguments
appear in the proper form in the documentation, not that they are in
the same order as they appear in the argument list. No mention is
made in the style guide relating to order."
:group 'checkdoc
:type 'boolean)
(defvar checkdoc-style-hooks nil
"Hooks called after the standard style check is completed.
All hooks must return nil or a string representing the error found.
Useful for adding new user implemented commands.
Each hook is called with two parameters, (DEFUNINFO ENDPOINT).
DEFUNINFO is the return value of `checkdoc-defun-info'. ENDPOINT is the
location of end of the documentation string.")
(defvar checkdoc-comment-style-hooks nil
"Hooks called after the standard comment style check is completed.
Must return nil if no errors are found, or a string describing the
problem discovered. This is useful for adding additional checks.")
(defvar checkdoc-diagnostic-buffer "*Style Warnings*"
"Name of warning message buffer.")
(defvar checkdoc-defun-regexp
"^(def\\(un\\|var\\|custom\\|macro\\|const\\|subst\\|advice\\)\
\\s-+\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]+"
"Regular expression used to identify a defun.
A search leaves the cursor in front of the parameter list.")
(defcustom checkdoc-verb-check-experimental-flag t
"Non-nil means to attempt to check the voice of the doc string.
This check keys off some words which are commonly misused. See the
variable `checkdoc-common-verbs-wrong-voice' if you wish to add your own."
:group 'checkdoc
:type 'boolean)
(defvar checkdoc-generate-compile-warnings-flag nil
"Non-nil means generate warnings in a buffer for browsing.
Do not set this by hand, use a function like `checkdoc-current-buffer'
with a universal argument.")
(defcustom checkdoc-symbol-words nil
"A list of symbols which also happen to make good words.
These symbol-words are ignored when unquoted symbols are searched for.
This should be set in an Emacs Lisp file's local variables."
:group 'checkdoc
:type '(repeat (symbol :tag "Word")))
(defvar checkdoc-proper-noun-list
'("ispell" "xemacs" "emacs" "lisp")
"List of words (not capitalized) which should be capitalized.")
(defvar checkdoc-proper-noun-regexp
(let ((expr "\\_<\\(")
(l checkdoc-proper-noun-list))
(while l
(setq expr (concat expr (car l) (if (cdr l) "\\|" ""))
l (cdr l)))
(concat expr "\\)\\_>"))
"Regular expression derived from `checkdoc-proper-noun-regexp'.")
(defvar checkdoc-common-verbs-regexp nil
"Regular expression derived from `checkdoc-common-verbs-regexp'.")
(defvar checkdoc-common-verbs-wrong-voice
'(("adds" . "add")
("allows" . "allow")
("appends" . "append")
("applies" . "apply")
("arranges" . "arrange")
("brings" . "bring")
("calls" . "call")
("catches" . "catch")
("changes" . "change")
("checks" . "check")
("contains" . "contain")
("converts" . "convert")
("creates" . "create")
("destroys" . "destroy")
("disables" . "disable")
("executes" . "execute")
("evals" . "evaluate")
("evaluates" . "evaluate")
("finds" . "find")
("forces" . "force")
("gathers" . "gather")
("generates" . "generate")
("goes" . "go")
("guesses" . "guess")
("highlights" . "highlight")
("holds" . "hold")
("ignores" . "ignore")
("indents" . "indent")
("initializes" . "initialize")
("inserts" . "insert")
("installs" . "install")
("investigates" . "investigate")
("keeps" . "keep")
("kills" . "kill")
("leaves" . "leave")
("lets" . "let")
("loads" . "load")
("looks" . "look")
("makes" . "make")
("marks" . "mark")
("matches" . "match")
("moves" . "move")
("notifies" . "notify")
("offers" . "offer")
("parses" . "parse")
("performs" . "perform")
("prepares" . "prepare")
("prepends" . "prepend")
("reads" . "read")
("raises" . "raise")
("removes" . "remove")
("replaces" . "replace")
("resets" . "reset")
("restores" . "restore")
("returns" . "return")
("runs" . "run")
("saves" . "save")
("says" . "say")
("searches" . "search")
("selects" . "select")
("sets" . "set")
("sex" . "s*x")
("shows" . "show")
("signifies" . "signify")
("sorts" . "sort")
("starts" . "start")
("stores" . "store")
("switches" . "switch")
("tells" . "tell")
("tests" . "test")
("toggles" . "toggle")
("tries" . "try")
("turns" . "turn")
("undoes" . "undo")
("unloads" . "unload")
("unmarks" . "unmark")
("updates" . "update")
("uses" . "use")
("yanks" . "yank")
)
"Alist of common words in the wrong voice and what should be used instead.
Set `checkdoc-verb-check-experimental-flag' to nil to avoid this costly
and experimental check. Do not modify this list without setting
the value of `checkdoc-common-verbs-regexp' to nil which cause it to
be re-created.")
(defvar checkdoc-syntax-table nil
"Syntax table used by checkdoc in document strings.")
(if checkdoc-syntax-table
nil
(setq checkdoc-syntax-table (copy-syntax-table emacs-lisp-mode-syntax-table))
(modify-syntax-entry ?- "w" checkdoc-syntax-table)
)
(defalias 'checkdoc-make-overlay
(if (featurep 'xemacs) 'make-extent 'make-overlay))
(defalias 'checkdoc-overlay-put
(if (featurep 'xemacs) 'set-extent-property 'overlay-put))
(defalias 'checkdoc-delete-overlay
(if (featurep 'xemacs) 'delete-extent 'delete-overlay))
(defalias 'checkdoc-overlay-start
(if (featurep 'xemacs) 'extent-start 'overlay-start))
(defalias 'checkdoc-overlay-end
(if (featurep 'xemacs) 'extent-end 'overlay-end))
(defalias 'checkdoc-mode-line-update
(if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update))
(defalias 'checkdoc-char=
(if (featurep 'xemacs) 'char= '=))
(defun checkdoc ()
"Interactively check the entire buffer for style errors.
The current status of the check will be displayed in a buffer which
the users will view as each check is completed."
(interactive)
(let ((status (list "Checking..." "-" "-" "-"))
(checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(buffer interactive t))))
(checkdoc-autofix-flag (if (or (not checkdoc-autofix-flag)
(eq checkdoc-autofix-flag 'never))
'query
checkdoc-autofix-flag))
tmp)
(checkdoc-display-status-buffer status)
(if (not buffer-file-name)
(setcar status "Not checked")
(if (checkdoc-file-comments-engine)
(setcar status "Errors")
(setcar status "Ok")))
(setcar (cdr status) "Checking...")
(checkdoc-display-status-buffer status)
(setq tmp (checkdoc-interactive nil t))
(if tmp
(setcar (cdr status) (format "%d Errors" (length tmp)))
(setcar (cdr status) "Ok"))
(setcar (cdr (cdr status)) "Checking...")
(checkdoc-display-status-buffer status)
(if (setq tmp (checkdoc-message-interactive nil t))
(setcar (cdr (cdr status)) (format "%d Errors" (length tmp)))
(setcar (cdr (cdr status)) "Ok"))
(setcar (cdr (cdr (cdr status))) "Checking...")
(checkdoc-display-status-buffer status)
(if (condition-case nil
(checkdoc-rogue-spaces nil t)
(error t))
(setcar (cdr (cdr (cdr status))) "Errors")
(setcar (cdr (cdr (cdr status))) "Ok"))
(checkdoc-display-status-buffer status)))
(defun checkdoc-display-status-buffer (check)
"Display and update the status buffer for the current checkdoc mode.
CHECK is a list of four strings stating the current status of each
test; the nth string describes the status of the nth test."
(let (temp-buffer-setup-hook)
(with-output-to-temp-buffer " *Checkdoc Status*"
(princ-list
"Buffer comments and tags: " (nth 0 check) "\n"
"Documentation style: " (nth 1 check) "\n"
"Message/Query text style: " (nth 2 check) "\n"
"Unwanted Spaces: " (nth 3 check)
)))
(shrink-window-if-larger-than-buffer
(get-buffer-window " *Checkdoc Status*"))
(message nil)
(sit-for 0))
(defun checkdoc-interactive (&optional start-here showstatus)
"Interactively check the current buffer for doc string errors.
Prefix argument START-HERE will start the checking from the current
point, otherwise the check starts at the beginning of the current
buffer. Allows navigation forward and backwards through document
errors. Does not check for comment or space warnings.
Optional argument SHOWSTATUS indicates that we should update the
checkdoc status window instead of the usual behavior."
(interactive "P")
(let ((checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(interactive t)))))
(prog1
(checkdoc-interactive-loop start-here showstatus
'checkdoc-next-error)
(checkdoc-interactive-ispell-loop start-here))))
(defun checkdoc-message-interactive (&optional start-here showstatus)
"Interactively check the current buffer for message string errors.
Prefix argument START-HERE will start the checking from the current
point, otherwise the check starts at the beginning of the current
buffer. Allows navigation forward and backwards through document
errors. Does not check for comment or space warnings.
Optional argument SHOWSTATUS indicates that we should update the
checkdoc status window instead of the usual behavior."
(interactive "P")
(let ((checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(interactive t)))))
(prog1
(checkdoc-interactive-loop start-here showstatus
'checkdoc-next-message-error)
(checkdoc-message-interactive-ispell-loop start-here))))
(defun checkdoc-interactive-loop (start-here showstatus findfunc)
"Interactively loop over all errors that can be found by a given method.
If START-HERE is nil, searching starts at the beginning of the current
buffer, otherwise searching starts at START-HERE. SHOWSTATUS
expresses the verbosity of the search, and whether ending the search
will auto-exit this function.
FINDFUNC is a symbol representing a function that will position the
cursor, and return error message text to present to the user. It is
assumed that the cursor will stop just before a major sexp, which will
be highlighted to present the user with feedback as to the offending
style."
(let* ((begin (prog1 (point)
(if (not start-here) (goto-char (point-min)))))
(checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(buffer interactive t))))
(err-list (list (funcall findfunc nil)))
(cdo nil)
(returnme nil)
c)
(save-window-excursion
(if (not (car err-list)) (setq err-list nil))
(beginning-of-defun)
(while err-list
(goto-char (cdr (car err-list)))
(if (stringp (car (car err-list)))
(setq cdo (save-excursion (checkdoc-make-overlay
(point) (progn (forward-sexp 1)
(point)))))
(setq cdo (checkdoc-make-overlay
(checkdoc-error-start (car (car err-list)))
(checkdoc-error-end (car (car err-list))))))
(unwind-protect
(progn
(checkdoc-overlay-put cdo 'face 'highlight)
(sit-for 0)
(if (and (looking-at "\"")
(not (pos-visible-in-window-p
(save-excursion (forward-sexp 1) (point))
(selected-window))))
(let ((l (count-lines (point)
(save-excursion
(forward-sexp 1) (point)))))
(if (> l (window-height))
(recenter 1)
(recenter (/ (- (window-height) l) 2))))
(recenter))
(message "%s (C-h,%se,n,p,q)" (checkdoc-error-text
(car (car err-list)))
(if (checkdoc-error-unfixable (car (car err-list)))
"" "f,"))
(save-excursion
(goto-char (checkdoc-error-start (car (car err-list))))
(if (not (pos-visible-in-window-p))
(recenter (- (window-height) 2)))
(setq c (read-event)))
(if (not (integerp c)) (setq c ??))
(cond
((checkdoc-char= c ?\C-g) (signal 'quit nil))
((or (checkdoc-char= c ?y) (checkdoc-char= c ?f))
(checkdoc-delete-overlay cdo)
(setq cdo nil)
(goto-char (cdr (car err-list)))
(let ((checkdoc-autofix-flag 'automatic-then-never)
(fixed nil))
(funcall findfunc t)
(setq fixed (not (eq checkdoc-autofix-flag
'automatic-then-never)))
(if (not fixed)
(progn
(message "A Fix was not available.")
(sit-for 2))
(setq err-list (cdr err-list))))
(beginning-of-defun)
(let ((ne (funcall findfunc nil)))
(if ne
(setq err-list (cons ne err-list))
(cond ((not err-list)
(message "No More Stylistic Errors.")
(sit-for 2))
(t
(message
"No Additional style errors. Continuing...")
(sit-for 2))))))
((or (checkdoc-char= c ?n) (checkdoc-char= c ?\s))
(let ((ne (funcall findfunc nil)))
(if (not ne)
(if showstatus
(setq returnme err-list
err-list nil)
(if (not err-list)
(message "No More Stylistic Errors.")
(message "No Additional style errors. Continuing..."))
(sit-for 2))
(setq err-list (cons ne err-list)))))
((or (checkdoc-char= c ?p) (checkdoc-char= c ?\C-?))
(if (/= (length err-list) 1)
(progn
(setq err-list (cdr err-list))
(goto-char (cdr (car err-list)))
(beginning-of-defun))
(message "No Previous Errors.")
(sit-for 2)))
((checkdoc-char= c ?e)
(checkdoc-recursive-edit
(checkdoc-error-text (car (car err-list))))
(checkdoc-delete-overlay cdo)
(setq err-list (cdr err-list)) (beginning-of-defun)
(let ((ne (funcall findfunc nil)))
(if (not ne)
(if showstatus
(setq returnme err-list
err-list nil)
(message "No More Stylistic Errors.")
(sit-for 2))
(setq err-list (cons ne err-list)))))
((checkdoc-char= c ?q)
(setq returnme err-list
err-list nil
begin (point)))
(t
(if (get-buffer-window "*Checkdoc Help*")
(progn
(delete-window (get-buffer-window "*Checkdoc Help*"))
(kill-buffer "*Checkdoc Help*"))
(with-output-to-temp-buffer "*Checkdoc Help*"
(princ-list
"Checkdoc Keyboard Summary:\n"
(if (checkdoc-error-unfixable (car (car err-list)))
""
(concat
"f, y - auto Fix this warning without asking (if\
available.)\n"
" Very complex operations will still query.\n")
)
"e - Enter recursive Edit. Press C-M-c to exit.\n"
"SPC, n - skip to the Next error.\n"
"DEL, p - skip to the Previous error.\n"
"q - Quit checkdoc.\n"
"C-h - Toggle this help buffer."))
(shrink-window-if-larger-than-buffer
(get-buffer-window "*Checkdoc Help*"))))))
(if cdo (checkdoc-delete-overlay cdo)))))
(goto-char begin)
(if (get-buffer "*Checkdoc Help*") (kill-buffer "*Checkdoc Help*"))
(message "Checkdoc: Done.")
returnme))
(defun checkdoc-interactive-ispell-loop (start-here)
"Interactively spell check doc strings in the current buffer.
If START-HERE is nil, searching starts at the beginning of the current
buffer, otherwise searching starts at START-HERE."
(when checkdoc-spellcheck-documentation-flag
(save-excursion
(if start-here
(beginning-of-defun)
(goto-char (point-min)))
(while (checkdoc-next-docstring)
(message "Searching for doc string spell error...%d%%"
(/ (* 100 (point)) (point-max)))
(if (looking-at "\"")
(checkdoc-ispell-docstring-engine
(save-excursion (forward-sexp 1) (point-marker)))))
(message "Checkdoc: Done."))))
(defun checkdoc-message-interactive-ispell-loop (start-here)
"Interactively spell check messages in the current buffer.
If START-HERE is nil, searching starts at the beginning of the current
buffer, otherwise searching starts at START-HERE."
(when checkdoc-spellcheck-documentation-flag
(save-excursion
(if start-here
(beginning-of-defun)
(goto-char (point-min)))
(while (checkdoc-message-text-next-string (point-max))
(message "Searching for message string spell error...%d%%"
(/ (* 100 (point)) (point-max)))
(if (looking-at "\"")
(checkdoc-ispell-docstring-engine
(save-excursion (forward-sexp 1) (point-marker)))))
(message "Checkdoc: Done."))))
(defun checkdoc-next-error (enable-fix)
"Find and return the next checkdoc error list, or nil.
Only documentation strings are checked.
An error list is of the form (WARNING . POSITION) where WARNING is the
warning text, and POSITION is the point in the buffer where the error
was found. We can use points and not markers because we promise not
to edit the buffer before point without re-executing this check.
Argument ENABLE-FIX will enable auto-fixing while looking for the next
error. This argument assumes that the cursor is already positioned to
perform the fix."
(if enable-fix
(checkdoc-this-string-valid)
(let ((msg nil) (p (point))
(checkdoc-autofix-flag nil))
(condition-case nil
(while (and (not msg) (checkdoc-next-docstring))
(message "Searching for doc string error...%d%%"
(/ (* 100 (point)) (point-max)))
(if (setq msg (checkdoc-this-string-valid))
(setq msg (cons msg (point)))))
(quit (goto-char p)))
msg)))
(defun checkdoc-next-message-error (enable-fix)
"Find and return the next checkdoc message related error list, or nil.
Only text for error and `y-or-n-p' strings are checked. See
`checkdoc-next-error' for details on the return value.
Argument ENABLE-FIX turns on the auto-fix feature. This argument
assumes that the cursor is already positioned to perform the fix."
(if enable-fix
(checkdoc-message-text-engine)
(let ((msg nil) (p (point)) (type nil)
(checkdoc-autofix-flag nil))
(condition-case nil
(while (and (not msg)
(setq type
(checkdoc-message-text-next-string (point-max))))
(message "Searching for message string error...%d%%"
(/ (* 100 (point)) (point-max)))
(if (setq msg (checkdoc-message-text-engine type))
(setq msg (cons msg (point)))))
(quit (goto-char p)))
msg)))
(defun checkdoc-recursive-edit (msg)
"Enter recursive edit to permit a user to fix some error checkdoc has found.
MSG is the error that was found, which is displayed in a help buffer."
(with-output-to-temp-buffer "*Checkdoc Help*"
(princ-list
"Error message:\n " msg
"\n\nEdit to fix this problem, and press C-M-c to continue."))
(shrink-window-if-larger-than-buffer
(get-buffer-window "*Checkdoc Help*"))
(message "When you're done editing press C-M-c to continue.")
(unwind-protect
(recursive-edit)
(if (get-buffer-window "*Checkdoc Help*")
(progn
(delete-window (get-buffer-window "*Checkdoc Help*"))
(kill-buffer "*Checkdoc Help*")))))
(defun checkdoc-eval-current-buffer ()
"Evaluate and check documentation for the current buffer.
Evaluation is done first because good documentation for something that
doesn't work is just not useful. Comments, doc strings, and rogue
spacing are all verified."
(interactive)
(eval-buffer nil)
(checkdoc-current-buffer t))
(defun checkdoc-current-buffer (&optional take-notes)
"Check current buffer for document, comment, error style, and rogue spaces.
With a prefix argument (in Lisp, the argument TAKE-NOTES),
store all errors found in a warnings buffer,
otherwise stop after the first error."
(interactive "P")
(if (interactive-p) (message "Checking buffer for style..."))
(let ((checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(buffer t))))
(checkdoc-autofix-flag (if take-notes 'never
checkdoc-autofix-flag))
(checkdoc-generate-compile-warnings-flag
(or take-notes checkdoc-generate-compile-warnings-flag)))
(if take-notes
(checkdoc-start-section "checkdoc-current-buffer"))
(or (and buffer-file-name (checkdoc-comments))
(checkdoc-start)
(checkdoc-message-text)
(checkdoc-rogue-spaces)
(not (interactive-p))
(if take-notes (checkdoc-show-diagnostics))
(message "Checking buffer for style...Done."))))
(defun checkdoc-start (&optional take-notes)
"Start scanning the current buffer for documentation string style errors.
Only documentation strings are checked.
Use `checkdoc-continue' to continue checking if an error cannot be fixed.
Prefix argument TAKE-NOTES means to collect all the warning messages into
a separate buffer."
(interactive "P")
(let ((p (point)))
(goto-char (point-min))
(if (and take-notes (interactive-p))
(checkdoc-start-section "checkdoc-start"))
(checkdoc-continue take-notes)
(goto-char p)
nil))
(defun checkdoc-continue (&optional take-notes)
"Find the next doc string in the current buffer which has a style error.
Prefix argument TAKE-NOTES means to continue through the whole buffer and
save warnings in a separate buffer. Second optional argument START-POINT
is the starting location. If this is nil, `point-min' is used instead."
(interactive "P")
(let ((wrong nil) (msg nil)
(checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(buffer t))))
(checkdoc-autofix-flag (if take-notes 'never
checkdoc-autofix-flag))
(checkdoc-generate-compile-warnings-flag
(or take-notes checkdoc-generate-compile-warnings-flag)))
(save-excursion
(while (and (not wrong) (checkdoc-next-docstring))
(setq msg (checkdoc-this-string-valid))
(if msg (setq wrong (point)))))
(if wrong
(progn
(goto-char wrong)
(if (not take-notes)
(error "%s" (checkdoc-error-text msg)))))
(checkdoc-show-diagnostics)
(if (interactive-p)
(message "No style warnings."))))
(defun checkdoc-next-docstring ()
"Move to the next doc string after point, and return t.
Return nil if there are no more doc strings."
(if (not (re-search-forward checkdoc-defun-regexp nil t))
nil
(forward-sexp 1)
(skip-chars-forward " \n\t")
t))
(defun checkdoc-comments (&optional take-notes)
"Find missing comment sections in the current Emacs Lisp file.
Prefix argument TAKE-NOTES non-nil means to save warnings in a
separate buffer. Otherwise print a message. This returns the error
if there is one."
(interactive "P")
(if take-notes (checkdoc-start-section "checkdoc-comments"))
(if (not buffer-file-name)
(error "Can only check comments for a file buffer"))
(let* ((checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(buffer t))))
(checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag))
(e (checkdoc-file-comments-engine))
(checkdoc-generate-compile-warnings-flag
(or take-notes checkdoc-generate-compile-warnings-flag)))
(if e (error "%s" (checkdoc-error-text e)))
(checkdoc-show-diagnostics)
e))
(defun checkdoc-rogue-spaces (&optional take-notes interact)
"Find extra spaces at the end of lines in the current file.
Prefix argument TAKE-NOTES non-nil means to save warnings in a
separate buffer. Otherwise print a message. This returns the error
if there is one.
Optional argument INTERACT permits more interactive fixing."
(interactive "P")
(if take-notes (checkdoc-start-section "checkdoc-rogue-spaces"))
(let* ((checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag))
(e (checkdoc-rogue-space-check-engine nil nil interact))
(checkdoc-generate-compile-warnings-flag
(or take-notes checkdoc-generate-compile-warnings-flag)))
(if (not (interactive-p))
e
(if e
(message (checkdoc-error-text e))
(checkdoc-show-diagnostics)
(message "Space Check: done.")))))
(defun checkdoc-message-text (&optional take-notes)
"Scan the buffer for occurrences of the error function, and verify text.
Optional argument TAKE-NOTES causes all errors to be logged."
(interactive "P")
(if take-notes (checkdoc-start-section "checkdoc-message-text"))
(let* ((p (point)) e
(checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag))
(checkdoc-generate-compile-warnings-flag
(or take-notes checkdoc-generate-compile-warnings-flag)))
(setq e (checkdoc-message-text-search))
(if (not (interactive-p))
e
(if e
(error "%s" (checkdoc-error-text e))
(checkdoc-show-diagnostics)))
(goto-char p))
(if (interactive-p) (message "Checking interactive message text...done.")))
(defun checkdoc-eval-defun ()
"Evaluate the current form with `eval-defun' and check its documentation.
Evaluation is done first so the form will be read before the
documentation is checked. If there is a documentation error, then the display
of what was evaluated will be overwritten by the diagnostic message."
(interactive)
(call-interactively 'eval-defun)
(checkdoc-defun))
(defun checkdoc-defun (&optional no-error)
"Examine the doc string of the function or variable under point.
Call `error' if the doc string has problems. If NO-ERROR is
non-nil, then do not call error, but call `message' instead.
If the doc string passes the test, then check the function for rogue white
space at the end of each line."
(interactive)
(save-excursion
(beginning-of-defun)
(if (not (looking-at checkdoc-defun-regexp))
nil
(goto-char (match-end 0))
(forward-sexp 1)
(skip-chars-forward " \n\t")
(let* ((checkdoc-spellcheck-documentation-flag
(car (memq checkdoc-spellcheck-documentation-flag
'(defun t))))
(beg (save-excursion (beginning-of-defun) (point)))
(end (save-excursion (end-of-defun) (point)))
(msg (checkdoc-this-string-valid)))
(if msg (if no-error
(message (checkdoc-error-text msg))
(error "%s" (checkdoc-error-text msg)))
(setq msg (checkdoc-message-text-search beg end))
(if msg (if no-error
(message (checkdoc-error-text msg))
(error "%s" (checkdoc-error-text msg)))
(setq msg (checkdoc-rogue-space-check-engine beg end))
(if msg (if no-error
(message (checkdoc-error-text msg))
(error "%s" (checkdoc-error-text msg))))))
(if (interactive-p) (message "Checkdoc: done."))))))
(defun checkdoc-ispell (&optional take-notes)
"Check the style and spelling of everything interactively.
Calls `checkdoc' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc nil current-prefix-arg)))
(defun checkdoc-ispell-current-buffer (&optional take-notes)
"Check the style and spelling of the current buffer.
Calls `checkdoc-current-buffer' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-current-buffer'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-current-buffer nil current-prefix-arg)))
(defun checkdoc-ispell-interactive (&optional take-notes)
"Check the style and spelling of the current buffer interactively.
Calls `checkdoc-interactive' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-interactive'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-interactive nil current-prefix-arg)))
(defun checkdoc-ispell-message-interactive (&optional take-notes)
"Check the style and spelling of message text interactively.
Calls `checkdoc-message-interactive' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-message-interactive'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-message-interactive nil current-prefix-arg)))
(defun checkdoc-ispell-message-text (&optional take-notes)
"Check the style and spelling of message text interactively.
Calls `checkdoc-message-text' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-message-text'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-message-text nil current-prefix-arg)))
(defun checkdoc-ispell-start (&optional take-notes)
"Check the style and spelling of the current buffer.
Calls `checkdoc-start' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-start'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-start nil current-prefix-arg)))
(defun checkdoc-ispell-continue (&optional take-notes)
"Check the style and spelling of the current buffer after point.
Calls `checkdoc-continue' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-continue'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-continue nil current-prefix-arg)))
(defun checkdoc-ispell-comments (&optional take-notes)
"Check the style and spelling of the current buffer's comments.
Calls `checkdoc-comments' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-comments'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-comments nil current-prefix-arg)))
(defun checkdoc-ispell-defun (&optional take-notes)
"Check the style and spelling of the current defun with Ispell.
Calls `checkdoc-defun' with spell-checking turned on.
Prefix argument TAKE-NOTES is the same as for `checkdoc-defun'"
(interactive)
(let ((checkdoc-spellcheck-documentation-flag t))
(call-interactively 'checkdoc-defun nil current-prefix-arg)))
(defun checkdoc-create-error (text start end &optional unfixable)
"Used to create the return error text returned from all engines.
TEXT is the descriptive text of the error. START and END define the region
it is sensible to highlight when describing the problem.
Optional argument UNFIXABLE means that the error has no auto-fix available.
A list of the form (TEXT START END UNFIXABLE) is returned if we are not
generating a buffered list of errors."
(if checkdoc-generate-compile-warnings-flag
(progn (checkdoc-error start text)
nil)
(list text start end unfixable)))
(defun checkdoc-error-text (err)
"Return the text specified in the checkdoc ERR."
(if (stringp err) err (car err)))
(defun checkdoc-error-start (err)
"Return the start point specified in the checkdoc ERR."
(if (stringp err) nil (nth 1 err)))
(defun checkdoc-error-end (err)
"Return the end point specified in the checkdoc ERR."
(if (stringp err) nil (nth 2 err)))
(defun checkdoc-error-unfixable (err)
"Return the t if we cannot autofix the error specified in the checkdoc ERR."
(if (stringp err) nil (nth 3 err)))
(defvar checkdoc-minor-mode-map
(let ((map (make-sparse-keymap))
(pmap (make-sparse-keymap)))
(define-key map "\C-\M-x" 'checkdoc-eval-defun)
(define-key map "\C-x`" 'checkdoc-continue)
(if (not (string-match "XEmacs" emacs-version))
(define-key map [menu-bar emacs-lisp eval-buffer]
'checkdoc-eval-current-buffer))
(define-key pmap "x" 'checkdoc-defun)
(define-key pmap "X" 'checkdoc-ispell-defun)
(define-key pmap "`" 'checkdoc-continue)
(define-key pmap "~" 'checkdoc-ispell-continue)
(define-key pmap "s" 'checkdoc-start)
(define-key pmap "S" 'checkdoc-ispell-start)
(define-key pmap "d" 'checkdoc)
(define-key pmap "D" 'checkdoc-ispell)
(define-key pmap "b" 'checkdoc-current-buffer)
(define-key pmap "B" 'checkdoc-ispell-current-buffer)
(define-key pmap "e" 'checkdoc-eval-current-buffer)
(define-key pmap "m" 'checkdoc-message-text)
(define-key pmap "M" 'checkdoc-ispell-message-text)
(define-key pmap "c" 'checkdoc-comments)
(define-key pmap "C" 'checkdoc-ispell-comments)
(define-key pmap " " 'checkdoc-rogue-spaces)
(define-key map "\C-c?" pmap)
map)
"Keymap used to override evaluation key-bindings for documentation checking.")
(defvaralias 'checkdoc-minor-keymap 'checkdoc-minor-mode-map)
(make-obsolete-variable 'checkdoc-minor-keymap
'checkdoc-minor-mode-map)
(easy-menu-define
nil checkdoc-minor-mode-map "Checkdoc Minor Mode Menu"
'("CheckDoc"
["Interactive Buffer Style Check" checkdoc t]
["Interactive Buffer Style and Spelling Check" checkdoc-ispell t]
["Check Buffer" checkdoc-current-buffer t]
["Check and Spell Buffer" checkdoc-ispell-current-buffer t]
"---"
["Interactive Style Check" checkdoc-interactive t]
["Interactive Style and Spelling Check" checkdoc-ispell-interactive t]
["Find First Style Error" checkdoc-start t]
["Find First Style or Spelling Error" checkdoc-ispell-start t]
["Next Style Error" checkdoc-continue t]
["Next Style or Spelling Error" checkdoc-ispell-continue t]
["Interactive Message Text Style Check" checkdoc-message-interactive t]
["Interactive Message Text Style and Spelling Check"
checkdoc-ispell-message-interactive t]
["Check Message Text" checkdoc-message-text t]
["Check and Spell Message Text" checkdoc-ispell-message-text t]
["Check Comment Style" checkdoc-comments buffer-file-name]
["Check Comment Style and Spelling" checkdoc-ispell-comments
buffer-file-name]
["Check for Rogue Spaces" checkdoc-rogue-spaces t]
"---"
["Check Defun" checkdoc-defun t]
["Check and Spell Defun" checkdoc-ispell-defun t]
["Check and Evaluate Defun" checkdoc-eval-defun t]
["Check and Evaluate Buffer" checkdoc-eval-current-buffer t]
))
(define-minor-mode checkdoc-minor-mode
"Toggle Checkdoc minor mode, a mode for checking Lisp doc strings.
With prefix ARG, turn Checkdoc minor mode on iff ARG is positive.
In Checkdoc minor mode, the usual bindings for `eval-defun' which is
bound to \\<checkdoc-minor-mode-map>\\[checkdoc-eval-defun] and `checkdoc-eval-current-buffer' are overridden to include
checking of documentation strings.
\\{checkdoc-minor-mode-map}"
nil " CDoc" nil
:group 'checkdoc)
(defsubst checkdoc-run-hooks (hookvar &rest args)
"Run hooks in HOOKVAR with ARGS."
(if (fboundp 'run-hook-with-args-until-success)
(apply 'run-hook-with-args-until-success hookvar args)
(apply 'run-hook-with-args hookvar args)))
(defsubst checkdoc-create-common-verbs-regexp ()
"Rebuild the contents of `checkdoc-common-verbs-regexp'."
(or checkdoc-common-verbs-regexp
(setq checkdoc-common-verbs-regexp
(concat "\\<\\("
(mapconcat (lambda (e) (concat (car e)))
checkdoc-common-verbs-wrong-voice "\\|")
"\\)\\>"))))
(defun checkdoc-this-string-valid ()
"Return a message string if the current doc string is invalid.
Check for style only, such as the first line always being a complete
sentence, whitespace restrictions, and making sure there are no
hard-coded key-codes such as C-[char] or mouse-[number] in the comment.
See the style guide in the Emacs Lisp manual for more details."
(while (looking-at "[ \t\n]*;")
(forward-line 1)
(beginning-of-line)
(skip-chars-forward " \n\t"))
(let ((fp (checkdoc-defun-info))
(err nil))
(setq
err
(if (and (not (nth 1 fp)) (or (nth 2 fp) checkdoc-force-docstrings-flag) (not (checkdoc-char= (following-char) ?\"))) ; no doc string
;; Sometimes old code has comments where the documentation should
;; be. Let's see if we can find the comment, and offer to turn it
;; into documentation for them.
(let ((have-comment nil)
(comment-start " (condition-case nil
(progn
(forward-sexp -1)
(forward-sexp 1)
(skip-chars-forward "\n \t")
(setq have-comment (looking-at comment-start)))
(error nil))
(if have-comment
(if (or (eq checkdoc-autofix-flag
'automatic-then-never)
(checkdoc-y-or-n-p
"Convert comment to documentation? "))
(save-excursion
(insert "\"")
(let ((docstring-start-point (point)))
(while (looking-at comment-start)
(while (looking-at comment-start)
(delete-char 1))
(if (looking-at "[ \t]+")
(delete-region (match-beginning 0) (match-end 0)))
(forward-line 1)
(beginning-of-line)
(skip-chars-forward " \t")
(if (looking-at comment-start)
(progn
(beginning-of-line)
(zap-to-char 1 ?\ (beginning-of-line)
(forward-char -1)
(insert "\"")
(forward-char -1)
(while (search-backward "\"" docstring-start-point t)
(insert "\\"))
(if (eq checkdoc-autofix-flag 'automatic-then-never)
(setq checkdoc-autofix-flag 'never))))
(checkdoc-create-error
"You should convert this comment to documentation"
(point) (save-excursion (end-of-line) (point))))
(checkdoc-create-error
(if (nth 2 fp)
"All interactive functions should have documentation"
"All variables and subroutines might as well have a \
documentation string")
(point) (+ (point) 1) t)))))
(if (and (not err) (looking-at "\""))
(let ((old-syntax-table (syntax-table)))
(unwind-protect
(progn
(set-syntax-table checkdoc-syntax-table)
(checkdoc-this-string-valid-engine fp))
(set-syntax-table old-syntax-table)))
err)))
(defun checkdoc-this-string-valid-engine (fp)
"Return an error list or string if the current doc string is invalid.
Depends on `checkdoc-this-string-valid' to reset the syntax table so that
regexp short cuts work. FP is the function defun information."
(let ((case-fold-search nil)
(s (point))
(e (if (looking-at "\"")
(save-excursion (forward-sexp 1) (point-marker))
(point))))
(or
(save-excursion
(forward-line 1)
(beginning-of-line)
(if (and (< (point) e)
(looking-at "\\([ \t]+\\)[^ \t\n]"))
(if (checkdoc-autofix-ask-replace (match-beginning 1)
(match-end 1)
"Remove this whitespace? "
"")
nil
(checkdoc-create-error
"Second line should not have indentation"
(match-beginning 1)
(match-end 1)))))
(save-excursion
(when (re-search-forward "^(" e t)
(if (checkdoc-autofix-ask-replace (match-beginning 0)
(match-end 0)
"Escape this '('? "
"\\(")
nil
(checkdoc-create-error
"Open parenthesis in column 0 should be escaped"
(match-beginning 0) (match-end 0)))))
(let (start end)
(if (or (if (looking-at "\"\\([ \t\n]+\\)")
(setq start (match-beginning 1)
end (match-end 1)))
(save-excursion
(forward-sexp 1)
(forward-char -1)
(if (/= (skip-chars-backward " \t\n") 0)
(setq start (point)
end (1- e)))))
(if (checkdoc-autofix-ask-replace
start end "Remove this whitespace? " "")
nil
(checkdoc-create-error
"Documentation strings should not start or end with whitespace"
start end))))
(save-excursion
(end-of-line)
(skip-chars-backward " \t\n")
(if (> (point) e) (goto-char e)) (forward-char -1)
(cond
((and (checkdoc-char= (following-char) ?\")
;; A backslashed double quote at the end of a sentence
(not (checkdoc-char= (preceding-char) ?\\)))
;; We might have to add a period in this case
(forward-char -1)
(if (looking-at "[.!?]")
nil
(forward-char 1)
(if (checkdoc-autofix-ask-replace
(point) (1+ (point)) "Add period to sentence? "
".\"" t)
nil
(checkdoc-create-error
"First sentence should end with punctuation"
(point) (1+ (point))))))
((looking-at "[\\!?;:.)]")
nil)
((and checkdoc-permit-comma-termination-flag (looking-at ","))
nil)
(t
(let ((msg "First line is not a complete sentence")
(e (point)))
(beginning-of-line)
(if (re-search-forward "\\. +" e t)
(if (checkdoc-autofix-ask-replace
(1+ (match-beginning 0)) (match-end 0)
"First line not a complete sentence. Add RET here? "
"\n" t)
(let (l1 l2)
(forward-line 1)
(end-of-line)
(setq l1 (current-column)
l2 (save-excursion
(forward-line 1)
(end-of-line)
(current-column)))
(if (> (+ l1 l2 1) 80)
(setq msg "Incomplete auto-fix; doc string \
may require more formatting")
(delete-char 1) (insert " ")
(setq msg nil))))
(let ((numc (progn (end-of-line) (- 80 (current-column))))
(p (point)))
(forward-line 1)
(beginning-of-line)
(if (and (re-search-forward "[.!?:\"]\\([ \t\n]+\\|\"\\)"
(save-excursion
(end-of-line)
(point))
t)
(< (current-column) numc))
(if (checkdoc-autofix-ask-replace
p (1+ p)
"1st line not a complete sentence. Join these lines? "
" " t)
(progn
(goto-char (match-beginning 1))
(delete-region (point) (match-end 1))
(insert "\n")
(setq msg nil))))))
(if msg
(checkdoc-create-error msg s (save-excursion
(goto-char s)
(end-of-line)
(point)))
nil) ))))
(save-excursion
(skip-chars-forward "\"\\*")
(if (looking-at "[a-z]")
(if (checkdoc-autofix-ask-replace
(match-beginning 0) (match-end 0)
"Capitalize your sentence? " (upcase (match-string 0))
t)
nil
(checkdoc-create-error
"First line should be capitalized"
(match-beginning 0) (match-end 0)))
nil))
(save-excursion
(let ((f nil) (m nil) (start (point))
(re "[^`A-Za-z0-9_]\\([CMA]-[a-zA-Z]\\|\\(\\([CMA]-\\)?\
mouse-[0-3]\\)\\)\\>"))
(while (and (not f) (setq m (re-search-forward re e t)))
(setq f (not (checkdoc-in-sample-code-p start e))))
(if m
(checkdoc-create-error
(concat
"Keycode " (match-string 1)
" embedded in doc string. Use \\\\<keymap> & \\\\[function] "
"instead")
(match-beginning 1) (match-end 1) t))))
(save-excursion
(if (and (re-search-forward "\\\\\\\\\\[\\w+" e t
(1+ checkdoc-max-keyref-before-warn))
(not (re-search-forward "\\\\\\\\{\\w+}" e t)))
(checkdoc-create-error
"Too many occurrences of \\[function]. Use \\{keymap} instead"
s (marker-position e))))
(save-excursion
(let ((case-fold-search t)
(ret nil) mb me)
(while (and (re-search-forward "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'" e t)
(not ret))
(let* ((ms1 (match-string 1))
(sym (intern-soft ms1)))
(setq mb (match-beginning 1)
me (match-end 1))
(if (and sym (boundp sym) (fboundp sym)
(save-excursion
(goto-char mb)
(forward-word -1)
(not (looking-at
"variable\\|option\\|function\\|command\\|symbol"))))
(if (checkdoc-autofix-ask-replace
mb me "Prefix this ambiguous symbol? " ms1 t)
(let ((disambiguate
(completing-read
"Disambiguating Keyword (default variable): "
'(("function") ("command") ("variable")
("option") ("symbol"))
nil t nil nil "variable")))
(goto-char (1- mb))
(insert disambiguate " ")
(forward-word 1))
(setq ret
(format "Disambiguate %s by preceding w/ \
function,command,variable,option or symbol." ms1))))))
(if ret
(checkdoc-create-error ret mb me)
nil)))
(save-excursion
(let ((start (point))
(eol nil))
(while (and (< (point) e)
(or (progn (end-of-line) (setq eol (point))
(< (current-column) 80))
(progn (beginning-of-line)
(re-search-forward "\\\\\\\\[[<{]"
eol t))
(checkdoc-in-sample-code-p start e)))
(forward-line 1))
(end-of-line)
(if (and (< (point) e) (> (current-column) 80))
(checkdoc-create-error
"Some lines are over 80 columns wide"
s (save-excursion (goto-char s) (end-of-line) (point)) ))))
(cond ((eq (nth 1 fp) t)
(or
(if (and (string-match "-flag$" (car fp))
(not (looking-at "\"\\*?Non-nil\\s-+means\\s-+")))
(checkdoc-create-error
"Flag variable doc strings should usually start: Non-nil means"
s (marker-position e) t))
(if (and (looking-at "\"\\*?Non-nil\\s-+means\\s-+")
(not (string-match "-flag$" (car fp))))
(let ((newname
(if (string-match "-p$" (car fp))
(concat (substring (car fp) 0 -2) "-flag")
(concat (car fp) "-flag"))))
(if (checkdoc-y-or-n-p
(format
"Rename to %s and Query-Replace all occurrences? "
newname))
(progn
(beginning-of-defun)
(query-replace-regexp
(concat "\\<" (regexp-quote (car fp)) "\\>")
newname))
(checkdoc-create-error
"Flag variable names should normally end in `-flag'" s
(marker-position e)))))
))
(t
(or
(let ((args (cdr (cdr (cdr (cdr fp)))))
(last-pos 0)
(found 1)
(order (and (nth 3 fp) (car (nth 3 fp))))
(nocheck (append '("&optional" "&rest") (nth 3 fp)))
(inopts nil))
(while (and args found (> found last-pos))
(if (member (car args) nocheck)
(setq args (cdr args)
inopts t)
(setq last-pos found
found (save-excursion
(re-search-forward
(concat "\\<" (upcase (car args))
"\\(\\>\\|th\\>\\|s\\>\\|[.,;:]\\)")
e t)))
(if (not found)
(let ((case-fold-search t))
(if (save-excursion
(re-search-forward
(concat "\\<\\(" (car args)
"\\)\\(\\>\\|th\\>\\|s\\>\\)")
e t))
(if (checkdoc-autofix-ask-replace
(match-beginning 1) (match-end 1)
(format
"If this is the argument `%s', it should appear as %s. Fix? "
(car args) (upcase (car args)))
(upcase (car args)) t)
(setq found (match-beginning 1))))))
(if found (setq args (cdr args)))))
(if (not found)
(if (checkdoc-y-or-n-p
(format
"Add %s documentation to end of doc string? "
(upcase (car args))))
(save-excursion
(goto-char e) (forward-char -1)
(insert "\n"
(if inopts "Optional a" "A")
"rgument " (upcase (car args))
" ")
(insert (read-string "Describe: "))
(if (not (save-excursion (forward-char -1)
(looking-at "[.?!]")))
(insert "."))
nil)
(checkdoc-create-error
(format
"Argument `%s' should appear (as %s) in the doc string"
(car args) (upcase (car args)))
s (marker-position e)))
(if (or (and order (eq order 'yes))
(and (not order) checkdoc-arguments-in-order-flag))
(if (< found last-pos)
(checkdoc-create-error
"Arguments occur in the doc string out of order"
s (marker-position e) t)))))
(and checkdoc-verb-check-experimental-flag
(save-excursion
(checkdoc-create-common-verbs-regexp)
(let ((lim (save-excursion
(end-of-line)
(if (checkdoc-char= (preceding-char) ?\\)
(progn (forward-line 1)
(end-of-line)))
(point)))
(rs nil) replace original (case-fold-search t))
(while (and (not rs)
(re-search-forward
checkdoc-common-verbs-regexp
lim t))
(setq original (buffer-substring-no-properties
(match-beginning 1) (match-end 1))
rs (assoc (downcase original)
checkdoc-common-verbs-wrong-voice))
(if (not rs) (error "Verb voice alist corrupted"))
(setq replace (let ((case-fold-search nil))
(save-match-data
(if (string-match "^[A-Z]" original)
(capitalize (cdr rs))
(cdr rs)))))
(if (checkdoc-autofix-ask-replace
(match-beginning 1) (match-end 1)
(format "Use the imperative for \"%s\". \
Replace with \"%s\"? " original replace)
replace t)
(setq rs nil)))
(if rs
(checkdoc-create-error
(format
"Probably \"%s\" should be imperative \"%s\""
original replace)
(match-beginning 1) (match-end 1))))))
)))
(save-excursion
(let ((found nil) (start (point)) (msg nil) (ms nil))
(while (and (not msg)
(re-search-forward
"[^-([`':a-zA-Z]\\(\\w+[:-]\\(\\w\\|\\s_\\)+\\)[^]']"
e t))
(setq ms (match-string 1))
(save-match-data
(if (string-match "\\.$" ms)
(setq ms (substring ms 0 (1- (length ms))))))
(if (and (not (checkdoc-in-sample-code-p start e))
(not (checkdoc-in-example-string-p start e))
(not (member ms checkdoc-symbol-words))
(setq found (intern-soft ms))
(or (boundp found) (fboundp found)))
(progn
(setq msg (format "Add quotes around Lisp symbol `%s'? "
ms))
(if (checkdoc-autofix-ask-replace
(match-beginning 1) (+ (match-beginning 1)
(length ms))
msg (concat "`" ms "'") t)
(setq msg nil)
(setq msg
(format "Lisp symbol `%s' should appear in quotes"
ms))))))
(if msg
(checkdoc-create-error msg (match-beginning 1)
(+ (match-beginning 1)
(length ms)))
nil)))
(save-excursion
(if (re-search-forward "\\(`\\(t\\|nil\\)'\\)" e t)
(if (checkdoc-autofix-ask-replace
(match-beginning 1) (match-end 1)
(format "%s should not appear in quotes. Remove? "
(match-string 2))
(match-string 2) t)
nil
(checkdoc-create-error
"Symbols t and nil should not appear in `...' quotes"
(match-beginning 1) (match-end 1)))))
(checkdoc-sentencespace-region-engine (point) e)
(checkdoc-proper-noun-region-engine (point) e)
(checkdoc-ispell-docstring-engine e)
(save-excursion (checkdoc-run-hooks 'checkdoc-style-hooks fp e))
)))
(defun checkdoc-defun-info nil
"Return a list of details about the current sexp.
It is a list of the form:
(NAME VARIABLE INTERACTIVE NODOCPARAMS PARAMETERS ...)
where NAME is the name, VARIABLE is t if this is a `defvar',
INTERACTIVE is nil if this is not an interactive function, otherwise
it is the position of the `interactive' call, and PARAMETERS is a
string which is the name of each variable in the function's argument
list. The NODOCPARAMS is a sublist of parameters specified by a checkdoc
comment for a given defun. If the first element is not a string, then
the token checkdoc-order: <TOKEN> exists, and TOKEN is a symbol read
from the comment."
(save-excursion
(beginning-of-defun)
(let ((defun (looking-at "(def\\(un\\|macro\\|subst\\|advice\\)"))
(is-advice (looking-at "(defadvice"))
(lst nil)
(ret nil)
(oo (make-vector 3 0))) (forward-char 1)
(forward-sexp 1)
(skip-chars-forward " \n\t")
(setq ret
(list (buffer-substring-no-properties
(point) (progn (forward-sexp 1) (point)))))
(if (not defun)
(setq ret (cons t ret))
(setq ret (cons nil ret))
(save-excursion
(setq ret (cons
(re-search-forward "^\\s-*(interactive"
(save-excursion (end-of-defun) (point))
t)
ret)))
(skip-chars-forward " \t\n")
(let ((bss (buffer-substring (point) (save-excursion (forward-sexp 1)
(point))))
(obarray oo))
(save-excursion
(setq ret
(cons
(let ((sl1 nil))
(if (re-search-forward ";\\s-+checkdoc-order:\\s-+"
(save-excursion (end-of-defun)
(point))
t)
(setq sl1 (list (cond ((looking-at "nil") 'no)
((looking-at "t") 'yes)))))
(if (re-search-forward ";\\s-+checkdoc-params:\\s-+"
(save-excursion (end-of-defun)
(point))
t)
(let ((sl nil))
(goto-char (match-end 0))
(condition-case nil
(setq lst (read (current-buffer)))
(error (setq lst nil))) (if (not (listp lst)) (setq lst (list lst)))
(if (and lst (not (symbolp (car lst)))) (setq lst nil))
(while lst
(setq sl (cons (symbol-name (car lst)) sl)
lst (cdr lst)))
(setq sl1 (append sl1 sl))))
sl1)
ret)))
(setq lst (read bss)))
(if (not (listp lst)) (setq lst nil))
(if is-advice nil
(while lst
(setq ret (cons (symbol-name (car lst)) ret)
lst (cdr lst)))))
(nreverse ret))))
(defun checkdoc-in-sample-code-p (start limit)
"Return non-nil if the current point is in a code fragment.
A code fragment is identified by an open parenthesis followed by a
symbol which is a valid function or a word in all CAPS, or a parenthesis
that is quoted with the ' character. Only the region from START to LIMIT
is is allowed while searching for the bounding parenthesis."
(save-match-data
(save-restriction
(narrow-to-region start limit)
(save-excursion
(and (condition-case nil (progn (up-list 1) t) (error nil))
(condition-case nil (progn (forward-list -1) t) (error nil))
(or (save-excursion (forward-char -1) (looking-at "'("))
(and (looking-at "(\\(\\(\\w\\|[-:_]\\)+\\)[ \t\n;]")
(let ((ms (buffer-substring-no-properties
(match-beginning 1) (match-end 1))))
(or (fboundp (intern-soft ms))
(let ((case-fold-search nil))
(string-match "^[A-Z-]+$" ms))
(string-match "\\w[-:_]+\\w" ms))))))))))
(defun checkdoc-in-example-string-p (start limit)
"Return non-nil if the current point is in an \"example string\".
This string is identified by the characters \\\" surrounding the text.
The text checked is between START and LIMIT."
(save-match-data
(save-excursion
(let ((p (point))
(c 0))
(goto-char start)
(while (and (< (point) p) (re-search-forward "\\\\\"" limit t))
(setq c (1+ c)))
(and (< 0 c) (= (% c 2) 0))))))
(defun checkdoc-proper-noun-region-engine (begin end)
"Check all text between BEGIN and END for lower case proper nouns.
These are Emacs centric proper nouns which should be capitalized for
consistency. Return an error list if any are not fixed, but
internally skip over no answers.
If the offending word is in a piece of quoted text, then it is skipped."
(save-excursion
(let ((case-fold-search nil)
(errtxt nil) bb be
(old-syntax-table (syntax-table)))
(unwind-protect
(progn
(set-syntax-table checkdoc-syntax-table)
(goto-char begin)
(while (re-search-forward checkdoc-proper-noun-regexp end t)
(let ((text (match-string 1))
(b (match-beginning 1))
(e (match-end 1)))
(if (and (not (save-excursion
(goto-char b)
(forward-char -1)
(looking-at "`\\|\"\\|\\.\\|\\\\")))
(not (and (= ?/ (char-after e))
(= ?/ (char-before b))))
(not (checkdoc-in-example-string-p begin end)))
(if (checkdoc-autofix-ask-replace
b e (format "Text %s should be capitalized. Fix? "
text)
(capitalize text) t)
nil
(if errtxt
(if checkdoc-generate-compile-warnings-flag
(checkdoc-create-error
(format
"Name %s should appear capitalized as %s"
text (capitalize text))
b e))
(setq errtxt
(format
"Name %s should appear capitalized as %s"
text (capitalize text))
bb b be e)))))))
(set-syntax-table old-syntax-table))
(if errtxt (checkdoc-create-error errtxt bb be)))))
(defun checkdoc-sentencespace-region-engine (begin end)
"Make sure all sentences have double spaces between BEGIN and END."
(if sentence-end-double-space
(save-excursion
(let ((case-fold-search nil)
(errtxt nil) bb be
(old-syntax-table (syntax-table)))
(unwind-protect
(progn
(set-syntax-table checkdoc-syntax-table)
(goto-char begin)
(while (re-search-forward "[^ .0-9]\\(\\. \\)[^ \n]" end t)
(let ((b (match-beginning 1))
(e (match-end 1)))
(unless (or (checkdoc-in-sample-code-p begin end)
(checkdoc-in-example-string-p begin end)
(save-excursion
(goto-char b)
(condition-case nil
(progn
(forward-sexp -1)
(looking-at
"\\([a-z]\\|[iI]\\.?e\\|[eE]\\.?g\\)\\."))
(error t))))
(if (checkdoc-autofix-ask-replace
b e
"There should be two spaces after a period. Fix? "
". ")
nil
(if errtxt
(if checkdoc-generate-compile-warnings-flag
(checkdoc-create-error
"There should be two spaces after a period"
b e))
(setq errtxt
"There should be two spaces after a period"
bb b be e)))))))
(set-syntax-table old-syntax-table))
(if errtxt (checkdoc-create-error errtxt bb be))))))
(eval-when-compile (require 'ispell))
(defun checkdoc-ispell-init ()
"Initialize Ispell process (default version) with Lisp words.
The words used are from `checkdoc-ispell-lisp-words'. If `ispell'
cannot be loaded, then set `checkdoc-spellcheck-documentation-flag' to
nil."
(require 'ispell)
(if (not (symbol-value 'ispell-process)) (condition-case nil
(progn
(ispell-buffer-local-words)
(let ((w checkdoc-ispell-lisp-words))
(while w
(process-send-string
(symbol-value 'ispell-process)
(concat "@" (car w) "\n"))
(setq w (cdr w)))))
(error (setq checkdoc-spellcheck-documentation-flag nil)))))
(defun checkdoc-ispell-docstring-engine (end)
"Run the Ispell tools on the doc string between point and END.
Since Ispell isn't Lisp-smart, we must pre-process the doc string
before using the Ispell engine on it."
(if (or (not checkdoc-spellcheck-documentation-flag)
(not checkdoc-autofix-flag)
(eq checkdoc-autofix-flag 'never))
nil
(checkdoc-ispell-init)
(save-excursion
(skip-chars-forward "^a-zA-Z")
(let ((word nil) (sym nil) (case-fold-search nil) (err nil))
(while (and (not err) (< (point) end))
(if (save-excursion (forward-char -1) (looking-at "[('`]"))
(forward-sexp 1)
(setq word (buffer-substring-no-properties
(point) (progn
(skip-chars-forward "a-zA-Z-")
(point)))
sym (intern-soft word))
(if (and sym (or (boundp sym) (fboundp sym)))
nil
(if (or
(string-match "^[A-Z][A-Z]+\\(s\\|th\\)?$" word)
(looking-at "}") )
nil
(save-excursion
(if (not (eq checkdoc-autofix-flag 'never))
(let ((lk last-input-event))
(ispell-word nil t)
(if (not (equal last-input-event lk))
(progn
(sit-for 0)
(message "Continuing..."))))
)))))
(skip-chars-forward "^a-zA-Z"))
err))))
(defun checkdoc-rogue-space-check-engine (&optional start end interact)
"Return a message list if there is a line with white space at the end.
If `checkdoc-autofix-flag' permits, delete that whitespace instead.
If optional arguments START and END are non-nil, bound the check to
this region.
Optional argument INTERACT may permit the user to fix problems on the fly."
(let ((p (point))
(msg nil) s e (f nil))
(if (not start) (setq start (point-min)))
(or
(progn
(goto-char start)
(while (and (not msg) (re-search-forward "\\?\\\\?[ \t][ \t]*$" end t))
(setq msg
"Don't use `? ' at the end of a line. \
News agents may remove it"
s (match-beginning 0) e (match-end 0) f t)
(if (and interact (y-or-n-p (concat msg ". Fix? ")))
(progn
(checkdoc-recursive-edit msg)
(setq msg nil)
(goto-char s)
(beginning-of-line)))))
(progn
(goto-char start)
(while (and (not msg) (re-search-forward "[^ \t\n;]\\([ \t]+\\)$" end t))
(if (checkdoc-autofix-ask-replace
(match-beginning 1) (match-end 1)
"White space at end of line. Remove? " "")
nil
(setq msg "White space found at end of line"
s (match-beginning 1) e (match-end 1))))))
(if msg
(checkdoc-create-error msg s e f)
(goto-char p)
nil)))
(eval-when-compile
(require 'lisp-mnt))
(defun checkdoc-file-comments-engine ()
"Return a message list if this file does not match the Emacs standard.
This checks for style only, such as the first line, Commentary:,
Code:, and others referenced in the style guide."
(if (featurep 'lisp-mnt)
nil
(require 'lisp-mnt)
(if (and (not (fboundp 'lm-commentary-mark)) (boundp 'lm-commentary))
(defalias 'lm-commentary-mark 'lm-commentary)))
(save-excursion
(let* ((f1 (file-name-nondirectory (buffer-file-name)))
(fn (file-name-sans-extension f1))
(fe (substring f1 (length fn)))
(err nil))
(goto-char (point-min))
(setq
err
(if (not (lm-summary))
(if (checkdoc-y-or-n-p "There is no first line summary! Add one? ")
(progn
(goto-char (point-min))
(insert ";;; " fn fe " --- " (read-string "Summary: ") "\n"))
(checkdoc-create-error
"The first line should be of the form: \";;; package --- Summary\""
(point-min) (save-excursion (goto-char (point-min)) (end-of-line)
(point))))
nil))
(setq
err
(or
(if (not (lm-commentary-mark))
(progn
(goto-char (point-min))
(cond
((re-search-forward
"write\\s-+to\\s-+the\\s-+Free Software Foundation, Inc."
nil t)
(re-search-forward "^;;\\s-*\n\\|^\n" nil t))
((or (re-search-forward "^;;; History" nil t)
(re-search-forward "^;;; Code" nil t)
(re-search-forward "^(require" nil t)
(re-search-forward "^(" nil t))
(beginning-of-line))
(t (re-search-forward ";;; .* --- .*\n")))
(if (checkdoc-y-or-n-p
"You should have a \";;; Commentary:\", add one? ")
(insert "\n;;; Commentary:\n;; \n\n")
(checkdoc-create-error
"You should have a section marked \";;; Commentary:\""
nil nil t)))
nil)
err))
(setq
err
(or
(if (or (not checkdoc-force-history-flag)
(file-exists-p "ChangeLog")
(file-exists-p "../ChangeLog")
(let ((fn 'lm-history-mark)) (and (fboundp fn) (funcall fn))))
nil
(progn
(goto-char (or (lm-commentary-mark) (point-min)))
(cond
((re-search-forward
"write\\s-+to\\s-+the\\s-+Free Software Foundation, Inc."
nil t)
(re-search-forward "^;;\\s-*\n\\|^\n" nil t))
((or (re-search-forward "^;;; Code" nil t)
(re-search-forward "^(require" nil t)
(re-search-forward "^(" nil t))
(beginning-of-line)))
(if (checkdoc-y-or-n-p
"You should have a \";;; History:\", add one? ")
(insert "\n;;; History:\n;; \n\n")
(checkdoc-create-error
"You should have a section marked \";;; History:\" or use a ChangeLog"
(point) nil))))
err))
(setq
err
(or
(if (not (lm-code-mark))
(let ((cont t))
(goto-char (point-min))
(while (and cont (re-search-forward "^(" nil t))
(setq cont (looking-at "require\\s-+")))
(if (and (not cont)
(checkdoc-y-or-n-p
"There is no ;;; Code: marker. Insert one? "))
(progn (beginning-of-line)
(insert ";;; Code:\n")
nil)
(checkdoc-create-error
"You should have a section marked \";;; Code:\""
(point) nil)))
nil)
err))
(setq
err
(or
(save-excursion
(goto-char (point-max))
(if (not (re-search-backward
(concat "^;;;[ \t]+" (regexp-quote fn) "\\(" (regexp-quote fe)
"\\)?[ \t]+ends here[ \t]*$"
"\\|^;;;[ \t]+ End of file[ \t]+"
(regexp-quote fn) "\\(" (regexp-quote fe) "\\)?")
nil t))
(if (checkdoc-y-or-n-p "No identifiable footer! Add one? ")
(progn
(goto-char (point-max))
(insert "\n(provide '" fn ")\n\n;;; " fn fe " ends here\n"))
(checkdoc-create-error
(format "The footer should be: (provide '%s)\\n;;; %s%s ends here"
fn fn fe)
(1- (point-max)) (point-max)))))
err))
(let ((cm (lm-commentary-mark)))
(when cm
(save-excursion
(goto-char cm)
(let ((e (copy-marker (lm-commentary-end))))
(checkdoc-sentencespace-region-engine (point) e)
(checkdoc-proper-noun-region-engine (point) e)
(checkdoc-ispell-docstring-engine e)))))
(setq
err
(or
(checkdoc-run-hooks 'checkdoc-comment-style-hooks)
err))
err)))
(defun checkdoc-outside-major-sexp ()
"Return t if point is outside the bounds of a valid sexp."
(save-match-data
(save-excursion
(let ((p (point)))
(or (progn (beginning-of-defun) (bobp))
(progn (end-of-defun) (< (point) p)))))))
(defun checkdoc-message-text-search (&optional beg end)
"Search between BEG and END for a style error with message text.
Optional arguments BEG and END represent the boundary of the check.
The default boundary is the entire buffer."
(let ((e nil)
(type nil))
(if (not (or beg end)) (setq beg (point-min) end (point-max)))
(goto-char beg)
(while (setq type (checkdoc-message-text-next-string end))
(setq e (checkdoc-message-text-engine type)))
e))
(defun checkdoc-message-text-next-string (end)
"Move cursor to the next checkable message string after point.
Return the message classification.
Argument END is the maximum bounds to search in."
(let ((return nil))
(while (and (not return)
(re-search-forward
"(\\s-*\\(\\(\\w\\|\\s_\\)*error\\|\
\\(\\w\\|\\s_\\)*y-or-n-p\\(-with-timeout\\)?\
\\|checkdoc-autofix-ask-replace\\)[ \t\n]+" end t))
(let* ((fn (match-string 1))
(type (cond ((string-match "error" fn)
'error)
(t 'y-or-n-p))))
(if (string-match "checkdoc-autofix-ask-replace" fn)
(progn (forward-sexp 2)
(skip-chars-forward " \t\n")))
(if (and (eq type 'y-or-n-p)
(looking-at "(format[ \t\n]+"))
(goto-char (match-end 0)))
(skip-chars-forward " \t\n")
(if (not (looking-at "\""))
nil
(setq return type))))
return))
(defun checkdoc-message-text-engine (&optional type)
"Return or fix errors found in strings passed to a message display function.
According to the documentation for the function `error', the error list
should not end with a period, and should start with a capital letter.
The function `y-or-n-p' has similar constraints.
Argument TYPE specifies the type of question, such as `error or `y-or-n-p."
(if (not type)
(save-excursion
(up-list -1)
(if (looking-at "(format")
(up-list -1))
(setq type
(cond ((looking-at "(error")
'error)
(t 'y-or-n-p)))))
(let ((case-fold-search nil))
(or
(if (and (save-excursion (forward-char 1)
(looking-at "[a-z]\\w+"))
(not (checkdoc-autofix-ask-replace
(match-beginning 0) (match-end 0)
"Capitalize your message text? "
(capitalize (match-string 0))
t)))
(checkdoc-create-error
"Messages should start with a capital letter"
(match-beginning 0) (match-end 0))
nil)
(checkdoc-sentencespace-region-engine (point)
(save-excursion (forward-sexp 1)
(point)))
(checkdoc-proper-noun-region-engine (point)
(save-excursion (forward-sexp 1)
(point)))
(if (and (eq type 'error)
(save-excursion (forward-sexp 1)
(forward-char -2)
(looking-at "\\."))
(not (checkdoc-autofix-ask-replace (match-beginning 0)
(match-end 0)
"Remove period from error? "
""
t)))
(checkdoc-create-error
"Error messages should *not* end with a period"
(match-beginning 0) (match-end 0))
nil)
(if (eq type 'y-or-n-p)
(if (not (save-excursion (forward-sexp 1)
(forward-char -3)
(not (looking-at "\\? "))))
nil
(if (save-excursion (forward-sexp 1)
(forward-char -2)
(looking-at "\\?"))
(if (checkdoc-autofix-ask-replace
(match-beginning 0) (match-end 0)
"`y-or-n-p' argument should end with \"? \". Fix? "
"? " t)
nil
(checkdoc-create-error
"`y-or-n-p' argument should end with \"? \""
(match-beginning 0) (match-end 0)))
(if (save-excursion (forward-sexp 1)
(forward-char -2)
(looking-at " "))
(if (checkdoc-autofix-ask-replace
(match-beginning 0) (match-end 0)
"`y-or-n-p' argument should end with \"? \". Fix? "
"? " t)
nil
(checkdoc-create-error
"`y-or-n-p' argument should end with \"? \""
(match-beginning 0) (match-end 0)))
(if (and (save-excursion (forward-sexp 1)
(forward-char -1)
(looking-at "\""))
(checkdoc-autofix-ask-replace
(match-beginning 0) (match-end 0)
"`y-or-n-p' argument should end with \"? \". Fix? "
"? \"" t))
nil
(checkdoc-create-error
"`y-or-n-p' argument should end with \"? \""
(match-beginning 0) (match-end 0)))))))
(checkdoc-ispell-docstring-engine (save-excursion (forward-sexp 1)
(point)))
)))
(defun checkdoc-y-or-n-p (question)
"Like `y-or-n-p', but pays attention to `checkdoc-autofix-flag'.
Argument QUESTION is the prompt passed to `y-or-n-p'."
(prog1
(if (or (not checkdoc-autofix-flag)
(eq checkdoc-autofix-flag 'never))
nil
(y-or-n-p question))
(if (eq checkdoc-autofix-flag 'automatic-then-never)
(setq checkdoc-autofix-flag 'never))))
(defun checkdoc-autofix-ask-replace (start end question replacewith
&optional complex)
"Highlight between START and END and queries the user with QUESTION.
If the user says yes, or if `checkdoc-autofix-flag' permits, replace
the region marked by START and END with REPLACEWITH. If optional flag
COMPLEX is non-nil, then we may ask the user a question. See the
documentation for `checkdoc-autofix-flag' for details.
If a section is auto-replaced without asking the user, this function
will pause near the fixed code so the user will briefly see what
happened.
This function returns non-nil if the text was replaced.
This function will not modify `match-data'."
(if (and checkdoc-autofix-flag
(not (eq checkdoc-autofix-flag 'never)))
(let ((o (checkdoc-make-overlay start end))
(ret nil)
(md (match-data)))
(unwind-protect
(progn
(checkdoc-overlay-put o 'face 'highlight)
(if (or (eq checkdoc-autofix-flag 'automatic)
(eq checkdoc-autofix-flag 'automatic-then-never)
(and (eq checkdoc-autofix-flag 'semiautomatic)
(not complex))
(and (or (eq checkdoc-autofix-flag 'query) complex)
(y-or-n-p question)))
(save-excursion
(goto-char start)
(if checkdoc-bouncy-flag (message "%s -> done" question))
(delete-region start end)
(insert replacewith)
(if checkdoc-bouncy-flag (sit-for 0))
(setq ret t)))
(checkdoc-delete-overlay o)
(set-match-data md))
(checkdoc-delete-overlay o)
(set-match-data md))
(if (eq checkdoc-autofix-flag 'automatic-then-never)
(setq checkdoc-autofix-flag 'never))
ret)))
(defvar checkdoc-output-font-lock-keywords
'(("^\\*\\*\\* \\(.+\\.el\\): \\([^ \n]+\\)"
(1 font-lock-function-name-face)
(2 font-lock-comment-face)))
"Keywords used to highlight a checkdoc diagnostic buffer.")
(defvar checkdoc-output-error-regex-alist
'(("^\\(.+\\.el\\):\\([0-9]+\\): " 1 2)))
(defvar checkdoc-pending-errors nil
"Non-nil when there are errors that have not been displayed yet.")
(define-derived-mode checkdoc-output-mode compilation-mode "Checkdoc"
"Set up the major mode for the buffer containing the list of errors."
(set (make-local-variable 'compilation-error-regexp-alist)
checkdoc-output-error-regex-alist)
(set (make-local-variable 'compilation-mode-font-lock-keywords)
checkdoc-output-font-lock-keywords))
(defun checkdoc-buffer-label ()
"The name to use for a checkdoc buffer in the error list."
(if (buffer-file-name)
(file-relative-name (buffer-file-name))
(concat "#<buffer "(buffer-name) ">")))
(defun checkdoc-start-section (check-type)
"Initialize the checkdoc diagnostic buffer for a pass.
Create the header so that the string CHECK-TYPE is displayed as the
function called to create the messages."
(let ((dir default-directory)
(label (checkdoc-buffer-label)))
(with-current-buffer (get-buffer-create checkdoc-diagnostic-buffer)
(checkdoc-output-mode)
(setq default-directory dir)
(goto-char (point-max))
(insert "\n\n\C-l\n*** " label ": " check-type " V " checkdoc-version))))
(defun checkdoc-error (point msg)
"Store POINT and MSG as errors in the checkdoc diagnostic buffer."
(setq checkdoc-pending-errors t)
(let ((text (list "\n" (checkdoc-buffer-label) ":"
(int-to-string
(count-lines (point-min) (or point (point-min))))
": " msg)))
(with-current-buffer (get-buffer checkdoc-diagnostic-buffer)
(goto-char (point-max))
(apply 'insert text))))
(defun checkdoc-show-diagnostics ()
"Display the checkdoc diagnostic buffer in a temporary window."
(if checkdoc-pending-errors
(let ((b (get-buffer checkdoc-diagnostic-buffer)))
(if b (progn (pop-to-buffer b)
(goto-char (point-max))
(re-search-backward "\C-l" nil t)
(beginning-of-line)
(forward-line 1)
(recenter 0)))
(other-window -1)
(setq checkdoc-pending-errors nil)
nil)))
(custom-add-option 'emacs-lisp-mode-hook
(lambda () (checkdoc-minor-mode 1)))
(add-to-list 'debug-ignored-errors
"Argument `.*' should appear (as .*) in the doc string")
(add-to-list 'debug-ignored-errors
"Lisp symbol `.*' should appear in quotes")
(add-to-list 'debug-ignored-errors "Disambiguate .* by preceding .*")
(provide 'checkdoc)