comparison lisp/emacs-lisp/checkdoc.el @ 111554:ebfca53e3979

* lisp/emacs-lisp/checkdoc.el (checkdoc-syntax-table): Fix last change. (checkdoc-sentencespace-region-engine, checkdoc-this-string-valid) (checkdoc-proper-noun-region-engine): Use with-syntax-table.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 15 Nov 2010 16:40:30 -0500
parents 72390b0b6207
children 417b1e4d63cd
comparison
equal deleted inserted replaced
111553:4b7ddc13005a 111554:ebfca53e3979
432 (defvar checkdoc-syntax-table 432 (defvar checkdoc-syntax-table
433 (let ((st (make-syntax-table emacs-lisp-mode-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 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, 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. 436 ;; not the end of a word in a conglomerate.
437 (modify-syntax-entry ?- "w" checkdoc-syntax-table) 437 (modify-syntax-entry ?- "w" st)
438 st) 438 st)
439 "Syntax table used by checkdoc in document strings.") 439 "Syntax table used by checkdoc in document strings.")
440 440
441 ;;; Compatibility 441 ;;; Compatibility
442 ;; 442 ;;
1368 "All interactive functions should have documentation" 1368 "All interactive functions should have documentation"
1369 "All variables and subroutines might as well have a \ 1369 "All variables and subroutines might as well have a \
1370 documentation string") 1370 documentation string")
1371 (point) (+ (point) 1) t))))) 1371 (point) (+ (point) 1) t)))))
1372 (if (and (not err) (looking-at "\"")) 1372 (if (and (not err) (looking-at "\""))
1373 (let ((old-syntax-table (syntax-table))) 1373 (with-syntax-table checkdoc-syntax-table
1374 (unwind-protect 1374 (checkdoc-this-string-valid-engine fp))
1375 (progn
1376 (set-syntax-table checkdoc-syntax-table)
1377 (checkdoc-this-string-valid-engine fp))
1378 (set-syntax-table old-syntax-table)))
1379 err))) 1375 err)))
1380 1376
1381 (defun checkdoc-this-string-valid-engine (fp) 1377 (defun checkdoc-this-string-valid-engine (fp)
1382 "Return an error list or string if the current doc string is invalid. 1378 "Return an error list or string if the current doc string is invalid.
1383 Depends on `checkdoc-this-string-valid' to reset the syntax table so that 1379 Depends on `checkdoc-this-string-valid' to reset the syntax table so that
1985 consistency. Return an error list if any are not fixed, but 1981 consistency. Return an error list if any are not fixed, but
1986 internally skip over no answers. 1982 internally skip over no answers.
1987 If the offending word is in a piece of quoted text, then it is skipped." 1983 If the offending word is in a piece of quoted text, then it is skipped."
1988 (save-excursion 1984 (save-excursion
1989 (let ((case-fold-search nil) 1985 (let ((case-fold-search nil)
1990 (errtxt nil) bb be 1986 (errtxt nil) bb be)
1991 (old-syntax-table (syntax-table))) 1987 (with-syntax-table checkdoc-syntax-table
1992 (unwind-protect 1988 (goto-char begin)
1993 (progn 1989 (while (re-search-forward checkdoc-proper-noun-regexp end t)
1994 (set-syntax-table checkdoc-syntax-table) 1990 (let ((text (match-string 1))
1995 (goto-char begin) 1991 (b (match-beginning 1))
1996 (while (re-search-forward checkdoc-proper-noun-regexp end t) 1992 (e (match-end 1)))
1997 (let ((text (match-string 1)) 1993 (if (and (not (save-excursion
1998 (b (match-beginning 1)) 1994 (goto-char b)
1999 (e (match-end 1))) 1995 (forward-char -1)
2000 (if (and (not (save-excursion 1996 (looking-at "`\\|\"\\|\\.\\|\\\\")))
2001 (goto-char b) 1997 ;; surrounded by /, as in a URL or filename: /emacs/
2002 (forward-char -1) 1998 (not (and (= ?/ (char-after e))
2003 (looking-at "`\\|\"\\|\\.\\|\\\\"))) 1999 (= ?/ (char-before b))))
2004 ;; surrounded by /, as in a URL or filename: /emacs/ 2000 (not (checkdoc-in-example-string-p begin end))
2005 (not (and (= ?/ (char-after e)) 2001 ;; info or url links left alone
2006 (= ?/ (char-before b)))) 2002 (not (thing-at-point-looking-at
2007 (not (checkdoc-in-example-string-p begin end)) 2003 help-xref-info-regexp))
2008 ;; info or url links left alone 2004 (not (thing-at-point-looking-at
2009 (not (thing-at-point-looking-at 2005 help-xref-url-regexp)))
2010 help-xref-info-regexp)) 2006 (if (checkdoc-autofix-ask-replace
2011 (not (thing-at-point-looking-at 2007 b e (format "Text %s should be capitalized. Fix? "
2012 help-xref-url-regexp))) 2008 text)
2013 (if (checkdoc-autofix-ask-replace 2009 (capitalize text) t)
2014 b e (format "Text %s should be capitalized. Fix? " 2010 nil
2015 text) 2011 (if errtxt
2016 (capitalize text) t) 2012 ;; If there is already an error, then generate
2017 nil 2013 ;; the warning output if applicable
2018 (if errtxt 2014 (if checkdoc-generate-compile-warnings-flag
2019 ;; If there is already an error, then generate 2015 (checkdoc-create-error
2020 ;; the warning output if applicable 2016 (format
2021 (if checkdoc-generate-compile-warnings-flag 2017 "Name %s should appear capitalized as %s"
2022 (checkdoc-create-error 2018 text (capitalize text))
2023 (format 2019 b e))
2024 "Name %s should appear capitalized as %s" 2020 (setq errtxt
2025 text (capitalize text)) 2021 (format
2026 b e)) 2022 "Name %s should appear capitalized as %s"
2027 (setq errtxt 2023 text (capitalize text))
2028 (format 2024 bb b be e)))))))
2029 "Name %s should appear capitalized as %s"
2030 text (capitalize text))
2031 bb b be e)))))))
2032 (set-syntax-table old-syntax-table))
2033 (if errtxt (checkdoc-create-error errtxt bb be))))) 2025 (if errtxt (checkdoc-create-error errtxt bb be)))))
2034 2026
2035 (defun checkdoc-sentencespace-region-engine (begin end) 2027 (defun checkdoc-sentencespace-region-engine (begin end)
2036 "Make sure all sentences have double spaces between BEGIN and END." 2028 "Make sure all sentences have double spaces between BEGIN and END."
2037 (if sentence-end-double-space 2029 (if sentence-end-double-space
2038 (save-excursion 2030 (save-excursion
2039 (let ((case-fold-search nil) 2031 (let ((case-fold-search nil)
2040 (errtxt nil) bb be 2032 (errtxt nil) bb be)
2041 (old-syntax-table (syntax-table))) 2033 (with-syntax-table checkdoc-syntax-table
2042 (unwind-protect 2034 (goto-char begin)
2043 (progn 2035 (while (re-search-forward "[^ .0-9]\\(\\. \\)[^ \n]" end t)
2044 (set-syntax-table checkdoc-syntax-table) 2036 (let ((b (match-beginning 1))
2045 (goto-char begin) 2037 (e (match-end 1)))
2046 (while (re-search-forward "[^ .0-9]\\(\\. \\)[^ \n]" end t) 2038 (unless (or (checkdoc-in-sample-code-p begin end)
2047 (let ((b (match-beginning 1)) 2039 (checkdoc-in-example-string-p begin end)
2048 (e (match-end 1))) 2040 (save-excursion
2049 (unless (or (checkdoc-in-sample-code-p begin end) 2041 (goto-char b)
2050 (checkdoc-in-example-string-p begin end) 2042 (condition-case nil
2051 (save-excursion 2043 (progn
2052 (goto-char b) 2044 (forward-sexp -1)
2053 (condition-case nil 2045 ;; piece of an abbreviation
2054 (progn 2046 ;; FIXME etc
2055 (forward-sexp -1) 2047 (looking-at
2056 ;; piece of an abbreviation 2048 "\\([a-z]\\|[iI]\\.?e\\|[eE]\\.?g\\)\\."))
2057 ;; FIXME etc 2049 (error t))))
2058 (looking-at 2050 (if (checkdoc-autofix-ask-replace
2059 "\\([a-z]\\|[iI]\\.?e\\|[eE]\\.?g\\)\\.")) 2051 b e
2060 (error t)))) 2052 "There should be two spaces after a period. Fix? "
2061 (if (checkdoc-autofix-ask-replace 2053 ". ")
2062 b e 2054 nil
2063 "There should be two spaces after a period. Fix? " 2055 (if errtxt
2064 ". ") 2056 ;; If there is already an error, then generate
2065 nil 2057 ;; the warning output if applicable
2066 (if errtxt 2058 (if checkdoc-generate-compile-warnings-flag
2067 ;; If there is already an error, then generate 2059 (checkdoc-create-error
2068 ;; the warning output if applicable 2060 "There should be two spaces after a period"
2069 (if checkdoc-generate-compile-warnings-flag 2061 b e))
2070 (checkdoc-create-error 2062 (setq errtxt
2071 "There should be two spaces after a period" 2063 "There should be two spaces after a period"
2072 b e)) 2064 bb b be e)))))))
2073 (setq errtxt
2074 "There should be two spaces after a period"
2075 bb b be e)))))))
2076 (set-syntax-table old-syntax-table))
2077 (if errtxt (checkdoc-create-error errtxt bb be)))))) 2065 (if errtxt (checkdoc-create-error errtxt bb be))))))
2078 2066
2079 ;;; Ispell engine 2067 ;;; Ispell engine
2080 ;; 2068 ;;
2081 (eval-when-compile (require 'ispell)) 2069 (eval-when-compile (require 'ispell))