feat(emacs/lean-company): add auto-completion for option names
This commit is contained in:
parent
51a0d154d1
commit
f7ab2f7903
2 changed files with 47 additions and 10 deletions
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
(defun company-lean-hook ()
|
(defun company-lean-hook ()
|
||||||
(set (make-local-variable 'company-backends) '(company-lean--import
|
(set (make-local-variable 'company-backends) '(company-lean--import
|
||||||
|
company-lean--option-name
|
||||||
company-lean--findg
|
company-lean--findg
|
||||||
company-lean--findp))
|
company-lean--findp))
|
||||||
(setq-local company-tooltip-limit 20) ; bigger popup window
|
(setq-local company-tooltip-limit 20) ; bigger popup window
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
(defun company-lean--check-prefix ()
|
(defun company-lean--check-prefix ()
|
||||||
"Check whether to use company-lean or not"
|
"Check whether to use company-lean or not"
|
||||||
(or (company-lean--import-prefix)
|
(or (company-lean--import-prefix)
|
||||||
|
(company-lean--option-name-prefix)
|
||||||
(company-lean--findg-prefix)
|
(company-lean--findg-prefix)
|
||||||
(company-lean--findp-prefix)))
|
(company-lean--findp-prefix)))
|
||||||
|
|
||||||
|
@ -55,7 +57,7 @@
|
||||||
(--zip-with (propertize it 'file-name other) candidates lean-files))))
|
(--zip-with (propertize it 'file-name other) candidates lean-files))))
|
||||||
|
|
||||||
(defun company-lean--import-prefix ()
|
(defun company-lean--import-prefix ()
|
||||||
"FINDG is triggered when it looks at '_'"
|
"Import auto-completion is triggered when it looks at 'import ...'"
|
||||||
(when (looking-back
|
(when (looking-back
|
||||||
(rx "import"
|
(rx "import"
|
||||||
(* (+ white)
|
(* (+ white)
|
||||||
|
@ -95,6 +97,26 @@
|
||||||
(location (company-lean--import-location arg))
|
(location (company-lean--import-location arg))
|
||||||
(sorted t)))
|
(sorted t)))
|
||||||
|
|
||||||
|
;; OPTION
|
||||||
|
;; ======
|
||||||
|
(defun company-lean--option-name-prefix ()
|
||||||
|
"Option auto-completion is triggered when it looks at 'set-option '"
|
||||||
|
(when (looking-back (rx "set_option" (+ white) (* (or alnum digit "." "_"))))
|
||||||
|
(company-grab-symbol)))
|
||||||
|
|
||||||
|
(defun company-lean--option-name-candidates (prefix)
|
||||||
|
(let ((candidates
|
||||||
|
(lean-get-options-sync-with-cont
|
||||||
|
(lambda (option-record-alist)
|
||||||
|
(-map 'car option-record-alist)))))
|
||||||
|
(--filter (s-starts-with? prefix it) candidates)))
|
||||||
|
|
||||||
|
(defun company-lean--option-name (command &optional arg &rest ignored)
|
||||||
|
(case command
|
||||||
|
(prefix (company-lean--option-name-prefix))
|
||||||
|
(candidates (company-lean--option-name-candidates arg))
|
||||||
|
(sorted t)))
|
||||||
|
|
||||||
;; FINDG
|
;; FINDG
|
||||||
;; =====
|
;; =====
|
||||||
|
|
||||||
|
@ -132,12 +154,21 @@
|
||||||
;; FINDP
|
;; FINDP
|
||||||
;; -----
|
;; -----
|
||||||
(defun company-lean--need-autocomplete ()
|
(defun company-lean--need-autocomplete ()
|
||||||
(not (looking-back
|
(interactive)
|
||||||
(rx (or "theorem" "definition" "lemma" "axiom" "parameter"
|
(cond ((looking-back
|
||||||
"variable" "hypothesis" "conjecture"
|
(rx (or "theorem" "definition" "lemma" "axiom" "parameter"
|
||||||
"corollary" "open")
|
"variable" "hypothesis" "conjecture"
|
||||||
(+ white)
|
"corollary" "open")
|
||||||
(* (not white))))))
|
(+ white)
|
||||||
|
(* (not white))))
|
||||||
|
nil)
|
||||||
|
((looking-back (rx "set_option"
|
||||||
|
(+ white)
|
||||||
|
(+ (or alnum digit "." "_"))
|
||||||
|
(+ white)
|
||||||
|
(* (or alnum digit "." "_"))))
|
||||||
|
nil)
|
||||||
|
(t t)))
|
||||||
|
|
||||||
(defun company-lean--findp-prefix ()
|
(defun company-lean--findp-prefix ()
|
||||||
"Returns the symbol to complete. Also, if point is on a dot,
|
"Returns the symbol to complete. Also, if point is on a dot,
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
(defun lean-set-option ()
|
(defun lean-set-option ()
|
||||||
"Set Lean option."
|
"Set Lean option."
|
||||||
(interactive)
|
(interactive)
|
||||||
(lean-get-options-with-cont 'lean-set-option-cont))
|
(lean-get-options-async-with-cont 'lean-set-option-cont))
|
||||||
|
|
||||||
(defun lean-option-read-bool (prompt)
|
(defun lean-option-read-bool (prompt)
|
||||||
(completing-read prompt'(("true" 1) ("false" 2)) nil t "" nil "true"))
|
(completing-read prompt'(("true" 1) ("false" 2)) nil t "" nil "true"))
|
||||||
|
@ -166,16 +166,22 @@
|
||||||
`(,(lean-option-record-name option-record) . ,option-record)))
|
`(,(lean-option-record-name option-record) . ,option-record)))
|
||||||
str-list)))
|
str-list)))
|
||||||
|
|
||||||
(defun lean-get-options-with-cont (cont)
|
(defun lean-get-options-async-with-cont (cont)
|
||||||
"Get Lean option and call continuation"
|
"Get Lean option and call continuation"
|
||||||
(lean-server-send-cmd-async (lean-cmd-options)
|
(lean-server-send-cmd-async (lean-cmd-options)
|
||||||
(lambda (option-record-alist)
|
(lambda (option-record-alist)
|
||||||
(funcall cont option-record-alist))))
|
(funcall cont option-record-alist))))
|
||||||
|
|
||||||
|
(defun lean-get-options-sync-with-cont (cont)
|
||||||
|
"Get Lean option and call continuation"
|
||||||
|
(lean-server-send-cmd-sync (lean-cmd-options)
|
||||||
|
(lambda (option-record-alist)
|
||||||
|
(funcall cont option-record-alist))))
|
||||||
|
|
||||||
(defun lean-get-options ()
|
(defun lean-get-options ()
|
||||||
"Get Lean option and call continuation"
|
"Get Lean option and call continuation"
|
||||||
(interactive)
|
(interactive)
|
||||||
(lean-get-options-with-cont
|
(lean-get-options-async-with-cont
|
||||||
(lambda (option-record-alist)
|
(lambda (option-record-alist)
|
||||||
(message
|
(message
|
||||||
(s-join "\n"
|
(s-join "\n"
|
||||||
|
|
Loading…
Reference in a new issue