diff options
| author | João Távora | 2017-11-11 23:44:52 +0000 |
|---|---|---|
| committer | João Távora | 2017-11-11 23:44:52 +0000 |
| commit | e286b3381fa1be64174832560da963b1c0191640 (patch) | |
| tree | 868f64028e662664e8d47d21027213f812f20d68 | |
| parent | 9533d76b0b5bfe2df1cccc55a92c2545b1de4e2b (diff) | |
| download | emacs-e286b3381fa1be64174832560da963b1c0191640.tar.gz emacs-e286b3381fa1be64174832560da963b1c0191640.zip | |
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.
| -rw-r--r-- | lisp/progmodes/flymake.el | 16 | ||||
| -rw-r--r-- | test/lisp/progmodes/flymake-tests.el | 32 |
2 files changed, 42 insertions, 6 deletions
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index b4ab7f223f2..241ea00d645 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el | |||
| @@ -318,7 +318,11 @@ region is invalid." | |||
| 318 | (goto-char (point-min)) | 318 | (goto-char (point-min)) |
| 319 | (forward-line (1- line)) | 319 | (forward-line (1- line)) |
| 320 | (cl-flet ((fallback-bol | 320 | (cl-flet ((fallback-bol |
| 321 | () (progn (back-to-indentation) (point))) | 321 | () |
| 322 | (back-to-indentation) | ||
| 323 | (if (eobp) | ||
| 324 | (line-beginning-position 0) | ||
| 325 | (point))) | ||
| 322 | (fallback-eol | 326 | (fallback-eol |
| 323 | (beg) | 327 | (beg) |
| 324 | (progn | 328 | (progn |
| @@ -335,11 +339,11 @@ region is invalid." | |||
| 335 | (not (= sexp-end beg)) | 339 | (not (= sexp-end beg)) |
| 336 | sexp-end) | 340 | sexp-end) |
| 337 | (and (< (goto-char (1+ beg)) (point-max)) | 341 | (and (< (goto-char (1+ beg)) (point-max)) |
| 338 | (point)))) | 342 | (point))))) |
| 339 | (safe-end (or end | 343 | (if end |
| 340 | (fallback-eol beg)))) | 344 | (cons beg end) |
| 341 | (cons (if end beg (fallback-bol)) | 345 | (cons (setq beg (fallback-bol)) |
| 342 | safe-end)) | 346 | (fallback-eol beg)))) |
| 343 | (let* ((beg (fallback-bol)) | 347 | (let* ((beg (fallback-bol)) |
| 344 | (end (fallback-eol beg))) | 348 | (end (fallback-eol beg))) |
| 345 | (cons beg end))))))) | 349 | (cons beg end))))))) |
diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el index 05214e7a927..bc194b69ccb 100644 --- a/test/lisp/progmodes/flymake-tests.el +++ b/test/lisp/progmodes/flymake-tests.el | |||
| @@ -333,6 +333,38 @@ SEVERITY-PREDICATE is used to setup | |||
| 333 | (should-error (flymake-goto-prev-error nil nil t)) | 333 | (should-error (flymake-goto-prev-error nil nil t)) |
| 334 | ))))) | 334 | ))))) |
| 335 | 335 | ||
| 336 | (ert-deftest eob-region-and-trailing-newline () | ||
| 337 | "`flymake-diag-region' at eob with varying trailing newlines." | ||
| 338 | (cl-flet ((diag-region-substring | ||
| 339 | (line col) | ||
| 340 | (pcase-let | ||
| 341 | ((`(,a . ,b) (flymake-diag-region (current-buffer) line col))) | ||
| 342 | (buffer-substring a b)))) | ||
| 343 | (with-temp-buffer | ||
| 344 | (insert "beg\nmmm\nend") | ||
| 345 | (should (equal | ||
| 346 | (diag-region-substring 3 3) | ||
| 347 | "d")) | ||
| 348 | (should (equal | ||
| 349 | (diag-region-substring 3 nil) | ||
| 350 | "end")) | ||
| 351 | (insert "\n") | ||
| 352 | (should (equal | ||
| 353 | (diag-region-substring 4 1) | ||
| 354 | "end")) | ||
| 355 | (should (equal | ||
| 356 | (diag-region-substring 4 nil) | ||
| 357 | "end")) | ||
| 358 | (insert "\n") | ||
| 359 | (should (equal | ||
| 360 | (diag-region-substring 5 1) | ||
| 361 | "\n")) | ||
| 362 | (should (equal | ||
| 363 | (diag-region-substring 5 nil) | ||
| 364 | "\n"))))) | ||
| 365 | |||
| 366 | |||
| 367 | |||
| 336 | (provide 'flymake-tests) | 368 | (provide 'flymake-tests) |
| 337 | 369 | ||
| 338 | ;;; flymake.el ends here | 370 | ;;; flymake.el ends here |