diff options
author | Stefan Kangas <stefan@marxist.se> | 2021-09-23 21:10:08 +0200 |
---|---|---|
committer | Stefan Kangas <stefan@marxist.se> | 2021-09-23 22:35:40 +0200 |
commit | 55083d90a30628d9eaa5b94196291ca15098aed0 (patch) | |
tree | 1bab2243c4edf1201c142f8c5bda07be61618571 /lisp/emacs-lisp | |
parent | 387af85c4d51dd98267f296bc91cf22d7ecc5374 (diff) | |
download | emacs-55083d90a30628d9eaa5b94196291ca15098aed0.tar.gz emacs-55083d90a30628d9eaa5b94196291ca15098aed0.tar.bz2 emacs-55083d90a30628d9eaa5b94196291ca15098aed0.zip |
Avoid jumping too far in checkdoc-in-abbreviation-p
* lisp/emacs-lisp/checkdoc.el (checkdoc-in-abbreviation-p): Use
'forward-ward' instead of 'forward-sexp' to avoid jumping too far in
some situations. (Bug#50731)
* test/lisp/emacs-lisp/checkdoc-tests.el
(checkdoc-tests--abbrev-test): New helper function.
(checkdoc-tests-in-abbrevation-p/basic-case): Rename from
'checkdoc-tests-in-abbrevation-p'.
(checkdoc-tests-in-abbrevation-p/with-parens)
(checkdoc-tests-in-abbrevation-p/with-escaped-parens): Use above new
helper function.
(checkdoc-tests-in-abbrevation-p/single-char)
(checkdoc-tests-in-abbrevation-p/with-em-dash)
(checkdoc-tests-in-abbrevation-p/incorrect-abbreviation): New tests.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/checkdoc.el | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el index 5224a943ac0..4243e828001 100644 --- a/lisp/emacs-lisp/checkdoc.el +++ b/lisp/emacs-lisp/checkdoc.el @@ -2097,27 +2097,31 @@ Examples of abbreviations handled: \"e.g.\", \"i.e.\", \"cf.\"." (save-excursion (goto-char begin) (condition-case nil - (progn - (forward-sexp -1) + (let ((single-letter t)) + (forward-word -1) + ;; Skip over all dots backwards, as `forward-word' will only + ;; go one dot at a time in a string like "e.g.". + (while (save-excursion (forward-char -1) + (looking-at (rx "."))) + (setq single-letter nil) + (forward-word -1)) ;; Piece of an abbreviation. (looking-at - (rx (or letter ; single letter, as in "a." - (seq - ;; There might exist an escaped parenthesis, as - ;; this is often used in docstrings. In this - ;; case, `forward-sexp' will have skipped over it, - ;; so we need to skip it here too. - (? "\\(") - ;; The abbreviations: - (or (seq (any "cC") "f") ; cf. - (seq (any "eE") ".g") ; e.g. - (seq (any "iI") "." (any "eE")))) ; i.e. - "etc" ; etc. - "vs" ; vs. - ;; Some non-standard or less common ones that we - ;; might as well ignore. - "Inc" "Univ" "misc" "resp") - "."))) + (if single-letter + ;; Handle a single letter, as in "a.", as this might be + ;; a part of a list. + (rx letter ".") + (rx (or + ;; The abbreviations: + (seq (or (seq (any "cC") "f") ; cf. + (seq (any "eE") ".g") ; e.g. + (seq (any "iI") "." (any "eE")))) ; i.e. + "etc" ; etc. + "vs" ; vs. + ;; Some non-standard or less common ones that we + ;; might as well ignore. + "Inc" "Univ" "misc" "resp") + ".")))) (error t)))) (defun checkdoc-proper-noun-region-engine (begin end) |