2012-11-19 20:49:17 +01:00
|
|
|
;;; ein-jedi.el --- ein Jedi
|
|
|
|
|
|
|
|
;; Copyright (C) 2012 Takafumi Arakaki
|
|
|
|
|
|
|
|
;; Author: Takafumi Arakaki <aka.tkf at gmail.com>
|
|
|
|
|
|
|
|
;; This file is NOT part of GNU Emacs.
|
|
|
|
|
|
|
|
;; ein-jedi.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.
|
|
|
|
|
|
|
|
;; ein-jedi.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.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with ein-jedi.el.
|
|
|
|
;; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2012-11-19 22:18:36 +01:00
|
|
|
(require 'jedi nil t)
|
2012-11-19 20:49:17 +01:00
|
|
|
|
2012-11-19 21:45:09 +01:00
|
|
|
(eval-when-compile (require 'ein-connect))
|
2012-11-19 20:49:17 +01:00
|
|
|
(require 'ein-ac)
|
|
|
|
(require 'ein-completer)
|
|
|
|
|
|
|
|
(defvar ein:jedi-dot-complete-sources
|
|
|
|
'(ac-source-jedi-direct ac-source-ein-direct))
|
|
|
|
|
2012-11-19 20:59:28 +01:00
|
|
|
(defun ein:jedi--completer-complete ()
|
|
|
|
(lexical-let ((d (deferred:new #'identity)))
|
|
|
|
(ein:and-let* ((kernel (ein:get-kernel))
|
|
|
|
((not (ac-cursor-on-diable-face-p)))
|
|
|
|
((ein:kernel-live-p kernel)))
|
|
|
|
(ein:completer-complete
|
|
|
|
kernel
|
|
|
|
(list :complete_reply
|
|
|
|
(cons (lambda (_ &rest args) (deferred:callback-post d args))
|
|
|
|
nil))))
|
|
|
|
d))
|
|
|
|
|
2012-11-19 21:25:41 +01:00
|
|
|
;;;###autoload
|
2012-12-05 22:52:05 +01:00
|
|
|
(defun* ein:jedi-complete (&key (expand ac-expand-on-auto-complete))
|
2012-11-19 22:02:55 +01:00
|
|
|
"Run completion using candidates calculated by EIN and Jedi."
|
2012-11-19 21:25:30 +01:00
|
|
|
(interactive)
|
2012-12-05 22:52:05 +01:00
|
|
|
(lexical-let ((expand expand))
|
|
|
|
(deferred:$
|
|
|
|
(deferred:parallel ; or `deferred:earlier' is better?
|
|
|
|
(jedi:complete-request)
|
|
|
|
(ein:jedi--completer-complete))
|
|
|
|
(deferred:nextc it
|
|
|
|
(lambda (replies)
|
|
|
|
(destructuring-bind
|
|
|
|
(_ ; ignore `jedi:complete-request' what returns.
|
|
|
|
((&key matched_text matches &allow-other-keys) ; :complete_reply
|
|
|
|
_)) ; ignore metadata
|
|
|
|
replies
|
|
|
|
(let ((ac-expand-on-auto-complete expand))
|
|
|
|
(if matches
|
|
|
|
(ein:completer-finish-completing-ac
|
|
|
|
matched_text matches
|
|
|
|
ein:jedi-dot-complete-sources)
|
|
|
|
(auto-complete ein:jedi-dot-complete-sources)))))))))
|
2012-11-19 20:49:17 +01:00
|
|
|
|
2012-11-19 21:25:41 +01:00
|
|
|
;;;###autoload
|
2012-11-19 20:49:17 +01:00
|
|
|
(defun ein:jedi-dot-complete ()
|
2012-11-19 22:02:55 +01:00
|
|
|
"Insert \".\" and run `ein:jedi-complete'."
|
2012-11-19 20:49:17 +01:00
|
|
|
(interactive)
|
|
|
|
(insert ".")
|
2012-12-05 22:52:34 +01:00
|
|
|
(ein:jedi-complete :expand nil))
|
2012-11-19 20:49:17 +01:00
|
|
|
|
|
|
|
(defun ein:jedi-complete-on-dot-install (map)
|
|
|
|
(ein:complete-on-dot-install map #'ein:jedi-dot-complete))
|
|
|
|
|
2012-11-19 21:45:09 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun ein:jedi-setup ()
|
2012-11-19 22:21:55 +01:00
|
|
|
"Setup auto-completion using EIN and Jedi.el_ together.
|
2012-11-19 22:02:55 +01:00
|
|
|
|
2012-11-19 22:21:55 +01:00
|
|
|
Jedi.el_ is a Python auto-completion library for Emacs.
|
2012-11-19 22:02:55 +01:00
|
|
|
To use EIN and Jedi together, add the following in your Emacs setup.::
|
|
|
|
|
2012-11-19 22:21:55 +01:00
|
|
|
(add-hook 'ein:connect-mode-hook 'ein:jedi-setup)
|
|
|
|
|
|
|
|
.. _Jedi.el: https://github.com/tkf/emacs-jedi"
|
2012-11-19 21:45:09 +01:00
|
|
|
(let ((map ein:connect-mode-map))
|
|
|
|
(define-key map "\C-c\C-i" 'ein:jedi-complete)
|
|
|
|
(ein:jedi-complete-on-dot-install map)))
|
2012-11-19 20:49:17 +01:00
|
|
|
|
|
|
|
(provide 'ein-jedi)
|
|
|
|
|
|
|
|
;;; ein-jedi.el ends here
|