feat(emacs/lean-cmd): add SYNC command

This commit is contained in:
Soonho Kong 2014-10-02 17:29:01 -07:00
parent a25f38cd6b
commit 91f789c3db
3 changed files with 50 additions and 6 deletions

View file

@ -7,7 +7,6 @@
(require 'cl-lib)
(require 'lean-util)
;; Load
;; ----
(defun lean-cmd-load (file-name)
@ -271,6 +270,28 @@ It has the effect of evaluating a command in the end of the current file"
"Convert wait command to string"
(format "WAIT"))
;; SYNC
;; -----
(defun lean-cmd-sync (&optional lines)
"Force lean-server to synchonize with emacs buffer. SYNC command provides a number of lines in a buffer, and the contents of the buffer"
(unless lines
(let* ((buffer-contents (buffer-substring-no-properties
(point-min)
(point-max))))
(setq lines (s-lines buffer-contents))))
`(SYNC ,lines))
(defun lean-cmd-sync-get-num-lines (sync-cmd)
(length (cl-second sync-cmd)))
(defun lean-cmd-sync-get-lines (sync-cmd)
(cl-second sync-cmd))
(defun lean-cmd-sync-to-string (cmd)
"Convert sync command to string"
(format "SYNC %d\n%s"
(lean-cmd-sync-get-num-lines cmd)
(s-join "\n" (lean-cmd-sync-get-lines cmd))))
;; Type
;; ====
@ -295,7 +316,8 @@ It has the effect of evaluating a command in the end of the current file"
('VALID (lean-cmd-valid-to-string cmd))
('FINDP (lean-cmd-findp-to-string cmd))
('FINDG (lean-cmd-findg-to-string cmd))
('WAIT (lean-cmd-wait-to-string cmd))))
('WAIT (lean-cmd-wait-to-string cmd))
('SYNC (lean-cmd-sync-to-string cmd))))
;; ----------------
(provide 'lean-cmd)

View file

@ -239,7 +239,8 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd.
(lean-server-check-current-file))
('FINDG (lean-server-flush-changed-lines)
(lean-server-check-current-file))
('WAIT (lean-server-check-current-file))))
('WAIT (lean-server-check-current-file))
('SYNC )))
(defun lean-server-after-send-cmd (cmd)
"Operations to perform after sending a command."
@ -258,7 +259,7 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd.
('VALID ())
('FINDP ())
('FINDG ())
('WAIT ())))
('SYNC ())))
(defun lean-server-send-cmd (cmd)
"Send cmd to lean-server"

View file

@ -73,7 +73,21 @@
10))
(should (string= (lean-cmd-findg-get-patterns
(lean-cmd-findg 48 10 "+intro -and -elim"))
"+intro -and -elim")))
"+intro -and -elim"))
(should (= (lean-cmd-sync-get-num-lines
(lean-cmd-sync '("line 1"
"line 2"
"line 3")))
3))
(should (equal (lean-cmd-sync-get-lines
(lean-cmd-sync '("line 1"
"line 2"
"line 3")))
'("line 1"
"line 2"
"line 3"))))
(ert-deftest lean-test-cmd-to-string ()
"Test lean-cmd-to-string"
@ -110,4 +124,11 @@
(should (string= (lean-cmd-to-string (lean-cmd-findg 48 10 "+intro -and -elim"))
(concat "FINDG 48 10" "\n" "+intro -and -elim")))
(should (string= (lean-cmd-to-string (lean-cmd-wait))
(concat "WAIT"))))
(concat "WAIT")))
(should (string= (lean-cmd-to-string (lean-cmd-sync '("line 1"
"line 2"
"line 3")))
(concat "SYNC 3\n"
"line 1\n"
"line 2\n"
"line 3"))))