Make company completion conditional

This commit is contained in:
Rudi Grinberg 2018-02-27 00:50:42 +07:00
parent 1f295f49da
commit 49de3344f7
1 changed files with 20 additions and 11 deletions

View File

@ -237,11 +237,15 @@ backend")
(defvar utop-version "0" (defvar utop-version "0"
"detected version of utop. 0 for unknown") "detected version of utop. 0 for unknown")
(defvar utop--company-loaded nil)
(defun utop--supports-company () (defun utop--supports-company ()
;; version< only works on version numbers (and
(condition-case nil ;; version< only works on version numbers
(version< "2.0.2" utop-version) (condition-case nil
(error t))) (version< "2.0.2" utop-version)
(error t))
(featurep 'company)))
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
;; | Compability with different ocaml major modes | ;; | Compability with different ocaml major modes |
@ -632,12 +636,14 @@ it is started."
;; End of completion ;; End of completion
("completion-stop" ("completion-stop"
(utop-set-state 'edit) (utop-set-state 'edit)
;; (if (> (length utop-completion) 1) (if (utop--supports-company)
;; (with-current-buffer utop-complete-buffer (funcall utop--complete-k (nreverse utop-completion))
;; (with-output-to-temp-buffer "*Completions*" (progn
;; (display-completion-list (nreverse utop-completion)))) (if (> (length utop-completion) 1)
;; (minibuffer-hide-completions)) (with-current-buffer utop-complete-buffer
(funcall utop--complete-k (nreverse utop-completion)) (with-output-to-temp-buffer "*Completions*"
(display-completion-list (nreverse utop-completion))))
(minibuffer-hide-completions))))
(setq utop-completion nil))))) (setq utop-completion nil)))))
(defun utop-process-output (_process output) (defun utop-process-output (_process output)
@ -725,7 +731,10 @@ If ADD-TO-HISTORY is t then the input will be added to history."
;; We are now waiting for completion ;; We are now waiting for completion
(utop-set-state 'comp) (utop-set-state 'comp)
;; Send all lines to utop ;; Send all lines to utop
(utop-send-string "complete-company:\n") (utop-send-string
(if (utop--supports-company)
"complete-company:\n"
"complete:\n"))
(while lines (while lines
;; Send the line ;; Send the line
(utop-send-string (concat "data:" (car lines) "\n")) (utop-send-string (concat "data:" (car lines) "\n"))