Skip to content

Commit cf3398a

Browse files
committed
fix prooftree for Coq/Rocq running completely silent
- Inside the urgent prooftree action, call now the proof assistant specific function `proof-tree-assistant-specific-urgent-action'. For Coq/Rocq this adds a show command which calls `proof-tree-display-goal-callback' in its callback, which processes the output and sends appropriate commands to prooftree. - Move the call of the urgent prooftree action before calling adding `proof-shell-empty-action-list-command', such that these last actions happen after the show command. - In `proof-shell-filter-manage-output', save the end of the previous command in new variable `proof-shell-old-proof-marker-position' such that callbacks running after the next command has been sent to Coq can access it. This is used inside `proof-tree-display-goal-callback'. - proof-tree display is now only supported when Coq runs completely silent. Supporting it in the other mode should not be too difficult, but I don't think it is worth the effort.
1 parent 8264bb1 commit cf3398a

5 files changed

Lines changed: 255 additions & 94 deletions

File tree

CHANGES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ the Git ChangeLog, the GitHub repo https://github.com/ProofGeneral/PG
5757
errors on correct code.
5858
*** Run Coq completely silent to fix #568. If you experience unexpected
5959
behavior, please report a bug and disable
60-
`coq-run-completely-silent' to switch back to old behavior.
60+
`coq-run-completely-silent' to switch back to old behavior. Note
61+
that external proof tree display is only supported if Coq/Rocq
62+
runs completely silent.
6163

6264

6365
* Changes of Proof General 4.5 from Proof General 4.4

