2017-03-04 21:25:21 -06:00
|
|
|
;;; ein-company.el --- Support for completion using company back-end.
|
2016-03-03 13:29:00 -06:00
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
;; Copyright (C) 2017 - John Miller
|
2016-03-03 13:29:00 -06:00
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
;; Author: John Miller <millejoh at mac.com>
|
2016-03-03 13:29:00 -06:00
|
|
|
|
|
|
|
;; This file is NOT part of GNU Emacs.
|
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
;; ein-company.el is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2016-03-03 13:29:00 -06:00
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
;; ein-company.el is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2016-03-03 13:29:00 -06:00
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with ein-ac.el. If not, see <http://www.gnu.org/licenses/>.
|
2016-03-03 13:29:00 -06:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
;;
|
2016-03-03 13:29:00 -06:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
(eval-when-compile (require 'cl))
|
|
|
|
(require 'company nil t)
|
|
|
|
(require 'dash)
|
2016-03-10 15:15:44 -06:00
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
(require 'ein-core)
|
2016-03-10 15:15:44 -06:00
|
|
|
|
2017-03-04 21:25:21 -06:00
|
|
|
(defun ein:company-backend (command &optional arg &rest ignore)
|
2016-03-03 13:29:00 -06:00
|
|
|
(interactive (list 'interactive))
|
|
|
|
(cl-case command
|
2017-03-04 21:25:21 -06:00
|
|
|
(interactive (company-begin-backend 'ein:company-backend) )
|
2017-04-19 10:12:45 -05:00
|
|
|
(prefix (and (--filter (and (boundp it) (symbol-value it) (eql it 'ein:notebook-minor-mode))
|
|
|
|
minor-mode-list)
|
2017-03-04 21:25:21 -06:00
|
|
|
(thing-at-point 'line)))
|
|
|
|
(candidates () (lexical-let ((kernel (ein:get-kernel-or-error))
|
|
|
|
(arg arg)
|
|
|
|
(col (current-column)))
|
|
|
|
(cons :async
|
|
|
|
(lambda (cb)
|
|
|
|
(ein:kernel-complete kernel
|
|
|
|
arg
|
|
|
|
col
|
|
|
|
(list :complete_reply
|
|
|
|
(list #'ein:completer-finish-completing-company cb)))))))))
|
|
|
|
|
|
|
|
(cl-defun ein:completer-finish-completing-company (callback content -metadata-not-used-)
|
|
|
|
(ein:log 'debug "EIN:COMPANY-FINISH-COMPLETING: content=%S" content)
|
|
|
|
(let* ((beg (point))
|
|
|
|
(delta (- (plist-get content :cursor_end)
|
|
|
|
(plist-get content :cursor_start)))
|
|
|
|
(matched-text (buffer-substring beg (- beg delta)))
|
|
|
|
(matches (plist-get content :matches)))
|
|
|
|
(ein:log 'debug "EIN:COMPANY-FINISH-COMPLETING: matches=%s" matches)
|
2017-04-19 10:12:45 -05:00
|
|
|
(condition-case err
|
|
|
|
(funcall (car callback) matches)
|
|
|
|
(error (error (format "Error %s running ein company completer." err))))))
|
|
|
|
|
|
|
|
(add-to-list 'company-backends #'ein:company-backend)
|
2017-03-04 21:25:21 -06:00
|
|
|
|
|
|
|
(setq ein:complete-on-dot nil)
|
2016-03-10 15:15:44 -06:00
|
|
|
|
|
|
|
(provide 'ein-company)
|