comparison lisp/emacs-lisp/checkdoc.el @ 50330:e3d87b72b575

(checkdoc-display-status-buffer): Fix docstring. (checkdoc-interactive, checkdoc-message-interactive): Make them perform spell checking when appropriate. (checkdoc-interactive-loop): Fix docstring and a few typos. (checkdoc-interactive-ispell-loop) (checkdoc-message-interactive-ispell-loop): New functions. (checkdoc-next-error): Fix docstring. (checkdoc-this-string-valid-engine): Fix typo. (checkdoc-ispell-docstring-engine): Do test for checkdoc-autofix-flag = nil.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 28 Mar 2003 17:38:50 +0000
parents 45cd70f39238
children 46ef9a326558
comparison
equal deleted inserted replaced
50329:e5ff1f539de2 50330:e3d87b72b575
507 (setcar (cdr (cdr (cdr status))) "Ok")) 507 (setcar (cdr (cdr (cdr status))) "Ok"))
508 (checkdoc-display-status-buffer status))) 508 (checkdoc-display-status-buffer status)))
509 509
510 (defun checkdoc-display-status-buffer (check) 510 (defun checkdoc-display-status-buffer (check)
511 "Display and update the status buffer for the current checkdoc mode. 511 "Display and update the status buffer for the current checkdoc mode.
512 CHECK is a vector stating the current status of each test as an 512 CHECK is a list of four strings stating the current status of each
513 element is the status of that level of test." 513 test; the nth string describes the status of the nth test."
514 (let (temp-buffer-setup-hook) 514 (let (temp-buffer-setup-hook)
515 (with-output-to-temp-buffer " *Checkdoc Status*" 515 (with-output-to-temp-buffer " *Checkdoc Status*"
516 (princ-list 516 (princ-list
517 "Buffer comments and tags: " (nth 0 check) "\n" 517 "Buffer comments and tags: " (nth 0 check) "\n"
518 "Documentation style: " (nth 1 check) "\n" 518 "Documentation style: " (nth 1 check) "\n"
535 checkdoc status window instead of the usual behavior." 535 checkdoc status window instead of the usual behavior."
536 (interactive "P") 536 (interactive "P")
537 (let ((checkdoc-spellcheck-documentation-flag 537 (let ((checkdoc-spellcheck-documentation-flag
538 (car (memq checkdoc-spellcheck-documentation-flag 538 (car (memq checkdoc-spellcheck-documentation-flag
539 '(interactive t))))) 539 '(interactive t)))))
540 (checkdoc-interactive-loop start-here showstatus 'checkdoc-next-error))) 540 (prog1
541 ;; Due to a design flaw, this will never spell check
542 ;; docstrings.
543 (checkdoc-interactive-loop start-here showstatus
544 'checkdoc-next-error)
545 ;; This is a workaround to perform spell checking.
546 (checkdoc-interactive-ispell-loop start-here))))
541 547
542 ;;;###autoload 548 ;;;###autoload
543 (defun checkdoc-message-interactive (&optional start-here showstatus) 549 (defun checkdoc-message-interactive (&optional start-here showstatus)
544 "Interactively check the current buffer for message string errors. 550 "Interactively check the current buffer for message string errors.
545 Prefix argument START-HERE will start the checking from the current 551 Prefix argument START-HERE will start the checking from the current
550 checkdoc status window instead of the usual behavior." 556 checkdoc status window instead of the usual behavior."
551 (interactive "P") 557 (interactive "P")
552 (let ((checkdoc-spellcheck-documentation-flag 558 (let ((checkdoc-spellcheck-documentation-flag
553 (car (memq checkdoc-spellcheck-documentation-flag 559 (car (memq checkdoc-spellcheck-documentation-flag
554 '(interactive t))))) 560 '(interactive t)))))
555 (checkdoc-interactive-loop start-here showstatus 561 (prog1
556 'checkdoc-next-message-error))) 562 ;; Due to a design flaw, this will never spell check messages.
563 (checkdoc-interactive-loop start-here showstatus
564 'checkdoc-next-message-error)
565 ;; This is a workaround to perform spell checking.
566 (checkdoc-message-interactive-ispell-loop start-here))))
557 567
558 (defun checkdoc-interactive-loop (start-here showstatus findfunc) 568 (defun checkdoc-interactive-loop (start-here showstatus findfunc)
559 "Interactively loop over all errors that can be found by a given method. 569 "Interactively loop over all errors that can be found by a given method.
560 Searching starts at START-HERE. SHOWSTATUS expresses the verbosity 570
561 of the search, and whether ending the search will auto-exit this function. 571 If START-HERE is nil, searching starts at the beginning of the current
572 buffer, otherwise searching starts at START-HERE. SHOWSTATUS
573 expresses the verbosity of the search, and whether ending the search
574 will auto-exit this function.
575
562 FINDFUNC is a symbol representing a function that will position the 576 FINDFUNC is a symbol representing a function that will position the
563 cursor, and return error message text to present to the user. It is 577 cursor, and return error message text to present to the user. It is
564 assumed that the cursor will stop just before a major sexp, which will 578 assumed that the cursor will stop just before a major sexp, which will
565 be highlighted to present the user with feedback as to the offending 579 be highlighted to present the user with feedback as to the offending
566 style." 580 style."
612 "" "f,")) 626 "" "f,"))
613 (save-excursion 627 (save-excursion
614 (goto-char (checkdoc-error-start (car (car err-list)))) 628 (goto-char (checkdoc-error-start (car (car err-list))))
615 (if (not (pos-visible-in-window-p)) 629 (if (not (pos-visible-in-window-p))
616 (recenter (- (window-height) 2))) 630 (recenter (- (window-height) 2)))
617 (setq c (checkdoc-read-event)))1 631 (setq c (checkdoc-read-event)))
618 (if (not (integerp c)) (setq c ??)) 632 (if (not (integerp c)) (setq c ??))
619 (cond 633 (cond
620 ;; Exit condition 634 ;; Exit condition
621 ((checkdoc-char= c ?\C-g) (signal 'quit nil)) 635 ((checkdoc-char= c ?\C-g) (signal 'quit nil))
622 ;; Request an auto-fix 636 ;; Request an auto-fix
624 (checkdoc-delete-overlay cdo) 638 (checkdoc-delete-overlay cdo)
625 (setq cdo nil) 639 (setq cdo nil)
626 (goto-char (cdr (car err-list))) 640 (goto-char (cdr (car err-list)))
627 ;; `automatic-then-never' tells the autofix function 641 ;; `automatic-then-never' tells the autofix function
628 ;; to only allow one fix to be automatic. The autofix 642 ;; to only allow one fix to be automatic. The autofix
629 ;; function will than set the flag to 'never, allowing 643 ;; function will then set the flag to 'never, allowing
630 ;; the checker to return a different error. 644 ;; the checker to return a different error.
631 (let ((checkdoc-autofix-flag 'automatic-then-never) 645 (let ((checkdoc-autofix-flag 'automatic-then-never)
632 (fixed nil)) 646 (fixed nil))
633 (funcall findfunc t) 647 (funcall findfunc t)
634 (setq fixed (not (eq checkdoc-autofix-flag 648 (setq fixed (not (eq checkdoc-autofix-flag
689 ;; Quit checkdoc 703 ;; Quit checkdoc
690 ((checkdoc-char= c ?q) 704 ((checkdoc-char= c ?q)
691 (setq returnme err-list 705 (setq returnme err-list
692 err-list nil 706 err-list nil
693 begin (point))) 707 begin (point)))
694 ;; Goofy s tuff 708 ;; Goofy stuff
695 (t 709 (t
696 (if (get-buffer-window "*Checkdoc Help*") 710 (if (get-buffer-window "*Checkdoc Help*")
697 (progn 711 (progn
698 (delete-window (get-buffer-window "*Checkdoc Help*")) 712 (delete-window (get-buffer-window "*Checkdoc Help*"))
699 (kill-buffer "*Checkdoc Help*")) 713 (kill-buffer "*Checkdoc Help*"))
718 (goto-char begin) 732 (goto-char begin)
719 (if (get-buffer "*Checkdoc Help*") (kill-buffer "*Checkdoc Help*")) 733 (if (get-buffer "*Checkdoc Help*") (kill-buffer "*Checkdoc Help*"))
720 (message "Checkdoc: Done.") 734 (message "Checkdoc: Done.")
721 returnme)) 735 returnme))
722 736
737 (defun checkdoc-interactive-ispell-loop (start-here)
738 "Interactively spell check doc strings in the current buffer.
739 If START-HERE is nil, searching starts at the beginning of the current
740 buffer, otherwise searching starts at START-HERE."
741 (when checkdoc-spellcheck-documentation-flag
742 (save-excursion
743 ;; Move point to where we need to start.
744 (if start-here
745 ;; Include whatever function point is in for good measure.
746 (beginning-of-defun)
747 (goto-char (point-min)))
748 ;; Loop over docstrings.
749 (while (checkdoc-next-docstring)
750 (message "Searching for doc string spell error...%d%%"
751 (/ (* 100 (point)) (point-max)))
752 (if (looking-at "\"")
753 (checkdoc-ispell-docstring-engine
754 (save-excursion (forward-sexp 1) (point-marker)))))
755 (message "Checkdoc: Done."))))
756
757 (defun checkdoc-message-interactive-ispell-loop (start-here)
758 "Interactively spell check messages in the current buffer.
759 If START-HERE is nil, searching starts at the beginning of the current
760 buffer, otherwise searching starts at START-HERE."
761 (when checkdoc-spellcheck-documentation-flag
762 (save-excursion
763 ;; Move point to where we need to start.
764 (if start-here
765 ;; Include whatever function point is in for good measure.
766 (beginning-of-defun)
767 (goto-char (point-min)))
768 ;; Loop over message strings.
769 (while (checkdoc-message-text-next-string (point-max))
770 (message "Searching for message string spell error...%d%%"
771 (/ (* 100 (point)) (point-max)))
772 (if (looking-at "\"")
773 (checkdoc-ispell-docstring-engine
774 (save-excursion (forward-sexp 1) (point-marker)))))
775 (message "Checkdoc: Done."))))
776
777
723 (defun checkdoc-next-error (enable-fix) 778 (defun checkdoc-next-error (enable-fix)
724 "Find and return the next checkdoc error list, or nil. 779 "Find and return the next checkdoc error list, or nil.
725 Only documentation strings are checked. 780 Only documentation strings are checked.
726 Add error vector is of the form (WARNING . POSITION) where WARNING 781 An error list is of the form (WARNING . POSITION) where WARNING is the
727 is the warning text, and POSITION is the point in the buffer where the 782 warning text, and POSITION is the point in the buffer where the error
728 error was found. We can use points and not markers because we promise 783 was found. We can use points and not markers because we promise not
729 not to edit the buffer before point without re-executing this check. 784 to edit the buffer before point without re-executing this check.
730 Argument ENABLE-FIX will enable auto-fixing while looking for the next 785 Argument ENABLE-FIX will enable auto-fixing while looking for the next
731 error. This argument assumes that the cursor is already positioned to 786 error. This argument assumes that the cursor is already positioned to
732 perform the fix." 787 perform the fix."
733 (if enable-fix 788 (if enable-fix
734 (checkdoc-this-string-valid) 789 (checkdoc-this-string-valid)
1705 ;; 1760 ;;
1706 ;; This is the least important of the above tests. Make sure 1761 ;; This is the least important of the above tests. Make sure
1707 ;; it occurs last. 1762 ;; it occurs last.
1708 (and checkdoc-verb-check-experimental-flag 1763 (and checkdoc-verb-check-experimental-flag
1709 (save-excursion 1764 (save-excursion
1710 ;; Maybe rebuild the monster-regex 1765 ;; Maybe rebuild the monster-regexp
1711 (checkdoc-create-common-verbs-regexp) 1766 (checkdoc-create-common-verbs-regexp)
1712 (let ((lim (save-excursion 1767 (let ((lim (save-excursion
1713 (end-of-line) 1768 (end-of-line)
1714 ;; check string-continuation 1769 ;; check string-continuation
1715 (if (checkdoc-char= (preceding-char) ?\\) 1770 (if (checkdoc-char= (preceding-char) ?\\)
2053 Since Ispell isn't Lisp-smart, we must pre-process the doc string 2108 Since Ispell isn't Lisp-smart, we must pre-process the doc string
2054 before using the Ispell engine on it." 2109 before using the Ispell engine on it."
2055 (if (or (not checkdoc-spellcheck-documentation-flag) 2110 (if (or (not checkdoc-spellcheck-documentation-flag)
2056 ;; If the user wants no questions or fixing, then we must 2111 ;; If the user wants no questions or fixing, then we must
2057 ;; disable spell checking as not useful. 2112 ;; disable spell checking as not useful.
2058 ;; FIXME: Somehow, `checkdoc-autofix-flag' is always nil 2113 (not checkdoc-autofix-flag)
2059 ;; when `checkdoc-ispell-docstring-engine' is called to be
2060 ;; used on a docstring. As a workround, I commented out the
2061 ;; next line.
2062 ;; (not checkdoc-autofix-flag)
2063 (eq checkdoc-autofix-flag 'never)) 2114 (eq checkdoc-autofix-flag 'never))
2064 nil 2115 nil
2065 (checkdoc-ispell-init) 2116 (checkdoc-ispell-init)
2066 (save-excursion 2117 (save-excursion
2067 (skip-chars-forward "^a-zA-Z") 2118 (skip-chars-forward "^a-zA-Z")