| 1 |
;;; checkdoc-batch.el --- batch report of M-x checkdoc things |
| 2 |
|
| 3 |
;; Copyright 2010, 2011, 2014, 2015, 2016, 2019 Kevin Ryde |
| 4 |
|
| 5 |
;; Author: Kevin Ryde <[email protected]> |
| 6 |
;; Version: 8 |
| 7 |
;; Keywords: lisp, maint, checkdoc |
| 8 |
;; URL: http://user42.tuxfamily.org/checkdoc-batch/index.html |
| 9 |
|
| 10 |
;; checkdoc-batch.el is free software; you can redistribute it and/or |
| 11 |
;; modify it under the terms of the GNU General Public License as published |
| 12 |
;; by the Free Software Foundation; either version 3, or (at your option) |
| 13 |
;; any later version. |
| 14 |
|
| 15 |
;; checkdoc-batch.el is distributed in the hope that it will be useful, |
| 16 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 18 |
;; Public License for more details. |
| 19 |
|
| 20 |
;; You can get a copy of the GNU General Public License online at |
| 21 |
;; <http://www.gnu.org/licenses/>. |
| 22 |
|
| 23 |
;;; Commentary: |
| 24 |
|
| 25 |
;; `M-x checkdoc-batch' runs checkdoc.el over the current buffer. It's not |
| 26 |
;; interactive and doesn't change anything but instead presents a report of |
| 27 |
;; problems found using a compilation-mode buffer. `M-x next-error' can |
| 28 |
;; step through the problems in the usual compilation-mode style. |
| 29 |
|
| 30 |
;; An accompanying script "emacs-checkdoc-batch" can run checkdoc-batch on |
| 31 |
;; .el files from the command line. It can be run under M-x compile if |
| 32 |
;; desired. |
| 33 |
|
| 34 |
;; See the `checkdoc-batch' docstring below for more. |
| 35 |
|
| 36 |
;;; Emacsen: |
| 37 |
|
| 38 |
;; Designed for Emacs 21 and up. Works in XEmacs 21 except |
| 39 |
;; M-x checkdoc-batch-files needs a `file-expand-wildcards' copied from |
| 40 |
;; Emacs. |
| 41 |
|
| 42 |
;;; Install: |
| 43 |
|
| 44 |
;; Put checkdoc-batch.el in one of your `load-path' directories and to make |
| 45 |
;; `M-x checkdoc-batch' etc available add to your .emacs |
| 46 |
;; |
| 47 |
;; (autoload 'checkdoc-batch "checkdoc-batch" nil t) |
| 48 |
;; (autoload 'checkdoc-batch-files "checkdoc-batch" nil t) |
| 49 |
;; |
| 50 |
;; There's autoload cookies for this if you install via |
| 51 |
;; `M-x package-install' or know `update-file-autoloads'. |
| 52 |
|
| 53 |
;;; History: |
| 54 |
|
| 55 |
;; Version 1 - the first version |
| 56 |
;; Version 2 - new checkdoc-batch-files, fix for linenum at end of file |
| 57 |
;; Version 3 - another linenum fix |
| 58 |
;; Version 4 - support checkdoc-spellcheck-documentation-flag |
| 59 |
;; Version 5 - revert-buffer and auto-revert-mode support |
| 60 |
;; - don't show ispell start/stop messages |
| 61 |
;; Version 6 - don't use remove-if |
| 62 |
;; Version 7 - macros not needed when running byte compiled |
| 63 |
;; Version 8 - explicit let of global |
| 64 |
|
| 65 |
;;; Code: |
| 66 |
|
| 67 |
;; for `ad-find-advice' macro when running uncompiled |
| 68 |
;; (don't unload 'advice before our -unload-function) |
| 69 |
(require 'advice) |
| 70 |
|
| 71 |
(require 'checkdoc) |
| 72 |
|
| 73 |
(eval-when-compile |
| 74 |
(unless (and (fboundp 'declare) |
| 75 |
(fboundp 'dolist) |
| 76 |
(fboundp 'declare)) |
| 77 |
(require 'cl))) ;; for `dolist' macro in emacs20, `declare' in emacs21 |
| 78 |
|
| 79 |
|
| 80 |
;;---------------------------------------------------------------------------- |
| 81 |
;; xemacs21 missing bits |
| 82 |
|
| 83 |
;; [same in ffap-makefile-vars.el, man-completion.el] |
| 84 |
;; |
| 85 |
(eval-and-compile ;; quieten emacs byte compiler |
| 86 |
;; no `eval-when-compile' on this fboundp because in xemacs 21.4.22 |
| 87 |
;; easy-mmode.el (which is define-minor-mode etc) rudely defines a |
| 88 |
;; replace-regexp-in-string, so a compile-time test is unreliable |
| 89 |
(if (fboundp 'replace-regexp-in-string) |
| 90 |
;; emacs (21 up) |
| 91 |
(defalias 'checkdoc-batch--replace-regexp-in-string |
| 92 |
'replace-regexp-in-string) |
| 93 |
|
| 94 |
;; xemacs21 |
| 95 |
(defun checkdoc-batch--replace-regexp-in-string |
| 96 |
(regexp rep string fixedcase literal) |
| 97 |
"`replace-regexp-in-string' made available in xemacs. |
| 98 |
The FIXEDCASE argument is ignored, case is always fixed." |
| 99 |
(replace-in-string string regexp rep literal)))) |
| 100 |
|
| 101 |
;;---------------------------------------------------------------------------- |
| 102 |
;; emacs22 new bits |
| 103 |
|
| 104 |
(defalias 'checkdoc-batch--buffer-chars-modified-tick |
| 105 |
(if (eval-when-compile (fboundp 'buffer-chars-modified-tick)) |
| 106 |
'buffer-chars-modified-tick |
| 107 |
'buffer-modified-tick)) |
| 108 |
|
| 109 |
|
| 110 |
;;---------------------------------------------------------------------------- |
| 111 |
;; generic |
| 112 |
|
| 113 |
(defun checkdoc-batch-column-at-pos (pos) |
| 114 |
"An internal part of checkdoc-batch.el. |
| 115 |
Return the column number of buffer position POS. |
| 116 |
The leftmost column is number 1, unlike `current-column' which |
| 117 |
gives 0." |
| 118 |
(save-excursion |
| 119 |
(goto-char pos) |
| 120 |
(1+ (current-column)))) |
| 121 |
|
| 122 |
(defun checkdoc-batch-completion-first-candidate (collection) |
| 123 |
"An internal part of checkdoc-batch.el. |
| 124 |
Return first candidate from completion COLLECTION. |
| 125 |
COLLECTION can be anything `all-completions' and friends accept, |
| 126 |
like an alist, handler function, etc." |
| 127 |
(let ((checkdoc-batch-completion-first-candidate--stop nil)) |
| 128 |
(car (all-completions |
| 129 |
"" |
| 130 |
collection |
| 131 |
(lambda (candidate) |
| 132 |
(if checkdoc-batch-completion-first-candidate--stop |
| 133 |
nil |
| 134 |
(setq checkdoc-batch-completion-first-candidate--stop t))))))) |
| 135 |
|
| 136 |
(eval-when-compile |
| 137 |
(defmacro checkdoc-batch--with-buffer-file-name (filename &rest body) |
| 138 |
;; checkdoc-params: (filename body) |
| 139 |
"An internal part of checkdoc-batch.el. |
| 140 |
This macro doesn't exist when running byte compiled. |
| 141 |
|
| 142 |
Temporarily set `buffer-file-name' to FILENAME and evaluate BODY. |
| 143 |
This is done by a `setq' and `unwind-protect' since not sure that |
| 144 |
a `let'-binding of `buffer-file-name' is safe against all kinds |
| 145 |
of buffer switching." |
| 146 |
|
| 147 |
(declare (debug t) |
| 148 |
(indent 1)) |
| 149 |
`(let ((checkdoc-batch--with-buffer-file-name buffer-file-name) |
| 150 |
(checkdoc-batch--with-buffer-file-name--buffer (current-buffer))) |
| 151 |
(unwind-protect |
| 152 |
(progn |
| 153 |
(setq buffer-file-name ,filename) |
| 154 |
,@body) |
| 155 |
(if (buffer-live-p checkdoc-batch--with-buffer-file-name--buffer) |
| 156 |
(with-current-buffer checkdoc-batch--with-buffer-file-name--buffer |
| 157 |
(setq buffer-file-name checkdoc-batch--with-buffer-file-name))))))) |
| 158 |
|
| 159 |
(defun checkdoc-batch-display-buffer-other-window (buffer) |
| 160 |
"An internal part of checkdoc-batch.el. |
| 161 |
Display BUFFER in another window. |
| 162 |
For a new window `shrink-window-if-larger-than-buffer' is used to |
| 163 |
set its size. If BUFFER is already in another window then its |
| 164 |
size is left alone." |
| 165 |
(unless (get-buffer-window buffer nil) ;; if not in a window already |
| 166 |
(save-current-buffer |
| 167 |
(save-selected-window |
| 168 |
(condition-case nil |
| 169 |
;; emacs two args |
| 170 |
(switch-to-buffer-other-window buffer t) ;; no-record |
| 171 |
(error |
| 172 |
;; xemacs one arg |
| 173 |
(switch-to-buffer-other-window buffer))) |
| 174 |
(shrink-window-if-larger-than-buffer |
| 175 |
(get-buffer-window buffer)))))) |
| 176 |
|
| 177 |
(defun checkdoc-batch-lock-file-p (filename) |
| 178 |
"An internal part of checkdoc-batch.el. |
| 179 |
Return non-nil if FILENAME is an Emacs lock file. |
| 180 |
A lock file is \".#foo.txt\" etc per `lock-buffer'." |
| 181 |
(string-match "\\`\\.#" (file-name-nondirectory filename))) |
| 182 |
|
| 183 |
(defun checkdoc-batch-prin1-strings-list (lst) |
| 184 |
"An internal part of checkdoc-batch.el. |
| 185 |
Return a string to display a list LST of strings. |
| 186 |
This is like `prin1-to-string' but without the surrounding |
| 187 |
parens." |
| 188 |
(mapconcat 'prin1-to-string lst " ")) |
| 189 |
|
| 190 |
(defun checkdoc-batch-file-truename (filename) |
| 191 |
"An internal part of checkdoc-batch.el. |
| 192 |
Return the true name of FILENAME. |
| 193 |
This is `file-truename', but nil on error in XEmacs 21." |
| 194 |
;; xemacs 21.4.22 `file-truename' throws an error if |
| 195 |
;; /foo/bar/quux has "foo" or "bar" as files instead of |
| 196 |
;; directories, treat that as nil |
| 197 |
(condition-case nil |
| 198 |
(file-truename filename) |
| 199 |
(error nil))) |
| 200 |
|
| 201 |
(defun checkdoc-batch-save-some-files (filename-list) |
| 202 |
"An internal part of checkdoc-batch.el. |
| 203 |
Offer to save buffers visiting any files in FILENAME-LIST. |
| 204 |
Saving is done with `save-some-buffers'. |
| 205 |
Filenames are compared with `file-truename'." |
| 206 |
(let ((checkdoc-batch--truename-list |
| 207 |
(delq nil (mapcar 'checkdoc-batch-file-truename filename-list)))) |
| 208 |
(save-some-buffers |
| 209 |
nil (lambda () |
| 210 |
(and buffer-file-name |
| 211 |
(member (checkdoc-batch-file-truename buffer-file-name) |
| 212 |
checkdoc-batch--truename-list)))))) |
| 213 |
|
| 214 |
|
| 215 |
;;---------------------------------------------------------------------------- |
| 216 |
|
| 217 |
(defvar checkdoc-batch-filename nil |
| 218 |
"An internal part of checkdoc-batch.el. |
| 219 |
Current buffer filename during a `checkdoc-batch'.") |
| 220 |
|
| 221 |
(defun checkdoc-batch-linenums-annotate () |
| 222 |
"An internal part of checkdoc-batch.el. |
| 223 |
Add some text properties to the buffer to record original line numbers." |
| 224 |
(let ((linenum 1)) |
| 225 |
(goto-char (point-min)) |
| 226 |
(while (search-forward "\n" nil t) |
| 227 |
(add-text-properties (match-beginning 0) (match-end 0) |
| 228 |
(list 'checkdoc-batch-linenum linenum)) |
| 229 |
(setq linenum (1+ linenum))))) |
| 230 |
|
| 231 |
(defun checkdoc-batch-linenum (pos) |
| 232 |
"An internal part of checkdoc-batch.el. |
| 233 |
Return original line number of buffer position POS." |
| 234 |
(or (get-text-property pos 'checkdoc-batch-linenum) |
| 235 |
(let ((ppos (next-single-property-change pos 'checkdoc-batch-linenum))) |
| 236 |
(if ppos |
| 237 |
(get-text-property ppos 'checkdoc-batch-linenum) |
| 238 |
(setq ppos (previous-single-property-change |
| 239 |
pos 'checkdoc-batch-linenum)) |
| 240 |
(if (not ppos) |
| 241 |
1 ;; no properties at all, eg. empty buffer |
| 242 |
(1+ (or (get-text-property ppos 'checkdoc-batch-linenum) |
| 243 |
(get-text-property (1- ppos) 'checkdoc-batch-linenum) |
| 244 |
0))))))) |
| 245 |
|
| 246 |
(defun checkdoc-batch-message (format-string &rest args) |
| 247 |
"An internal part of checkdoc-batch.el. |
| 248 |
Output a `checkdoc-batch' message." |
| 249 |
;; checkdoc-params: (format-string args) |
| 250 |
;; strip trailing whitespace from lines, since the questions from checkdoc |
| 251 |
;; often include that at the end of prompts |
| 252 |
(princ (checkdoc-batch--replace-regexp-in-string |
| 253 |
"[ \t]+$" "" |
| 254 |
(apply 'format format-string args) |
| 255 |
t ;; fixedcase |
| 256 |
t))) |
| 257 |
(eval-when-compile |
| 258 |
(put 'checkdoc-batch-message 'byte-compile-format-like t)) ;; literal |
| 259 |
|
| 260 |
(defun checkdoc-batch-error (pos text) |
| 261 |
"An internal part of checkdoc-batch.el. |
| 262 |
Output a `checkdoc-batch' error about buffer position POS." |
| 263 |
;; checkdoc-params: (pos text) |
| 264 |
(checkdoc-batch-message "%s:%s:%s: %s\n" |
| 265 |
checkdoc-batch-filename |
| 266 |
(checkdoc-batch-linenum pos) |
| 267 |
(checkdoc-batch-column-at-pos pos) |
| 268 |
text)) |
| 269 |
|
| 270 |
;;----------------------------------------------------------------------------- |
| 271 |
|
| 272 |
(defadvice checkdoc-autofix-ask-replace (around checkdoc-batch) |
| 273 |
"Temporary hack to capture message and say yes to change." |
| 274 |
(checkdoc-batch-error start (concat question " " replacewith)) |
| 275 |
(delete-region start end) |
| 276 |
(save-excursion |
| 277 |
(goto-char start) |
| 278 |
(insert replacewith) |
| 279 |
(set-buffer-modified-p nil)) |
| 280 |
(setq ad-return-value t)) |
| 281 |
|
| 282 |
(defadvice checkdoc-y-or-n-p (around checkdoc-batch) |
| 283 |
"Temporary hack to capture message and say yes to change." |
| 284 |
(checkdoc-batch-error (point) |
| 285 |
(ad-get-arg 0)) ;; QUESTION |
| 286 |
(setq ad-return-value t)) |
| 287 |
|
| 288 |
(defadvice checkdoc-recursive-edit (around checkdoc-batch) |
| 289 |
"Temporary hack to capture message and suppress edit." |
| 290 |
(checkdoc-batch-error (point) |
| 291 |
(ad-get-arg 0)) ;; MSG |
| 292 |
(setq ad-return-value t)) |
| 293 |
|
| 294 |
(defadvice checkdoc-create-error (around checkdoc-batch) |
| 295 |
"Temporary hack to capture checkdoc error messages." |
| 296 |
;; START is nil for a whole-buffer thing like missing ";;; Commentary" |
| 297 |
;; section |
| 298 |
(checkdoc-batch-error (or start (point-min)) |
| 299 |
text) |
| 300 |
(setq ad-return-value nil)) |
| 301 |
|
| 302 |
(defadvice message (around checkdoc-batch) |
| 303 |
"Temporary hack to capture checkdoc messages." |
| 304 |
(let ((format (ad-get-arg 0))) |
| 305 |
(if (null format) |
| 306 |
(setq ad-return-value nil) |
| 307 |
(let ((str (apply 'format (ad-get-args 0)))) |
| 308 |
(setq ad-return-value str) |
| 309 |
(unless (string-match "\\(\\`Searching for \\|Done\\|Starting new Ispell\\|Ispell process killed\\)" format) |
| 310 |
(checkdoc-batch-message "%s\n" str)))))) |
| 311 |
|
| 312 |
(defadvice read-string (around checkdoc-batch) |
| 313 |
"Temporary hack to just return an empty string." |
| 314 |
(setq ad-return-value "")) |
| 315 |
|
| 316 |
(defadvice completing-read (around checkdoc-batch) |
| 317 |
"Temporary hack to just return first completion candidate." |
| 318 |
(setq ad-return-value |
| 319 |
(or (checkdoc-batch-completion-first-candidate |
| 320 |
(ad-get-arg 1)) ;; COLLECTION or TABLE |
| 321 |
""))) |
| 322 |
|
| 323 |
(defadvice ispell-command-loop (around checkdoc-batch) |
| 324 |
"Temporary hack to capture spelling error reports." |
| 325 |
(let ((maybe (delq nil (list miss guess)))) |
| 326 |
(setq maybe |
| 327 |
(if maybe |
| 328 |
(concat "\n maybe " |
| 329 |
(mapconcat 'checkdoc-batch-prin1-strings-list maybe |
| 330 |
" or ")) |
| 331 |
"")) |
| 332 |
(checkdoc-batch-error (point) |
| 333 |
(format "spelling %S%s" word maybe))) |
| 334 |
nil) ;; keep word |
| 335 |
|
| 336 |
(defconst checkdoc-batch-advised-functions |
| 337 |
'(checkdoc-autofix-ask-replace |
| 338 |
checkdoc-y-or-n-p |
| 339 |
checkdoc-recursive-edit |
| 340 |
checkdoc-create-error |
| 341 |
message |
| 342 |
read-string |
| 343 |
completing-read |
| 344 |
ispell-command-loop) |
| 345 |
"An internal part of checkdoc-batch.el. |
| 346 |
List of functions (symbols) with `checkdoc-batch' advice.") |
| 347 |
|
| 348 |
(defun checkdoc-batch-advice (action) |
| 349 |
"An internal part of checkdoc-batch.el. |
| 350 |
Call ACTION on `checkdoc-batch-advised-functions'. |
| 351 |
ACTION can be symbol `ad-enable-advice' or `ad-disable-advice'." |
| 352 |
(dolist (func checkdoc-batch-advised-functions) |
| 353 |
(funcall action func 'around 'checkdoc-batch) |
| 354 |
(ad-activate func))) |
| 355 |
|
| 356 |
;; this cleans up in emacs22 up, but since the advice is only enabled while |
| 357 |
;; checkdoc-batch executes it doesn't matter if it's left behind in |
| 358 |
;; emacs21/xemacs21 |
| 359 |
;; |
| 360 |
(defun checkdoc-batch-unload-function () |
| 361 |
"An internal part of checkdoc-batch.el. |
| 362 |
Remove advice from `checkdoc-batch-advised-functions'. |
| 363 |
This is called by `unload-feature'." |
| 364 |
(dolist (func checkdoc-batch-advised-functions) |
| 365 |
(when (ad-find-advice func 'around 'checkdoc-batch) |
| 366 |
(ad-remove-advice func 'around 'checkdoc-batch) |
| 367 |
(ad-activate func))) |
| 368 |
nil) ;; and do normal unload-feature actions too |
| 369 |
|
| 370 |
|
| 371 |
;;----------------------------------------------------------------------------- |
| 372 |
;; revert and stale |
| 373 |
|
| 374 |
(defvar checkdoc-batch-originating-buffer nil) |
| 375 |
(defvar checkdoc-batch-originating-files nil) |
| 376 |
(defvar checkdoc-batch-stale-data nil) |
| 377 |
|
| 378 |
(defun checkdoc-batch-stale-buffer (&optional noconfirm) |
| 379 |
"An internal part of checkdoc-batch.el. |
| 380 |
Return non-nil if the checkdoc output is stale. |
| 381 |
This is the `buffer-stale-function' for the output of a |
| 382 |
`checkdoc-batch'. It should be called with \"*checkdoc-batch |
| 383 |
output*\" as the current buffer. |
| 384 |
|
| 385 |
If the originating buffer has changed then the output is |
| 386 |
considered stale. (But the output buffer is flagged as modified, |
| 387 |
which means `auto-revert-mode' and friends won't automatically |
| 388 |
re-run the checking.)" |
| 389 |
|
| 390 |
(not (equal checkdoc-batch-stale-data |
| 391 |
(checkdoc-batch--buffer-chars-modified-tick checkdoc-batch-originating-buffer)))) |
| 392 |
|
| 393 |
(defun checkdoc-batch-stale-files (&optional noconfirm) |
| 394 |
"An internal part of checkdoc-batch.el. |
| 395 |
Return non-nil if the checkdoc output is stale. |
| 396 |
This is the `buffer-stale-function' of a `checkdoc-batch' run on |
| 397 |
a set of files. It should be called with \"*checkdoc-batch |
| 398 |
output*\" as the current buffer. |
| 399 |
|
| 400 |
If the file modtimes have changed then the checking output is |
| 401 |
considered stale. (But the output buffer is flagged as modified, |
| 402 |
which means `auto-revert-mode' and friends won't automatically |
| 403 |
re-run the checking.)" |
| 404 |
|
| 405 |
(not (equal checkdoc-batch-stale-data |
| 406 |
(mapcar (lambda (filename) |
| 407 |
(nth 5 (file-attributes filename))) |
| 408 |
checkdoc-batch-originating-files)))) |
| 409 |
|
| 410 |
(defun checkdoc-batch-revert-from-buffer (&optional ignore-auto noconfirm) |
| 411 |
"An internal part of checkdoc-batch.el. |
| 412 |
Re-run `checkdoc-batch' to update an output buffer. |
| 413 |
This is the `revert-buffer-function' in a \"*checkdoc-batch |
| 414 |
output*\" buffer run from `checkdoc-batch' of a buffer. It |
| 415 |
re-runs that `checkdoc-batch', replacing the previous checking |
| 416 |
output." |
| 417 |
|
| 418 |
(unless (buffer-live-p checkdoc-batch-originating-buffer) |
| 419 |
(error "Original buffer gone")) |
| 420 |
(save-window-excursion |
| 421 |
(with-current-buffer checkdoc-batch-originating-buffer |
| 422 |
(checkdoc-batch)))) |
| 423 |
|
| 424 |
(defun checkdoc-batch-revert-from-files (&optional ignore-auto noconfirm) |
| 425 |
"An internal part of checkdoc-batch.el. |
| 426 |
Re-run `checkdoc-batch-files' to update an output buffer. |
| 427 |
This is the `revert-buffer-function' in a \"*checkdoc-batch |
| 428 |
output*\" buffer run from `checkdoc-batch-files' of a set of |
| 429 |
files. It re-runs that check on the same files, replacing the |
| 430 |
previous checking output." |
| 431 |
|
| 432 |
(save-window-excursion |
| 433 |
(checkdoc-batch-files checkdoc-batch-originating-files))) |
| 434 |
|
| 435 |
|
| 436 |
;;----------------------------------------------------------------------------- |
| 437 |
;; checking proper |
| 438 |
|
| 439 |
(defun checkdoc-batch-temp-buffer (filename) |
| 440 |
"An internal part of checkdoc-batch.el. |
| 441 |
Generate a report for the current temp buffer contents." |
| 442 |
;; checkdoc-params: (checkdoc-batch-filename) |
| 443 |
|
| 444 |
(let ((checkdoc-batch-filename filename)) |
| 445 |
(checkdoc-batch-linenums-annotate) |
| 446 |
|
| 447 |
;; must be in elisp mode for various moving things |
| 448 |
(emacs-lisp-mode) |
| 449 |
(setq buffer-read-only nil) |
| 450 |
|
| 451 |
(checkdoc-batch--with-buffer-file-name |
| 452 |
(and checkdoc-batch-filename |
| 453 |
(concat "/tmp/checkdoc-batch/mangled/" |
| 454 |
(file-name-nondirectory checkdoc-batch-filename))) |
| 455 |
(let ((checkdoc-autofix-flag 'automatic)) |
| 456 |
(unwind-protect |
| 457 |
(progn |
| 458 |
(checkdoc-batch-advice 'ad-enable-advice) |
| 459 |
(checkdoc)) |
| 460 |
(checkdoc-batch-advice 'ad-disable-advice)))))) |
| 461 |
|
| 462 |
;;;###autoload |
| 463 |
(defun checkdoc-batch () |
| 464 |
"Run `checkdoc' on the current buffer, showing results in batch form. |
| 465 |
The advantage of `checkdoc-batch' is that it's not interactive, |
| 466 |
you just get a list of the problems to step through with |
| 467 |
`next-error'. Some things you might not want to fix, or not yet, |
| 468 |
etc. The full list of problems helps avoid confusion with the |
| 469 |
way interactively \"n\" means next docstring, not next |
| 470 |
problem (where refusing one change means you don't see other |
| 471 |
things in that docstring). |
| 472 |
|
| 473 |
The disadvantage of `checkdoc-batch' is that it's not |
| 474 |
interactive, so you don't get the auto-fixes `checkdoc' can |
| 475 |
apply. Normally they're not too complicated though and can be |
| 476 |
done manually, or do an interactive `checkdoc' when ready. |
| 477 |
|
| 478 |
The summary output is a bit rough and the way it hooks into |
| 479 |
checkdoc.el is very nasty and probably rather fragile. |
| 480 |
|
| 481 |
\\[revert-buffer] in the summary buffer re-runs the checks. |
| 482 |
`auto-revert-mode' can be used there too, though its re-running |
| 483 |
might be a bit intrusive. |
| 484 |
|
| 485 |
---------- |
| 486 |
See `checkdoc-current-buffer' (with prefix arg) for much the same |
| 487 |
non-interactive checking, but without spell checking of |
| 488 |
`checkdoc-spellcheck-documentation-flag'. |
| 489 |
|
| 490 |
The checkdoc-batch.el home page is |
| 491 |
URL `http://user42.tuxfamily.org/checkdoc-batch/index.html'" |
| 492 |
|
| 493 |
(interactive) |
| 494 |
(let ((orig-buffer (current-buffer)) |
| 495 |
(orig-filename buffer-file-name) |
| 496 |
(orig-directory default-directory) |
| 497 |
(output-buffer (get-buffer-create "*checkdoc-batch output*"))) |
| 498 |
|
| 499 |
(with-current-buffer output-buffer |
| 500 |
(fundamental-mode) |
| 501 |
(setq buffer-read-only nil) |
| 502 |
(erase-buffer)) |
| 503 |
|
| 504 |
(with-temp-buffer |
| 505 |
(let ((tempbuf (current-buffer))) |
| 506 |
(with-current-buffer orig-buffer |
| 507 |
(copy-to-buffer tempbuf (point-min) (point-max)))) |
| 508 |
|
| 509 |
(let ((standard-output output-buffer)) |
| 510 |
(checkdoc-batch-message |
| 511 |
"-*- mode: compilation; default-directory: %S -*-\n\n" orig-directory) |
| 512 |
(checkdoc-batch-temp-buffer (and orig-filename |
| 513 |
(file-name-nondirectory orig-filename))) |
| 514 |
(checkdoc-batch-message "done\n"))) |
| 515 |
|
| 516 |
(with-current-buffer output-buffer |
| 517 |
(goto-char (point-min)) |
| 518 |
(compilation-mode) |
| 519 |
(set-buffer-modified-p nil) |
| 520 |
(setq default-directory orig-directory) |
| 521 |
(set (make-local-variable 'checkdoc-batch-originating-buffer) |
| 522 |
orig-buffer) |
| 523 |
(set (make-local-variable 'checkdoc-batch-stale-data) |
| 524 |
(checkdoc-batch--buffer-chars-modified-tick orig-buffer)) |
| 525 |
(set (make-local-variable 'revert-buffer-function) |
| 526 |
'checkdoc-batch-revert-from-buffer) |
| 527 |
(set (make-local-variable 'buffer-stale-function) |
| 528 |
'checkdoc-batch-stale-buffer)) |
| 529 |
(checkdoc-batch-display-buffer-other-window output-buffer))) |
| 530 |
|
| 531 |
;;;###autoload |
| 532 |
(defun checkdoc-batch-files (filename-list) |
| 533 |
;; checkdoc-params: (filename-list) |
| 534 |
"Run `checkdoc-batch' on multiple files. |
| 535 |
Interatively a wildcard like \"*.el\" is read. |
| 536 |
|
| 537 |
See the \"emacs-checkdoc-batch\" script (which comes with |
| 538 |
checkdoc-batch.el) for running on multiple files in a separate |
| 539 |
process. |
| 540 |
|
| 541 |
\\[revert-buffer] in the summary buffer re-runs the checks. |
| 542 |
`auto-revert-mode' can be used there too, though its re-running |
| 543 |
might be a bit intrusive." |
| 544 |
|
| 545 |
(interactive |
| 546 |
(let* ((pattern (read-file-name "Filename with wildcards: " nil)) |
| 547 |
(filename-list (file-expand-wildcards pattern))) |
| 548 |
|
| 549 |
;; not .#foo lockfiles |
| 550 |
(dolist (filename filename-list) |
| 551 |
(if (checkdoc-batch-lock-file-p filename) |
| 552 |
(setq filename-list (remove filename filename-list)))) |
| 553 |
|
| 554 |
(unless filename-list |
| 555 |
(error "No files: %S" pattern)) |
| 556 |
(checkdoc-batch-save-some-files filename-list) |
| 557 |
(list filename-list))) |
| 558 |
|
| 559 |
(let ((output-buffer (get-buffer-create "*checkdoc-batch output*"))) |
| 560 |
|
| 561 |
(with-current-buffer output-buffer |
| 562 |
(fundamental-mode) |
| 563 |
(setq buffer-read-only nil) |
| 564 |
(erase-buffer)) |
| 565 |
|
| 566 |
(let ((standard-output output-buffer)) |
| 567 |
(checkdoc-batch-message "-*- mode: compilation -*-\n\n") |
| 568 |
(dolist (filename filename-list) |
| 569 |
(checkdoc-batch-message "%s:\n" filename) |
| 570 |
(with-temp-buffer |
| 571 |
(insert-file-contents filename) |
| 572 |
(checkdoc-batch-temp-buffer filename))) |
| 573 |
(checkdoc-batch-message "done\n")) |
| 574 |
|
| 575 |
(with-current-buffer output-buffer |
| 576 |
(goto-char (point-min)) |
| 577 |
(compilation-mode) |
| 578 |
(set-buffer-modified-p nil) |
| 579 |
(set (make-local-variable 'checkdoc-batch-originating-files) |
| 580 |
filename-list) |
| 581 |
(set (make-local-variable 'revert-buffer-function) |
| 582 |
'checkdoc-batch-revert-from-files) |
| 583 |
(setq checkdoc-batch-stale-data |
| 584 |
(mapcar (lambda (filename) |
| 585 |
(nth 5 (file-attributes filename))) |
| 586 |
checkdoc-batch-originating-files)) |
| 587 |
(set (make-local-variable 'buffer-stale-function) |
| 588 |
'checkdoc-batch-stale-files)) |
| 589 |
(checkdoc-batch-display-buffer-other-window output-buffer))) |
| 590 |
|
| 591 |
(defun checkdoc-batch-commandline () |
| 592 |
"Run `checkdoc-batch' on files in `command-line-args-left'. |
| 593 |
This is designed for use from Emacs startup as |
| 594 |
|
| 595 |
emacs -batch -f checkdoc-batch-commandline filename.el... |
| 596 |
|
| 597 |
See the \"emacs-checkdoc-batch\" script for a handy way to run |
| 598 |
this line." |
| 599 |
|
| 600 |
(dolist (filename command-line-args-left) |
| 601 |
(checkdoc-batch-message "%s:\n" filename) |
| 602 |
(condition-case err |
| 603 |
(with-temp-buffer |
| 604 |
(insert-file-contents filename) |
| 605 |
(checkdoc-batch-temp-buffer filename)) |
| 606 |
(error |
| 607 |
(checkdoc-batch-message "Oops, error: %S\n" |
| 608 |
(error-message-string err)))))) |
| 609 |
|
| 610 |
;; LocalWords: parens docstring txt filename Filenames arg startup el |
| 611 |
;; LocalWords: modtimes foo |
| 612 |
|
| 613 |
(provide 'checkdoc-batch) |
| 614 |
|
| 615 |
;; Local Variables: |
| 616 |
;; indent-tabs-mode: nil |
| 617 |
;; End: |
| 618 |
|
| 619 |
;;; checkdoc-batch.el ends here |