Mercurial > emacs
annotate lisp/emacs-lisp/checkdoc.el @ 25975:e368b754fe25
Add patch from rms around line 1870.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sun, 10 Oct 1999 21:25:17 +0000 |
parents | 6060f83b1ffc |
children | 1d769c66f407 |
rev | line source |
---|---|
20085 | 1 ;;; checkdoc --- Check documentation strings for style requirements |
2 | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
3 ;;; Copyright (C) 1997, 1998 Free Software Foundation |
21181 | 4 |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
5 ;; Author: Eric M. Ludlam <zappo@gnu.org> |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
6 ;; Version: 0.6.2 |
20085 | 7 ;; Keywords: docs, maint, lisp |
21181 | 8 |
20085 | 9 ;; This file is part of GNU Emacs. |
21181 | 10 |
20085 | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
21181 | 15 |
20085 | 16 ;; GNU Emacs is distributed in the hope that it will be useful, |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
21181 | 20 |
20085 | 21 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 ;; | |
22195 | 28 ;; The Emacs Lisp manual has a nice chapter on how to write |
20085 | 29 ;; documentation strings. Many stylistic suggestions are fairly |
30 ;; deterministic and easy to check for syntactically, but also easy | |
31 ;; to forget. The main checkdoc engine will perform the stylistic | |
32 ;; checks needed to make sure these styles are remembered. | |
33 ;; | |
34 ;; There are two ways to use checkdoc: | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
35 ;; 1) Periodically use `checkdoc' or `checkdoc-current-buffer'. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
36 ;; `checkdoc' is a more interactive version of |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
37 ;; `checkdoc-current-buffer' |
20085 | 38 ;; 2) Use `checkdoc-minor-mode' to automatically check your |
22195 | 39 ;; documentation whenever you evaluate Lisp code with C-M-x |
20085 | 40 ;; or [menu-bar emacs-lisp eval-buffer]. Additional key-bindings |
41 ;; are also provided under C-c ? KEY | |
42 ;; (require 'checkdoc) | |
43 ;; (add-hook 'emacs-lisp-mode-hook | |
44 ;; '(lambda () (checkdoc-minor-mode 1))) | |
45 ;; | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
46 ;; Using `checkdoc': |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
47 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
48 ;; The commands `checkdoc' and `checkdoc-ispell' are the top-level |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
49 ;; entry points to all of the different checks that are available. It |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
50 ;; breaks examination of your Lisp file into four sections (comments, |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
51 ;; documentation, messages, and spacing) and indicates its current |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
52 ;; state in a status buffer. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
53 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
54 ;; The Comments check examines your headers, footers, and |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
55 ;; various tags (such as "Code:") to make sure that your code is ready |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
56 ;; for easy integration into existing systems. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
57 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
58 ;; The Documentation check deals with documentation strings |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
59 ;; and their elements that help make Emacs easier to use. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
60 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
61 ;; The Messages check ensures that the strings displayed in the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
62 ;; minibuffer by some commands (such as `error' and `y-or-n-p') |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
63 ;; are consistent with the Emacs environment. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
64 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
65 ;; The Spacing check cleans up white-space at the end of lines. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
66 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
67 ;; The interface while working with documentation and messages is |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
68 ;; slightly different when being run in the interactive mode. The |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
69 ;; interface offers several options, including the ability to skip to |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
70 ;; the next error, or back up to previous errors. Auto-fixing is |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
71 ;; turned off at this stage, but you can use the `f' or `F' key to fix |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
72 ;; a given error (if the fix is available.) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
73 ;; |
20085 | 74 ;; Auto-fixing: |
75 ;; | |
76 ;; There are four classifications of style errors in terms of how | |
77 ;; easy they are to fix. They are simple, complex, really complex, | |
78 ;; and impossible. (Impossible really means that checkdoc does not | |
79 ;; have a fixing routine yet.) Typically white-space errors are | |
80 ;; classified as simple, and are auto-fixed by default. Typographic | |
81 ;; changes are considered complex, and the user is asked if they want | |
82 ;; the problem fixed before checkdoc makes the change. These changes | |
83 ;; can be done without asking if `checkdoc-autofix-flag' is properly | |
84 ;; set. Potentially redundant changes are considered really complex, | |
85 ;; and the user is always asked before a change is inserted. The | |
86 ;; variable `checkdoc-autofix-flag' controls how these types of errors | |
87 ;; are fixed. | |
88 ;; | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
89 ;; Spell checking text: |
20085 | 90 ;; |
91 ;; The variable `checkdoc-spellcheck-documentation-flag' can be set | |
92 ;; to customize how spell checking is to be done. Since spell | |
93 ;; checking can be quite slow, you can optimize how best you want your | |
94 ;; checking done. The default is 'defun, which spell checks each time | |
95 ;; `checkdoc-defun' or `checkdoc-eval-defun' is used. Setting to nil | |
96 ;; prevents spell checking during normal usage. | |
97 ;; Setting this variable to nil does not mean you cannot take | |
98 ;; advantage of the spell checking. You can instead use the | |
99 ;; interactive functions `checkdoc-ispell-*' to check the spelling of | |
100 ;; your documentation. | |
22195 | 101 ;; There is a list of Lisp-specific words which checkdoc will |
102 ;; install into Ispell on the fly, but only if Ispell is not already | |
20085 | 103 ;; running. Use `ispell-kill-ispell' to make checkdoc restart it with |
104 ;; these words enabled. | |
105 ;; | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
106 ;; Checking parameters: |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
107 ;; |
22514
dee11277c07d
(checkdoc-eval-defun): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
22195
diff
changeset
|
108 ;; 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
|
109 ;; 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
|
110 ;; 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
|
111 ;; 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
|
112 ;; |
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
113 ;; 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
|
114 ;; 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
|
115 ;; 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
|
116 ;; 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
|
117 ;; 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
|
118 ;; |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
119 ;; Checking message strings: |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
120 ;; |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
121 ;; The text that follows the `error' and `y-or-n-p' commands is |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
122 ;; 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
|
123 ;; 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
|
124 ;; `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
|
125 ;; 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
|
126 ;; |
20085 | 127 ;; Adding your own checks: |
128 ;; | |
129 ;; You can experiment with adding your own checks by setting the | |
130 ;; hooks `checkdoc-style-hooks' and `checkdoc-comment-style-hooks'. | |
131 ;; Return a string which is the error you wish to report. The cursor | |
132 ;; position should be preserved. | |
133 ;; | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
134 ;; Error errors: |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
135 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
136 ;; Checkdoc does not always flag errors correctly. There are a |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
137 ;; couple ways you can coax your file into passing all of checkdoc's |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
138 ;; tests through buffer local variables. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
139 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
140 ;; The variable `checkdoc-verb-check-experimental-flag' can be used |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
141 ;; to turn off the check for verb-voice in case you use words that are |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
142 ;; not semantically verbs, but are still in the incomplete list. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
143 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
144 ;; The variable `checkdoc-symbol-words' can be a list of words that |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
145 ;; happen to also be symbols. This is not a problem for one-word |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
146 ;; symbols, but if you use a hyphenated word that is also a symbol, |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
147 ;; then you may need this. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
148 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
149 ;; The symbol `checkdoc-force-docstrings-flag' can be set to nil if |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
150 ;; you have many undocumented functions you don't wish to document. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
151 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
152 ;; See the above section "Checking Parameters" for details about |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
153 ;; parameter checking. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
154 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
155 ;; Dependencies: |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
156 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
157 ;; This file requires lisp-mnt (Lisp maintenance routines) for the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
158 ;; comment checkers. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
159 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
160 ;; Requires custom for Emacs v20. |
20085 | 161 |
162 ;;; TO DO: | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
163 ;; Hook into the byte compiler on a defun/defvar level to generate |
20085 | 164 ;; warnings in the byte-compiler's warning/error buffer. |
165 ;; Better ways to override more typical `eval' functions. Advice | |
166 ;; might be good but hard to turn on/off as a minor mode. | |
167 ;; | |
168 ;;; Maybe Do: | |
169 ;; Code sweep checks for "forbidden functions", proper use of hooks, | |
170 ;; proper keybindings, and other items from the manual that are | |
171 ;; not specifically docstring related. Would this even be useful? | |
172 | |
173 ;;; Code: | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
174 (defvar checkdoc-version "0.6.1" |
20085 | 175 "Release version of checkdoc you are currently running.") |
176 | |
177 ;; From custom web page for compatibility between versions of custom: | |
178 (eval-and-compile | |
179 (condition-case () | |
180 (require 'custom) | |
181 (error nil)) | |
182 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
183 nil ;; We've got what we needed | |
184 ;; We have the old custom-library, hack around it! | |
185 (defmacro defgroup (&rest args) | |
186 nil) | |
187 (defmacro custom-add-option (&rest args) | |
188 nil) | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
189 (defmacro defcustom (var value doc &rest args) |
20085 | 190 (` (defvar (, var) (, value) (, doc)))))) |
191 | |
192 (defcustom checkdoc-autofix-flag 'semiautomatic | |
22195 | 193 "*Non-nil means attempt auto-fixing of doc strings. |
194 If this value is the symbol `query', then the user is queried before | |
195 any change is made. If the value is `automatic', then all changes are | |
20085 | 196 made without asking unless the change is very-complex. If the value |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
197 is `semiautomatic' or any other value, then simple fixes are made |
20085 | 198 without asking, and complex changes are made by asking the user first. |
22195 | 199 The value `never' is the same as nil, never ask or change anything." |
20085 | 200 :group 'checkdoc |
201 :type '(choice (const automatic) | |
202 (const query) | |
22579
d0ad271c7774
(checkdoc-autofix-flag): Use `other'
Andreas Schwab <schwab@suse.de>
parents:
22514
diff
changeset
|
203 (const never) |
d0ad271c7774
(checkdoc-autofix-flag): Use `other'
Andreas Schwab <schwab@suse.de>
parents:
22514
diff
changeset
|
204 (other :tag "semiautomatic" semiautomatic))) |
20085 | 205 |
206 (defcustom checkdoc-bouncy-flag t | |
22195 | 207 "*Non-nil means to \"bounce\" to auto-fix locations. |
20085 | 208 Setting this to nil will silently make fixes that require no user |
209 interaction. See `checkdoc-autofix-flag' for auto-fixing details." | |
210 :group 'checkdoc | |
211 :type 'boolean) | |
212 | |
213 (defcustom checkdoc-force-docstrings-flag t | |
214 "*Non-nil means that all checkable definitions should have documentation. | |
215 Style guide dictates that interactive functions MUST have documentation, | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
216 and that it's good but not required practice to make non user visible items |
22195 | 217 have doc strings." |
20085 | 218 :group 'checkdoc |
219 :type 'boolean) | |
220 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
221 (defcustom checkdoc-force-history-flag t |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
222 "*Non-nil means that files should have a History section or ChangeLog file. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
223 This helps document the evolution of, and recent changes to, the package." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
224 :group 'checkdoc |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
225 :type 'boolean) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
226 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
227 (defcustom checkdoc-permit-comma-termination-flag nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
228 "*Non-nil means the first line of a docstring may end with a comma. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
229 Ordinarily, a full sentence is required. This may be misleading when |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
230 there is a substantial caveat to the one-line description -- the comma |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
231 should be used when the first part could stand alone as a sentence, but |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
232 it indicates that a modifying clause follows." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
233 :group 'checkdoc |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
234 :type 'boolean) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
235 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
236 (defcustom checkdoc-triple-semi-comment-check-flag t |
20085 | 237 "*Non-nil means to check for multiple adjacent occurrences of ;;; comments. |
22195 | 238 According to the style of Emacs code in the Lisp libraries, a block |
20085 | 239 comment can look like this: |
240 ;;; Title | |
241 ;; text | |
242 ;; text | |
243 But when inside a function, code can be commented out using the ;;; | |
244 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
|
245 is ignored regardless of its location in the code." |
20085 | 246 :group 'checkdoc |
247 :type 'boolean) | |
248 | |
249 (defcustom checkdoc-spellcheck-documentation-flag nil | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
250 "*Non-nil means run Ispell on text based on value. |
22195 | 251 This is automatically set to nil if Ispell does not exist on your |
20085 | 252 system. Possible values are: |
253 | |
22195 | 254 nil - Don't spell-check during basic style checks. |
255 defun - Spell-check when style checking a single defun | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
256 buffer - Spell-check when style checking the whole buffer |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
257 interactive - Spell-check during any interactive check. |
22195 | 258 t - Always spell-check" |
20085 | 259 :group 'checkdoc |
260 :type '(choice (const nil) | |
261 (const defun) | |
262 (const buffer) | |
263 (const interactive) | |
264 (const t))) | |
265 | |
266 (defvar checkdoc-ispell-lisp-words | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
267 '("alist" "emacs" "etags" "iff" "keymap" "paren" "regexp" "sexp" "xemacs") |
22195 | 268 "List of words that are correct when spell-checking Lisp documentation.") |
20085 | 269 |
270 (defcustom checkdoc-max-keyref-before-warn 10 | |
22195 | 271 "*The number of \\ [command-to-keystroke] tokens allowed in a doc string. |
20085 | 272 Any more than this and a warning is generated suggesting that the construct |
273 \\ {keymap} be used instead." | |
274 :group 'checkdoc | |
275 :type 'integer) | |
276 | |
277 (defcustom checkdoc-arguments-in-order-flag t | |
278 "*Non-nil means warn if arguments appear out of order. | |
279 Setting this to nil will mean only checking that all the arguments | |
280 appear in the proper form in the documentation, not that they are in | |
281 the same order as they appear in the argument list. No mention is | |
282 made in the style guide relating to order." | |
283 :group 'checkdoc | |
284 :type 'boolean) | |
285 | |
286 (defvar checkdoc-style-hooks nil | |
287 "Hooks called after the standard style check is completed. | |
288 All hooks must return nil or a string representing the error found. | |
289 Useful for adding new user implemented commands. | |
290 | |
291 Each hook is called with two parameters, (DEFUNINFO ENDPOINT). | |
292 DEFUNINFO is the return value of `checkdoc-defun-info'. ENDPOINT is the | |
293 location of end of the documentation string.") | |
294 | |
295 (defvar checkdoc-comment-style-hooks nil | |
296 "Hooks called after the standard comment style check is completed. | |
297 Must return nil if no errors are found, or a string describing the | |
298 problem discovered. This is useful for adding additional checks.") | |
299 | |
300 (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
|
301 "Name of warning message buffer.") |
20085 | 302 |
303 (defvar checkdoc-defun-regexp | |
304 "^(def\\(un\\|var\\|custom\\|macro\\|const\\|subst\\|advice\\)\ | |
305 \\s-+\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]+" | |
306 "Regular expression used to identify a defun. | |
307 A search leaves the cursor in front of the parameter list.") | |
308 | |
309 (defcustom checkdoc-verb-check-experimental-flag t | |
22195 | 310 "*Non-nil means to attempt to check the voice of the doc string. |
20085 | 311 This check keys off some words which are commonly misused. See the |
22195 | 312 variable `checkdoc-common-verbs-wrong-voice' if you wish to add your own." |
20085 | 313 :group 'checkdoc |
314 :type 'boolean) | |
315 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
316 (defvar checkdoc-generate-compile-warnings-flag nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
317 "Non-nil means generage warnings in a buffer for browsing. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
318 Do not set this by hand, use a function like `checkdoc-current-buffer' |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
319 with a universal argument.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
320 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
321 (defcustom checkdoc-symbol-words nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
322 "A list of symbols which also happen to make good words. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
323 These symbol-words are ignored when unquoted symbols are searched for. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
324 This should be set in an Emacs Lisp file's local variables." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
325 :group 'checkdoc |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
326 :type '(repeat (symbol :tag "Word"))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
327 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
328 (defvar checkdoc-proper-noun-list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
329 '("ispell" "xemacs" "emacs" "lisp") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
330 "List of words (not capitalized) which should be capitalized.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
331 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
332 (defvar checkdoc-proper-noun-regexp |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
333 (let ((expr "\\<\\(") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
334 (l checkdoc-proper-noun-list)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
335 (while l |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
336 (setq expr (concat expr (car l) (if (cdr l) "\\|" "")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
337 l (cdr l))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
338 (concat expr "\\)\\>")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
339 "Regular expression derived from `checkdoc-proper-noun-regexp'.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
340 |
20085 | 341 (defvar checkdoc-common-verbs-regexp nil |
342 "Regular expression derived from `checkdoc-common-verbs-regexp'.") | |
343 | |
344 (defvar checkdoc-common-verbs-wrong-voice | |
345 '(("adds" . "add") | |
346 ("allows" . "allow") | |
347 ("appends" . "append") | |
22514
dee11277c07d
(checkdoc-eval-defun): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
22195
diff
changeset
|
348 ("applies" . "apply") |
dee11277c07d
(checkdoc-eval-defun): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
22195
diff
changeset
|
349 ("arranges" . "arrange") |
20085 | 350 ("brings" . "bring") |
351 ("calls" . "call") | |
352 ("catches" . "catch") | |
353 ("changes" . "change") | |
354 ("checks" . "check") | |
355 ("contains" . "contain") | |
356 ("creates" . "create") | |
357 ("destroys" . "destroy") | |
358 ("disables" . "disable") | |
359 ("executes" . "execute") | |
22514
dee11277c07d
(checkdoc-eval-defun): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
22195
diff
changeset
|
360 ("evals" . "evaluate") |
20085 | 361 ("evaluates" . "evaluate") |
362 ("finds" . "find") | |
363 ("forces" . "force") | |
364 ("gathers" . "gather") | |
365 ("generates" . "generate") | |
366 ("goes" . "go") | |
367 ("guesses" . "guess") | |
368 ("highlights" . "highlight") | |
369 ("holds" . "hold") | |
370 ("ignores" . "ignore") | |
371 ("indents" . "indent") | |
372 ("initializes" . "initialize") | |
373 ("inserts" . "insert") | |
374 ("installs" . "install") | |
375 ("investigates" . "investigate") | |
376 ("keeps" . "keep") | |
377 ("kills" . "kill") | |
378 ("leaves" . "leave") | |
379 ("lets" . "let") | |
380 ("loads" . "load") | |
381 ("looks" . "look") | |
382 ("makes" . "make") | |
383 ("marks" . "mark") | |
384 ("matches" . "match") | |
385 ("notifies" . "notify") | |
386 ("offers" . "offer") | |
387 ("parses" . "parse") | |
388 ("performs" . "perform") | |
389 ("prepares" . "prepare") | |
390 ("prepends" . "prepend") | |
391 ("reads" . "read") | |
392 ("raises" . "raise") | |
393 ("removes" . "remove") | |
394 ("replaces" . "replace") | |
395 ("resets" . "reset") | |
396 ("restores" . "restore") | |
397 ("returns" . "return") | |
398 ("runs" . "run") | |
399 ("saves" . "save") | |
400 ("says" . "say") | |
401 ("searches" . "search") | |
402 ("selects" . "select") | |
403 ("sets" . "set") | |
404 ("sex" . "s*x") | |
405 ("shows" . "show") | |
406 ("signifies" . "signify") | |
407 ("sorts" . "sort") | |
408 ("starts" . "start") | |
409 ("stores" . "store") | |
410 ("switches" . "switch") | |
411 ("tells" . "tell") | |
412 ("tests" . "test") | |
413 ("toggles" . "toggle") | |
22514
dee11277c07d
(checkdoc-eval-defun): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
22195
diff
changeset
|
414 ("tries" . "try") |
20085 | 415 ("turns" . "turn") |
416 ("undoes" . "undo") | |
417 ("unloads" . "unload") | |
418 ("unmarks" . "unmark") | |
419 ("updates" . "update") | |
420 ("uses" . "use") | |
421 ("yanks" . "yank") | |
422 ) | |
423 "Alist of common words in the wrong voice and what should be used instead. | |
424 Set `checkdoc-verb-check-experimental-flag' to nil to avoid this costly | |
425 and experimental check. Do not modify this list without setting | |
426 the value of `checkdoc-common-verbs-regexp' to nil which cause it to | |
427 be re-created.") | |
428 | |
429 (defvar checkdoc-syntax-table nil | |
430 "Syntax table used by checkdoc in document strings.") | |
431 | |
432 (if checkdoc-syntax-table | |
433 nil | |
434 (setq checkdoc-syntax-table (copy-syntax-table emacs-lisp-mode-syntax-table)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
435 ;; When dealing with syntax in doc strings, make sure that - are encompassed |
20085 | 436 ;; in words so we can use cheap \\> to get the end of a symbol, not the |
437 ;; end of a word in a conglomerate. | |
438 (modify-syntax-entry ?- "w" checkdoc-syntax-table) | |
439 ) | |
440 | |
441 | |
442 ;;; Compatibility | |
443 ;; | |
444 (if (string-match "X[Ee]macs" emacs-version) | |
445 (progn | |
446 (defalias 'checkdoc-make-overlay 'make-extent) | |
447 (defalias 'checkdoc-overlay-put 'set-extent-property) | |
448 (defalias 'checkdoc-delete-overlay 'delete-extent) | |
449 (defalias 'checkdoc-overlay-start 'extent-start) | |
450 (defalias 'checkdoc-overlay-end 'extent-end) | |
451 (defalias 'checkdoc-mode-line-update 'redraw-modeline) | |
452 (defalias 'checkdoc-call-eval-buffer 'eval-buffer) | |
453 ) | |
454 (defalias 'checkdoc-make-overlay 'make-overlay) | |
455 (defalias 'checkdoc-overlay-put 'overlay-put) | |
456 (defalias 'checkdoc-delete-overlay 'delete-overlay) | |
457 (defalias 'checkdoc-overlay-start 'overlay-start) | |
458 (defalias 'checkdoc-overlay-end 'overlay-end) | |
459 (defalias 'checkdoc-mode-line-update 'force-mode-line-update) | |
460 (defalias 'checkdoc-call-eval-buffer 'eval-current-buffer) | |
461 ) | |
462 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
463 ;; Emacs 20 has this handy function. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
464 (if (not (fboundp 'princ-list)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
465 (defun princ-list (&rest args) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
466 "Call `princ' on ARGS." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
467 (mapcar 'princ args))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
468 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
469 ;; Emacs 20s have MULE characters which don't equate to numbers. |
20085 | 470 (if (fboundp 'char=) |
471 (defalias 'checkdoc-char= 'char=) | |
472 (defalias 'checkdoc-char= '=)) | |
473 | |
474 ;; Emacs 19.28 and earlier don't have the handy 'add-to-list function | |
475 (if (fboundp 'add-to-list) | |
476 | |
477 (defalias 'checkdoc-add-to-list 'add-to-list) | |
478 | |
479 (defun checkdoc-add-to-list (list-var element) | |
480 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet." | |
481 (if (not (member element (symbol-value list-var))) | |
482 (set list-var (cons element (symbol-value list-var))))) | |
483 ) | |
484 | |
22195 | 485 ;; To be safe in new Emacsen, we want to read events, not characters |
20085 | 486 (if (fboundp 'read-event) |
487 (defalias 'checkdoc-read-event 'read-event) | |
488 (defalias 'checkdoc-read-event 'read-char)) | |
489 | |
490 ;;; User level commands | |
491 ;; | |
492 ;;;###autoload | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
493 (defun checkdoc () |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
494 "Interactivly check the entire buffer for style errors. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
495 The current status of the ckeck will be displayed in a buffer which |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
496 the users will view as each check is completed." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
497 (interactive) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
498 (let ((status (list "Checking..." "-" "-" "-")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
499 (checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
500 (member checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
501 '(buffer interactive t))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
502 ;; if the user set autofix to never, then that breaks the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
503 ;; obviously requested asking implied by using this function. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
504 ;; Set it to paranoia level. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
505 (checkdoc-autofix-flag (if (or (not checkdoc-autofix-flag) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
506 (eq checkdoc-autofix-flag 'never)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
507 'query |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
508 checkdoc-autofix-flag)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
509 tmp) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
510 (checkdoc-display-status-buffer status) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
511 ;; check the comments |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
512 (if (not buffer-file-name) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
513 (setcar status "Not checked") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
514 (if (checkdoc-file-comments-engine) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
515 (setcar status "Errors") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
516 (setcar status "Ok"))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
517 (setcar (cdr status) "Checking...") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
518 (checkdoc-display-status-buffer status) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
519 ;; Check the documentation |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
520 (setq tmp (checkdoc-interactive nil t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
521 (if tmp |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
522 (setcar (cdr status) (format "%d Errors" (length tmp))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
523 (setcar (cdr status) "Ok")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
524 (setcar (cdr (cdr status)) "Checking...") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
525 (checkdoc-display-status-buffer status) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
526 ;; Check the message text |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
527 (if (setq tmp (checkdoc-message-interactive nil t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
528 (setcar (cdr (cdr status)) (format "%d Errors" (length tmp))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
529 (setcar (cdr (cdr status)) "Ok")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
530 (setcar (cdr (cdr (cdr status))) "Checking...") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
531 (checkdoc-display-status-buffer status) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
532 ;; Rogue spacing |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
533 (if (condition-case nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
534 (checkdoc-rogue-spaces nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
535 (error t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
536 (setcar (cdr (cdr (cdr status))) "Errors") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
537 (setcar (cdr (cdr (cdr status))) "Ok")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
538 (checkdoc-display-status-buffer status))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
539 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
540 (defun checkdoc-display-status-buffer (check) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
541 "Display and update the status buffer for the current checkdoc mode. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
542 CHECK is a vector stating the current status of each test as an |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
543 element is the status of that level of teset." |
25697
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
544 (let (temp-buffer-setup-hook) |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
545 (with-output-to-temp-buffer " *Checkdoc Status*" |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
546 (princ-list |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
547 "Buffer comments and tags: " (nth 0 check) "\n" |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
548 "Documentation style: " (nth 1 check) "\n" |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
549 "Message/Query text style: " (nth 2 check) "\n" |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
550 "Unwanted Spaces: " (nth 3 check) |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
551 ))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
552 (shrink-window-if-larger-than-buffer |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
553 (get-buffer-window " *Checkdoc Status*")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
554 (message nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
555 (sit-for 0)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
556 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
557 ;;;###autoload |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
558 (defun checkdoc-interactive (&optional start-here showstatus) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
559 "Interactively check the current buffer for doc string errors. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
560 Prefix argument START-HERE will start the checking from the current |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
561 point, otherwise the check starts at the beginning of the current |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
562 buffer. Allows navigation forward and backwards through document |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
563 errors. Does not check for comment or space warnings. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
564 Optional argument SHOWSTATUS indicates that we should update the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
565 checkdoc status window instead of the usual behavior." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
566 (interactive "P") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
567 (let ((checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
568 (member checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
569 '(interactive t)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
570 (checkdoc-interactive-loop start-here showstatus 'checkdoc-next-error))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
571 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
572 ;;;###autoload |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
573 (defun checkdoc-message-interactive (&optional start-here showstatus) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
574 "Interactively check the current buffer for message string errors. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
575 Prefix argument START-HERE will start the checking from the current |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
576 point, otherwise the check starts at the beginning of the current |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
577 buffer. Allows navigation forward and backwards through document |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
578 errors. Does not check for comment or space warnings. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
579 Optional argument SHOWSTATUS indicates that we should update the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
580 checkdoc status window instead of the usual behavior." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
581 (interactive "P") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
582 (let ((checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
583 (member checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
584 '(interactive t)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
585 (checkdoc-interactive-loop start-here showstatus |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
586 'checkdoc-next-message-error))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
587 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
588 (defun checkdoc-interactive-loop (start-here showstatus findfunc) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
589 "Interactivly loop over all errors that can be found by a given method. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
590 Searching starts at START-HERE. SHOWSTATUS expresses the verbosity |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
591 of the search, and wether ending the search will auto-exit this function. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
592 FINDFUNC is a symbol representing a function that will position the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
593 cursor, and return error message text to present the the user. It is |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
594 assumed that the cursor will stop just before a major sexp, which will |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
595 be highlighted to present the user with feedback as to the offending |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
596 style." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
597 ;; Determine where to start the test |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
598 (let* ((begin (prog1 (point) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
599 (if (not start-here) (goto-char (point-min))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
600 ;; Assign a flag to spellcheck flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
601 (checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
602 (member checkdoc-spellcheck-documentation-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
603 '(buffer interactive t))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
604 ;; Fetch the error list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
605 (err-list (list (funcall findfunc nil))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
606 (cdo nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
607 (returnme nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
608 c) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
609 (save-window-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
610 (if (not (car err-list)) (setq err-list nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
611 ;; Include whatever function point is in for good measure. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
612 (beginning-of-defun) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
613 (while err-list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
614 (goto-char (cdr (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
615 ;; The cursor should be just in front of the offending doc string |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
616 (if (stringp (car (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
617 (setq cdo (save-excursion (checkdoc-make-overlay |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
618 (point) (progn (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
619 (point))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
620 (setq cdo (checkdoc-make-overlay |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
621 (checkdoc-error-start (car (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
622 (checkdoc-error-end (car (car err-list)))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
623 (unwind-protect |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
624 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
625 (checkdoc-overlay-put cdo 'face 'highlight) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
626 ;; Make sure the whole doc string is visible if possible. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
627 (sit-for 0) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
628 (if (not (pos-visible-in-window-p |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
629 (save-excursion (forward-sexp 1) (point)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
630 (selected-window))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
631 (if (looking-at "\"") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
632 (let ((l (count-lines (point) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
633 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
634 (forward-sexp 1) (point))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
635 (if (> l (window-height)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
636 (recenter 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
637 (recenter (/ (- (window-height) l) 2)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
638 (recenter))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
639 (message "%s (C-h,%se,n,p,q)" (checkdoc-error-text |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
640 (car (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
641 (if (checkdoc-error-unfixable (car (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
642 "" "f,")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
643 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
644 (goto-char (checkdoc-error-start (car (car err-list)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
645 (if (not (pos-visible-in-window-p)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
646 (recenter (- (window-height) 2))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
647 (setq c (checkdoc-read-event)))1 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
648 (if (not (integerp c)) (setq c ??)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
649 (cond |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
650 ;; Exit condition |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
651 ((checkdoc-char= c ?\C-g) (signal 'quit nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
652 ;; Request an auto-fix |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
653 ((or (checkdoc-char= c ?y) (checkdoc-char= c ?f)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
654 (checkdoc-delete-overlay cdo) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
655 (setq cdo nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
656 (goto-char (cdr (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
657 ;; `automatic-then-never' tells the autofix function |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
658 ;; to only allow one fix to be automatic. The autofix |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
659 ;; function will than set the flag to 'never, allowing |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
660 ;; the checker to return a different error. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
661 (let ((checkdoc-autofix-flag 'automatic-then-never) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
662 (fixed nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
663 (funcall findfunc t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
664 (setq fixed (not (eq checkdoc-autofix-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
665 'automatic-then-never))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
666 (if (not fixed) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
667 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
668 (message "A Fix was not available.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
669 (sit-for 2)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
670 (setq err-list (cdr err-list)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
671 (beginning-of-defun) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
672 (let ((pe (car err-list)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
673 (ne (funcall findfunc nil))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
674 (if ne |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
675 (setq err-list (cons ne err-list)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
676 (cond ((not err-list) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
677 (message "No More Stylistic Errors.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
678 (sit-for 2)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
679 (t |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
680 (message |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
681 "No Additional style errors. Continuing...") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
682 (sit-for 2)))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
683 ;; Move to the next error (if available) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
684 ((or (checkdoc-char= c ?n) (checkdoc-char= c ?\ )) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
685 (let ((ne (funcall findfunc nil))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
686 (if (not ne) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
687 (if showstatus |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
688 (setq returnme err-list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
689 err-list nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
690 (if (not err-list) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
691 (message "No More Stylistic Errors.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
692 (message "No Additional style errors. Continuing...")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
693 (sit-for 2)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
694 (setq err-list (cons ne err-list))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
695 ;; Go backwards in the list of errors |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
696 ((or (checkdoc-char= c ?p) (checkdoc-char= c ?\C-?)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
697 (if (/= (length err-list) 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
698 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
699 (setq err-list (cdr err-list)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
700 (goto-char (cdr (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
701 (beginning-of-defun)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
702 (message "No Previous Errors.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
703 (sit-for 2))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
704 ;; Edit the buffer recursively. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
705 ((checkdoc-char= c ?e) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
706 (checkdoc-recursive-edit |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
707 (checkdoc-error-text (car (car err-list)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
708 (checkdoc-delete-overlay cdo) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
709 (setq err-list (cdr err-list)) ;back up the error found. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
710 (beginning-of-defun) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
711 (let ((ne (funcall findfunc nil))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
712 (if (not ne) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
713 (if showstatus |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
714 (setq returnme err-list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
715 err-list nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
716 (message "No More Stylistic Errors.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
717 (sit-for 2)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
718 (setq err-list (cons ne err-list))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
719 ;; Quit checkdoc |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
720 ((checkdoc-char= c ?q) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
721 (setq returnme err-list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
722 err-list nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
723 begin (point))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
724 ;; Goofy s tuff |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
725 (t |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
726 (if (get-buffer-window "*Checkdoc Help*") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
727 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
728 (delete-window (get-buffer-window "*Checkdoc Help*")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
729 (kill-buffer "*Checkdoc Help*")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
730 (with-output-to-temp-buffer "*Checkdoc Help*" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
731 (princ-list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
732 "Checkdoc Keyboard Summary:\n" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
733 (if (checkdoc-error-unfixable (car (car err-list))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
734 "" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
735 (concat |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
736 "f, y - auto Fix this warning without asking (if\ |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
737 available.)\n" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
738 " Very complex operations will still query.\n") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
739 ) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
740 "e - Enter recursive Edit. Press C-M-c to exit.\n" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
741 "SPC, n - skip to the Next error.\n" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
742 "DEL, p - skip to the Previous error.\n" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
743 "q - Quit checkdoc.\n" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
744 "C-h - Toggle this help buffer.")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
745 (shrink-window-if-larger-than-buffer |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
746 (get-buffer-window "*Checkdoc Help*")))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
747 (if cdo (checkdoc-delete-overlay cdo))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
748 (goto-char begin) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
749 (if (get-buffer "*Checkdoc Help*") (kill-buffer "*Checkdoc Help*")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
750 (message "Checkdoc: Done.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
751 returnme)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
752 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
753 (defun checkdoc-next-error (enable-fix) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
754 "Find and return the next checkdoc error list, or nil. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
755 Only documentation strings are checked. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
756 Add error vector is of the form (WARNING . POSITION) where WARNING |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
757 is the warning text, and POSITION is the point in the buffer where the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
758 error was found. We can use points and not markers because we promise |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
759 not to edit the buffer before point without re-executing this check. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
760 Argument ENABLE-FIX will enable auto-fixing while looking for the next |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
761 error. This argument assumes that the cursor is already positioned to |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
762 perform the fix." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
763 (if enable-fix |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
764 (checkdoc-this-string-valid) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
765 (let ((msg nil) (p (point)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
766 (checkdoc-autofix-flag nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
767 (condition-case nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
768 (while (and (not msg) (checkdoc-next-docstring)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
769 (message "Searching for doc string error...%d%%" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
770 (/ (* 100 (point)) (point-max))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
771 (if (setq msg (checkdoc-this-string-valid)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
772 (setq msg (cons msg (point))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
773 ;; Quit.. restore position, Other errors, leave alone |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
774 (quit (goto-char p))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
775 msg))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
776 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
777 (defun checkdoc-next-message-error (enable-fix) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
778 "Find and return the next checkdoc mesasge related error list, or nil. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
779 Only text for error and `y-or-n-p' strings are checked. See |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
780 `checkdoc-next-error' for details on the return value. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
781 Argument ENABLE-FIX turns on the auto-fix feature. This argument |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
782 assumes that the cursor is already positioned to perform the fix." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
783 (if enable-fix |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
784 (checkdoc-message-text-engine) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
785 (let ((msg nil) (p (point)) (type nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
786 (checkdoc-autofix-flag nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
787 (condition-case nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
788 (while (and (not msg) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
789 (setq type |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
790 (checkdoc-message-text-next-string (point-max)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
791 (message "Searching for message string error...%d%%" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
792 (/ (* 100 (point)) (point-max))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
793 (if (setq msg (checkdoc-message-text-engine type)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
794 (setq msg (cons msg (point))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
795 ;; Quit.. restore position, Other errors, leave alone |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
796 (quit (goto-char p))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
797 msg))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
798 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
799 (defun checkdoc-recursive-edit (msg) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
800 "Enter recursive edit to permit a user to fix some error checkdoc has found. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
801 MSG is the error that was found, which is displayed in a help buffer." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
802 (with-output-to-temp-buffer "*Checkdoc Help*" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
803 (princ-list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
804 "Error message:\n " msg |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
805 "\n\nEdit to fix this problem, and press C-M-c to continue.")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
806 (shrink-window-if-larger-than-buffer |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
807 (get-buffer-window "*Checkdoc Help*")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
808 (message "When you're done editing press C-M-c to continue.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
809 (unwind-protect |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
810 (recursive-edit) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
811 (if (get-buffer-window "*Checkdoc Help*") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
812 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
813 (delete-window (get-buffer-window "*Checkdoc Help*")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
814 (kill-buffer "*Checkdoc Help*"))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
815 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
816 ;;;###autoload |
20085 | 817 (defun checkdoc-eval-current-buffer () |
818 "Evaluate and check documentation for the current buffer. | |
819 Evaluation is done first because good documentation for something that | |
22195 | 820 doesn't work is just not useful. Comments, doc strings, and rogue |
20085 | 821 spacing are all verified." |
822 (interactive) | |
823 (checkdoc-call-eval-buffer nil) | |
824 (checkdoc-current-buffer t)) | |
825 | |
826 ;;;###autoload | |
827 (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
|
828 "Check current buffer for document, comment, error style, and rogue spaces. |
22195 | 829 With a prefix argument (in Lisp, the argument TAKE-NOTES), |
830 store all errors found in a warnings buffer, | |
831 otherwise stop after the first error." | |
20085 | 832 (interactive "P") |
833 (if (interactive-p) (message "Checking buffer for style...")) | |
834 ;; Assign a flag to spellcheck flag | |
835 (let ((checkdoc-spellcheck-documentation-flag | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
836 (memq checkdoc-spellcheck-documentation-flag '(buffer t))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
837 (checkdoc-autofix-flag (if take-notes 'never |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
838 checkdoc-autofix-flag)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
839 (checkdoc-generate-compile-warnings-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
840 (or take-notes checkdoc-generate-compile-warnings-flag))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
841 (if take-notes |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
842 (checkdoc-start-section "checkdoc-current-buffer")) |
20085 | 843 ;; every test is responsible for returning the cursor. |
844 (or (and buffer-file-name ;; only check comments in a file | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
845 (checkdoc-comments)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
846 (checkdoc-start) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
847 (checkdoc-message-text) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
848 (checkdoc-rogue-spaces) |
20085 | 849 (not (interactive-p)) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
850 (if take-notes (checkdoc-show-diagnostics)) |
20085 | 851 (message "Checking buffer for style...Done.")))) |
852 | |
853 ;;;###autoload | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
854 (defun checkdoc-start (&optional take-notes) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
855 "Start scanning the current buffer for documentation string style errors. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
856 Only documentation strings are checked. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
857 Use `checkdoc-continue' to continue checking if an error cannot be fixed. |
20085 | 858 Prefix argument TAKE-NOTES means to collect all the warning messages into |
859 a separate buffer." | |
860 (interactive "P") | |
861 (let ((p (point))) | |
862 (goto-char (point-min)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
863 (if (and take-notes (interactive-p)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
864 (checkdoc-start-section "checkdoc-start")) |
20085 | 865 (checkdoc-continue take-notes) |
866 ;; Go back since we can't be here without success above. | |
867 (goto-char p) | |
868 nil)) | |
869 | |
870 ;;;###autoload | |
871 (defun checkdoc-continue (&optional take-notes) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
872 "Find the next doc string in the current buffer which has a style error. |
20085 | 873 Prefix argument TAKE-NOTES means to continue through the whole buffer and |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
874 save warnings in a separate buffer. Second optional argument START-POINT |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
875 is the starting location. If this is nil, `point-min' is used instead." |
20085 | 876 (interactive "P") |
877 (let ((wrong nil) (msg nil) (errors nil) | |
878 ;; Assign a flag to spellcheck flag | |
879 (checkdoc-spellcheck-documentation-flag | |
880 (member checkdoc-spellcheck-documentation-flag | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
881 '(buffer t))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
882 (checkdoc-autofix-flag (if take-notes 'never |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
883 checkdoc-autofix-flag)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
884 (checkdoc-generate-compile-warnings-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
885 (or take-notes checkdoc-generate-compile-warnings-flag))) |
20085 | 886 (save-excursion |
887 ;; If we are taking notes, encompass the whole buffer, otherwise | |
888 ;; the user is navigating down through the buffer. | |
889 (while (and (not wrong) (checkdoc-next-docstring)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
890 ;; OK, let's look at the doc string. |
21181 | 891 (setq msg (checkdoc-this-string-valid)) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
892 (if msg (setq wrong (point))))) |
20085 | 893 (if wrong |
894 (progn | |
895 (goto-char wrong) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
896 (if (not take-notes) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
897 (error (checkdoc-error-text msg))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
898 (checkdoc-show-diagnostics) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
899 (if (interactive-p) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
900 (message "No style warnings.")))) |
20085 | 901 |
902 (defun checkdoc-next-docstring () | |
22195 | 903 "Move to the next doc string after point, and return t. |
904 Return nil if there are no more doc strings." | |
20085 | 905 (if (not (re-search-forward checkdoc-defun-regexp nil t)) |
906 nil | |
907 ;; search drops us after the identifier. The next sexp is either | |
908 ;; the argument list or the value of the variable. skip it. | |
909 (forward-sexp 1) | |
910 (skip-chars-forward " \n\t") | |
911 t)) | |
912 | |
913 ;;; ###autoload | |
914 (defun checkdoc-comments (&optional take-notes) | |
22195 | 915 "Find missing comment sections in the current Emacs Lisp file. |
20085 | 916 Prefix argument TAKE-NOTES non-nil means to save warnings in a |
917 separate buffer. Otherwise print a message. This returns the error | |
918 if there is one." | |
919 (interactive "P") | |
920 (if take-notes (checkdoc-start-section "checkdoc-comments")) | |
921 (if (not buffer-file-name) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
922 (error "Can only check comments for a file buffer")) |
20085 | 923 (let* ((checkdoc-spellcheck-documentation-flag |
924 (member checkdoc-spellcheck-documentation-flag | |
925 '(buffer t))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
926 (checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
927 ;; This is just irritating when taking notes. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
928 (checkdoc-triple-semi-comment-check-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
929 (if take-notes nil checkdoc-triple-semi-comment-check-flag)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
930 (e (checkdoc-file-comments-engine)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
931 (checkdoc-generate-compile-warnings-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
932 (or take-notes checkdoc-generate-compile-warnings-flag))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
933 (if e (error (checkdoc-error-text e))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
934 (checkdoc-show-diagnostics) |
20085 | 935 e)) |
936 | |
937 ;;;###autoload | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
938 (defun checkdoc-rogue-spaces (&optional take-notes interact) |
20085 | 939 "Find extra spaces at the end of lines in the current file. |
940 Prefix argument TAKE-NOTES non-nil means to save warnings in a | |
941 separate buffer. Otherwise print a message. This returns the error | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
942 if there is one. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
943 Optional argument INTERACT permits more interactive fixing." |
20085 | 944 (interactive "P") |
945 (if take-notes (checkdoc-start-section "checkdoc-rogue-spaces")) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
946 (let* ((checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
947 (e (checkdoc-rogue-space-check-engine nil nil interact)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
948 (checkdoc-generate-compile-warnings-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
949 (or take-notes checkdoc-generate-compile-warnings-flag))) |
20085 | 950 (if (not (interactive-p)) |
951 e | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
952 (if e |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
953 (message (checkdoc-error-text e)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
954 (checkdoc-show-diagnostics) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
955 (message "Space Check: done."))))) |
20085 | 956 |
957 ;;;###autoload | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
958 (defun checkdoc-message-text (&optional take-notes) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
959 "Scan the buffer for occurrences of the error function, and verify text. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
960 Optional argument TAKE-NOTES causes all errors to be logged." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
961 (interactive "P") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
962 (if take-notes (checkdoc-start-section "checkdoc-message-text")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
963 (let* ((p (point)) e |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
964 (checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
965 (checkdoc-generate-compile-warnings-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
966 (or take-notes checkdoc-generate-compile-warnings-flag))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
967 (setq e (checkdoc-message-text-search)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
968 (if (not (interactive-p)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
969 e |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
970 (if e |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
971 (error (checkdoc-error-text e)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
972 (checkdoc-show-diagnostics))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
973 (goto-char p)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
974 (if (interactive-p) (message "Checking interactive message text...done."))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
975 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
976 ;;;###autoload |
20085 | 977 (defun checkdoc-eval-defun () |
22514
dee11277c07d
(checkdoc-eval-defun): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
22195
diff
changeset
|
978 "Evaluate the current form with `eval-defun' and check its documentation. |
20085 | 979 Evaluation is done first so the form will be read before the |
980 documentation is checked. If there is a documentation error, then the display | |
981 of what was evaluated will be overwritten by the diagnostic message." | |
982 (interactive) | |
983 (eval-defun nil) | |
984 (checkdoc-defun)) | |
985 | |
986 ;;;###autoload | |
987 (defun checkdoc-defun (&optional no-error) | |
22195 | 988 "Examine the doc string of the function or variable under point. |
989 Call `error' if the doc string has problems. If NO-ERROR is | |
20085 | 990 non-nil, then do not call error, but call `message' instead. |
22195 | 991 If the doc string passes the test, then check the function for rogue white |
20085 | 992 space at the end of each line." |
993 (interactive) | |
994 (save-excursion | |
995 (beginning-of-defun) | |
996 (if (not (looking-at checkdoc-defun-regexp)) | |
997 ;; I found this more annoying than useful. | |
998 ;;(if (not no-error) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
999 ;; (message "Cannot check this sexp's doc string.")) |
20085 | 1000 nil |
1001 ;; search drops us after the identifier. The next sexp is either | |
1002 ;; the argument list or the value of the variable. skip it. | |
1003 (goto-char (match-end 0)) | |
1004 (forward-sexp 1) | |
1005 (skip-chars-forward " \n\t") | |
1006 (let* ((checkdoc-spellcheck-documentation-flag | |
1007 (member checkdoc-spellcheck-documentation-flag | |
1008 '(defun t))) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1009 (beg (save-excursion (beginning-of-defun) (point))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1010 (end (save-excursion (end-of-defun) (point))) |
20085 | 1011 (msg (checkdoc-this-string-valid))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1012 (if msg (if no-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1013 (message (checkdoc-error-text msg)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1014 (error (checkdoc-error-text msg))) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1015 (setq msg (checkdoc-message-text-search beg end)) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1016 (if msg (if no-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1017 (message (checkdoc-error-text msg)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1018 (error (checkdoc-error-text msg))) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1019 (setq msg (checkdoc-rogue-space-check-engine beg end)) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1020 (if msg (if no-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1021 (message (checkdoc-error-text msg)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1022 (error (checkdoc-error-text msg)))))) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1023 (if (interactive-p) (message "Checkdoc: done.")))))) |
20085 | 1024 |
1025 ;;; Ispell interface for forcing a spell check | |
1026 ;; | |
1027 | |
1028 ;;;###autoload | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1029 (defun checkdoc-ispell (&optional take-notes) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1030 "Check the style and spelling of everything interactively. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1031 Calls `checkdoc' with spell-checking turned on. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1032 Prefix argument TAKE-NOTES is the same as for `checkdoc'" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1033 (interactive) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1034 (let ((checkdoc-spellcheck-documentation-flag t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1035 (call-interactively 'checkdoc nil current-prefix-arg))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1036 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1037 ;;;###autoload |
20085 | 1038 (defun checkdoc-ispell-current-buffer (&optional take-notes) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1039 "Check the style and spelling of the current buffer. |
20085 | 1040 Calls `checkdoc-current-buffer' with spell-checking turned on. |
1041 Prefix argument TAKE-NOTES is the same as for `checkdoc-current-buffer'" | |
1042 (interactive) | |
1043 (let ((checkdoc-spellcheck-documentation-flag t)) | |
1044 (call-interactively 'checkdoc-current-buffer nil current-prefix-arg))) | |
1045 | |
1046 ;;;###autoload | |
1047 (defun checkdoc-ispell-interactive (&optional take-notes) | |
1048 "Check the style and spelling of the current buffer interactively. | |
1049 Calls `checkdoc-interactive' with spell-checking turned on. | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1050 Prefix argument TAKE-NOTES is the same as for `checkdoc-interactive'" |
20085 | 1051 (interactive) |
1052 (let ((checkdoc-spellcheck-documentation-flag t)) | |
1053 (call-interactively 'checkdoc-interactive nil current-prefix-arg))) | |
1054 | |
1055 ;;;###autoload | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1056 (defun checkdoc-ispell-message-interactive (&optional take-notes) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1057 "Check the style and spelling of message text interactively. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1058 Calls `checkdoc-message-interactive' with spell-checking turned on. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1059 Prefix argument TAKE-NOTES is the same as for `checkdoc-message-interactive'" |
20085 | 1060 (interactive) |
1061 (let ((checkdoc-spellcheck-documentation-flag t)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1062 (call-interactively 'checkdoc-message-interactive nil current-prefix-arg))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1063 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1064 ;;;###autoload |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1065 (defun checkdoc-ispell-message-text (&optional take-notes) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1066 "Check the style and spelling of message text interactively. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1067 Calls `checkdoc-message-text' with spell-checking turned on. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1068 Prefix argument TAKE-NOTES is the same as for `checkdoc-message-text'" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1069 (interactive) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1070 (let ((checkdoc-spellcheck-documentation-flag t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1071 (call-interactively 'checkdoc-message-text nil current-prefix-arg))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1072 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1073 ;;;###autoload |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1074 (defun checkdoc-ispell-start (&optional take-notes) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1075 "Check the style and spelling of the current buffer. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1076 Calls `checkdoc-start' with spell-checking turned on. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1077 Prefix argument TAKE-NOTES is the same as for `checkdoc-start'" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1078 (interactive) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1079 (let ((checkdoc-spellcheck-documentation-flag t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1080 (call-interactively 'checkdoc-start nil current-prefix-arg))) |
20085 | 1081 |
1082 ;;;###autoload | |
1083 (defun checkdoc-ispell-continue (&optional take-notes) | |
1084 "Check the style and spelling of the current buffer after point. | |
1085 Calls `checkdoc-continue' with spell-checking turned on. | |
1086 Prefix argument TAKE-NOTES is the same as for `checkdoc-continue'" | |
1087 (interactive) | |
1088 (let ((checkdoc-spellcheck-documentation-flag t)) | |
1089 (call-interactively 'checkdoc-continue nil current-prefix-arg))) | |
1090 | |
1091 ;;;###autoload | |
1092 (defun checkdoc-ispell-comments (&optional take-notes) | |
1093 "Check the style and spelling of the current buffer's comments. | |
1094 Calls `checkdoc-comments' with spell-checking turned on. | |
1095 Prefix argument TAKE-NOTES is the same as for `checkdoc-comments'" | |
1096 (interactive) | |
1097 (let ((checkdoc-spellcheck-documentation-flag t)) | |
1098 (call-interactively 'checkdoc-comments nil current-prefix-arg))) | |
1099 | |
1100 ;;;###autoload | |
1101 (defun checkdoc-ispell-defun (&optional take-notes) | |
22195 | 1102 "Check the style and spelling of the current defun with Ispell. |
20085 | 1103 Calls `checkdoc-defun' with spell-checking turned on. |
1104 Prefix argument TAKE-NOTES is the same as for `checkdoc-defun'" | |
1105 (interactive) | |
1106 (let ((checkdoc-spellcheck-documentation-flag t)) | |
1107 (call-interactively 'checkdoc-defun nil current-prefix-arg))) | |
1108 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1109 ;;; Error Management |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1110 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1111 ;; Errors returned from checkdoc functions can have various |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1112 ;; features and behaviors, so we need some ways of specifying |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1113 ;; them, and making them easier to use in the wacked-out interfaces |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1114 ;; people are requesting |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1115 (defun checkdoc-create-error (text start end &optional unfixable) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1116 "Used to create the return error text returned from all engines. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1117 TEXT is the descriptive text of the error. START and END define the region |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1118 it is sensible to highlight when describing the problem. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1119 Optional argument UNFIXABLE means that the error has no auto-fix available. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1120 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1121 A list of the form (TEXT START END UNFIXABLE) is returned if we are not |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1122 generating a buffered list of errors." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1123 (if checkdoc-generate-compile-warnings-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1124 (progn (checkdoc-error start text) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1125 nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1126 (list text start end unfixable))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1127 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1128 (defun checkdoc-error-text (err) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1129 "Return the text specified in the checkdoc ERR." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1130 ;; string-p part is for backwards compatibility |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1131 (if (stringp err) err (car err))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1132 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1133 (defun checkdoc-error-start (err) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1134 "Return the start point specified in the checkdoc ERR." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1135 ;; string-p part is for backwards compatibility |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1136 (if (stringp err) nil (nth 1 err))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1137 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1138 (defun checkdoc-error-end (err) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1139 "Return the end point specified in the checkdoc ERR." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1140 ;; string-p part is for backwards compatibility |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1141 (if (stringp err) nil (nth 2 err))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1142 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1143 (defun checkdoc-error-unfixable (err) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1144 "Return the t if we cannot autofix the error specified in the checkdoc ERR." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1145 ;; string-p part is for backwards compatibility |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1146 (if (stringp err) nil (nth 3 err))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1147 |
20085 | 1148 ;;; Minor Mode specification |
1149 ;; | |
1150 (defvar checkdoc-minor-mode nil | |
1151 "Non-nil in `emacs-lisp-mode' for automatic documentation checking.") | |
1152 (make-variable-buffer-local 'checkdoc-minor-mode) | |
1153 | |
1154 (checkdoc-add-to-list 'minor-mode-alist '(checkdoc-minor-mode " CDoc")) | |
1155 | |
1156 (defvar checkdoc-minor-keymap | |
1157 (let ((map (make-sparse-keymap)) | |
1158 (pmap (make-sparse-keymap))) | |
1159 ;; Override some bindings | |
1160 (define-key map "\C-\M-x" 'checkdoc-eval-defun) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1161 (define-key map "\C-x`" 'checkdoc-continue) |
20085 | 1162 (if (not (string-match "XEmacs" emacs-version)) |
1163 (define-key map [menu-bar emacs-lisp eval-buffer] | |
1164 'checkdoc-eval-current-buffer)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1165 ;; Add some new bindings under C-c ? |
20085 | 1166 (define-key pmap "x" 'checkdoc-defun) |
1167 (define-key pmap "X" 'checkdoc-ispell-defun) | |
1168 (define-key pmap "`" 'checkdoc-continue) | |
1169 (define-key pmap "~" 'checkdoc-ispell-continue) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1170 (define-key pmap "s" 'checkdoc-start) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1171 (define-key pmap "S" 'checkdoc-ispell-start) |
20085 | 1172 (define-key pmap "d" 'checkdoc) |
1173 (define-key pmap "D" 'checkdoc-ispell) | |
1174 (define-key pmap "b" 'checkdoc-current-buffer) | |
1175 (define-key pmap "B" 'checkdoc-ispell-current-buffer) | |
1176 (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
|
1177 (define-key pmap "m" 'checkdoc-message-text) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1178 (define-key pmap "M" 'checkdoc-ispell-message-text) |
20085 | 1179 (define-key pmap "c" 'checkdoc-comments) |
1180 (define-key pmap "C" 'checkdoc-ispell-comments) | |
1181 (define-key pmap " " 'checkdoc-rogue-spaces) | |
1182 | |
1183 ;; bind our submap into map | |
1184 (define-key map "\C-c?" pmap) | |
1185 map) | |
1186 "Keymap used to override evaluation key-bindings for documentation checking.") | |
1187 | |
1188 ;; Add in a menubar with easy-menu | |
1189 | |
1190 (if checkdoc-minor-keymap | |
1191 (easy-menu-define | |
1192 checkdoc-minor-menu checkdoc-minor-keymap "Checkdoc Minor Mode Menu" | |
1193 '("CheckDoc" | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1194 ["Interactive Buffer Style Check" checkdoc t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1195 ["Interactive Buffer Style and Spelling Check" checkdoc-ispell t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1196 ["Check Buffer" checkdoc-current-buffer t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1197 ["Check and Spell Buffer" checkdoc-ispell-current-buffer t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1198 "---" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1199 ["Interactive Style Check" checkdoc-interactive t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1200 ["Interactive Style and Spelling Check" checkdoc-ispell-interactive t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1201 ["Find First Style Error" checkdoc-start t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1202 ["Find First Style or Spelling Error" checkdoc-ispell-start t] |
20085 | 1203 ["Next Style Error" checkdoc-continue t] |
1204 ["Next Style or Spelling Error" checkdoc-ispell-continue t] | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1205 ["Interactive Message Text Style Check" checkdoc-message-interactive t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1206 ["Interactive Message Text Style and Spelling Check" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1207 checkdoc-ispell-message-interactive t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1208 ["Check Message Text" checkdoc-message-text t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1209 ["Check and Spell Message Text" checkdoc-ispell-message-text t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1210 ["Check Comment Style" checkdoc-comments buffer-file-name] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1211 ["Check Comment Style and Spelling" checkdoc-ispell-comments |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1212 buffer-file-name] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1213 ["Check for Rogue Spaces" checkdoc-rogue-spaces t] |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1214 "---" |
20085 | 1215 ["Check Defun" checkdoc-defun t] |
1216 ["Check and Spell Defun" checkdoc-ispell-defun t] | |
1217 ["Check and Evaluate Defun" checkdoc-eval-defun t] | |
1218 ["Check and Evaluate Buffer" checkdoc-eval-current-buffer t] | |
1219 ))) | |
1220 ;; XEmacs requires some weird stuff to add this menu in a minor mode. | |
1221 ;; What is it? | |
1222 | |
1223 ;; Allow re-insertion of a new keymap | |
1224 (let ((a (assoc 'checkdoc-minor-mode minor-mode-map-alist))) | |
1225 (if a | |
1226 (setcdr a checkdoc-minor-keymap) | |
1227 (checkdoc-add-to-list 'minor-mode-map-alist (cons 'checkdoc-minor-mode | |
1228 checkdoc-minor-keymap)))) | |
1229 | |
1230 ;;;###autoload | |
1231 (defun checkdoc-minor-mode (&optional arg) | |
22195 | 1232 "Toggle Checkdoc minor mode, a mode for checking Lisp doc strings. |
1233 With prefix ARG, turn Checkdoc minor mode on iff ARG is positive. | |
20085 | 1234 |
22195 | 1235 In Checkdoc minor mode, the usual bindings for `eval-defun' which is |
20085 | 1236 bound to \\<checkdoc-minor-keymap> \\[checkdoc-eval-defun] and `checkdoc-eval-current-buffer' are overridden to include |
1237 checking of documentation strings. | |
1238 | |
1239 \\{checkdoc-minor-keymap}" | |
1240 (interactive "P") | |
1241 (setq checkdoc-minor-mode | |
1242 (not (or (and (null arg) checkdoc-minor-mode) | |
1243 (<= (prefix-numeric-value arg) 0)))) | |
1244 (checkdoc-mode-line-update)) | |
1245 | |
1246 ;;; Subst utils | |
1247 ;; | |
1248 (defsubst checkdoc-run-hooks (hookvar &rest args) | |
1249 "Run hooks in HOOKVAR with ARGS." | |
1250 (if (fboundp 'run-hook-with-args-until-success) | |
1251 (apply 'run-hook-with-args-until-success hookvar args) | |
1252 ;; This method was similar to above. We ignore the warning | |
22195 | 1253 ;; since we will use the above for future Emacs versions |
20085 | 1254 (apply 'run-hook-with-args hookvar args))) |
1255 | |
1256 (defsubst checkdoc-create-common-verbs-regexp () | |
1257 "Rebuild the contents of `checkdoc-common-verbs-regexp'." | |
1258 (or checkdoc-common-verbs-regexp | |
1259 (setq checkdoc-common-verbs-regexp | |
1260 (concat "\\<\\(" | |
1261 (mapconcat (lambda (e) (concat (car e))) | |
1262 checkdoc-common-verbs-wrong-voice "\\|") | |
1263 "\\)\\>")))) | |
1264 | |
1265 ;; Profiler says this is not yet faster than just calling assoc | |
1266 ;;(defun checkdoc-word-in-alist-vector (word vector) | |
1267 ;; "Check to see if WORD is in the car of an element of VECTOR. | |
1268 ;;VECTOR must be sorted. The CDR should be a replacement. Since the | |
1269 ;;word list is getting bigger, it is time for a quick bisecting search." | |
1270 ;; (let ((max (length vector)) (min 0) i | |
1271 ;; (found nil) (fw nil)) | |
1272 ;; (setq i (/ max 2)) | |
1273 ;; (while (and (not found) (/= min max)) | |
1274 ;; (setq fw (car (aref vector i))) | |
1275 ;; (cond ((string= word fw) (setq found (cdr (aref vector i)))) | |
1276 ;; ((string< word fw) (setq max i)) | |
1277 ;; (t (setq min i))) | |
1278 ;; (setq i (/ (+ max min) 2)) | |
1279 ;; ) | |
1280 ;; found)) | |
1281 | |
1282 ;;; Checking engines | |
1283 ;; | |
1284 (defun checkdoc-this-string-valid () | |
22195 | 1285 "Return a message string if the current doc string is invalid. |
20085 | 1286 Check for style only, such as the first line always being a complete |
1287 sentence, whitespace restrictions, and making sure there are no | |
1288 hard-coded key-codes such as C-[char] or mouse-[number] in the comment. | |
1289 See the style guide in the Emacs Lisp manual for more details." | |
1290 | |
22195 | 1291 ;; Jump over comments between the last object and the doc string |
20085 | 1292 (while (looking-at "[ \t\n]*;") |
1293 (forward-line 1) | |
1294 (beginning-of-line) | |
1295 (skip-chars-forward " \n\t")) | |
1296 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1297 (let ((fp (checkdoc-defun-info)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1298 (err nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1299 (setq |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1300 err |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1301 ;; * Every command, function, or variable intended for users to know |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1302 ;; about should have a documentation string. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1303 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1304 ;; * An internal variable or subroutine of a Lisp program might as well |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1305 ;; have a documentation string. In earlier Emacs versions, you could |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1306 ;; save space by using a comment instead of a documentation string, |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1307 ;; but that is no longer the case. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1308 (if (and (not (nth 1 fp)) ; not a variable |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1309 (or (nth 2 fp) ; is interactive |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1310 checkdoc-force-docstrings-flag) ;or we always complain |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1311 (not (checkdoc-char= (following-char) ?\"))) ; no doc string |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1312 ;; Sometimes old code has comments where the documentation should |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1313 ;; be. Let's see if we can find the comment, and offer to turn it |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1314 ;; into documentation for them. |
25697
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
1315 (let ((have-comment nil) |
6060f83b1ffc
(checkdoc-display-status-buffer): Avoid
Dave Love <fx@gnu.org>
parents:
23371
diff
changeset
|
1316 (comment-start ";")) ; in case it's not default |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1317 (condition-case nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1318 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1319 (forward-sexp -1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1320 (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1321 (skip-chars-forward "\n \t") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1322 (setq have-comment (looking-at comment-start))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1323 (error nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1324 (if have-comment |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1325 (if (or (eq checkdoc-autofix-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1326 'automatic-then-never) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1327 (checkdoc-y-or-n-p |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1328 "Convert comment to documentation? ")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1329 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1330 ;; Our point is at the beginning of the comment! |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1331 ;; Insert a quote, then remove the comment chars. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1332 (insert "\"") |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1333 (let ((docstring-start-point (point))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1334 (while (looking-at comment-start) |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1335 (while (looking-at comment-start) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1336 (delete-char 1)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1337 (if (looking-at "[ \t]+") |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1338 (delete-region (match-beginning 0) (match-end 0))) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1339 (forward-line 1) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1340 (beginning-of-line) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1341 (skip-chars-forward " \t") |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1342 (if (looking-at comment-start) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1343 (progn |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1344 (beginning-of-line) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1345 (zap-to-char 1 ?\;)))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1346 (beginning-of-line) |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1347 (forward-char -1) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1348 (insert "\"") |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1349 (forward-char -1) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1350 ;; quote any double-quote characters in the comment. |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1351 (while (search-backward "\"" docstring-start-point t) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1352 (insert "\\")) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1353 (if (eq checkdoc-autofix-flag 'automatic-then-never) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1354 (setq checkdoc-autofix-flag 'never)))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1355 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1356 "You should convert this comment to documentation" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1357 (point) (save-excursion (end-of-line) (point)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1358 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1359 (if (nth 2 fp) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1360 "All interactive functions should have documentation" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1361 "All variables and subroutines might as well have a \ |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1362 documentation string") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1363 (point) (+ (point) 1) t))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1364 (if (and (not err) (looking-at "\"")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1365 (let ((old-syntax-table (syntax-table))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1366 (unwind-protect |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1367 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1368 (set-syntax-table checkdoc-syntax-table) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1369 (checkdoc-this-string-valid-engine fp)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1370 (set-syntax-table old-syntax-table))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1371 err))) |
20085 | 1372 |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1373 (defun checkdoc-this-string-valid-engine (fp) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1374 "Return an error list or string if the current doc string is invalid. |
20085 | 1375 Depends on `checkdoc-this-string-valid' to reset the syntax table so that |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1376 regexp short cuts work. FP is the function defun information." |
20085 | 1377 (let ((case-fold-search nil) |
1378 ;; Use a marker so if an early check modifies the text, | |
1379 ;; we won't accidentally loose our place. This could cause | |
22195 | 1380 ;; end-of doc string whitespace to also delete the " char. |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1381 (s (point)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1382 (e (if (looking-at "\"") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1383 (save-excursion (forward-sexp 1) (point-marker)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1384 (point)))) |
20085 | 1385 (or |
1386 ;; * *Do not* indent subsequent lines of a documentation string so that | |
1387 ;; the text is lined up in the source code with the text of the first | |
1388 ;; line. This looks nice in the source code, but looks bizarre when | |
1389 ;; users view the documentation. Remember that the indentation | |
1390 ;; before the starting double-quote is not part of the string! | |
1391 (save-excursion | |
1392 (forward-line 1) | |
1393 (beginning-of-line) | |
1394 (if (and (< (point) e) | |
1395 (looking-at "\\([ \t]+\\)[^ \t\n]")) | |
1396 (if (checkdoc-autofix-ask-replace (match-beginning 1) | |
1397 (match-end 1) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1398 "Remove this whitespace? " |
20085 | 1399 "") |
1400 nil | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1401 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1402 "Second line should not have indentation" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1403 (match-beginning 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1404 (match-end 1))))) |
20085 | 1405 ;; * Do not start or end a documentation string with whitespace. |
1406 (let (start end) | |
1407 (if (or (if (looking-at "\"\\([ \t\n]+\\)") | |
1408 (setq start (match-beginning 1) | |
1409 end (match-end 1))) | |
1410 (save-excursion | |
1411 (forward-sexp 1) | |
1412 (forward-char -1) | |
1413 (if (/= (skip-chars-backward " \t\n") 0) | |
1414 (setq start (point) | |
1415 end (1- e))))) | |
1416 (if (checkdoc-autofix-ask-replace | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1417 start end "Remove this whitespace? " "") |
20085 | 1418 nil |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1419 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1420 "Documentation strings should not start or end with whitespace" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1421 start end)))) |
20085 | 1422 ;; * The first line of the documentation string should consist of one |
1423 ;; or two complete sentences that stand on their own as a summary. | |
1424 ;; `M-x apropos' displays just the first line, and if it doesn't | |
1425 ;; stand on its own, the result looks bad. In particular, start the | |
1426 ;; first line with a capital letter and end with a period. | |
1427 (save-excursion | |
1428 (end-of-line) | |
1429 (skip-chars-backward " \t\n") | |
1430 (if (> (point) e) (goto-char e)) ;of the form (defun n () "doc" nil) | |
1431 (forward-char -1) | |
1432 (cond | |
1433 ((and (checkdoc-char= (following-char) ?\") | |
1434 ;; A backslashed double quote at the end of a sentence | |
1435 (not (checkdoc-char= (preceding-char) ?\\))) | |
1436 ;; We might have to add a period in this case | |
1437 (forward-char -1) | |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1438 (if (looking-at "[.!?]") |
20085 | 1439 nil |
1440 (forward-char 1) | |
1441 (if (checkdoc-autofix-ask-replace | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1442 (point) (1+ (point)) "Add period to sentence? " |
20085 | 1443 ".\"" t) |
1444 nil | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1445 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1446 "First sentence should end with punctuation" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1447 (point) (1+ (point)))))) |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1448 ((looking-at "[\\!?;:.)]") |
20085 | 1449 ;; These are ok |
1450 nil) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1451 ((and checkdoc-permit-comma-termination-flag (looking-at ",")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1452 nil) |
20085 | 1453 (t |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1454 ;; If it is not a complete sentence, let's see if we can |
20085 | 1455 ;; predict a clever way to make it one. |
1456 (let ((msg "First line is not a complete sentence") | |
1457 (e (point))) | |
1458 (beginning-of-line) | |
1459 (if (re-search-forward "\\. +" e t) | |
1460 ;; Here we have found a complete sentence, but no break. | |
1461 (if (checkdoc-autofix-ask-replace | |
1462 (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
|
1463 "First line not a complete sentence. Add RET here? " |
20085 | 1464 "\n" t) |
1465 (let (l1 l2) | |
1466 (forward-line 1) | |
1467 (end-of-line) | |
1468 (setq l1 (current-column) | |
1469 l2 (save-excursion | |
1470 (forward-line 1) | |
1471 (end-of-line) | |
1472 (current-column))) | |
1473 (if (> (+ l1 l2 1) 80) | |
22195 | 1474 (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
|
1475 may require more formatting") |
20085 | 1476 ;; We can merge these lines! Replace this CR |
1477 ;; with a space. | |
1478 (delete-char 1) (insert " ") | |
1479 (setq msg nil)))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1480 ;; Let's see if there is enough room to draw the next |
20085 | 1481 ;; line's sentence up here. I often get hit w/ |
1482 ;; auto-fill moving my words around. | |
1483 (let ((numc (progn (end-of-line) (- 80 (current-column)))) | |
1484 (p (point))) | |
1485 (forward-line 1) | |
1486 (beginning-of-line) | |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1487 (if (and (re-search-forward "[.!?:\"]\\([ \t\n]+\\|\"\\)" |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1488 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1489 (end-of-line) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1490 (point)) |
20085 | 1491 t) |
1492 (< (current-column) numc)) | |
1493 (if (checkdoc-autofix-ask-replace | |
1494 p (1+ p) | |
22195 | 1495 "1st line not a complete sentence. Join these lines? " |
20085 | 1496 " " t) |
1497 (progn | |
1498 ;; They said yes. We have more fill work to do... | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1499 (goto-char (match-beginning 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1500 (delete-region (point) (match-end 1)) |
20085 | 1501 (insert "\n") |
1502 (setq msg nil)))))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1503 (if msg |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1504 (checkdoc-create-error msg s (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1505 (goto-char s) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1506 (end-of-line) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1507 (point))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1508 nil) )))) |
20085 | 1509 ;; Continuation of above. Make sure our sentence is capitalized. |
1510 (save-excursion | |
1511 (skip-chars-forward "\"\\*") | |
1512 (if (looking-at "[a-z]") | |
1513 (if (checkdoc-autofix-ask-replace | |
1514 (match-beginning 0) (match-end 0) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1515 "Capitalize your sentence? " (upcase (match-string 0)) |
20085 | 1516 t) |
1517 nil | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1518 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1519 "First line should be capitalized" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1520 (match-beginning 0) (match-end 0))) |
20085 | 1521 nil)) |
1522 ;; * Don't write key sequences directly in documentation strings. | |
1523 ;; Instead, use the `\\[...]' construct to stand for them. | |
1524 (save-excursion | |
1525 (let ((f nil) (m nil) (start (point)) | |
21181 | 1526 (re "[^`A-Za-z0-9_]\\([CMA]-[a-zA-Z]\\|\\(\\([CMA]-\\)?\ |
20085 | 1527 mouse-[0-3]\\)\\)\\>")) |
1528 ;; Find the first key sequence not in a sample | |
1529 (while (and (not f) (setq m (re-search-forward re e t))) | |
1530 (setq f (not (checkdoc-in-sample-code-p start e)))) | |
1531 (if m | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1532 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1533 (concat |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1534 "Keycode " (match-string 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1535 " embedded in doc string. Use \\\\<keymap> & \\\\[function] " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1536 "instead") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1537 (match-beginning 1) (match-end 1) t)))) |
20085 | 1538 ;; It is not practical to use `\\[...]' very many times, because |
1539 ;; display of the documentation string will become slow. So use this | |
1540 ;; to describe the most important commands in your major mode, and | |
1541 ;; then use `\\{...}' to display the rest of the mode's keymap. | |
1542 (save-excursion | |
1543 (if (re-search-forward "\\\\\\\\\\[\\w+" e t | |
1544 (1+ checkdoc-max-keyref-before-warn)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1545 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1546 "Too many occurrences of \\[function]. Use \\{keymap} instead" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1547 s (marker-position e)))) |
22195 | 1548 ;; 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
|
1549 ;; 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
|
1550 ;; 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
|
1551 ;; 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
|
1552 (save-excursion |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1553 (let ((case-fold-search t) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1554 (ret nil) mb me) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1555 (while (and (re-search-forward "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'" e t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1556 (not ret)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1557 (let* ((ms1 (match-string 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1558 (sym (intern-soft ms1))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1559 (setq mb (match-beginning 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1560 me (match-end 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1561 (if (and sym (boundp sym) (fboundp sym) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1562 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1563 (goto-char mb) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1564 (forward-word -1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1565 (not (looking-at |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1566 "variable\\|option\\|function\\|command\\|symbol")))) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1567 (if (checkdoc-autofix-ask-replace |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1568 mb me "Prefix this ambiguous symbol? " ms1 t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1569 ;; We didn't actually replace anything. Here we find |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1570 ;; 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
|
1571 ;; a prefix. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1572 (let ((disambiguate |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1573 (completing-read |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1574 "Disambiguating Keyword (default: variable): " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1575 '(("function") ("command") ("variable") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1576 ("option") ("symbol")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1577 nil t nil nil "variable"))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1578 (goto-char (1- mb)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1579 (insert disambiguate " ") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1580 (forward-word 1)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1581 (setq ret |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1582 (format "Disambiguate %s by preceding w/ \ |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1583 function,command,variable,option or symbol." ms1)))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1584 (if ret |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1585 (checkdoc-create-error ret mb me) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1586 nil))) |
20085 | 1587 ;; * Format the documentation string so that it fits in an |
1588 ;; Emacs window on an 80-column screen. It is a good idea | |
1589 ;; for most lines to be no wider than 60 characters. The | |
1590 ;; first line can be wider if necessary to fit the | |
1591 ;; information that ought to be there. | |
1592 (save-excursion | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1593 (let ((start (point)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1594 (eol nil)) |
20085 | 1595 (while (and (< (point) e) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1596 (or (progn (end-of-line) (setq eol (point)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1597 (< (current-column) 80)) |
20085 | 1598 (progn (beginning-of-line) |
1599 (re-search-forward "\\\\\\\\[[<{]" | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1600 eol t)) |
20085 | 1601 (checkdoc-in-sample-code-p start e))) |
1602 (forward-line 1)) | |
1603 (end-of-line) | |
1604 (if (and (< (point) e) (> (current-column) 80)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1605 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1606 "Some lines are over 80 columns wide" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1607 s (save-excursion (goto-char s) (end-of-line) (point)) )))) |
20085 | 1608 ;; Here we deviate to tests based on a variable or function. |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1609 ;; We must do this before checking for symbols in quotes because there |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1610 ;; is a chance that just such a symbol might really be an argument. |
20085 | 1611 (cond ((eq (nth 1 fp) t) |
1612 ;; This is if we are in a variable | |
1613 (or | |
1614 ;; * The documentation string for a variable that is a | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1615 ;; yes-or-no flag should start with words such as Non-nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1616 ;; means..., to make it clear that all non-`nil' values are |
20085 | 1617 ;; equivalent and indicate explicitly what `nil' and non-`nil' |
1618 ;; mean. | |
1619 ;; * If a user option variable records a true-or-false | |
1620 ;; condition, give it a name that ends in `-flag'. | |
1621 | |
1622 ;; If the variable has -flag in the name, make sure | |
1623 (if (and (string-match "-flag$" (car fp)) | |
1624 (not (looking-at "\"\\*?Non-nil\\s-+means\\s-+"))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1625 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1626 "Flag variable doc strings should start: Non-nil means" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1627 s (marker-position e) t)) |
22195 | 1628 ;; If the doc string starts with "Non-nil means" |
20085 | 1629 (if (and (looking-at "\"\\*?Non-nil\\s-+means\\s-+") |
1630 (not (string-match "-flag$" (car fp)))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1631 (if (checkdoc-y-or-n-p |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1632 (format |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1633 "Rename to %s and Query-Replace all occurances? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1634 (concat (car fp) "-flag"))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1635 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1636 (beginning-of-defun) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1637 (query-replace-regexp |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1638 (concat "\\<" (regexp-quote (car fp)) "\\>") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1639 (concat (car fp) "-flag"))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1640 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1641 "Flag variables should end in `-flag'" s |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1642 (marker-position e)))) |
20085 | 1643 ;; Done with variables |
1644 )) | |
1645 (t | |
1646 ;; This if we are in a function definition | |
1647 (or | |
1648 ;; * When a function's documentation string mentions the value | |
1649 ;; of an argument of the function, use the argument name in | |
1650 ;; capital letters as if it were a name for that value. Thus, | |
1651 ;; the documentation string of the function `/' refers to its | |
1652 ;; second argument as `DIVISOR', because the actual argument | |
1653 ;; name is `divisor'. | |
1654 | |
1655 ;; Addendum: Make sure they appear in the doc in the same | |
1656 ;; order that they are found in the arg list. | |
1657 (let ((args (cdr (cdr (cdr (cdr fp))))) | |
1658 (last-pos 0) | |
1659 (found 1) | |
1660 (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
|
1661 (nocheck (append '("&optional" "&rest") (nth 3 fp))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1662 (inopts nil)) |
20085 | 1663 (while (and args found (> found last-pos)) |
1664 (if (member (car args) nocheck) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1665 (setq args (cdr args) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1666 inopts t) |
20085 | 1667 (setq last-pos found |
1668 found (save-excursion | |
1669 (re-search-forward | |
1670 (concat "\\<" (upcase (car args)) | |
1671 ;; Require whitespace OR | |
1672 ;; ITEMth<space> OR | |
1673 ;; ITEMs<space> | |
1674 "\\(\\>\\|th\\>\\|s\\>\\)") | |
1675 e t))) | |
1676 (if (not found) | |
1677 (let ((case-fold-search t)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1678 ;; If the symbol was not found, let's see if we |
20085 | 1679 ;; can find it with a different capitalization |
1680 ;; and see if the user wants to capitalize it. | |
1681 (if (save-excursion | |
1682 (re-search-forward | |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1683 (concat "\\<\\(" (car args) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1684 ;; Require whitespace OR |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1685 ;; ITEMth<space> OR |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1686 ;; ITEMs<space> |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1687 "\\)\\(\\>\\|th\\>\\|s\\>\\)") |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1688 e t)) |
20085 | 1689 (if (checkdoc-autofix-ask-replace |
1690 (match-beginning 1) (match-end 1) | |
1691 (format | |
22195 | 1692 "Argument `%s' should appear as `%s'. Fix? " |
20085 | 1693 (car args) (upcase (car args))) |
1694 (upcase (car args)) t) | |
1695 (setq found (match-beginning 1)))))) | |
1696 (if found (setq args (cdr args))))) | |
1697 (if (not found) | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1698 ;; 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
|
1699 ;; to the end of the documentation string. |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1700 (if (checkdoc-y-or-n-p |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1701 (format |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1702 "Add %s documentation to end of doc string? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1703 (upcase (car args)))) |
22195 | 1704 ;; 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
|
1705 (save-excursion |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1706 (goto-char e) (forward-char -1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1707 (insert "\n" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1708 (if inopts "Optional a" "A") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1709 "rgument " (upcase (car args)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1710 " ") |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1711 (insert (read-string "Describe: ")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1712 (if (not (save-excursion (forward-char -1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1713 (looking-at "[.?!]"))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1714 (insert ".")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
1715 nil) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1716 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1717 (format |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1718 "Argument `%s' should appear (as `%s') in the doc string" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1719 (car args) (upcase (car args))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1720 s (marker-position e))) |
20085 | 1721 (if (or (and order (eq order 'yes)) |
1722 (and (not order) checkdoc-arguments-in-order-flag)) | |
1723 (if (< found last-pos) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1724 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1725 "Arguments occur in the doc string out of order" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1726 s (marker-position e) t))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1727 ;; * For consistency, phrase the verb in the first sentence of a |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1728 ;; documentation string for functions as an infinitive with |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1729 ;; "to" omitted. For instance, use `Return the cons of A and |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1730 ;; B.' in preference to `Returns the cons of A and B.' |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1731 ;; Usually it looks good to do likewise for the rest of the |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1732 ;; first paragraph. Subsequent paragraphs usually look better |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1733 ;; if they have proper subjects. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1734 ;; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1735 ;; This is the least important of the above tests. Make sure |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1736 ;; it occurs last. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1737 (and checkdoc-verb-check-experimental-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1738 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1739 ;; Maybe rebuild the monster-regex |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1740 (checkdoc-create-common-verbs-regexp) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1741 (let ((lim (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1742 (end-of-line) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1743 ;; check string-continuation |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1744 (if (checkdoc-char= (preceding-char) ?\\) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1745 (progn (forward-line 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1746 (end-of-line))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1747 (point))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1748 (rs nil) replace original (case-fold-search t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1749 (while (and (not rs) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1750 (re-search-forward |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1751 checkdoc-common-verbs-regexp |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1752 lim t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1753 (setq original (buffer-substring-no-properties |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1754 (match-beginning 1) (match-end 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1755 rs (assoc (downcase original) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1756 checkdoc-common-verbs-wrong-voice)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1757 (if (not rs) (error "Verb voice alist corrupted")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1758 (setq replace (let ((case-fold-search nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1759 (save-match-data |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1760 (if (string-match "^[A-Z]" original) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1761 (capitalize (cdr rs)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1762 (cdr rs))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1763 (if (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1764 (match-beginning 1) (match-end 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1765 (format "Use the infinitive for `%s'. \ |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1766 Replace with `%s'? " original replace) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1767 replace t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1768 (setq rs nil))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1769 (if rs |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1770 ;; there was a match, but no replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1771 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1772 (format |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1773 "Infinitive `%s' should be replaced with `%s'" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1774 original replace) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1775 (match-beginning 1) (match-end 1)))))) |
20085 | 1776 ;; Done with functions |
1777 ))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1778 ;;* When a documentation string refers to a Lisp symbol, write it as |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1779 ;; it would be printed (which usually means in lower case), with |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1780 ;; single-quotes around it. For example: `lambda'. There are two |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1781 ;; exceptions: write t and nil without single-quotes. (In this |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1782 ;; manual, we normally do use single-quotes for those symbols.) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1783 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1784 (let ((found nil) (start (point)) (msg nil) (ms nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1785 (while (and (not msg) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1786 (re-search-forward |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1787 "[^([`':a-zA-Z]\\(\\w+[:-]\\(\\w\\|\\s_\\)+\\)[^]']" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1788 e t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1789 (setq ms (match-string 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1790 (save-match-data |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1791 ;; A . is a \s_ char, so we must remove periods from |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1792 ;; sentences more carefully. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1793 (if (string-match "\\.$" ms) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1794 (setq ms (substring ms 0 (1- (length ms)))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1795 (if (and (not (checkdoc-in-sample-code-p start e)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1796 (not (checkdoc-in-example-string-p start e)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1797 (not (member ms checkdoc-symbol-words)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1798 (setq found (intern-soft ms)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1799 (or (boundp found) (fboundp found))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1800 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1801 (setq msg (format "Add quotes around Lisp symbol `%s'? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1802 ms)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1803 (if (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1804 (match-beginning 1) (+ (match-beginning 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1805 (length ms)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1806 msg (concat "`" ms "'") t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1807 (setq msg nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1808 (setq msg |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1809 (format "Lisp symbol `%s' should appear in quotes" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1810 ms)))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1811 (if msg |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1812 (checkdoc-create-error msg (match-beginning 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1813 (+ (match-beginning 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1814 (length ms))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1815 nil))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1816 ;; t and nil case |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1817 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1818 (if (re-search-forward "\\(`\\(t\\|nil\\)'\\)" e t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1819 (if (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1820 (match-beginning 1) (match-end 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1821 (format "%s should not appear in quotes. Remove? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1822 (match-string 2)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1823 (match-string 2) t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1824 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1825 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1826 "Symbols t and nil should not appear in `quotes'" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1827 (match-beginning 1) (match-end 1))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1828 ;; Here is some basic sentence formatting |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1829 (checkdoc-sentencespace-region-engine (point) e) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1830 ;; Here are common proper nouns that should always appear capitalized. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1831 (checkdoc-proper-noun-region-engine (point) e) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1832 ;; Make sure the doc string has correctly spelled English words |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1833 ;; in it. This function is extracted due to its complexity, |
22195 | 1834 ;; and reliance on the Ispell program. |
20085 | 1835 (checkdoc-ispell-docstring-engine e) |
1836 ;; User supplied checks | |
1837 (save-excursion (checkdoc-run-hooks 'checkdoc-style-hooks fp e)) | |
1838 ;; Done! | |
1839 ))) | |
1840 | |
1841 (defun checkdoc-defun-info nil | |
1842 "Return a list of details about the current sexp. | |
1843 It is a list of the form: | |
22195 | 1844 (NAME VARIABLE INTERACTIVE NODOCPARAMS PARAMETERS ...) |
20085 | 1845 where NAME is the name, VARIABLE is t if this is a `defvar', |
1846 INTERACTIVE is nil if this is not an interactive function, otherwise | |
1847 it is the position of the `interactive' call, and PARAMETERS is a | |
1848 string which is the name of each variable in the function's argument | |
1849 list. The NODOCPARAMS is a sublist of parameters specified by a checkdoc | |
1850 comment for a given defun. If the first element is not a string, then | |
1851 the token checkdoc-order: <TOKEN> exists, and TOKEN is a symbol read | |
1852 from the comment." | |
1853 (save-excursion | |
1854 (beginning-of-defun) | |
1855 (let ((defun (looking-at "(def\\(un\\|macro\\|subst\\|advice\\)")) | |
1856 (is-advice (looking-at "(defadvice")) | |
1857 (lst nil) | |
1858 (ret nil) | |
1859 (oo (make-vector 3 0))) ;substitute obarray for `read' | |
1860 (forward-char 1) | |
1861 (forward-sexp 1) | |
1862 (skip-chars-forward " \n\t") | |
1863 (setq ret | |
1864 (list (buffer-substring-no-properties | |
1865 (point) (progn (forward-sexp 1) (point))))) | |
1866 (if (not defun) | |
1867 (setq ret (cons t ret)) | |
1868 ;; The variable spot | |
1869 (setq ret (cons nil ret)) | |
1870 ;; Interactive | |
1871 (save-excursion | |
1872 (setq ret (cons | |
1873 (re-search-forward "(interactive" | |
1874 (save-excursion (end-of-defun) (point)) | |
1875 t) | |
1876 ret))) | |
1877 (skip-chars-forward " \t\n") | |
1878 (let ((bss (buffer-substring (point) (save-excursion (forward-sexp 1) | |
1879 (point)))) | |
1880 ;; Overload th main obarray so read doesn't intern the | |
1881 ;; local symbols of the function we are checking. | |
1882 ;; Without this we end up cluttering the symbol space w/ | |
1883 ;; useless symbols. | |
1884 (obarray oo)) | |
1885 ;; Ok, check for checkdoc parameter comment here | |
1886 (save-excursion | |
1887 (setq ret | |
1888 (cons | |
1889 (let ((sl1 nil)) | |
1890 (if (re-search-forward ";\\s-+checkdoc-order:\\s-+" | |
1891 (save-excursion (end-of-defun) | |
1892 (point)) | |
1893 t) | |
1894 (setq sl1 (list (cond ((looking-at "nil") 'no) | |
1895 ((looking-at "t") 'yes))))) | |
1896 (if (re-search-forward ";\\s-+checkdoc-params:\\s-+" | |
1897 (save-excursion (end-of-defun) | |
1898 (point)) | |
1899 t) | |
1900 (let ((sl nil)) | |
1901 (goto-char (match-end 0)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1902 (condition-case nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1903 (setq lst (read (current-buffer))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1904 (error (setq lst nil))) ; error in text |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1905 (if (not (listp lst)) ; not a list of args |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1906 (setq lst (list lst))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1907 (if (and lst (not (symbolp (car lst)))) ;weird arg |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1908 (setq lst nil)) |
20085 | 1909 (while lst |
1910 (setq sl (cons (symbol-name (car lst)) sl) | |
1911 lst (cdr lst))) | |
1912 (setq sl1 (append sl1 sl)))) | |
1913 sl1) | |
1914 ret))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1915 ;; Read the list of parameters, but do not put the symbols in |
20085 | 1916 ;; the standard obarray. |
1917 (setq lst (read bss))) | |
1918 ;; This is because read will intern nil if it doesn't into the | |
1919 ;; new obarray. | |
1920 (if (not (listp lst)) (setq lst nil)) | |
1921 (if is-advice nil | |
1922 (while lst | |
1923 (setq ret (cons (symbol-name (car lst)) ret) | |
1924 lst (cdr lst))))) | |
1925 (nreverse ret)))) | |
1926 | |
1927 (defun checkdoc-in-sample-code-p (start limit) | |
22195 | 1928 "Return non-nil if the current point is in a code fragment. |
20085 | 1929 A code fragment is identified by an open parenthesis followed by a |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1930 symbol which is a valid function or a word in all CAPS, or a parenthesis |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1931 that is quoted with the ' character. Only the region from START to LIMIT |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1932 is is allowed while searching for the bounding parenthesis." |
20085 | 1933 (save-match-data |
1934 (save-restriction | |
1935 (narrow-to-region start limit) | |
1936 (save-excursion | |
1937 (and (condition-case nil (progn (up-list 1) t) (error nil)) | |
1938 (condition-case nil (progn (forward-list -1) t) (error nil)) | |
1939 (or (save-excursion (forward-char -1) (looking-at "'(")) | |
1940 (and (looking-at "(\\(\\(\\w\\|[-:_]\\)+\\)[ \t\n;]") | |
1941 (let ((ms (buffer-substring-no-properties | |
1942 (match-beginning 1) (match-end 1)))) | |
1943 ;; if this string is function bound, we are in | |
1944 ;; sample code. If it has a - or : character in | |
1945 ;; the name, then it is probably supposed to be bound | |
1946 ;; but isn't yet. | |
1947 (or (fboundp (intern-soft ms)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1948 (let ((case-fold-search nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1949 (string-match "^[A-Z-]+$" ms)) |
20085 | 1950 (string-match "\\w[-:_]+\\w" ms)))))))))) |
1951 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1952 (defun checkdoc-in-example-string-p (start limit) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1953 "Return non-nil if the current point is in an \"example string\". |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1954 This string is identified by the characters \\\" surrounding the text. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1955 The text checked is between START and LIMIT." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1956 (save-match-data |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1957 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1958 (let ((p (point)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1959 (c 0)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1960 (goto-char start) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1961 (while (and (< (point) p) (re-search-forward "\\\\\"" limit t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1962 (setq c (1+ c))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1963 (and (< 0 c) (= (% c 2) 0)))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1964 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1965 (defun checkdoc-proper-noun-region-engine (begin end) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1966 "Check all text between BEGIN and END for lower case proper nouns. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1967 These are Emacs centric proper nouns which should be capitalized for |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1968 consistency. Return an error list if any are not fixed, but |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1969 internally skip over no answers. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1970 If the offending word is in a piece of quoted text, then it is skipped." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1971 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1972 (let ((case-fold-search nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1973 (errtxt nil) bb be |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1974 (old-syntax-table (syntax-table))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1975 (unwind-protect |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1976 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1977 (set-syntax-table checkdoc-syntax-table) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1978 (goto-char begin) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1979 (while (re-search-forward checkdoc-proper-noun-regexp end t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1980 (let ((text (match-string 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1981 (b (match-beginning 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1982 (e (match-end 1))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1983 (if (and (not (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1984 (goto-char b) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1985 (forward-char -1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1986 (looking-at "`\\|\"\\|\\.\\|\\\\"))) |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1987 ;; surrounded by /, as in a URL or filename: /emacs/ |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1988 (not (and (= ?/ (char-after e)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
1989 (= ?/ (char-before b)))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1990 (not (checkdoc-in-example-string-p begin end))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1991 (if (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1992 b e (format "Text %s should be capitalized. Fix? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1993 text) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1994 (capitalize text) t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1995 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1996 (if errtxt |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1997 ;; If there is already an error, then generate |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1998 ;; the warning output if applicable |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
1999 (if checkdoc-generate-compile-warnings-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2000 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2001 (format |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2002 "Name %s should appear capitalized as %s" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2003 text (capitalize text)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2004 b e)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2005 (setq errtxt |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2006 (format |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2007 "Name %s should appear capitalized as %s" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2008 text (capitalize text)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2009 bb b be e))))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2010 (set-syntax-table old-syntax-table)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2011 (if errtxt (checkdoc-create-error errtxt bb be))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2012 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2013 (defun checkdoc-sentencespace-region-engine (begin end) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2014 "Make sure all sentences have double spaces between BEGIN and END." |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2015 (if sentence-end-double-space |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2016 (save-excursion |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2017 (let ((case-fold-search nil) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2018 (errtxt nil) bb be |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2019 (old-syntax-table (syntax-table))) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2020 (unwind-protect |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2021 (progn |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2022 (set-syntax-table checkdoc-syntax-table) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2023 (goto-char begin) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2024 (while (re-search-forward "[^.0-9]\\(\\. \\)[^ \n]" end t) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2025 (let ((b (match-beginning 1)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2026 (e (match-end 1))) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2027 (if (and (not (checkdoc-in-sample-code-p begin end)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2028 (not (checkdoc-in-example-string-p begin end)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2029 (not (save-excursion |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2030 (goto-char (match-beginning 1)) |
23371
9808edcd3c95
(checkdoc-sentencespace-region-engine): Protect a `forward-sexp' call
Eric M. Ludlam <zappo@gnu.org>
parents:
23192
diff
changeset
|
2031 (condition-case nil |
9808edcd3c95
(checkdoc-sentencespace-region-engine): Protect a `forward-sexp' call
Eric M. Ludlam <zappo@gnu.org>
parents:
23192
diff
changeset
|
2032 (progn |
9808edcd3c95
(checkdoc-sentencespace-region-engine): Protect a `forward-sexp' call
Eric M. Ludlam <zappo@gnu.org>
parents:
23192
diff
changeset
|
2033 (forward-sexp -1) |
9808edcd3c95
(checkdoc-sentencespace-region-engine): Protect a `forward-sexp' call
Eric M. Ludlam <zappo@gnu.org>
parents:
23192
diff
changeset
|
2034 ;; piece of an abbreviation |
9808edcd3c95
(checkdoc-sentencespace-region-engine): Protect a `forward-sexp' call
Eric M. Ludlam <zappo@gnu.org>
parents:
23192
diff
changeset
|
2035 (looking-at |
9808edcd3c95
(checkdoc-sentencespace-region-engine): Protect a `forward-sexp' call
Eric M. Ludlam <zappo@gnu.org>
parents:
23192
diff
changeset
|
2036 "\\([a-z]\\|[iI]\\.?e\\|[eE]\\.?g\\)\\.")) |
9808edcd3c95
(checkdoc-sentencespace-region-engine): Protect a `forward-sexp' call
Eric M. Ludlam <zappo@gnu.org>
parents:
23192
diff
changeset
|
2037 (error t))))) |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2038 (if (checkdoc-autofix-ask-replace |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2039 b e |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2040 "There should be two spaces after a period. Fix? " |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2041 ". ") |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2042 nil |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2043 (if errtxt |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2044 ;; If there is already an error, then generate |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2045 ;; the warning output if applicable |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2046 (if checkdoc-generate-compile-warnings-flag |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2047 (checkdoc-create-error |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2048 "There should be two spaces after a period" |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2049 b e)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2050 (setq errtxt |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2051 "There should be two spaces after a period" |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2052 bb b be e))))))) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2053 (set-syntax-table old-syntax-table)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2054 (if errtxt (checkdoc-create-error errtxt bb be)))))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2055 |
20085 | 2056 ;;; Ispell engine |
2057 ;; | |
2058 (eval-when-compile (require 'ispell)) | |
2059 | |
2060 (defun checkdoc-ispell-init () | |
22195 | 2061 "Initialize Ispell process (default version) with Lisp words. |
20085 | 2062 The words used are from `checkdoc-ispell-lisp-words'. If `ispell' |
2063 cannot be loaded, then set `checkdoc-spellcheck-documentation-flag' to | |
2064 nil." | |
2065 (require 'ispell) | |
2066 (if (not (symbol-value 'ispell-process)) ;Silence byteCompiler | |
2067 (condition-case nil | |
2068 (progn | |
2069 (ispell-buffer-local-words) | |
22195 | 2070 ;; This code copied in part from ispell.el Emacs 19.34 |
20085 | 2071 (let ((w checkdoc-ispell-lisp-words)) |
2072 (while w | |
2073 (process-send-string | |
2074 ;; Silence byte compiler | |
2075 (symbol-value 'ispell-process) | |
2076 (concat "@" (car w) "\n")) | |
2077 (setq w (cdr w))))) | |
2078 (error (setq checkdoc-spellcheck-documentation-flag nil))))) | |
2079 | |
2080 (defun checkdoc-ispell-docstring-engine (end) | |
22195 | 2081 "Run the Ispell tools on the doc string between point and END. |
2082 Since Ispell isn't Lisp-smart, we must pre-process the doc string | |
2083 before using the Ispell engine on it." | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2084 (if (or (not checkdoc-spellcheck-documentation-flag) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2085 ;; If the user wants no questions or fixing, then we must |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2086 ;; disable spell checking as not useful. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2087 (not checkdoc-autofix-flag) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2088 (eq checkdoc-autofix-flag 'never)) |
20085 | 2089 nil |
2090 (checkdoc-ispell-init) | |
2091 (save-excursion | |
2092 (skip-chars-forward "^a-zA-Z") | |
2093 (let ((word nil) (sym nil) (case-fold-search nil) (err nil)) | |
2094 (while (and (not err) (< (point) end)) | |
2095 (if (save-excursion (forward-char -1) (looking-at "[('`]")) | |
2096 ;; Skip lists describing meta-syntax, or bound variables | |
2097 (forward-sexp 1) | |
2098 (setq word (buffer-substring-no-properties | |
2099 (point) (progn | |
2100 (skip-chars-forward "a-zA-Z-") | |
2101 (point))) | |
2102 sym (intern-soft word)) | |
2103 (if (and sym (or (boundp sym) (fboundp sym))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2104 ;; This is probably repetitive in most cases, but not always. |
20085 | 2105 nil |
2106 ;; Find out how we spell-check this word. | |
2107 (if (or | |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
2108 ;; All caps w/ option th, or s tacked on the end |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2109 ;; for pluralization or numberthness. |
20603
24dda0afd915
Added some more comments in the commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
20085
diff
changeset
|
2110 (string-match "^[A-Z][A-Z]+\\(s\\|th\\)?$" word) |
20085 | 2111 (looking-at "}") ; a keymap expression |
2112 ) | |
2113 nil | |
2114 (save-excursion | |
2115 (if (not (eq checkdoc-autofix-flag 'never)) | |
2116 (let ((lk last-input-event)) | |
2117 (ispell-word nil t) | |
2118 (if (not (equal last-input-event lk)) | |
2119 (progn | |
2120 (sit-for 0) | |
2121 (message "Continuing...")))) | |
2122 ;; Nothing here. | |
2123 ))))) | |
2124 (skip-chars-forward "^a-zA-Z")) | |
2125 err)))) | |
2126 | |
2127 ;;; Rogue space checking engine | |
2128 ;; | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2129 (defun checkdoc-rogue-space-check-engine (&optional start end interact) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2130 "Return a message list if there is a line with white space at the end. |
20085 | 2131 If `checkdoc-autofix-flag' permits, delete that whitespace instead. |
2132 If optional arguments START and END are non nil, bound the check to | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2133 this region. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2134 Optional argument INTERACT may permit the user to fix problems on the fly." |
20085 | 2135 (let ((p (point)) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2136 (msg nil) s e (f nil)) |
20085 | 2137 (if (not start) (setq start (point-min))) |
2138 ;; If end is nil, it means end of buffer to search anyway | |
2139 (or | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2140 ;; Check for an error if `? ' or `?\ ' is used at the end of a line. |
20085 | 2141 ;; (It's dangerous) |
2142 (progn | |
2143 (goto-char start) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2144 (while (and (not msg) (re-search-forward "\\?\\\\?[ \t][ \t]*$" end t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2145 (setq msg |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2146 "Don't use `? ' at the end of a line. \ |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2147 News agents may remove it" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2148 s (match-beginning 0) e (match-end 0) f t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2149 ;; If interactive is passed down, give them a chance to fix things. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2150 (if (and interact (y-or-n-p (concat msg ". Fix? "))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2151 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2152 (checkdoc-recursive-edit msg) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2153 (setq msg nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2154 (goto-char s) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2155 (beginning-of-line))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2156 ;; Check for, and potentially remove whitespace appearing at the |
20085 | 2157 ;; end of different lines. |
2158 (progn | |
2159 (goto-char start) | |
22195 | 2160 ;; There is no documentation in the Emacs Lisp manual about this check, |
20085 | 2161 ;; it is intended to help clean up messy code and reduce the file size. |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2162 (while (and (not msg) (re-search-forward "[^ \t\n;]\\([ \t]+\\)$" end t)) |
20085 | 2163 ;; This is not a complex activity |
2164 (if (checkdoc-autofix-ask-replace | |
2165 (match-beginning 1) (match-end 1) | |
22195 | 2166 "White space at end of line. Remove? " "") |
20085 | 2167 nil |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2168 (setq msg "White space found at end of line" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2169 s (match-beginning 1) e (match-end 1)))))) |
20085 | 2170 ;; Return an error and leave the cursor at that spot, or restore |
2171 ;; the cursor. | |
2172 (if msg | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2173 (checkdoc-create-error msg s e f) |
20085 | 2174 (goto-char p) |
2175 nil))) | |
2176 | |
2177 ;;; Comment checking engine | |
2178 ;; | |
2179 (eval-when-compile | |
2180 ;; We must load this to: | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2181 ;; a) get symbols for compile and |
20085 | 2182 ;; b) determine if we have lm-history symbol which doesn't always exist |
2183 (require 'lisp-mnt)) | |
2184 | |
2185 (defun checkdoc-file-comments-engine () | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2186 "Return a message list if this file does not match the Emacs standard. |
20085 | 2187 This checks for style only, such as the first line, Commentary:, |
2188 Code:, and others referenced in the style guide." | |
2189 (if (featurep 'lisp-mnt) | |
2190 nil | |
2191 (require 'lisp-mnt) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2192 ;; Old XEmacs don't have `lm-commentary-mark' |
20085 | 2193 (if (and (not (fboundp 'lm-commentary-mark)) (boundp 'lm-commentary)) |
2194 (defalias 'lm-commentary-mark 'lm-commentary))) | |
2195 (save-excursion | |
2196 (let* ((f1 (file-name-nondirectory (buffer-file-name))) | |
2197 (fn (file-name-sans-extension f1)) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2198 (fe (substring f1 (length fn))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2199 (err nil)) |
20085 | 2200 (goto-char (point-min)) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2201 ;; This file has been set up where ERR is a variable. Each check is |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2202 ;; asked, and the function will make sure that if the user does not |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2203 ;; auto-fix some error, that we still move on to the next auto-fix, |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2204 ;; AND we remember the past errors. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2205 (setq |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2206 err |
20085 | 2207 ;; Lisp Maintenance checks first |
2208 ;; Was: (lm-verify) -> not flexible enough for some people | |
2209 ;; * Summary at the beginning of the file: | |
2210 (if (not (lm-summary)) | |
2211 ;; This certifies as very complex so always ask unless | |
2212 ;; it's set to never | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2213 (if (checkdoc-y-or-n-p "There is no first line summary! Add one? ") |
20085 | 2214 (progn |
2215 (goto-char (point-min)) | |
2216 (insert ";;; " fn fe " --- " (read-string "Summary: ") "\n")) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2217 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2218 "The first line should be of the form: \";;; package --- Summary\"" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2219 (point-min) (save-excursion (goto-char (point-min)) (end-of-line) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2220 (point)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2221 nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2222 (setq |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2223 err |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2224 (or |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2225 ;; * Commentary Section |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2226 (if (not (lm-commentary-mark)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2227 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2228 (goto-char (point-min)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2229 (cond |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2230 ((re-search-forward |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2231 "write\\s-+to\\s-+the\\s-+Free Software Foundation, Inc." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2232 nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2233 (re-search-forward "^;;\\s-*\n\\|^\n" nil t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2234 ((or (re-search-forward "^;;; History" nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2235 (re-search-forward "^;;; Code" nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2236 (re-search-forward "^(require" nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2237 (re-search-forward "^(")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2238 (beginning-of-line))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2239 (if (checkdoc-y-or-n-p |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2240 "You should have a \";;; Commentary:\", add one? ") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2241 (insert "\n;;; Commentary:\n;; \n\n") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2242 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2243 "You should have a section marked \";;; Commentary:\"" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2244 nil nil t))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2245 nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2246 err)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2247 (setq |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2248 err |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2249 (or |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2250 ;; * History section. Say nothing if there is a file ChangeLog |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2251 (if (or (not checkdoc-force-history-flag) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2252 (file-exists-p "ChangeLog") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2253 (file-exists-p "../ChangeLog") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2254 (let ((fn 'lm-history-mark)) ;bestill byte-compiler |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2255 (and (fboundp fn) (funcall fn)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2256 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2257 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2258 (goto-char (or (lm-commentary-mark) (point-min))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2259 (cond |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2260 ((re-search-forward |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2261 "write\\s-+to\\s-+the\\s-+Free Software Foundation, Inc." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2262 nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2263 (re-search-forward "^;;\\s-*\n\\|^\n" nil t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2264 ((or (re-search-forward "^;;; Code" nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2265 (re-search-forward "^(require" nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2266 (re-search-forward "^(")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2267 (beginning-of-line))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2268 (if (checkdoc-y-or-n-p |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2269 "You should have a \";;; History:\", add one? ") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2270 (insert "\n;;; History:\n;; \n\n") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2271 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2272 "You should have a section marked \";;; History:\" or use a ChangeLog" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2273 (point) nil)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2274 err)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2275 (setq |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2276 err |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2277 (or |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2278 ;; * Code section |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2279 (if (not (lm-code-mark)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2280 (let ((cont t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2281 (goto-char (point-min)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2282 (while (and cont (re-search-forward "^(" nil t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2283 (setq cont (looking-at "require\\s-+"))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2284 (if (and (not cont) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2285 (checkdoc-y-or-n-p |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2286 "There is no ;;; Code: marker. Insert one? ")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2287 (progn (beginning-of-line) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2288 (insert ";;; Code:\n") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2289 nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2290 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2291 "You should have a section marked \";;; Code:\"" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2292 (point) nil))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2293 nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2294 err)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2295 (setq |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2296 err |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2297 (or |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2298 ;; * A footer. Not compartmentalized from lm-verify: too bad. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2299 ;; The following is partially clipped from lm-verify |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2300 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2301 (goto-char (point-max)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2302 (if (not (re-search-backward |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2303 (concat "^;;;[ \t]+" fn "\\(" (regexp-quote fe) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2304 "\\)?[ \t]+ends here[ \t]*$" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2305 "\\|^;;;[ \t]+ End of file[ \t]+" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2306 fn "\\(" (regexp-quote fe) "\\)?") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2307 nil t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2308 (if (checkdoc-y-or-n-p "No identifiable footer! Add one? ") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2309 (progn |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2310 (goto-char (point-max)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2311 (insert "\n(provide '" fn ")\n\n;;; " fn fe " ends here\n")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2312 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2313 (format "The footer should be: (provide '%s)\\n;;; %s%s ends here" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2314 fn fn fe) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2315 (1- (point-max)) (point-max))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2316 err)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2317 ;; The below checks will not return errors if the user says NO |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2318 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2319 ;; Ok, now let's look for multiple occurrences of ;;;, and offer |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2320 ;; to remove the extra ";" if applicable. This pre-supposes |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2321 ;; that the user has semiautomatic fixing on to be useful. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2322 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2323 ;; In the info node (elisp)Library Headers a header is three ; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2324 ;; (the header) followed by text of only two ; |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2325 ;; In (elisp)Comment Tips, however it says this: |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2326 ;; * Another use for triple-semicolon comments is for commenting out |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2327 ;; lines within a function. We use triple-semicolons for this |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2328 ;; precisely so that they remain at the left margin. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2329 (let ((msg nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2330 (goto-char (point-min)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2331 (while (and checkdoc-triple-semi-comment-check-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2332 (not msg) (re-search-forward "^;;;[^;]" nil t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2333 ;; We found a triple, let's check all following lines. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2334 (if (not (bolp)) (progn (beginning-of-line) (forward-line 1))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2335 (let ((complex-replace t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2336 (dont-replace nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2337 (while (looking-at ";;\\(;\\)[^;#]") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2338 (if (and (not dont-replace) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2339 (checkdoc-outside-major-sexp) ;in code is ok. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2340 (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2341 (match-beginning 1) (match-end 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2342 "Multiple occurrences of ;;; found. Use ;; instead? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2343 "" complex-replace)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2344 ;; Learn that, yea, the user did want to do this a |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2345 ;; whole bunch of times. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2346 (setq complex-replace nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2347 ;; In this case, skip all this crap |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2348 (setq dont-replace t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2349 (beginning-of-line) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2350 (forward-line 1))))) |
20085 | 2351 |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2352 ;; Let's spellcheck the commentary section. This is the only |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2353 ;; section that is easy to pick out, and it is also the most |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2354 ;; visible section (with the finder). |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2355 (let ((cm (lm-commentary-mark))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2356 (if cm |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2357 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2358 (goto-char (lm-commentary-mark)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2359 ;; Spellcheck between the commentary, and the first |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2360 ;; non-comment line. We could use lm-commentary, but that |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2361 ;; returns a string, and Ispell wants to talk to a buffer. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2362 ;; Since the comments talk about Lisp, use the specialized |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2363 ;; spell-checker we also used for doc strings. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2364 (let ((e (save-excursion (re-search-forward "^[^;]" nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2365 (point)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2366 (checkdoc-sentencespace-region-engine (point) e) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2367 (checkdoc-proper-noun-region-engine (point) e) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2368 (checkdoc-ispell-docstring-engine e))))) |
20085 | 2369 ;;; test comment out code |
2370 ;;; (foo 1 3) | |
2371 ;;; (bar 5 7) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2372 (setq |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2373 err |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2374 (or |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2375 ;; Generic Full-file checks (should be comment related) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2376 (checkdoc-run-hooks 'checkdoc-comment-style-hooks) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2377 err)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2378 ;; Done with full file comment checks |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2379 err))) |
20085 | 2380 |
2381 (defun checkdoc-outside-major-sexp () | |
2382 "Return t if point is outside the bounds of a valid sexp." | |
2383 (save-match-data | |
2384 (save-excursion | |
2385 (let ((p (point))) | |
2386 (or (progn (beginning-of-defun) (bobp)) | |
2387 (progn (end-of-defun) (< (point) p))))))) | |
2388 | |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2389 ;;; `error' and `message' text verifier. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2390 ;; |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2391 (defun checkdoc-message-text-search (&optional beg end) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2392 "Search between BEG and END for a style error with message text. |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2393 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
|
2394 The default boundary is the entire buffer." |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2395 (let ((e nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2396 (type nil)) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2397 (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
|
2398 (goto-char beg) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2399 (while (setq type (checkdoc-message-text-next-string end)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2400 (setq e (checkdoc-message-text-engine type))) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2401 e)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2402 |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2403 (defun checkdoc-message-text-next-string (end) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2404 "Move cursor to the next checkable message string after point. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2405 Return the message classification. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2406 Argument END is the maximum bounds to search in." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2407 (let ((return nil)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2408 (while (and (not return) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2409 (re-search-forward |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2410 "(\\s-*\\(\\(\\w\\|\\s_\\)*error\\|\ |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2411 \\(\\w\\|\\s_\\)*y-or-n-p\\(-with-timeout\\)?\ |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2412 \\|checkdoc-autofix-ask-replace\\)[ \t\n]+" end t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2413 (let* ((fn (match-string 1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2414 (type (cond ((string-match "error" fn) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2415 'error) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2416 (t 'y-or-n-p)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2417 (if (string-match "checkdoc-autofix-ask-replace" fn) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2418 (progn (forward-sexp 2) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2419 (skip-chars-forward " \t\n"))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2420 (if (and (eq type 'y-or-n-p) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2421 (looking-at "(format[ \t\n]+")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2422 (goto-char (match-end 0))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2423 (skip-chars-forward " \t\n") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2424 (if (not (looking-at "\"")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2425 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2426 (setq return type)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2427 return)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2428 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2429 (defun checkdoc-message-text-engine (&optional type) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2430 "Return or fix errors found in strings passed to a message display function. |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2431 According to the documentation for the function `error', the error list |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2432 should not end with a period, and should start with a capital letter. |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2433 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
|
2434 Argument TYPE specifies the type of question, such as `error or `y-or-n-p." |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2435 ;; If type is nil, then attempt to derive it. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2436 (if (not type) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2437 (save-excursion |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2438 (up-list -1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2439 (if (looking-at "(format") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2440 (up-list -1)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2441 (setq type |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2442 (cond ((looking-at "(error") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2443 'error) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2444 (t 'y-or-n-p))))) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2445 (let ((case-fold-search nil)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2446 (or |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2447 ;; From the documentation of the symbol `error': |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2448 ;; 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
|
2449 ;; 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
|
2450 ;; for the sake of consistency. |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2451 (if (and (save-excursion (forward-char 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2452 (looking-at "[a-z]\\w+")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2453 (not (checkdoc-autofix-ask-replace |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2454 (match-beginning 0) (match-end 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2455 "Capitalize your message text? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2456 (capitalize (match-string 0)) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2457 t))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2458 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2459 "Messages should start with a capital letter" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2460 (match-beginning 0) (match-end 0)) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2461 nil) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2462 ;; In general, sentences should have two spaces after the period. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2463 (checkdoc-sentencespace-region-engine (point) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2464 (save-excursion (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2465 (point))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2466 ;; Look for proper nouns in this region too. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2467 (checkdoc-proper-noun-region-engine (point) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2468 (save-excursion (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2469 (point))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2470 ;; Here are message type specific questions. |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2471 (if (and (eq type 'error) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2472 (save-excursion (forward-sexp 1) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2473 (forward-char -2) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2474 (looking-at "\\.")) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2475 (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
|
2476 (match-end 0) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2477 "Remove period from error? " |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2478 "" |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2479 t))) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2480 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2481 "Error messages should *not* end with a period" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2482 (match-beginning 0) (match-end 0)) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2483 nil) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2484 ;; `y-or-n-p' documentation explicitly says: |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2485 ;; 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
|
2486 ;; 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
|
2487 ;; ask a question and it appears to be an undocumented style. |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2488 (if (eq type 'y-or-n-p) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2489 (if (not (save-excursion (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2490 (forward-char -3) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2491 (not (looking-at "\\? ")))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2492 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2493 (if (save-excursion (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2494 (forward-char -2) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2495 (looking-at "\\?")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2496 ;; If we see a ?, then replace with "? ". |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2497 (if (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2498 (match-beginning 0) (match-end 0) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2499 "y-or-n-p text should end with \"? \". Fix? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2500 "? " t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2501 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2502 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2503 "y-or-n-p text should end with \"? \"" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2504 (match-beginning 0) (match-end 0))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2505 (if (save-excursion (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2506 (forward-char -2) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2507 (looking-at " ")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2508 (if (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2509 (match-beginning 0) (match-end 0) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2510 "y-or-n-p text should end with \"? \". Fix? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2511 "? " t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2512 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2513 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2514 "y-or-n-p text should end with \"? \"" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2515 (match-beginning 0) (match-end 0))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2516 (if (and ;; if this isn't true, we have a problem. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2517 (save-excursion (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2518 (forward-char -1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2519 (looking-at "\"")) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2520 (checkdoc-autofix-ask-replace |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2521 (match-beginning 0) (match-end 0) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2522 "y-or-n-p text should end with \"? \". Fix? " |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2523 "? \"" t)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2524 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2525 (checkdoc-create-error |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2526 "y-or-n-p text should end with \"? \"" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2527 (match-beginning 0) (match-end 0))))))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2528 ;; Now, let's just run the spell checker on this guy. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2529 (checkdoc-ispell-docstring-engine (save-excursion (forward-sexp 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2530 (point))) |
22111
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2531 ))) |
38f78542051a
Updated with latest version. Changes include:
Eric M. Ludlam <zappo@gnu.org>
parents:
21651
diff
changeset
|
2532 |
20085 | 2533 ;;; Auto-fix helper functions |
2534 ;; | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2535 (defun checkdoc-y-or-n-p (question) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2536 "Like `y-or-n-p', but pays attention to `checkdoc-autofix-flag'. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2537 Argument QUESTION is the prompt passed to `y-or-n-p'." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2538 (prog1 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2539 (if (or (not checkdoc-autofix-flag) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2540 (eq checkdoc-autofix-flag 'never)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2541 nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2542 (y-or-n-p question)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2543 (if (eq checkdoc-autofix-flag 'automatic-then-never) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2544 (setq checkdoc-autofix-flag 'never)))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2545 |
20085 | 2546 (defun checkdoc-autofix-ask-replace (start end question replacewith |
2547 &optional complex) | |
2548 "Highlight between START and END and queries the user with QUESTION. | |
2549 If the user says yes, or if `checkdoc-autofix-flag' permits, replace | |
2550 the region marked by START and END with REPLACEWITH. If optional flag | |
2551 COMPLEX is non-nil, then we may ask the user a question. See the | |
2552 documentation for `checkdoc-autofix-flag' for details. | |
2553 | |
2554 If a section is auto-replaced without asking the user, this function | |
2555 will pause near the fixed code so the user will briefly see what | |
2556 happened. | |
2557 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2558 This function returns non-nil if the text was replaced. |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2559 |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2560 This function will not modify `match-data'." |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2561 (if (and checkdoc-autofix-flag |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2562 (not (eq checkdoc-autofix-flag 'never))) |
20085 | 2563 (let ((o (checkdoc-make-overlay start end)) |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2564 (ret nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2565 (md (match-data))) |
20085 | 2566 (unwind-protect |
2567 (progn | |
2568 (checkdoc-overlay-put o 'face 'highlight) | |
2569 (if (or (eq checkdoc-autofix-flag 'automatic) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2570 (eq checkdoc-autofix-flag 'automatic-then-never) |
20085 | 2571 (and (eq checkdoc-autofix-flag 'semiautomatic) |
2572 (not complex)) | |
2573 (and (or (eq checkdoc-autofix-flag 'query) complex) | |
2574 (y-or-n-p question))) | |
2575 (save-excursion | |
2576 (goto-char start) | |
2577 ;; On the off chance this is automatic, display | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2578 ;; the question anyway so the user knows what's |
20085 | 2579 ;; going on. |
2580 (if checkdoc-bouncy-flag (message "%s -> done" question)) | |
2581 (delete-region start end) | |
2582 (insert replacewith) | |
2583 (if checkdoc-bouncy-flag (sit-for 0)) | |
2584 (setq ret t))) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2585 (checkdoc-delete-overlay o) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2586 (set-match-data md)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2587 (checkdoc-delete-overlay o) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2588 (set-match-data md)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2589 (if (eq checkdoc-autofix-flag 'automatic-then-never) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2590 (setq checkdoc-autofix-flag 'never)) |
20085 | 2591 ret))) |
2592 | |
2593 ;;; Warning management | |
2594 ;; | |
2595 (defvar checkdoc-output-font-lock-keywords | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2596 '(("\\(\\w+\\.el\\): \\(\\w+\\)" |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2597 (1 font-lock-function-name-face) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2598 (2 font-lock-comment-face)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2599 ("^\\(\\w+\\.el\\):" 1 font-lock-function-name-face) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2600 (":\\([0-9]+\\):" 1 font-lock-constant-face)) |
20085 | 2601 "Keywords used to highlight a checkdoc diagnostic buffer.") |
2602 | |
2603 (defvar checkdoc-output-mode-map nil | |
2604 "Keymap used in `checkdoc-output-mode'.") | |
2605 | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2606 (defvar checkdoc-pending-errors nil |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2607 "Non-nil when there are errors that have not been displayed yet.") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2608 |
20085 | 2609 (if checkdoc-output-mode-map |
2610 nil | |
2611 (setq checkdoc-output-mode-map (make-sparse-keymap)) | |
2612 (if (not (string-match "XEmacs" emacs-version)) | |
2613 (define-key checkdoc-output-mode-map [mouse-2] | |
2614 'checkdoc-find-error-mouse)) | |
2615 (define-key checkdoc-output-mode-map "\C-c\C-c" 'checkdoc-find-error) | |
2616 (define-key checkdoc-output-mode-map "\C-m" 'checkdoc-find-error)) | |
2617 | |
2618 (defun checkdoc-output-mode () | |
2619 "Create and setup the buffer used to maintain checkdoc warnings. | |
2620 \\<checkdoc-output-mode-map>\\[checkdoc-find-error] - Go to this error location | |
2621 \\[checkdoc-find-error-mouse] - Goto the error clicked on." | |
2622 (if (get-buffer checkdoc-diagnostic-buffer) | |
2623 (get-buffer checkdoc-diagnostic-buffer) | |
2624 (save-excursion | |
2625 (set-buffer (get-buffer-create checkdoc-diagnostic-buffer)) | |
2626 (kill-all-local-variables) | |
2627 (setq mode-name "Checkdoc" | |
2628 major-mode 'checkdoc-output-mode) | |
2629 (set (make-local-variable 'font-lock-defaults) | |
2630 '((checkdoc-output-font-lock-keywords) t t ((?- . "w") (?_ . "w")))) | |
2631 (use-local-map checkdoc-output-mode-map) | |
2632 (run-hooks 'checkdoc-output-mode-hook) | |
2633 (current-buffer)))) | |
2634 | |
2635 (defun checkdoc-find-error-mouse (e) | |
2636 ;; checkdoc-params: (e) | |
2637 "Call `checkdoc-find-error' where the user clicks the mouse." | |
2638 (interactive "e") | |
2639 (mouse-set-point e) | |
2640 (checkdoc-find-error)) | |
2641 | |
2642 (defun checkdoc-find-error () | |
2643 "In a checkdoc diagnostic buffer, find the error under point." | |
2644 (interactive) | |
2645 (beginning-of-line) | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2646 (if (looking-at "\\(\\(\\w+\\|\\s_\\)+\\.el\\):\\([0-9]+\\):") |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2647 (let ((l (string-to-int (match-string 3))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2648 (f (match-string 1))) |
20085 | 2649 (if (not (get-buffer f)) |
2650 (error "Can't find buffer %s" f)) | |
2651 (switch-to-buffer-other-window (get-buffer f)) | |
2652 (goto-line l)))) | |
2653 | |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2654 (defun checkdoc-buffer-label () |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2655 "The name to use for a checkdoc buffer in the error list." |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2656 (if (buffer-file-name) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2657 (file-name-nondirectory (buffer-file-name)) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2658 (concat "#<buffer "(buffer-name) ">"))) |
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2659 |
20085 | 2660 (defun checkdoc-start-section (check-type) |
2661 "Initialize the checkdoc diagnostic buffer for a pass. | |
2662 Create the header so that the string CHECK-TYPE is displayed as the | |
2663 function called to create the messages." | |
2664 (checkdoc-output-to-error-buffer | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2665 "\n\n\C-l\n*** " |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2666 (checkdoc-buffer-label) ": " check-type " V " checkdoc-version)) |
20085 | 2667 |
2668 (defun checkdoc-error (point msg) | |
2669 "Store POINT and MSG as errors in the checkdoc diagnostic buffer." | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2670 (setq checkdoc-pending-errors t) |
20085 | 2671 (checkdoc-output-to-error-buffer |
23192
1ea9db09a678
(checkdoc-buffer-label): New function.
Eric M. Ludlam <zappo@gnu.org>
parents:
22674
diff
changeset
|
2672 "\n" (checkdoc-buffer-label) ":" |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2673 (int-to-string (count-lines (point-min) (or point 1))) ": " |
20085 | 2674 msg)) |
2675 | |
2676 (defun checkdoc-output-to-error-buffer (&rest text) | |
2677 "Place TEXT into the checkdoc diagnostic buffer." | |
2678 (save-excursion | |
2679 (set-buffer (checkdoc-output-mode)) | |
2680 (goto-char (point-max)) | |
2681 (apply 'insert text))) | |
2682 | |
2683 (defun checkdoc-show-diagnostics () | |
2684 "Display the checkdoc diagnostic buffer in a temporary window." | |
22674
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2685 (if checkdoc-pending-errors |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2686 (let ((b (get-buffer checkdoc-diagnostic-buffer))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2687 (if b (progn (pop-to-buffer b) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2688 (goto-char (point-max)) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2689 (re-search-backward "\C-l" nil t) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2690 (beginning-of-line) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2691 (forward-line 1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2692 (recenter 0))) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2693 (other-window -1) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2694 (setq checkdoc-pending-errors nil) |
f72e7540940a
(checkdoc): Updated commentary.
Eric M. Ludlam <zappo@gnu.org>
parents:
22579
diff
changeset
|
2695 nil))) |
20085 | 2696 |
2697 (defgroup checkdoc nil | |
22195 | 2698 "Support for doc string checking in Emacs Lisp." |
20085 | 2699 :prefix "checkdoc" |
21651
86fcccceba7b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21181
diff
changeset
|
2700 :group 'lisp |
86fcccceba7b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21181
diff
changeset
|
2701 :version "20.3") |
20085 | 2702 |
2703 (custom-add-option 'emacs-lisp-mode-hook | |
2704 (lambda () (checkdoc-minor-mode 1))) | |
2705 | |
2706 (provide 'checkdoc) | |
22195 | 2707 |
20085 | 2708 ;;; checkdoc.el ends here |