From eb6bba151b27f4d821088e10e1bda5cad0b70a28 Mon Sep 17 00:00:00 2001 From: Pierre Courtieu Date: Fri, 16 Oct 2020 16:33:34 +0200 Subject: Fix #518: "Proof using" mode corrupts "Proof with tac". --- coq/coq.el | 75 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/coq/coq.el b/coq/coq.el index 8cbf84a6..663279cf 100644 --- a/coq/coq.el +++ b/coq/coq.el @@ -2621,9 +2621,28 @@ Warning: this makes the error messages (and location) wrong.") (save-excursion (string-match "\\" s))) ;::::::::::::: inserting suggested Proof using XXX... ;;;;;;;;;; - +;; global mechanism: + +;; When some dependency oinformation is detected (see +;; `coq-shell-theorem-dependency-list-regexp') a hook is triggered by pg. We +;; configure this hook to perform the following: if the user set +;; `coq-accept-proof-using-suggestion' to 'always, then perform the insertion +;; immediately via using `coq-insert-proof-using', otherwise add the menu entry +;; to make it later (actually the current impolementation always adds the menu +;; entry, which is wrong because the span is not there if the insertion was +;; already performed.). + + +;; This variable is used by generic pg code. Every time this is detected in the +;; output, it sets the `proof-last-theorem-dependencies' variable. Substring 1 +;; should contain the name of the theorem, and substring 2 should contain its +;; dependencies. The content of `proof-last-theorem-dependencies' is then used +;; by pg generic code to trigger `proof-depends-process-dependencies', which +;; itself sets the 'dependencies property of the span, and calls +;; `proof-dependencies-system-specific'. The latter is bound to +;; `coq-dependencies-system-specific' below. (setq coq-shell-theorem-dependency-list-regexp - "\n?The proof of \\([^ \n]+\\)\\(?: \\|\n\\)should start with one of the following commands:\\(?: \\|\n\\)Proof using\\([^.]*\\)\\.") + "\n?The proof of \\(?1:[^ \n]+\\)\\(?: \\|\n\\)should start with one of the following commands:\\(?: \\|\n\\)Proof using\\(?2:[^.]*\\)\\.") (defcustom coq-accept-proof-using-suggestion 'highlight "Whether and how proofgeneral should insert \"Proof using\" suggestions. @@ -2662,6 +2681,12 @@ Remarks and limitations: (const :tag "Ignore completely" ignore)) :group 'coq) +;; putting "Type" instead of nothing, otherwise Coq may fail if a "with" +;; anotation is also present: (Proof using with auto raises an error in +;; coq<=8.12 at least). +(defun coq-hack-proofusing-suggestion (suggested) + (if (string-equal "" suggested) "Type" suggested)) + ;; the additional menu for "proof using". highlights the "Proof." command, and ;; have a entry to insert the annotation and remove the highlight. (defvar coq-dependency-menu-system-specific @@ -2669,20 +2694,31 @@ Remarks and limitations: (let* ((deps (span-property-safe span 'dependencies)) (specialspans (spans-at-region-prop (span-start span) (span-end span) 'proofusing)) (specialspan (and specialspans (not (cdr specialspans)) (car specialspans))) - (name (concat " insert \"proof using " (mapconcat 'identity deps " ") "\"")) + (suggested (mapconcat 'identity deps " ")) + (suggested (coq-hack-proofusing-suggestion suggested)) + (name (concat " insert \"proof using " suggested "\"")) (fn `(lambda (sp) (coq-insert-proof-using-suggestion sp t) - (span-delete ,specialspan)))) + (and ,specialspan (span-delete ,specialspan))))) (list "-------------" (vector name `(,fn ,span) t)))) "Coq specific additional menu entry for \"Proof using\". annotation. See `proof-dependency-menu-system-specific'." ) -(defconst coq-proof-using-regexp "\\_\\)?\\([^.]*\\)\\." - "regexp matching Coq \"Proof( using xxx)?.\" annotation. -There should be one subexp numbered 1 matching xxx if present.") +(defconst coq-proof-using-regexp "\\_