comparison lisp/emacs-lisp/checkdoc.el @ 111443:72390b0b6207

* lisp/emacs-lisp/checkdoc.el (checkdoc-display-status-buffer) (checkdoc-interactive-loop, checkdoc-recursive-edit): Avoid princ-list. (checkdoc-syntax-table): Initialize in the declaration. (emacs-lisp-mode-hook): Use just checkdoc-minor-mode now that it turns the mode on unconditionally.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 08 Nov 2010 15:01:01 -0500
parents ec9d8615510e
children ebfca53e3979
comparison
equal deleted inserted replaced
111442:7094295b2a61 111443:72390b0b6207
199 is `semiautomatic' or any other value, then simple fixes are made 199 is `semiautomatic' or any other value, then simple fixes are made
200 without asking, and complex changes are made by asking the user first. 200 without asking, and complex changes are made by asking the user first.
201 The value `never' is the same as nil, never ask or change anything." 201 The value `never' is the same as nil, never ask or change anything."
202 :group 'checkdoc 202 :group 'checkdoc
203 :type '(choice (const automatic) 203 :type '(choice (const automatic)
204 (const query) 204 (const query)
205 (const never) 205 (const never)
206 (other :tag "semiautomatic" semiautomatic))) 206 (other :tag "semiautomatic" semiautomatic)))
207 207
208 (defcustom checkdoc-bouncy-flag t 208 (defcustom checkdoc-bouncy-flag t
209 "Non-nil means to \"bounce\" to auto-fix locations. 209 "Non-nil means to \"bounce\" to auto-fix locations.
210 Setting this to nil will silently make fixes that require no user 210 Setting this to nil will silently make fixes that require no user
211 interaction. See `checkdoc-autofix-flag' for auto-fixing details." 211 interaction. See `checkdoc-autofix-flag' for auto-fixing details."
248 buffer - Spell-check when style checking the whole buffer 248 buffer - Spell-check when style checking the whole buffer
249 interactive - Spell-check during any interactive check. 249 interactive - Spell-check during any interactive check.
250 t - Always spell-check" 250 t - Always spell-check"
251 :group 'checkdoc 251 :group 'checkdoc
252 :type '(choice (const nil) 252 :type '(choice (const nil)
253 (const defun) 253 (const defun)
254 (const buffer) 254 (const buffer)
255 (const interactive) 255 (const interactive)
256 (const t))) 256 (const t)))
257 257
258 (defvar checkdoc-ispell-lisp-words 258 (defvar checkdoc-ispell-lisp-words
259 '("alist" "emacs" "etags" "keymap" "paren" "regexp" "sexp" "xemacs") 259 '("alist" "emacs" "etags" "keymap" "paren" "regexp" "sexp" "xemacs")
260 "List of words that are correct when spell-checking Lisp documentation.") 260 "List of words that are correct when spell-checking Lisp documentation.")
261 261
427 Set `checkdoc-verb-check-experimental-flag' to nil to avoid this costly 427 Set `checkdoc-verb-check-experimental-flag' to nil to avoid this costly
428 and experimental check. Do not modify this list without setting 428 and experimental check. Do not modify this list without setting
429 the value of `checkdoc-common-verbs-regexp' to nil which cause it to 429 the value of `checkdoc-common-verbs-regexp' to nil which cause it to
430 be re-created.") 430 be re-created.")
431 431
432 (defvar checkdoc-syntax-table nil 432 (defvar checkdoc-syntax-table
433 (let ((st (make-syntax-table emacs-lisp-mode-syntax-table)))
434 ;; When dealing with syntax in doc strings, make sure that - are
435 ;; encompassed in words so we can use cheap \\> to get the end of a symbol,
436 ;; not the end of a word in a conglomerate.
437 (modify-syntax-entry ?- "w" checkdoc-syntax-table)
438 st)
433 "Syntax table used by checkdoc in document strings.") 439 "Syntax table used by checkdoc in document strings.")
434
435 (if checkdoc-syntax-table
436 nil
437 (setq checkdoc-syntax-table (copy-syntax-table emacs-lisp-mode-syntax-table))
438 ;; When dealing with syntax in doc strings, make sure that - are encompassed
439 ;; in words so we can use cheap \\> to get the end of a symbol, not the
440 ;; end of a word in a conglomerate.
441 (modify-syntax-entry ?- "w" checkdoc-syntax-table)
442 )
443
444 440
445 ;;; Compatibility 441 ;;; Compatibility
446 ;; 442 ;;
447 (defalias 'checkdoc-make-overlay 443 (defalias 'checkdoc-make-overlay
448 (if (featurep 'xemacs) 'make-extent 'make-overlay)) 444 (if (featurep 'xemacs) 'make-extent 'make-overlay))
513 "Display and update the status buffer for the current checkdoc mode. 509 "Display and update the status buffer for the current checkdoc mode.
514 CHECK is a list of four strings stating the current status of each 510 CHECK is a list of four strings stating the current status of each
515 test; the nth string describes the status of the nth test." 511 test; the nth string describes the status of the nth test."
516 (let (temp-buffer-setup-hook) 512 (let (temp-buffer-setup-hook)
517 (with-output-to-temp-buffer "*Checkdoc Status*" 513 (with-output-to-temp-buffer "*Checkdoc Status*"
518 (princ-list 514 (mapc #'princ
519 "Buffer comments and tags: " (nth 0 check) "\n" 515 (list "Buffer comments and tags: " (nth 0 check)
520 "Documentation style: " (nth 1 check) "\n" 516 "\nDocumentation style: " (nth 1 check)
521 "Message/Query text style: " (nth 2 check) "\n" 517 "\nMessage/Query text style: " (nth 2 check)
522 "Unwanted Spaces: " (nth 3 check) 518 "\nUnwanted Spaces: " (nth 3 check)))))
523 )))
524 (shrink-window-if-larger-than-buffer 519 (shrink-window-if-larger-than-buffer
525 (get-buffer-window "*Checkdoc Status*")) 520 (get-buffer-window "*Checkdoc Status*"))
526 (message nil) 521 (message nil)
527 (sit-for 0)) 522 (sit-for 0))
528 523
621 (if (> l (window-height)) 616 (if (> l (window-height))
622 (recenter 1) 617 (recenter 1)
623 (recenter (/ (- (window-height) l) 2)))) 618 (recenter (/ (- (window-height) l) 2))))
624 (recenter)) 619 (recenter))
625 (message "%s (C-h,%se,n,p,q)" (checkdoc-error-text 620 (message "%s (C-h,%se,n,p,q)" (checkdoc-error-text
626 (car (car err-list))) 621 (car (car err-list)))
627 (if (checkdoc-error-unfixable (car (car err-list))) 622 (if (checkdoc-error-unfixable (car (car err-list)))
628 "" "f,")) 623 "" "f,"))
629 (save-excursion 624 (save-excursion
630 (goto-char (checkdoc-error-start (car (car err-list)))) 625 (goto-char (checkdoc-error-start (car (car err-list))))
631 (if (not (pos-visible-in-window-p)) 626 (if (not (pos-visible-in-window-p))
711 (if (get-buffer-window "*Checkdoc Help*") 706 (if (get-buffer-window "*Checkdoc Help*")
712 (progn 707 (progn
713 (delete-window (get-buffer-window "*Checkdoc Help*")) 708 (delete-window (get-buffer-window "*Checkdoc Help*"))
714 (kill-buffer "*Checkdoc Help*")) 709 (kill-buffer "*Checkdoc Help*"))
715 (with-output-to-temp-buffer "*Checkdoc Help*" 710 (with-output-to-temp-buffer "*Checkdoc Help*"
716 (princ-list 711 (with-current-buffer standard-output
717 "Checkdoc Keyboard Summary:\n" 712 (insert
718 (if (checkdoc-error-unfixable (car (car err-list))) 713 "Checkdoc Keyboard Summary:\n"
719 "" 714 (if (checkdoc-error-unfixable (car (car err-list)))
720 (concat 715 ""
721 "f, y - auto Fix this warning without asking (if\ 716 (concat
717 "f, y - auto Fix this warning without asking (if\
722 available.)\n" 718 available.)\n"
723 " Very complex operations will still query.\n") 719 " Very complex operations will still query.\n")
724 ) 720 )
725 "e - Enter recursive Edit. Press C-M-c to exit.\n" 721 "e - Enter recursive Edit. Press C-M-c to exit.\n"
726 "SPC, n - skip to the Next error.\n" 722 "SPC, n - skip to the Next error.\n"
727 "DEL, p - skip to the Previous error.\n" 723 "DEL, p - skip to the Previous error.\n"
728 "q - Quit checkdoc.\n" 724 "q - Quit checkdoc.\n"
729 "C-h - Toggle this help buffer.")) 725 "C-h - Toggle this help buffer.")))
730 (shrink-window-if-larger-than-buffer 726 (shrink-window-if-larger-than-buffer
731 (get-buffer-window "*Checkdoc Help*")))))) 727 (get-buffer-window "*Checkdoc Help*"))))))
732 (if cdo (checkdoc-delete-overlay cdo))))) 728 (if cdo (checkdoc-delete-overlay cdo)))))
733 (goto-char begin) 729 (goto-char begin)
734 (if (get-buffer "*Checkdoc Help*") (kill-buffer "*Checkdoc Help*")) 730 (if (get-buffer "*Checkdoc Help*") (kill-buffer "*Checkdoc Help*"))
824 820
825 (defun checkdoc-recursive-edit (msg) 821 (defun checkdoc-recursive-edit (msg)
826 "Enter recursive edit to permit a user to fix some error checkdoc has found. 822 "Enter recursive edit to permit a user to fix some error checkdoc has found.
827 MSG is the error that was found, which is displayed in a help buffer." 823 MSG is the error that was found, which is displayed in a help buffer."
828 (with-output-to-temp-buffer "*Checkdoc Help*" 824 (with-output-to-temp-buffer "*Checkdoc Help*"
829 (princ-list 825 (mapc #'princ
830 "Error message:\n " msg 826 (list "Error message:\n " msg
831 "\n\nEdit to fix this problem, and press C-M-c to continue.")) 827 "\n\nEdit to fix this problem, and press C-M-c to continue.")))
832 (shrink-window-if-larger-than-buffer 828 (shrink-window-if-larger-than-buffer
833 (get-buffer-window "*Checkdoc Help*")) 829 (get-buffer-window "*Checkdoc Help*"))
834 (message "When you're done editing press C-M-c to continue.") 830 (message "When you're done editing press C-M-c to continue.")
835 (unwind-protect 831 (unwind-protect
836 (recursive-edit) 832 (recursive-edit)
945 separate buffer. Otherwise print a message. This returns the error 941 separate buffer. Otherwise print a message. This returns the error
946 if there is one." 942 if there is one."
947 (interactive "P") 943 (interactive "P")
948 (if take-notes (checkdoc-start-section "checkdoc-comments")) 944 (if take-notes (checkdoc-start-section "checkdoc-comments"))
949 (if (not buffer-file-name) 945 (if (not buffer-file-name)
950 (error "Can only check comments for a file buffer")) 946 (error "Can only check comments for a file buffer"))
951 (let* ((checkdoc-spellcheck-documentation-flag 947 (let* ((checkdoc-spellcheck-documentation-flag
952 (car (memq checkdoc-spellcheck-documentation-flag 948 (car (memq checkdoc-spellcheck-documentation-flag
953 '(buffer t)))) 949 '(buffer t))))
954 (checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag)) 950 (checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag))
955 (e (checkdoc-file-comments-engine)) 951 (e (checkdoc-file-comments-engine))
956 (checkdoc-generate-compile-warnings-flag 952 (checkdoc-generate-compile-warnings-flag
957 (or take-notes checkdoc-generate-compile-warnings-flag))) 953 (or take-notes checkdoc-generate-compile-warnings-flag)))
958 (if e (error "%s" (checkdoc-error-text e))) 954 (if e (error "%s" (checkdoc-error-text e)))
959 (checkdoc-show-diagnostics) 955 (checkdoc-show-diagnostics)
960 e)) 956 e))
961 957
962 ;;;###autoload 958 ;;;###autoload
968 Optional argument INTERACT permits more interactive fixing." 964 Optional argument INTERACT permits more interactive fixing."
969 (interactive "P") 965 (interactive "P")
970 (if take-notes (checkdoc-start-section "checkdoc-rogue-spaces")) 966 (if take-notes (checkdoc-start-section "checkdoc-rogue-spaces"))
971 (let* ((checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag)) 967 (let* ((checkdoc-autofix-flag (if take-notes 'never checkdoc-autofix-flag))
972 (e (checkdoc-rogue-space-check-engine nil nil interact)) 968 (e (checkdoc-rogue-space-check-engine nil nil interact))
973 (checkdoc-generate-compile-warnings-flag 969 (checkdoc-generate-compile-warnings-flag
974 (or take-notes checkdoc-generate-compile-warnings-flag))) 970 (or take-notes checkdoc-generate-compile-warnings-flag)))
975 (if (not (called-interactively-p 'interactive)) 971 (if (not (called-interactively-p 'interactive))
976 e 972 e
977 (if e 973 (if e
978 (message "%s" (checkdoc-error-text e)) 974 (message "%s" (checkdoc-error-text e))
979 (checkdoc-show-diagnostics) 975 (checkdoc-show-diagnostics)
1208 "Keymap used to override evaluation key-bindings for documentation checking.") 1204 "Keymap used to override evaluation key-bindings for documentation checking.")
1209 1205
1210 ;; Add in a menubar with easy-menu 1206 ;; Add in a menubar with easy-menu
1211 1207
1212 (easy-menu-define 1208 (easy-menu-define
1213 nil checkdoc-minor-mode-map "Checkdoc Minor Mode Menu" 1209 nil checkdoc-minor-mode-map "Checkdoc Minor Mode Menu"
1214 '("CheckDoc" 1210 '("CheckDoc"
1215 ["Interactive Buffer Style Check" checkdoc t] 1211 ["Interactive Buffer Style Check" checkdoc t]
1216 ["Interactive Buffer Style and Spelling Check" checkdoc-ispell t] 1212 ["Interactive Buffer Style and Spelling Check" checkdoc-ispell t]
1217 ["Check Buffer" checkdoc-current-buffer t] 1213 ["Check Buffer" checkdoc-current-buffer t]
1218 ["Check and Spell Buffer" checkdoc-ispell-current-buffer t] 1214 ["Check and Spell Buffer" checkdoc-ispell-current-buffer t]
1219 "---" 1215 "---"
1220 ["Interactive Style Check" checkdoc-interactive t] 1216 ["Interactive Style Check" checkdoc-interactive t]
1221 ["Interactive Style and Spelling Check" checkdoc-ispell-interactive t] 1217 ["Interactive Style and Spelling Check" checkdoc-ispell-interactive t]
1222 ["Find First Style Error" checkdoc-start t] 1218 ["Find First Style Error" checkdoc-start t]
1223 ["Find First Style or Spelling Error" checkdoc-ispell-start t] 1219 ["Find First Style or Spelling Error" checkdoc-ispell-start t]
1224 ["Next Style Error" checkdoc-continue t] 1220 ["Next Style Error" checkdoc-continue t]
1225 ["Next Style or Spelling Error" checkdoc-ispell-continue t] 1221 ["Next Style or Spelling Error" checkdoc-ispell-continue t]
1226 ["Interactive Message Text Style Check" checkdoc-message-interactive t] 1222 ["Interactive Message Text Style Check" checkdoc-message-interactive t]
1227 ["Interactive Message Text Style and Spelling Check" 1223 ["Interactive Message Text Style and Spelling Check"
1228 checkdoc-ispell-message-interactive t] 1224 checkdoc-ispell-message-interactive t]
1229 ["Check Message Text" checkdoc-message-text t] 1225 ["Check Message Text" checkdoc-message-text t]
1230 ["Check and Spell Message Text" checkdoc-ispell-message-text t] 1226 ["Check and Spell Message Text" checkdoc-ispell-message-text t]
1231 ["Check Comment Style" checkdoc-comments buffer-file-name] 1227 ["Check Comment Style" checkdoc-comments buffer-file-name]
1232 ["Check Comment Style and Spelling" checkdoc-ispell-comments 1228 ["Check Comment Style and Spelling" checkdoc-ispell-comments
1233 buffer-file-name] 1229 buffer-file-name]
1234 ["Check for Rogue Spaces" checkdoc-rogue-spaces t] 1230 ["Check for Rogue Spaces" checkdoc-rogue-spaces t]
1235 "---" 1231 "---"
1236 ["Check Defun" checkdoc-defun t] 1232 ["Check Defun" checkdoc-defun t]
1237 ["Check and Spell Defun" checkdoc-ispell-defun t] 1233 ["Check and Spell Defun" checkdoc-ispell-defun t]
1238 ["Check and Evaluate Defun" checkdoc-eval-defun t] 1234 ["Check and Evaluate Defun" checkdoc-eval-defun t]
1239 ["Check and Evaluate Buffer" checkdoc-eval-current-buffer t] 1235 ["Check and Evaluate Buffer" checkdoc-eval-current-buffer t]
1240 )) 1236 ))
1241 ;; XEmacs requires some weird stuff to add this menu in a minor mode. 1237 ;; XEmacs requires some weird stuff to add this menu in a minor mode.
1242 ;; What is it? 1238 ;; What is it?
1243 1239
1244 ;;;###autoload 1240 ;;;###autoload
1245 (define-minor-mode checkdoc-minor-mode 1241 (define-minor-mode checkdoc-minor-mode
2655 (recenter 0))) 2651 (recenter 0)))
2656 (other-window -1) 2652 (other-window -1)
2657 (setq checkdoc-pending-errors nil) 2653 (setq checkdoc-pending-errors nil)
2658 nil))) 2654 nil)))
2659 2655
2660 (custom-add-option 'emacs-lisp-mode-hook 2656 (custom-add-option 'emacs-lisp-mode-hook 'checkdoc-minor-mode)
2661 (lambda () (checkdoc-minor-mode 1)))
2662 2657
2663 (add-to-list 'debug-ignored-errors 2658 (add-to-list 'debug-ignored-errors
2664 "Argument `.*' should appear (as .*) in the doc string") 2659 "Argument `.*' should appear (as .*) in the doc string")
2665 (add-to-list 'debug-ignored-errors 2660 (add-to-list 'debug-ignored-errors
2666 "Lisp symbol `.*' should appear in quotes") 2661 "Lisp symbol `.*' should appear in quotes")