Commit e286b338 authored by João Távora's avatar João Távora

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.
parent 9533d76b
......@@ -318,7 +318,11 @@ region is invalid."
(goto-char (point-min))
(forward-line (1- line))
(cl-flet ((fallback-bol
() (progn (back-to-indentation) (point)))
(if (eobp)
(line-beginning-position 0)
......@@ -335,11 +339,11 @@ region is invalid."
(not (= sexp-end beg))
(and (< (goto-char (1+ beg)) (point-max))
(safe-end (or end
(fallback-eol beg))))
(cons (if end beg (fallback-bol))
(if end
(cons beg end)
(cons (setq beg (fallback-bol))
(fallback-eol beg))))
(let* ((beg (fallback-bol))
(end (fallback-eol beg)))
(cons beg end)))))))
......@@ -333,6 +333,38 @@ SEVERITY-PREDICATE is used to setup
(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)
((`(,a . ,b) (flymake-diag-region (current-buffer) line col)))
(buffer-substring a b))))
(insert "beg\nmmm\nend")
(should (equal
(diag-region-substring 3 3)
(should (equal
(diag-region-substring 3 nil)
(insert "\n")
(should (equal
(diag-region-substring 4 1)
(should (equal
(diag-region-substring 4 nil)
(insert "\n")
(should (equal
(diag-region-substring 5 1)
(should (equal
(diag-region-substring 5 nil)
(provide 'flymake-tests)
;;; flymake.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment