From 6973d3e7aaa447c7fbc275545ce5024a1c3d1819 Mon Sep 17 00:00:00 2001 From: Soonho Kong Date: Wed, 29 Oct 2014 17:05:07 -0700 Subject: [PATCH] feat(emacs/lean-info): add goal visualization options 'lean-proofstate-display-style' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lean-proofstate-display-style: - 'show-all: Show all goals a : Prop, b : Prop, c : Prop, H_1 : a, H_2 : b, H_3 : c ⊢ id a a : Prop, b : Prop, c : Prop, H_1 : a, H_2 : b, H_3 : c ⊢ b ∧ c - 'show-first: Show only the first a : Prop, b : Prop, c : Prop, H_1 : a, H_2 : b, H_3 : c ⊢ id a - 'show-first-and-other-conclusions: Show the first goal, and the conclusions of all other goals (DEFAULT OPTION) a : Prop, b : Prop, c : Prop, H_1 : a, H_2 : b, H_3 : c ⊢ id a ⊢ b ∧ c Close #279 --- src/emacs/lean-info.el | 35 +++++++++++++++++++++++++++-------- src/emacs/lean-settings.el | 7 +++++++ src/emacs/lean-type.el | 10 +++++++--- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/emacs/lean-info.el b/src/emacs/lean-info.el index 7d904beb1..35845238f 100644 --- a/src/emacs/lean-info.el +++ b/src/emacs/lean-info.el @@ -229,11 +229,32 @@ (cl-third proofstate)) (defun lean-info-proofstate-state-str (string-seq) (string-join string-seq "\n")) -(defun lean-info-proofstate-states-str (proofstate) - (string-join - (-map 'lean-info-proofstate-state-str - (lean-info-proofstate-states proofstate)) - "\n\n")) +(defun lean-info-proofstate-extract-conclusion (string-seq) + (--drop-while (not (s-starts-with? "⊢" it)) string-seq)) +(defun lean-info-proofstate-extract-premises (string-seq) + (--take-while (not (s-starts-with? "⊢" it)) string-seq)) +(defun lean-info-proofstate-states-str (proofstate &optional display-style) + (let* ((states (lean-info-proofstate-states proofstate)) + (first-state (-first-item states)) + (rest-states (cdr states)) + (display-style (or display-style lean-proofstate-display-style))) + (cond + (first-state + (pcase display-style + (`show-all + (string-join + (-map 'lean-info-proofstate-state-str states) + "\n\n")) + (`show-first + (lean-info-proofstate-state-str first-state)) + (`show-first-and-other-conclusions + (string-join + (-map 'lean-info-proofstate-state-str + (cons first-state (-map + 'lean-info-proofstate-extract-conclusion + rest-states))) + "\n\n")))) + (t "No Goal")))) ;; Basic ;; ----- @@ -469,9 +490,7 @@ Take out \"BEGININFO\" and \"ENDINFO\" and Use \"ACK\" as a delim." (propertize "overloaded" 'face 'font-lock-keyword-face) overload-str)))) (when proofstate - (cond ((not (lean-info-proofstate-states proofstate)) - (setq str "No Goal")) - (t (setq str (lean-info-proofstate-states-str proofstate))))) + (setq str (lean-info-proofstate-states-str proofstate))) (when (and stale str) (setq stale-str (format "[%s]" (propertize "stale" 'face '(foreground-color . "red"))))) diff --git a/src/emacs/lean-settings.el b/src/emacs/lean-settings.el index 9a6dce42e..e85eb18a6 100644 --- a/src/emacs/lean-settings.el +++ b/src/emacs/lean-settings.el @@ -134,4 +134,11 @@ false (nil)." :group 'lean :type 'boolean) +(defcustom lean-proofstate-display-style 'show-first-and-other-conclusions + "Choose how to display proof state in *lean-info* buffer." + :group 'lean + :type '(choice (const :tag "Show all goals" show-all) + (const :tag "Show only the first" show-first) + (const :tag "Show the first goal, and the conclusions of all other goals" show-first-and-other-conclusions))) + (provide 'lean-settings) diff --git a/src/emacs/lean-type.el b/src/emacs/lean-type.el index d9b49440c..607c3c859 100644 --- a/src/emacs/lean-type.el +++ b/src/emacs/lean-type.el @@ -59,15 +59,19 @@ buffer. It's used to avoid outputting the same message") "Continuation for lean-eldoc-documentation-function" (let* ((info-strings (lean-info-record-to-strings info-record)) (info-string-mini-buffer (and info-strings (string-join info-strings " "))) - (info-string-info-buffer (and info-strings (-last-item info-strings)))) + (info-string-info-buffer (and info-strings (-last-item info-strings))) + (proofstate (lean-info-record-proofstate info-record))) (when info-strings (when add-to-kill-ring (kill-new (substring-no-properties info-string-mini-buffer))) + ;; Display on Mini-buffer (when (or lean-show-proofstate-in-minibuffer - (not (lean-info-record-proofstate info-record))) + (not proofstate)) (message "%s" info-string-mini-buffer)) - (lean-output-to-lean-info-buffer "%s" (list info-string-info-buffer))))) + ;; Display on Info Buffer + (when info-string-info-buffer + (lean-output-to-lean-info-buffer "%s" (list info-string-info-buffer)))))) (defun lean-eldoc-documentation-function (&optional add-to-kill-ring) "Show information of lean expression at point if any"