Fix more flymake-diag-region eob corner cases and add tests (bug#29201)
* lisp/progmodes/flymake.el (flymake-diag-region): Correct more eob corner cases. * test/lisp/progmodes/flymake-tests.el (eob-region-and-trailing-newline): New test.
This commit is contained in:
parent
9533d76b0b
commit
e286b3381f
2 changed files with 42 additions and 6 deletions
|
@ -318,7 +318,11 @@ region is invalid."
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(forward-line (1- line))
|
(forward-line (1- line))
|
||||||
(cl-flet ((fallback-bol
|
(cl-flet ((fallback-bol
|
||||||
() (progn (back-to-indentation) (point)))
|
()
|
||||||
|
(back-to-indentation)
|
||||||
|
(if (eobp)
|
||||||
|
(line-beginning-position 0)
|
||||||
|
(point)))
|
||||||
(fallback-eol
|
(fallback-eol
|
||||||
(beg)
|
(beg)
|
||||||
(progn
|
(progn
|
||||||
|
@ -335,11 +339,11 @@ region is invalid."
|
||||||
(not (= sexp-end beg))
|
(not (= sexp-end beg))
|
||||||
sexp-end)
|
sexp-end)
|
||||||
(and (< (goto-char (1+ beg)) (point-max))
|
(and (< (goto-char (1+ beg)) (point-max))
|
||||||
(point))))
|
(point)))))
|
||||||
(safe-end (or end
|
(if end
|
||||||
|
(cons beg end)
|
||||||
|
(cons (setq beg (fallback-bol))
|
||||||
(fallback-eol beg))))
|
(fallback-eol beg))))
|
||||||
(cons (if end beg (fallback-bol))
|
|
||||||
safe-end))
|
|
||||||
(let* ((beg (fallback-bol))
|
(let* ((beg (fallback-bol))
|
||||||
(end (fallback-eol beg)))
|
(end (fallback-eol beg)))
|
||||||
(cons beg end)))))))
|
(cons beg end)))))))
|
||||||
|
|
|
@ -333,6 +333,38 @@ SEVERITY-PREDICATE is used to setup
|
||||||
(should-error (flymake-goto-prev-error nil nil t))
|
(should-error (flymake-goto-prev-error nil nil t))
|
||||||
)))))
|
)))))
|
||||||
|
|
||||||
|
(ert-deftest eob-region-and-trailing-newline ()
|
||||||
|
"`flymake-diag-region' at eob with varying trailing newlines."
|
||||||
|
(cl-flet ((diag-region-substring
|
||||||
|
(line col)
|
||||||
|
(pcase-let
|
||||||
|
((`(,a . ,b) (flymake-diag-region (current-buffer) line col)))
|
||||||
|
(buffer-substring a b))))
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert "beg\nmmm\nend")
|
||||||
|
(should (equal
|
||||||
|
(diag-region-substring 3 3)
|
||||||
|
"d"))
|
||||||
|
(should (equal
|
||||||
|
(diag-region-substring 3 nil)
|
||||||
|
"end"))
|
||||||
|
(insert "\n")
|
||||||
|
(should (equal
|
||||||
|
(diag-region-substring 4 1)
|
||||||
|
"end"))
|
||||||
|
(should (equal
|
||||||
|
(diag-region-substring 4 nil)
|
||||||
|
"end"))
|
||||||
|
(insert "\n")
|
||||||
|
(should (equal
|
||||||
|
(diag-region-substring 5 1)
|
||||||
|
"\n"))
|
||||||
|
(should (equal
|
||||||
|
(diag-region-substring 5 nil)
|
||||||
|
"\n")))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'flymake-tests)
|
(provide 'flymake-tests)
|
||||||
|
|
||||||
;;; flymake.el ends here
|
;;; flymake.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue