annotate lisp/emacs-lisp/checkdoc.el @ 22605:c3ffffc994d1

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