coq/coq.el

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ of commands and switched to verbose before the last command. A
8989
manual Show command (C-c C-p) is necessary if the last command
9090
fails to update the goals buffer (e.g., if it is a comment or it
9191
is not executed because some other command before failed, see
92-
also bug report #568)."
92+
also bug report #568). External proof tree display is only
93+
supported if this option is t."
9394
:type 'boolean
9495
:safe 'booleanp
9596
:group 'coq)
@@ -233,7 +234,7 @@ It is mostly useful in three window mode, see also
233234
:package-version '(ProofGeneral . "4.2"))
234235

235236
(defcustom coq-proof-tree-ignored-commands-regexp
236-
"^\\(\\(Show\\)\\|\\(Locate\\)\\)"
237+
"^\\(\\(Show\\)\\|\\(Locate\\)\\|\\(Proof\\)\\)"
237238
"Regexp for `proof-tree-ignored-commands-regexp'."
238239
:type 'regexp
239240
:group 'coq-proof-tree)
@@ -1998,12 +1999,15 @@ at `proof-assistant-settings-cmds' evaluation time.")
19981999
(setq proof-shell-start-silent-cmd "Set Silent."
19992000
proof-shell-stop-silent-cmd "Unset Silent."))
20002001

2001-
;; prooftree config
2002-
(setq
2003-
proof-tree-configured (coq--post-v810)
2004-
proof-tree-get-proof-info 'coq-proof-tree-get-proof-info
2005-
proof-tree-find-begin-of-unfinished-proof
2006-
'coq-find-begin-of-unfinished-proof)
2002+
;; prooftree config - prooftree is only supported for Coq/Rocq running silent
2003+
(when coq-run-completely-silent
2004+
(setq
2005+
proof-tree-configured (coq--post-v810)
2006+
proof-tree-get-proof-info 'coq-proof-tree-get-proof-info
2007+
proof-tree-find-begin-of-unfinished-proof
2008+
'coq-find-begin-of-unfinished-proof
2009+
proof-tree-assistant-specific-urgent-action
2010+
'proof-tree-coq-urgent-action))
20072011

20082012
;; proof-omit-proofs config
20092013
(setq
@@ -2330,11 +2334,16 @@ This is the Coq incarnation of `proof-tree-find-undo-position'."
23302334
;; in the middle of a proof and then to undo a few tactics.
23312335

23322336
(defun coq-proof-tree-evar-command (cmd)
2333-
"Return the evar printing command for CMD as action list item."
2337+
"Return the evar printing command for CMD as action list item.
2338+
Adds, among others, `'empty-action-list' to flags to avoid that
2339+
`coq-empty-action-list-command' adds a show command because it
2340+
recognizes a change of a printing option. When the user quits the
2341+
proof tree display inside prooftree, then the evar command likely
2342+
runs as single command."
23342343
(proof-shell-action-list-item
23352344
(concat cmd " Printing Dependent Evars Line.")
23362345
'proof-done-invisible
2337-
(list 'invisible 'no-response-display)))
2346+
(list 'invisible 'no-response-display 'empty-action-list)))
23382347

23392348
(defun coq-proof-tree-enable-evars ()
23402349
"Enable the evar status line."
@@ -2354,6 +2363,35 @@ Function for `proof-tree-display-stop-command'."
23542363
(when (and (coq--post-v86) coq-proof-tree-manage-dependent-evar-line)
23552364
(coq-proof-tree-evar-command "Unset")))
23562365

2366+
(defun proof-tree-coq-urgent-action (last-item)
2367+
"Insert show-goal commands when running completely silent.
2368+
Coq specific function for `proof-tree-assistant-specific-urgent-action'.
2369+
When running completely silent, insert a show-goal command for commands
2370+
comming from the user. Be careful to not insert show-goal commands for
2371+
show-goal requests from prooftree or for the items inserted by this
2372+
function. LAST-ITEM is the last proof-action item that has just been
2373+
processed. This function is guaranteed to be called at a place where
2374+
`proof-action-list' can be directly manipulated.
2375+
2376+
When single stepping through a proof, this function inserts a second
2377+
show command, which is inserted before the one from
2378+
`coq-show-goals-inside-proof'. One would of course be enough, but fixing
2379+
this would be difficult."
2380+
(let ((flags (nth 3 last-item)))
2381+
(unless (or (memq 'invisible flags)
2382+
(memq 'proof-tree-show-subgoal flags))
2383+
(let ((proof-info (coq-proof-tree-get-proof-info)))
2384+
;; Ignore retractions, prooftree only needs fresh sequents.
2385+
(when (and (>= (car proof-info) proof-tree-last-state)
2386+
(cadr proof-info))
2387+
(push
2388+
(proof-shell-action-list-item
2389+
"Show."
2390+
(lambda (_span)
2391+
(proof-tree-display-goal-callback last-item proof-info))
2392+
'(invisible no-goals-display no-response-display
2393+
proof-tree-show-subgoal))
2394+
proof-action-list))))))
23572395

23582396
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23592397
;;
@@ -3159,7 +3197,7 @@ Do nothing if `coq-run-completely-silent' is disabled."
31593197
(let* ((flags-1 (list 'dont-show-when-silent 'invisible 'empty-action-list))
31603198
(flags (if keep-response (cons 'keep-response flags-1) flags-1)))
31613199
(proof-add-to-priority-queue
3162-
(proof-shell-action-list-item "Show. " 'proof-done-invisible flags)))))
3200+
(proof-shell-action-list-item "Show." 'proof-done-invisible flags)))))
31633201

31643202
(defun coq-show-goals-on-error ()
31653203
"Update goals after error.

doc/PG-adapting.texi

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ tokens (for example, editing documentation or source code files).
26752675
@chapter Configuring Proof-Tree Visualization
26762676

26772677
@b{Parts of this section are outdated. Please create an issue at
2678-
github.com/ProofGeneral/Proof General if you have a question for
2678+
github.com/ProofGeneral/PG if you have a question for
26792679
adapting Prooftree for a new proof assistant.}
26802680

26812681
The proof-tree visualization feature was written with the idea of
@@ -2939,29 +2939,26 @@ Urgent actions are those that must be executed before
29392939
@code{proof-action-list} to the proof assistant. For execution
29402940
speed, the amount of urgent code should be kept small.
29412941

2942-
@c TEXI DOCSTRING MAGIC: proof-tree-check-proof-finish
2943-
@defun proof-tree-check-proof-finish last-item
2944-
Urgent action to delay processing at proof end.@*
2945-
This function is called from @samp{@code{proof-shell-exec-loop}} after the
2946-
old item has been removed and before the next item from
2947-
@samp{@code{proof-action-list}} is sent to the proof assistant. Of course
2948-
only when the proof-tree display is active. At the end of the
2949-
proof, this function delays items just following the previous
2950-
proof until all show-goal commands from prooftree and the
2951-
@samp{@code{proof-tree-display-stop-command}} (which switches the dependent
2952-
evar line off for Coq) have been processed.
2953-
2954-
If this function detects the end of the proof, it moves
2955-
non-priority items following in @samp{@code{proof-action-list}} to
2956-
@samp{@code{proof-tree--delayed-actions}} and sets
2957-
@samp{@code{proof-second-action-list-active}}. When later the command from
2958-
@samp{@code{proof-tree-display-stop-command}} is recognized, the items are
2959-
moved back. If no items follow the end of the previous proof,
2960-
@samp{@code{proof-tree-display-stop-command}} is set to t.
2942+
@c TEXI DOCSTRING MAGIC: proof-tree-urgent-action
2943+
@defun proof-tree-urgent-action last-item
2944+
Urgent actions for proof-tree display.@*
2945+
This is the second entry point of the Proof General prooftree support,
2946+
see also @samp{@code{proof-tree-handle-delayed-output}}. Call
2947+
@samp{@code{proof-tree-check-proof-finish}} to delay processing the queue region at
2948+
the end of a proof until all show-goal commands from prooftree have been
2949+
processed. Do also call @samp{@code{proof-tree-assistant-specific-urgent-action}},
2950+
which appropriately inserts show-goal commands if Coq is running
2951+
completely silent. @var{last-item} is the last proof-action item that has just
2952+
been processed.
2953+
2954+
When the proof-tree display is active, this function is called from
2955+
@samp{@code{proof-shell-exec-loop}} after the old item has been removed and before
2956+
the next item from @samp{@code{proof-action-list}} is sent to the proof assistant.
2957+
At this place @samp{@code{proof-action-list}} can be directly manipulated.
29612958
@end defun
29622959

29632960

2964-
The function @code{proof-tree-check-proof-finish} is called at a point
2961+
The function @code{proof-tree-urgent-action} is called at a point
29652962
where it is save to manipulate @code{proof-action-list}. This is
29662963
essential, because @code{proof-tree-urgent-action} inserts goal
29672964
display commands into @code{proof-action-list} when existential
@@ -2976,9 +2973,10 @@ assistant is already busy with the next item from
29762973
@c TEXI DOCSTRING MAGIC: proof-tree-handle-delayed-output
29772974
@defun proof-tree-handle-delayed-output old-proof-marker cmd flags _span
29782975
Process delayed output for prooftree.@*
2979-
This function is the main entry point of the Proof General
2980-
prooftree support. It examines the delayed output in order to
2981-
take appropriate actions and maintains the internal state.
2976+
This function is the main entry point of the Proof General prooftree
2977+
support, but see also @samp{@code{proof-tree-urgent-action}}. It examines the
2978+
delayed output in order to take appropriate actions and maintains the
2979+
internal state.
29822980

29832981
The delayed output to handle is in the region
29842982
[@code{proof-shell-delayed-output-start}, @code{proof-shell-delayed-output-end}].
@@ -3918,7 +3916,7 @@ See also functions @samp{@code{proof-activate-scripting}} and
39183916

39193917
@c TEXI DOCSTRING MAGIC: proof-marker
39203918
@defvar proof-marker
3921-
Marker in proof shell buffer pointing to previous command input.
3919+
Marker in proof shell buffer pointing to the end of previous command input.
39223920
@end defvar
39233921

39243922
@c TEXI DOCSTRING MAGIC: proof-action-list
@@ -3957,7 +3955,12 @@ bother the user. They may include
39573955
@code{'no-error-display} do not display errors/take error action
39583956
@code{'no-goals-display} do not goals in @strong{goals} buffer
39593957
@code{'keep-response} do not erase the response buffer when goals are shown
3960-
@code{'proof-tree-show-subgoal} item inserted by the proof-tree package
3958+
@code{'proof-tree-show-subgoal} item inserted by the proof-tree package to display
3959+
the current or some other goal
3960+
@code{'proof-tree-last-item} marks the item that follows the last show-goal
3961+
request after a proof finished with proof-tree
3962+
display, causes switch back to normal queue region
3963+
processing
39613964
@code{'priority-action} item added via @code{proof-add-to-priority-queue}
39623965
@code{'empty-action-list} @code{proof-shell-empty-action-list-command} should not be
39633966
called if this is the last item in the action list
@@ -3971,6 +3974,17 @@ printing hints).
39713974
See the functions @samp{@code{proof-start-queue}} and @samp{@code{proof-shell-exec-loop}}.
39723975
@end defvar
39733976

3977+
@c TEXI DOCSTRING MAGIC: proof-shell-old-proof-marker-position
3978+
@defvar proof-shell-old-proof-marker-position
3979+
Position of end of second last input inside delayed callbacks.@*
3980+
When callbacks of action items are processed, @samp{@code{proof-marker}} has already
3981+
been advanced to the end of the next input that the proof assistant
3982+
processes in parallel with the callback. This variable permits the
3983+
callback to access the end of the input belonging to its action-list
3984+
item and then process the complete output that the proof assistant has
3985+
sent.
3986+
@end defvar
3987+
39743988
In Proof General 4.2 and earlier it was always the case that all
39753989
items from the queue region were present in
39763990
@code{proof-action-list}. Because of the new parallel background

generic/proof-shell.el

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
;; -> proof-shell-handle-error-or-interrupt
4242
;; -> proof-shell-error-or-interrupt-action
4343
;; -> proof-shell-exec-loop
44-
;; -> proof-tree-check-proof-finish
44+
;; -> proof-tree-urgent-action
4545
;; -> proof-shell-handle-error-or-interrupt
4646
;; -> proof-shell-insert-action-item
4747
;; -> proof-shell-invoke-callback
@@ -64,7 +64,7 @@
6464
;; require proof-tree the compiler complains about a recusive
6565
;; dependency.
6666
(declare-function proof-tree-handle-delayed-output "proof-tree"
67-
(old-proof-marker cmd flags span))
67+
(old-proof-marker cmd flags _span))
6868
;; without the nil initialization the compiler still warns about this variable
6969
(defvar proof-tree-external-display)
7070

@@ -79,7 +79,7 @@
7979
;;
8080

8181
(defvar proof-marker nil
82-
"Marker in proof shell buffer pointing to previous command input.")
82+
"Marker in proof shell buffer pointing to the end of previous command input.")
8383

8484
(defvar proof-action-list nil
8585
"The main queue of things to do: spans, commands and actions.
@@ -116,7 +116,12 @@ bother the user. They may include
116116
'no-error-display do not display errors/take error action
117117
'no-goals-display do not goals in *goals* buffer
118118
'keep-response do not erase the response buffer when goals are shown
119-
'proof-tree-show-subgoal item inserted by the proof-tree package
119+
'proof-tree-show-subgoal item inserted by the proof-tree package to display
120+
the current or some other goal
121+
'proof-tree-last-item marks the item that follows the last show-goal
122+
request after a proof finished with proof-tree
123+
display, causes switch back to normal queue region
124+
processing
120125
'priority-action item added via proof-add-to-priority-queue
121126
'empty-action-list proof-shell-empty-action-list-command should not be
122127
called if this is the last item in the action list
@@ -181,6 +186,15 @@ background compilation finishes. Then those items are put into
181186
(defvar proof-shell-last-response-output ""
182187
"The last displayed response message.")
183188

189+
(defvar proof-shell-old-proof-marker-position nil
190+
"Position of end of second last input inside delayed callbacks.
191+
When callbacks of action items are processed, `proof-marker' has already
192+
been advanced to the end of the next input that the proof assistant
193+
processes in parallel with the callback. This variable permits the
194+
callback to access the end of the input belonging to its action-list
195+
item and then process the complete output that the proof assistant has
196+
sent.")
197+
184198
(defvar proof-shell-delayed-output-start nil
185199
"A record of the start of the previous output in the shell buffer.
186200
The previous output is held back for processing at end of queue.")
@@ -1235,6 +1249,17 @@ contains only invisible elements for Prooftree synchronization."
12351249
(setq cbitems (cons item
12361250
(proof-shell-slurp-comments)))
12371251

1252+
;; This is the point where old items have been removed from
1253+
;; proof-action-list and where the next item has not yet been
1254+
;; sent to the proof assistant. This is therefore one of the
1255+
;; few points where it is safe to manipulate
1256+
;; proof-action-list.
1257+
1258+
;; Call the urgent action of prooftree, if the display is on.
1259+
;; This might add or remove stuff to/from `proof-action-list'.
1260+
(when proof-tree-external-display
1261+
(proof-tree-urgent-action item))
1262+
12381263
;; If proof-action-list is empty after removing the already
12391264
;; processed actions and the last action was not already
12401265
;; added by proof-shell-empty-action-list-command (prover
@@ -1252,17 +1277,6 @@ contains only invisible elements for Prooftree synchronization."
12521277
;; action-list should be empty at this point
12531278
(setq proof-action-list (append extra-items proof-action-list))))
12541279

1255-
;; This is the point where old items have been removed from
1256-
;; proof-action-list and where the next item has not yet been
1257-
;; sent to the proof assistant. This is therefore one of the
1258-
;; few points where it is safe to manipulate
1259-
;; proof-action-list.
1260-
1261-
;; Call the urgent action of prooftree, if the display is on.
1262-
;; This might enqueue items in the priority action list.
1263-
(when proof-tree-external-display
1264-
(proof-tree-check-proof-finish item))
1265-
12661280
;; Add priority actions to the front of proof-action-list.
12671281
;; Delay adding of priority items until there is no priority
12681282
;; item at the head of `proof-action-list', such that more
@@ -1722,8 +1736,12 @@ After processing the current output, the last step undertaken
17221736
by the filter is to send the next command from the queue."
17231737
(let ((span (caar proof-action-list))
17241738
(cmd (nth 1 (car proof-action-list)))
1725-
(flags (nth 3 (car proof-action-list)))
1726-
(old-proof-marker (marker-position proof-marker)))
1739+
(flags (nth 3 (car proof-action-list))))
1740+
1741+
;; Save position of end of last input, such that callbacks called
1742+
;; inside `proof-shell-exec-loop' and proof-tree delayed output
1743+
;; handling can access it.
1744+
(setq proof-shell-old-proof-marker-position (marker-position proof-marker))
17271745

17281746
;; A copy of the last message, verbatim, never modified.
17291747
(setq proof-shell-last-output
@@ -1741,7 +1759,8 @@ by the filter is to send the next command from the queue."
17411759
(proof-shell-handle-delayed-output))
17421760
;; send output to the proof tree visualizer
17431761
(if proof-tree-external-display
1744-
(proof-tree-handle-delayed-output old-proof-marker cmd flags span)))))
1762+
(proof-tree-handle-delayed-output
1763+
proof-shell-old-proof-marker-position cmd flags span)))))
17451764

17461765

17471766
(defsubst proof-shell-display-output-as-response (flags str)

0 commit comments

Comments
 (0)