diff --git a/CHANGES b/CHANGES index 813ef71c3..10e0c8c0b 100644 --- a/CHANGES +++ b/CHANGES @@ -54,8 +54,13 @@ the Git ChangeLog, the GitHub repo https://github.com/ProofGeneral/PG preferably on commands common to all backends (see the manual). Those for the commands of `coq-all-buffers-commands' (queries, display, printing options) apply also in the goals and response - buffers. C-c C-a C-r and C-c C-a C-g store the response and the - goals in the goals buffer too, not only in the response buffer. + buffers. Each Coq interaction backend can add commands whose + bindings in `coq-mode-map' apply also in the goals and response + buffers that it manages. The Proof General backend adds its + all-buffer commands, processing and retracting the script, and + highlighting a hypothesis. C-c C-a C-r and C-c C-a C-g store the + response and the goals in the goals buffer too, not only in the + response buffer. *** The toggle commands of the user options of Proof General (`proof-three-window-toggle', `proof-electric-terminator-toggle'…), of `coq-show-proof-stepwise' and of `coq-auto-adapt-printing-width' diff --git a/ci/simple-tests/coq-test-queries.el b/ci/simple-tests/coq-test-queries.el index b64558ff1..a84ff2a03 100644 --- a/ci/simple-tests/coq-test-queries.el +++ b/ci/simple-tests/coq-test-queries.el @@ -30,6 +30,9 @@ (defvar proof-goals-buffer) (defvar coq-mode-map) (defvar proof-mode-map) +(defvar proof-all-buffers-commands) +(defvar proof-universal-keys) +(defvar coq-pg-all-buffers-commands) (defvar coq-goals-mode-map) (defvar coq-query-function) (defvar coq-query-result-function) @@ -56,6 +59,7 @@ (declare-function coq-store-goals-win "coq-goals") (declare-function coq-toggle-fold-hyp-at-point "coq-goals") (declare-function coq-store-response-win "coq-goals") +(declare-function coq-toggle-highlight-hyp-at-point "coq-goals") (declare-function coq-insert-intros "coq") (declare-function coq-insert-tactic "coq-templates") (declare-function coq-insert-as-in-next-command "coq-queries") @@ -80,6 +84,11 @@ (declare-function coq-query-flags-from-prefix "coq-queries") (declare-function proof-electric-terminator-toggle "pg-user") (declare-function proof-double-hit-toggle "pg-terminator") +(declare-function proof-assert-next-command-interactive "pg-user") +(declare-function proof-assert-until-point-interactive "pg-user") +(declare-function proof-process-buffer "pg-user") +(declare-function proof-retract-buffer "pg-user") +(declare-function proof-undo-last-successful-command "pg-user") ;;; utility functions @@ -165,8 +174,27 @@ the user in `coq-goals-mode-map'. See also `coq-test-without-pg-user-keys'." (unwind-protect (progn + (dolist (binding proof-universal-keys) + (should (memq (cdr binding) proof-all-buffers-commands))) + ;; Removing a default key does not make its command invalid in + ;; output buffers: key choices and command validity are independent. + (let ((proof-universal-keys nil)) + (should (memq 'proof-assert-next-command-interactive + coq-pg-all-buffers-commands))) (define-key coq-mode-map (kbd "C-c y") #'coq-Check) (define-key coq-mode-map (kbd "C-c C-t") #'coq-About) + (define-key coq-mode-map (kbd "C-M-") + #'proof-assert-next-command-interactive) + (define-key coq-mode-map (kbd "C-M-") + #'proof-undo-last-successful-command) + (define-key coq-mode-map (kbd "C-M-b") #'proof-process-buffer) + (define-key coq-mode-map (kbd "C-M-r") #'proof-retract-buffer) + (define-key coq-mode-map (kbd "") + #'coq-toggle-highlight-hyp-at-point) + ;; This command depends on point in the script buffer: do not + ;; propagate its user binding to the output buffers. + (define-key coq-mode-map (kbd "C-M-e") + #'proof-assert-until-point-interactive) (define-key proof-mode-map (kbd "C-c x") #'coq-Print) (define-key coq-goals-mode-map (kbd "C-c C-a C-p") #'coq-Inspect) (coq-test-queries-with-file @@ -181,6 +209,17 @@ the user in `coq-goals-mode-map'. See also (should-not (eq (key-binding (kbd "C-c x")) #'coq-Print)) (should (eq (key-binding (kbd "C-c C-a C-r")) #'coq-store-response-win)) (should (eq (key-binding (kbd "C-c C-a C-g")) #'coq-store-goals-win)) + ;; User bindings for commands valid in every PG buffer. + (should (eq (key-binding (kbd "C-M-")) + #'proof-assert-next-command-interactive)) + (should (eq (key-binding (kbd "C-M-")) + #'proof-undo-last-successful-command)) + (should (eq (key-binding (kbd "C-M-b")) #'proof-process-buffer)) + (should (eq (key-binding (kbd "C-M-r")) #'proof-retract-buffer)) + (should (eq (key-binding (kbd "")) + #'coq-toggle-highlight-hyp-at-point)) + (should-not (eq (key-binding (kbd "C-M-e")) + #'proof-assert-until-point-interactive)) ;; the keys of Proof General there (should (eq (key-binding [mouse-1]) #'pg-goals-button-action)))) (with-current-buffer proof-goals-buffer @@ -192,6 +231,12 @@ the user in `coq-goals-mode-map'. See also (should-not (eq (key-binding (kbd "f")) #'coq-toggle-fold-hyp-at-point))))) (define-key coq-mode-map (kbd "C-c y") nil) (define-key coq-mode-map (kbd "C-c C-t") nil) + (define-key coq-mode-map (kbd "C-M-") nil) + (define-key coq-mode-map (kbd "C-M-") nil) + (define-key coq-mode-map (kbd "C-M-b") nil) + (define-key coq-mode-map (kbd "C-M-r") nil) + (define-key coq-mode-map (kbd "") nil) + (define-key coq-mode-map (kbd "C-M-e") nil) (define-key proof-mode-map (kbd "C-c x") nil) (define-key coq-goals-mode-map (kbd "C-c C-a C-p") nil))) diff --git a/ci/simple-tests/coq-test-without-pg.el b/ci/simple-tests/coq-test-without-pg.el index 0682b94fd..6d6f85fce 100644 --- a/ci/simple-tests/coq-test-without-pg.el +++ b/ci/simple-tests/coq-test-without-pg.el @@ -379,21 +379,28 @@ those of the parent of `coq-mode-map' nor of the insertions." (dolist (command coq-all-buffers-commands) (should (commandp command))) (define-key coq-mode-map (kbd "C-c y") #'coq-Check) + (define-key coq-mode-map (kbd "C-c v") #'forward-char) (define-key other (kbd "C-c w") #'coq-About) (set-keymap-parent coq-mode-map other) (let ((map (coq-all-buffers-keymap))) (should (eq (lookup-key map (kbd "C-c C-a C-b")) #'coq-About)) (should (eq (lookup-key map (kbd "C-c C-a g")) #'coq-store-goals-win)) (should (eq (lookup-key map (kbd "C-c y")) #'coq-Check)) + (should-not (lookup-key map (kbd "C-c v"))) (should-not (lookup-key map (kbd "C-c w"))) (should-not (lookup-key map (kbd "C-c C-a C-i"))) ;; insertions in the script buffer (should (eq (lookup-key map (kbd "C-c C-a C-r")) #'coq-store-response-win)) (should (eq (lookup-key map (kbd "C-c C-a C-g")) #'coq-store-goals-win)) (should (eq (lookup-key coq-mode-map (kbd "C-c C-a C-r")) - #'coq-insert-requires)))) + #'coq-insert-requires))) + ;; An interaction backend extends the commands copied from + ;; `coq-mode-map' to the goals and response keymaps it manages. + (let ((map (coq-all-buffers-keymap '(forward-char)))) + (should (eq (lookup-key map (kbd "C-c v")) #'forward-char)))) (set-keymap-parent coq-mode-map parent) - (define-key coq-mode-map (kbd "C-c y") nil)))) + (define-key coq-mode-map (kbd "C-c y") nil) + (define-key coq-mode-map (kbd "C-c v") nil)))) ;; compatibility files of the files merged into others diff --git a/coq/coq-queries.el b/coq/coq-queries.el index 4f3da33b1..3f8ff469c 100644 --- a/coq/coq-queries.el +++ b/coq/coq-queries.el @@ -843,19 +843,21 @@ Their key bindings in `coq-mode-map', the default ones and those of the user, are also in the goals and response buffers of all backends, see `coq-all-buffers-keymap'.") -(defun coq-all-buffers-keymap () +(defun coq-all-buffers-keymap (&optional backend-commands) "Return a new keymap for the goals and response buffers. With the key bindings of `coq-mode-map' for `coq-all-buffers-commands', the default ones and those of the user, but not those of its parent \(in Proof General, `proof-mode-map'). Also C-c C-a C-r and C-c C-a C-g for `coq-store-response-win' and `coq-store-goals-win': in the script -buffer, these keys are insertions. Each backend makes it a parent of -the keymaps of its goals and response buffers, when it sets them up, -after the configuration of the user." +buffer, these keys are insertions. Each Coq interaction backend makes +it a parent of the keymaps of the goals and response buffers that it +manages, when it sets them up, after the configuration of the user. +BACKEND-COMMANDS are additional commands whose bindings in +`coq-mode-map' should also apply in these two kinds of output buffer." (let ((map (make-sparse-keymap)) (own (copy-keymap coq-mode-map))) (set-keymap-parent own nil) - (dolist (command coq-all-buffers-commands) + (dolist (command (append coq-all-buffers-commands backend-commands)) (dolist (key (where-is-internal command (list own) nil t)) (unless (memq (aref key 0) '(menu-bar tool-bar)) (define-key map key command)))) diff --git a/coq/coq.el b/coq/coq.el index aaad8de4d..e5dfced4c 100644 --- a/coq/coq.el +++ b/coq/coq.el @@ -1554,14 +1554,25 @@ shortly before `proof-assert-command-hook', respectively, (setq coq-goals-buffer-function (lambda () proof-goals-buffer)) (setq coq-response-buffer-function (lambda () proof-response-buffer)) +(defconst coq-pg-all-buffers-commands + (append proof-all-buffers-commands + '(coq-toggle-highlight-hyp-at-point)) + "Commands propagated to Coq output buffers by the PG backend. +Their bindings in `coq-mode-map' also apply in the Coq goals and +response buffers managed by the Proof General interaction backend. +Highlighting a hypothesis depends on point in the current Coq buffer, +not on point in the active script.") + (defun coq-pg-set-buffer-keys (map generic-map) "Make the keys of `coq-all-buffers-keymap' a parent of MAP. Before GENERIC-MAP, the keymap of Proof General, parent of MAP. MAP keeps the priority, with the key bindings of the user there. Called each time the goals or response buffer is set up, for the key bindings of the user in `coq-mode-map'." - (set-keymap-parent map (make-composed-keymap (coq-all-buffers-keymap) - generic-map))) + (set-keymap-parent + map (make-composed-keymap + (coq-all-buffers-keymap coq-pg-all-buffers-commands) + generic-map))) (defun coq-goals-mode-config () (coq-pg-set-backend-functions) diff --git a/generic/pg-vars.el b/generic/pg-vars.el index 44977b3eb..e34c9865e 100644 --- a/generic/pg-vars.el +++ b/generic/pg-vars.el @@ -283,6 +283,27 @@ Internal variable dynamically bound.") :type 'string :group 'proof-general-internals) +(defconst proof-all-buffers-commands + '(proof-next-error + proof-interrupt-process + proof-assert-next-command-interactive + proof-undo-last-successful-command + proof-prf + proof-layout-windows + proof-shell-exit + proof-minibuffer-cmd + pg-response-clear-displays + proof-goto-end-of-locked + proof-find-theorems + proof-display-some-buffers + pg-identifier-under-mouse-query + proof-process-buffer + proof-retract-buffer) + "Commands that can be invoked from every Proof General buffer. +Independent of their default key bindings in `proof-universal-keys': +users can remove or replace a default key without making its command +invalid in a script, goals, response or shell buffer.") + (defcustom proof-universal-keys '(([(control c) ?`] . proof-next-error) ([(control c) (control c)] . proof-interrupt-process)