feat(emacs/lean-mode): lean-exec-at-pos uses timer to wait until flycheck process is over
close #790
This commit is contained in:
parent
40471ca8e3
commit
6443de67d4
2 changed files with 41 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
;;; lean-mode.el --- Emacs mode for Lean theorem prover
|
;;; lean-mode.el --- Emacs mode for Lean theorem prover
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2013, 2014 Microsoft Corporation. All rights reserved.
|
;; Copyright (c) 2013, 2014 Microsoft Corporation. All rights reserved.
|
||||||
;; Copyright (c) 2015, 2014 Soonho Kong. All rights reserved.
|
;; Copyright (c) 2014, 2015 Soonho Kong. All rights reserved.
|
||||||
;;
|
;;
|
||||||
;; Author: Leonardo de Moura <leonardo@microsoft.com>
|
;; Author: Leonardo de Moura <leonardo@microsoft.com>
|
||||||
;; Soonho Kong <soonhok@cs.cmu.edu>
|
;; Soonho Kong <soonhok@cs.cmu.edu>
|
||||||
|
@ -93,6 +93,31 @@
|
||||||
g-lean-exec-at-pos-buf variable"
|
g-lean-exec-at-pos-buf variable"
|
||||||
(setq g-lean-exec-at-pos-buf (s-append string g-lean-exec-at-pos-buf)))
|
(setq g-lean-exec-at-pos-buf (s-append string g-lean-exec-at-pos-buf)))
|
||||||
|
|
||||||
|
(defun lean-start-process (args filter-fn sentinel-fn)
|
||||||
|
"Start process with filter and sentinel functions"
|
||||||
|
(let ((p (apply 'start-process args)))
|
||||||
|
(set-process-filter p filter-fn)
|
||||||
|
(set-process-sentinel p sentinel-fn)
|
||||||
|
(set-process-coding-system p 'utf-8 'utf-8)
|
||||||
|
(set-process-query-on-exit-flag p nil)))
|
||||||
|
|
||||||
|
(defvar lean-exec-at-pos-timer nil
|
||||||
|
"Timer for `lean-exec-at-pos-with-timer' to reschedule itself, or nil.")
|
||||||
|
|
||||||
|
(defun lean-exec-at-pos-with-timer (args filter-fn sentinel-fn)
|
||||||
|
"Run lean-exec-at-pos with a timer. It waits until flycheck is finished."
|
||||||
|
(when lean-exec-at-pos-timer
|
||||||
|
(cancel-timer lean-exec-at-pos-timer))
|
||||||
|
(cond ((flycheck-running-p)
|
||||||
|
(message "flycheck-lean is running...")
|
||||||
|
(setq lean-exec-at-pos-timer
|
||||||
|
(run-at-time
|
||||||
|
lean-exec-at-pos-wait-time nil
|
||||||
|
`(lambda () (lean-exec-at-pos-with-timer ',args ',filter-fn ',sentinel-fn)))))
|
||||||
|
(t
|
||||||
|
(message "flycheck is over, start lean-process...")
|
||||||
|
(lean-start-process args filter-fn sentinel-fn))))
|
||||||
|
|
||||||
(defun lean-exec-at-pos (process-name process-buffer-name &rest options)
|
(defun lean-exec-at-pos (process-name process-buffer-name &rest options)
|
||||||
"Execute Lean by providing current position with optional
|
"Execute Lean by providing current position with optional
|
||||||
agruments. The output goes to 'process-buffer-name' buffer, which
|
agruments. The output goes to 'process-buffer-name' buffer, which
|
||||||
|
@ -135,12 +160,13 @@ will be flushed everytime it's executed."
|
||||||
,(int-to-string (current-column)))
|
,(int-to-string (current-column)))
|
||||||
options
|
options
|
||||||
cache-option
|
cache-option
|
||||||
`(,target-file-name)))
|
`(,target-file-name))))
|
||||||
(p (apply 'start-process process-args)))
|
(cond ((and cache-option (flycheck-running-p))
|
||||||
(set-process-filter p 'lean-exec-at-pos-filter)
|
;; Cache is used and flycheck is running
|
||||||
(set-process-sentinel p 'lean-exec-at-pos-sentinel)
|
(lean-exec-at-pos-with-timer process-args 'lean-exec-at-pos-filter 'lean-exec-at-pos-sentinel))
|
||||||
(set-process-coding-system p 'utf-8 'utf-8)
|
(t
|
||||||
(set-process-query-on-exit-flag p nil)))
|
;; start lean-process immediately
|
||||||
|
(lean-start-process process-args 'lean-exec-at-pos-filter 'lean-exec-at-pos-sentinel)))))
|
||||||
|
|
||||||
(defun lean-show-goal-at-pos ()
|
(defun lean-show-goal-at-pos ()
|
||||||
"Show goal at the current point. If the current point is a
|
"Show goal at the current point. If the current point is a
|
||||||
|
|
|
@ -183,6 +183,14 @@ false (nil)."
|
||||||
:group 'lean
|
:group 'lean
|
||||||
:type 'number)
|
:type 'number)
|
||||||
|
|
||||||
|
(defcustom lean-exec-at-pos-wait-time 0.1
|
||||||
|
"When flycheck process is running, wait for
|
||||||
|
lean-exec-at-pos-wait-time (seconds) and try to run
|
||||||
|
lean-exec-at-pos-with-timer again.
|
||||||
|
See the body of lean-exec-at-pos-with-timer"
|
||||||
|
:group 'lean
|
||||||
|
:type 'number)
|
||||||
|
|
||||||
(defcustom lean-keybinding-std-exe1 (kbd "C-c C-x")
|
(defcustom lean-keybinding-std-exe1 (kbd "C-c C-x")
|
||||||
"Lean Keybinding for std-exe #1"
|
"Lean Keybinding for std-exe #1"
|
||||||
:group 'lean-keybinding :type 'key-sequence)
|
:group 'lean-keybinding :type 'key-sequence)
|
||||||
|
|
Loading…
Reference in a new issue