Skip to content

Commit 0b42f93

Browse files
committed
coq: fix goals update after error
This commit fixes two more cases of ProofGeneral#568: The goals buffer is updated in case of an error if Coq is inside a proof. Care is taken to keep the error message in the response buffer and to show the response buffer in two-pane mode. The fix works by issuing a Show command as a priority action item from proof-shell-handle-error-or-interrupt-hook, which runs at the end of the error processing. The new action item flag 'keep-response tells the generic machinery to not clear the response buffer and to keep it in two-pane mode.
1 parent fb442fd commit 0b42f93

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

ci/simple-tests/coq-test-goals-present.el

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ which action the goals buffer should have been reset."
251251

252252
(ert-deftest goals-after-error ()
253253
"Test goals are present after an error."
254-
:expected-result :failed
255254
(goals-after-test coq-src-error "error" t))
256255

257256
(ert-deftest goals-reset-after-admitted ()
@@ -272,7 +271,6 @@ which action the goals buffer should have been reset."
272271

273272
(ert-deftest update-goals-after-error ()
274273
"Test goals are updated after an error."
275-
:expected-result :failed
276274
(message "update-goals-after-error: Check goals are updated after error")
277275
(setq proof-three-window-enable nil)
278276
(let (buffer)

coq/coq.el

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ buffer.
133133
134134
Sets silent mode.
135135
136-
In normal interaction, the Coq is started because the user assert
136+
In normal interaction, Coq is started because the user assert
137137
some commands. Therefore the commands here are followed by those
138138
inserted inside `proof-assert-command-hook', respectively,
139139
`coq-adapt-printing-width'.")
@@ -1874,7 +1874,7 @@ at `proof-assistant-settings-cmds' evaluation time.")
18741874
(let ((pt2 (point)))
18751875
(re-search-backward "Goal:\\|^TcDebug\\|^</prompt>" nil t)
18761876
(when (looking-at "Goal")
1877-
(pg-goals-display (buffer-substring (point) pt2) nil))))))))
1877+
(pg-goals-display (buffer-substring (point) pt2) nil nil))))))))
18781878

18791879
;; overwrite the generic one, interactive prompt is Debug mode;; try to display
18801880
;; the debug goal in the goals buffer.
@@ -3063,6 +3063,26 @@ buffer."
30633063
(add-hook 'proof-shell-handle-error-or-interrupt-hook #'coq-highlight-error-hook t)
30643064

30653065

3066+
(defun coq-show-goals-on-error ()
3067+
"Update goals buffer on error if necessary.
3068+
This function is intended for
3069+
`proof-shell-handle-error-or-interrupt-hook'. When Coq reported
3070+
an error, this function issues a Show command to update the goals
3071+
buffer, in case we are inside a proof. The hook is processed deep
3072+
inside `proof-shell-filter' after the action list has been reset
3073+
and the proof shell lock `proof-shell-busy' has been released,
3074+
all because of the error. The Show must therefore be added as
3075+
priority action. The flags of the action item must contain
3076+
`'keep-response', because in two-pane mode we want to show the
3077+
response buffer to the user."
3078+
(when coq-last-but-one-proofstack
3079+
(proof-add-to-priority-queue
3080+
(proof-shell-action-list-item
3081+
"Show. " 'proof-done-invisible
3082+
(list 'keep-response 'invisible 'empty-action-list)))))
3083+
3084+
(add-hook 'proof-shell-handle-error-or-interrupt-hook #'coq-show-goals-on-error)
3085+
30663086
;;
30673087
;; Scroll response buffer to maximize display of first goal
30683088
;;

doc/PG-adapting.texi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,6 +3888,7 @@ bother the user. They may include
38883888
@code{'no-response-display} do not display messages in @strong{response} buffer
38893889
@code{'no-error-display} do not display errors/take error action
38903890
@code{'no-goals-display} do not goals in @strong{goals} buffer
3891+
@code{'keep-response} do not erase the response buffer when goals are shown
38913892
@code{'proof-tree-show-subgoal} item inserted by the proof-tree package
38923893
@code{'priority-action} item added via @code{proof-add-to-priority-queue}
38933894
@code{'empty-action-list} @code{proof-shell-empty-action-list-command} should not be

generic/pg-goals.el

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ May enable proof-by-pointing or similar features.
7979
;;
8080
;; Goals buffer processing
8181
;;
82-
(defun pg-goals-display (string keepresponse)
82+
(defun pg-goals-display (string keepresponse nodisplay)
8383
"Display STRING in the `proof-goals-buffer', properly marked up.
8484
Converts term substructure markup into mouse-highlighted extents.
8585
@@ -90,7 +90,13 @@ function tries to do that by calling `pg-response-maybe-erase'.
9090
If KEEPRESPONSE is non-nil, we assume that a response message
9191
corresponding to this goals message has already been displayed
9292
before this goals message (see `proof-shell-handle-delayed-output'),
93-
so the response buffer should not be cleared."
93+
so the response buffer should not be cleared.
94+
95+
IF NODISPLAY is non-nil, do not display the goals buffer in some
96+
window (but the goals buffer is updated as described above and
97+
any window currently showing it will keep it). In two-pane mode,
98+
NODISPLAY has the effect that the goals are updated but the
99+
response buffer is displayed."
94100
;; Response buffer may be out of date. It may contain (error)
95101
;; messages relating to earlier proof states
96102

@@ -114,8 +120,11 @@ so the response buffer should not be cleared."
114120
(set-buffer-modified-p nil)
115121

116122
;; Keep point at the start of the buffer.
117-
(proof-display-and-keep-buffer
118-
proof-goals-buffer (point-min))))
123+
;; (For Coq, somebody sets point to the conclusion in the goal, so the
124+
;; position argument in proof-display-and-keep-buffer has no effect.)
125+
(unless nodisplay
126+
(proof-display-and-keep-buffer
127+
proof-goals-buffer (point-min)))))
119128

120129
;;
121130
;; Actions in the goals buffer

generic/proof-shell.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
;; -> proof-shell-process-urgent-message
3939
;; -> proof-shell-filter-manage-output
4040
;; -> proof-shell-handle-immediate-output
41+
;; -> proof-shell-handle-error-or-interrupt
42+
;; -> proof-shell-error-or-interrupt-action
4143
;; -> proof-shell-exec-loop
4244
;; -> proof-tree-check-proof-finish
4345
;; -> proof-shell-handle-error-or-interrupt
@@ -113,6 +115,7 @@ bother the user. They may include
113115
'no-response-display do not display messages in *response* buffer
114116
'no-error-display do not display errors/take error action
115117
'no-goals-display do not goals in *goals* buffer
118+
'keep-response do not erase the response buffer when goals are shown
116119
'proof-tree-show-subgoal item inserted by the proof-tree package
117120
'priority-action item added via proof-add-to-priority-queue
118121
'empty-action-list proof-shell-empty-action-list-command should not be
@@ -1818,7 +1821,9 @@ i.e., 'goals or 'response."
18181821
(buffer-substring-no-properties rstart gmark)))
18191822
;; display goals output second so it persists in 2-pane mode
18201823
(unless (memq 'no-goals-display flags)
1821-
(pg-goals-display proof-shell-last-goals-output both))
1824+
(pg-goals-display proof-shell-last-goals-output
1825+
(or both (member 'keep-response flags))
1826+
(member 'keep-response flags)))
18221827
;; indicate a goals output has been given
18231828
'goals))
18241829

0 commit comments

Comments
 (0)