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-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"
|
|
|
|
(let ((info-string (lean-info-record-to-string info-record)))
|
|
|
|
(when info-string
|
2014-10-14 16:27:25 +00:00
|
|
|
(when add-to-kill-ring
|
|
|
|
(kill-new
|
|
|
|
(substring-no-properties info-string)))
|
2014-10-28 21:06:03 +00:00
|
|
|
(when (or lean-show-proofstate-in-minibuffer
|
|
|
|
(not (lean-info-record-proofstate info-record)))
|
|
|
|
(message "%s" info-string))
|
|
|
|
(lean-output-to-buffer "*lean-info*" "--------------------------\n" nil)
|
|
|
|
(lean-output-to-buffer "*lean-info*" "%s\n" (list info-string)))))
|
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)
|