2014-09-03 15:08:28 +00:00
|
|
|
;; -*- lexical-binding: t; -*-
|
2014-08-14 00:02:49 +00:00
|
|
|
;; Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
;; Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
;;
|
|
|
|
;; Author: Soonho Kong
|
|
|
|
;;
|
|
|
|
|
|
|
|
(require 'cl-lib)
|
2014-08-25 20:31:12 +00:00
|
|
|
(require 'dash)
|
|
|
|
(require 'dash-functional)
|
2014-08-14 00:02:49 +00:00
|
|
|
(require 'lean-variable)
|
|
|
|
(require 'lean-util)
|
2014-08-14 15:42:52 +00:00
|
|
|
(require 'lean-cmd)
|
2014-08-14 00:02:49 +00:00
|
|
|
(require 'lean-server)
|
2014-09-12 21:22:39 +00:00
|
|
|
(require 'lean-changes)
|
2014-08-14 00:02:49 +00:00
|
|
|
(require 'lean-debug)
|
2014-08-25 20:31:12 +00:00
|
|
|
(require 'flymake)
|
2014-08-14 00:02:49 +00:00
|
|
|
|
2014-09-03 07:39:54 +00:00
|
|
|
(defun lean-fill-placeholder-cont (info-record)
|
|
|
|
"Continuation for lean-fill-placeholder"
|
|
|
|
(let ((synth (and info-record (cl-first (lean-info-record-synth info-record)))))
|
2014-08-25 20:31:12 +00:00
|
|
|
(when synth
|
|
|
|
(let ((synth-str
|
|
|
|
(replace-regexp-in-string "?M_[0-9]+" "_" (lean-info-synth-body-str synth))))
|
|
|
|
(when (search " " synth-str)
|
|
|
|
(setq synth-str (concat "(" synth-str ")")))
|
2014-09-09 20:22:07 +00:00
|
|
|
(when (looking-at "_")
|
2014-09-03 07:39:54 +00:00
|
|
|
(delete-forward-char 1)
|
|
|
|
(insert synth-str))))))
|
|
|
|
|
|
|
|
(defun lean-fill-placeholder ()
|
|
|
|
"Fill the placeholder with a synthesized expression by Lean."
|
|
|
|
(interactive)
|
|
|
|
(lean-get-info-record-at-point 'lean-fill-placeholder-cont))
|
|
|
|
|
2014-10-29 21:31:03 +00:00
|
|
|
(defconst lean-info-buffer-name "*lean-info*")
|
2014-10-29 23:02:48 +00:00
|
|
|
(defconst lean-info-buffer-delimiter "-------------------------------\n")
|
2014-10-29 21:31:03 +00:00
|
|
|
|
|
|
|
(defun lean-setup-info-buffer ()
|
|
|
|
(unless (get-buffer lean-info-buffer-name)
|
|
|
|
(with-current-buffer (get-buffer-create lean-info-buffer-name)
|
|
|
|
(lean-info-mode))))
|
|
|
|
|
2014-10-29 23:02:48 +00:00
|
|
|
(defvar-local lean-info-prev-message nil
|
|
|
|
"A variable storing the previous message written to *lean-info*
|
|
|
|
buffer. It's used to avoid outputting the same message")
|
|
|
|
|
|
|
|
(defun lean-output-to-lean-info-buffer (fmt args)
|
|
|
|
(lean-setup-info-buffer)
|
|
|
|
(let ((output (apply 'format fmt args)))
|
|
|
|
(when (and (> (length output) 0)
|
|
|
|
(or (not lean-info-prev-message)
|
|
|
|
(not (string= lean-info-prev-message output))))
|
|
|
|
(setq lean-info-prev-message output)
|
|
|
|
(lean-output-to-buffer lean-info-buffer-name lean-info-buffer-delimiter nil)
|
|
|
|
(lean-output-to-buffer lean-info-buffer-name "%s\n" (list output)))))
|
|
|
|
|
2014-10-14 16:27:25 +00:00
|
|
|
(defun lean-eldoc-documentation-function-cont (info-record &optional add-to-kill-ring)
|
2014-09-03 07:39:54 +00:00
|
|
|
"Continuation for lean-eldoc-documentation-function"
|
2014-10-29 21:31:03 +00:00
|
|
|
(let* ((info-strings (lean-info-record-to-strings info-record))
|
|
|
|
(info-string-mini-buffer (and info-strings (string-join info-strings " ")))
|
feat(emacs/lean-info): add goal visualization options 'lean-proofstate-display-style'
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
2014-10-30 00:05:07 +00:00
|
|
|
(info-string-info-buffer (and info-strings (-last-item info-strings)))
|
|
|
|
(proofstate (lean-info-record-proofstate info-record)))
|
2014-10-29 21:31:03 +00:00
|
|
|
(when info-strings
|
2014-10-14 16:27:25 +00:00
|
|
|
(when add-to-kill-ring
|
|
|
|
(kill-new
|
2014-10-29 21:31:03 +00:00
|
|
|
(substring-no-properties info-string-mini-buffer)))
|
feat(emacs/lean-info): add goal visualization options 'lean-proofstate-display-style'
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
2014-10-30 00:05:07 +00:00
|
|
|
;; Display on Mini-buffer
|
2014-10-28 21:06:03 +00:00
|
|
|
(when (or lean-show-proofstate-in-minibuffer
|
feat(emacs/lean-info): add goal visualization options 'lean-proofstate-display-style'
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
2014-10-30 00:05:07 +00:00
|
|
|
(not proofstate))
|
2014-10-29 21:31:03 +00:00
|
|
|
(message "%s" info-string-mini-buffer))
|
feat(emacs/lean-info): add goal visualization options 'lean-proofstate-display-style'
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
2014-10-30 00:05:07 +00:00
|
|
|
;; Display on Info Buffer
|
|
|
|
(when info-string-info-buffer
|
|
|
|
(lean-output-to-lean-info-buffer "%s" (list info-string-info-buffer))))))
|
2014-08-15 00:10:58 +00:00
|
|
|
|
2014-10-14 16:27:25 +00:00
|
|
|
(defun lean-eldoc-documentation-function (&optional add-to-kill-ring)
|
2014-08-14 13:22:01 +00:00
|
|
|
"Show information of lean expression at point if any"
|
2014-08-14 00:02:49 +00:00
|
|
|
(interactive)
|
2014-09-20 17:18:43 +00:00
|
|
|
(cond ((and lean-flycheck-use
|
|
|
|
(or (get-char-property (point) 'flycheck-error)
|
|
|
|
(get-char-property (point) 'flycheck-warning)))
|
|
|
|
nil)
|
|
|
|
((or (and (not (looking-at (rx white)))
|
|
|
|
(not (eolp)))
|
|
|
|
(and (looking-back (rx (not white)))
|
|
|
|
(not (bolp))))
|
2014-10-14 16:27:25 +00:00
|
|
|
(lean-get-info-record-at-point
|
|
|
|
(lambda (info-record)
|
|
|
|
(lean-eldoc-documentation-function-cont info-record add-to-kill-ring))))))
|
|
|
|
|
|
|
|
(defun lean-show-type ()
|
|
|
|
"Show information of lean-expression at point if any."
|
|
|
|
(interactive)
|
|
|
|
(lean-eldoc-documentation-function lean-show-type-add-to-kill-ring))
|
2014-08-25 20:31:12 +00:00
|
|
|
|
2014-08-25 23:26:29 +00:00
|
|
|
;; =======================================================
|
|
|
|
;; eval
|
|
|
|
;; =======================================================
|
|
|
|
|
|
|
|
(defun lean-eval-parse-string (str)
|
|
|
|
"Parse the output of eval command."
|
|
|
|
(let ((str-list (split-string str "\n")))
|
|
|
|
;; Drop the first line "-- BEGINEVAL" and
|
|
|
|
;; the last line "-- ENDEVAL"
|
|
|
|
(setq str-list
|
|
|
|
(-take (- (length str-list) 2)
|
|
|
|
(-drop 1 str-list)))
|
|
|
|
(string-join str-list "\n")))
|
|
|
|
|
|
|
|
(defun lean-eval-cmd (lean-cmd)
|
|
|
|
"Evaluate lean command."
|
|
|
|
(interactive "sLean CMD: ")
|
2014-09-04 22:43:31 +00:00
|
|
|
(lean-server-send-cmd-async (lean-cmd-eval lean-cmd)
|
|
|
|
'message))
|
2014-08-25 20:31:12 +00:00
|
|
|
|
2014-09-02 05:36:26 +00:00
|
|
|
;; Clear Cache
|
|
|
|
(defun lean-clear-cache ()
|
|
|
|
"Send CLEAR_CACHE command to lean-server"
|
|
|
|
(interactive)
|
|
|
|
(call-process (lean-get-executable "linja") nil 0 nil "clear-cache")
|
2014-09-04 22:43:31 +00:00
|
|
|
(lean-server-send-cmd-async (lean-cmd-clear-cache)))
|
2014-09-02 05:36:26 +00:00
|
|
|
|
2014-08-14 00:02:49 +00:00
|
|
|
(provide 'lean-type)
|