Skip to content

Commit 809b01e

Browse files
authored
Merge pull request #816 from Matafou/fix-first-cmd
Fix problems with error on the first command of a file.
2 parents e0ec3db + 4cd61e2 commit 809b01e

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

ci/coq-tests.el

+41-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,47 @@ For example, COMMENT could be (*test-definition*)"
446446
(coq-test-goto-before "(*proof*)")
447447
(backward-char 3)
448448
(should (span-at (point) 'proofusing))))))
449-
449+
450+
451+
452+
(ert-deftest 110_coq-test-regression_error_on_fst_cmd ()
453+
"Test error highlghting in the first line."
454+
(coq-fixture-on-file
455+
(coq-test-full-path "test_error_loc_fst_cmd.v")
456+
(lambda ()
457+
(coq-test-goto-before " (*after-error*)")
458+
;; redefining this function locally so that self removing spans
459+
;; remain longer. Cf span.el
460+
(cl-letf (((symbol-function 'span-make-self-removing-span)
461+
(lambda (beg end &rest props)
462+
(let ((ol (span-make beg end)))
463+
(while props
464+
(overlay-put ol (car props) (cadr props))
465+
(setq props (cddr props)))
466+
(add-timeout 10 'delete-overlay ol)
467+
ol))))
468+
469+
(let ((proof-cmd-point (save-excursion
470+
(coq-test-goto-before "(*after-error*)")
471+
(re-search-backward "bar"))))
472+
(coq-test-goto-after " (*after-error*)")
473+
(proof-goto-point)
474+
(proof-shell-wait)
475+
(coq-should-buffer-string "Error: The reference bar was not found in the current environment.")
476+
;; checking that there is an overlay with warning face
477+
;; exactly on "bar". WARNING: this overlay lasts only for 12
478+
;; secs (thx to the add-timeout above), if this test is done
479+
;; in a (very) slow virtual machine this may fail.
480+
(should (equal (point) proof-cmd-point))
481+
(let ((sp (span-at proof-cmd-point 'face)))
482+
(should sp)
483+
(should (equal (span-property sp 'face) 'proof-warning-face))
484+
(should (equal (span-start sp) proof-cmd-point))
485+
;; coq-8.11 used to hace ending ps shifted by one
486+
(should (or (equal (span-end sp) (+ proof-cmd-point (length "bar")))
487+
(equal (span-end sp) (+ 1 proof-cmd-point (length "bar")))))
488+
)
489+
(should (equal (proof-queue-or-locked-end) (point-min))))))))
450490
(provide 'coq-tests)
451491

452492
;;; coq-tests.el ends here

ci/test_error_loc_fst_cmd.v

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Definition foo:= bar. (*after-error*)
2+
3+
Definition foobar := nat.
4+

coq/coq-indent.el

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ position."
208208
(while (coq-looking-at-comment) ;; we are looking for ". " so this is enough
209209
(re-search-backward (concat "\\(?2:" coq-simple-cmd-ender-prefix-regexp-backward "\\)\\.\\s-") (point-min) 'dummy))
210210
;; unless we reached point-min, jump over the "."
211-
(when (match-end 2) (goto-char (match-end 2)) (forward-char 1))
211+
(when (and (not (eq (point) (point-min))) (match-end 2))
212+
(goto-char (match-end 2)) (forward-char 1))
212213
(point))
213214

214215
(defun coq-find-start-of-cmd ()

0 commit comments

Comments
 (0)