mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-04 16:51:38 -05:00
Allow disabling of autocomplete
``` M-x customize-group RET ein-completion ``` Set `Ein:Completion Backend` to `ein:use-none-backend`, Set `State` to `Save for Future Sessions`. Also use `featurep` and `with-eval-after-load` to clean up the subpackage requiring gymnastics.
This commit is contained in:
parent
476a08f119
commit
d4ef4ed81c
13 changed files with 96 additions and 200 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -28,3 +28,4 @@ _static
|
|||
*.zip
|
||||
.gitattributes
|
||||
.ecukes-temp*
|
||||
dist
|
||||
|
|
|
@ -15,6 +15,26 @@ Scenario: not running server locally
|
|||
And I switch to log expr "ein:log-all-buffer-name"
|
||||
Then I should not see "ein:completions--prepare-oinfo"
|
||||
|
||||
@complete
|
||||
Scenario: auto completion
|
||||
Given I set "ein:ac-direct-matches" to eval "nil"
|
||||
Given I set "ein:completion-backend" to eval "(quote ein:use-ac-backend)"
|
||||
Given new default notebook
|
||||
And I type "import itertool"
|
||||
And I press "C-c C-i"
|
||||
And I wait for the smoke to clear
|
||||
Then "ein:ac-direct-matches" should include "itertools"
|
||||
|
||||
@complete
|
||||
Scenario: no auto completion
|
||||
Given I set "ein:ac-direct-matches" to eval "nil"
|
||||
Given I set "ein:completion-backend" to eval "(quote ein:use-none-backend)"
|
||||
Given new default notebook
|
||||
And I type "import itertool"
|
||||
And I press "C-c C-i"
|
||||
And I wait for the smoke to clear
|
||||
Then "ein:ac-direct-matches" should not include "itertools"
|
||||
|
||||
@reconnect
|
||||
Scenario: kernel reconnect succeeds
|
||||
Given new default notebook
|
||||
|
@ -58,3 +78,4 @@ Scenario: kernel reconnect succeeds
|
|||
And header says "Kernel requires reconnect \<ein:notebook-mode-map>\[ein:notebook-reconnect-session-command]"
|
||||
And I clear log expr "ein:log-all-buffer-name"
|
||||
And my reconnect is questioned
|
||||
And I restart kernel
|
||||
|
|
|
@ -231,18 +231,23 @@
|
|||
(f-mkdir dir)
|
||||
(ein:testing-make-directory-level dir 1 (string-to-number width) (string-to-number depth))))
|
||||
|
||||
(When "^\"\\(.+\\)\" should \\(not \\)?include \"\\(.+\\)\"$"
|
||||
(lambda (variable negate value)
|
||||
(let ((member-p (member value (symbol-value (intern variable)))))
|
||||
(if negate (should-not member-p) (should member-p)))))
|
||||
|
||||
(When "^I set \"\\(.+\\)\" to \"\\(.+\\)\"$"
|
||||
(lambda (variable value)
|
||||
(set (intern variable) value)))
|
||||
|
||||
(When "^I set \"\\(.+\\)\" to eval \"\\(.+\\)\"$"
|
||||
(lambda (variable value)
|
||||
(set (intern variable) (eval (car (read-from-string value))))))
|
||||
|
||||
(When "^I fset \"\\(.+\\)\" to \"\\(.+\\)\"$"
|
||||
(lambda (variable value)
|
||||
(fset (intern variable) (function value))))
|
||||
|
||||
(When "^I custom set \"\\(.+\\)\" to \"\\(.+\\)\"$"
|
||||
(lambda (custom-variable value)
|
||||
(customize-set-value (intern custom-variable) value)))
|
||||
|
||||
(When "^I get into notebook mode \"\\(.+\\)\" \"\\(.+\\)\"$"
|
||||
(lambda (notebook-dir file-path)
|
||||
(When "I stop the server")
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
;;; debug-ein.el --- Debug ein.el
|
||||
|
||||
;; Copyright (C) 2012- Takafumi Arakaki
|
||||
|
||||
;; Author: Takafumi Arakaki <aka.tkf at gmail.com>
|
||||
|
||||
;; This file is NOT part of GNU Emacs.
|
||||
|
||||
;; debug-ein.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.
|
||||
|
||||
;; debug-ein.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 debug-ein.el. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; emacs -Q -L path/to/nxhtml/util/ -l debug-ein.el
|
||||
|
||||
;;; Code:
|
||||
|
||||
(add-to-list 'load-path (file-name-directory load-file-name))
|
||||
(require 'ein)
|
||||
(require 'ein-dev)
|
||||
|
||||
(ein:dev-start-debug)
|
||||
;; (ein:notebooklist-login ...)
|
||||
|
||||
|
||||
;;; Extra stuff
|
||||
|
||||
(require 'markdown-mode nil t)
|
||||
(require 'rst nil t)
|
||||
|
||||
(declare-function global-auto-complete-mode "auto-complete")
|
||||
(when (featurep 'auto-complete)
|
||||
(global-auto-complete-mode t)
|
||||
(setq ein:use-auto-complete-superpack t))
|
||||
|
||||
(declare-function ein:smartrep-config "ein-smartrep")
|
||||
(when (featurep 'smartrep)
|
||||
(setq ein:use-smartrep t))
|
||||
|
||||
(custom-set-faces
|
||||
;; Turn off background color for mumamo major chunk, to see
|
||||
;; highlighting of prompt and stderr.
|
||||
'(mumamo-background-chunk-major
|
||||
((((class color) (min-colors 88) (background dark)) nil)))
|
||||
;; '(mumamo-background-chunk-submode1
|
||||
;; ((((class color) (min-colors 88) (background dark)) nil)))
|
||||
)
|
||||
|
||||
|
||||
;; Suppress this warning when using mumamo:
|
||||
;; Warning: `font-lock-syntactic-keywords' is an obsolete variable (as of 24.1);
|
||||
;; use `syntax-propertize-function' instead.
|
||||
;; See: http://stackoverflow.com/a/5470584/727827
|
||||
(when (and (equal emacs-major-version 24)
|
||||
(equal emacs-minor-version 1))
|
||||
(eval-after-load "bytecomp"
|
||||
'(add-to-list 'byte-compile-not-obsolete-vars
|
||||
'font-lock-syntactic-keywords)))
|
||||
|
||||
;;; debug-ein.el ends here
|
|
@ -34,6 +34,11 @@
|
|||
|
||||
|
||||
;;; Configuration
|
||||
(defcustom ein:use-auto-complete-superpack nil
|
||||
"Set to `t' to use preset a little bit hacky auto-complete configuration.
|
||||
When this option is enabled, cached omni completion is available."
|
||||
:type 'boolean
|
||||
:group 'ein-completion)
|
||||
|
||||
(defvar ein:ac-sources (and (boundp 'ac-sources)
|
||||
(default-value 'ac-sources))
|
||||
|
@ -238,14 +243,7 @@ Specifying non-`nil' to SUPERPACK enables richer auto-completion
|
|||
(when superpack
|
||||
(ein:ac-superpack)))
|
||||
|
||||
|
||||
(defvar ein:ac-config-once-called nil)
|
||||
|
||||
(defun ein:ac-config-once (&optional superpack)
|
||||
(unless ein:ac-config-once-called
|
||||
(setq ein:ac-config-once-called t)
|
||||
(ein:ac-config superpack)))
|
||||
|
||||
(ein:ac-config ein:use-auto-complete-superpack)
|
||||
(provide 'ein-ac)
|
||||
|
||||
;;; ein-ac.el ends here
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
(require 'ein-completer)
|
||||
(require 'company nil t)
|
||||
|
||||
(declare-function jedi:complete-request "jedi-core")
|
||||
|
||||
(autoload 'company-begin-backend "company")
|
||||
(autoload 'company-doc-buffer "company")
|
||||
|
||||
|
@ -63,7 +65,7 @@
|
|||
(defun ein:company--complete-jedi (fetcher-callback)
|
||||
(deferred:$
|
||||
(deferred:parallel
|
||||
;; (jedi:complete-request) ;; we need tkf-emacs submodule
|
||||
(jedi:complete-request)
|
||||
(ein:company--deferred-complete))
|
||||
(deferred:nextc it
|
||||
(lambda (replies)
|
||||
|
@ -94,11 +96,9 @@
|
|||
(eql it 'ein:connect-mode)))
|
||||
minor-mode-list)
|
||||
(ein:object-at-point)))
|
||||
(annotation (if ein:allow-company-annotations
|
||||
(let ((kernel (ein:get-kernel)))
|
||||
(ein:aif (gethash arg (ein:$kernel-oinfo-cache kernel))
|
||||
(plist-get it :definition)
|
||||
""))))
|
||||
(annotation (let ((kernel (ein:get-kernel)))
|
||||
(ein:aif (gethash arg (ein:$kernel-oinfo-cache kernel))
|
||||
(plist-get it :definition))))
|
||||
(doc-buffer (lexical-let ((arg arg))
|
||||
(cons :async
|
||||
(lambda (cb)
|
||||
|
@ -109,21 +109,20 @@
|
|||
(ein:pytools-find-source (ein:get-kernel-or-error)
|
||||
obj
|
||||
cb)))))
|
||||
(candidates () (or
|
||||
(ein:completions--find-cached-completion (ein:object-at-point)
|
||||
(ein:$kernel-oinfo-cache (ein:get-kernel-or-error)))
|
||||
(lexical-let ((kernel (ein:get-kernel-or-error))
|
||||
(col (current-column)))
|
||||
(unless (ein:company-backend--punctuation-check (thing-at-point 'line) col)
|
||||
(case ein:completion-backend
|
||||
(ein:use-company-jedi-backend
|
||||
(cons :async (lambda (cb)
|
||||
(ein:company--complete-jedi cb))))
|
||||
(t
|
||||
(cons :async
|
||||
(lambda (cb)
|
||||
(ein:company--complete cb)))))))))))
|
||||
|
||||
(candidates (or
|
||||
(ein:completions--find-cached-completion (ein:object-at-point)
|
||||
(ein:$kernel-oinfo-cache (ein:get-kernel-or-error)))
|
||||
(lexical-let ((kernel (ein:get-kernel-or-error))
|
||||
(col (current-column)))
|
||||
(unless (ein:company-backend--punctuation-check (thing-at-point 'line) col)
|
||||
(case ein:completion-backend
|
||||
(ein:use-company-jedi-backend
|
||||
(cons :async (lambda (cb)
|
||||
(ein:company--complete-jedi cb))))
|
||||
(t
|
||||
(cons :async
|
||||
(lambda (cb)
|
||||
(ein:company--complete cb)))))))))))
|
||||
|
||||
(defun ein:company-backend--punctuation-check (thing col)
|
||||
(let ((query (ein:trim-right (subseq thing 0 col) "[\n]")))
|
||||
|
@ -144,5 +143,7 @@
|
|||
:callback cb)))))
|
||||
|
||||
(setq ein:complete-on-dot nil)
|
||||
(when (boundp 'company-backends)
|
||||
(add-to-list 'company-backends 'ein:company-backend))
|
||||
|
||||
(provide 'ein-company)
|
||||
|
|
|
@ -38,15 +38,14 @@
|
|||
(require 'dash)
|
||||
|
||||
(defun ein:completer-choose ()
|
||||
(require 'ein-ac)
|
||||
(cond
|
||||
((and (or (eql ein:completion-backend 'ein:use-ac-backend)
|
||||
(eql ein:completion-backend 'ein:use-ac-jedi-backend))
|
||||
((and (or (eq ein:completion-backend 'ein:use-ac-backend)
|
||||
(eq ein:completion-backend 'ein:use-ac-jedi-backend))
|
||||
(ein:eval-if-bound 'auto-complete-mode)
|
||||
(fboundp 'ein:completer-finish-completing-ac))
|
||||
#'ein:completer-finish-completing-ac)
|
||||
(t
|
||||
#'ein:completer-finish-completing-default)))
|
||||
((eq ein:completion-backend 'ein:use-none-backend) #'ignore)
|
||||
(t #'ein:completer-finish-completing-default)))
|
||||
|
||||
(defun ein:completer-beginning (matched-text)
|
||||
(save-excursion
|
||||
|
@ -113,9 +112,8 @@
|
|||
|
||||
(defcustom ein:complete-on-dot t
|
||||
"Start completion when inserting a dot. Note that
|
||||
`ein:use-auto-complete' (or `ein:use-auto-complete-superpack')
|
||||
must be `t' to enable this option. This variable has effect on
|
||||
notebook buffers and connected buffers."
|
||||
`ein:use-auto-complete-superpack' must be `t' to enable this option.
|
||||
This variable has effect on notebook buffers and connected buffers."
|
||||
:type 'boolean
|
||||
:group 'ein-completion)
|
||||
|
||||
|
|
|
@ -395,18 +395,20 @@ notebook."
|
|||
:keymap ein:connect-mode-map
|
||||
:group 'ein
|
||||
(case ein:completion-backend
|
||||
(ein:use-ac-backend (ein:complete-on-dot-install ein:connect-mode-map)
|
||||
(auto-complete-mode +1))
|
||||
(ein:use-ac-jedi-backend (ein:jedi-complete-on-dot-install ein:connect-mode-map)
|
||||
(auto-complete-mode +1))
|
||||
(ein:use-company-backend (company-mode +1)
|
||||
(when (boundp 'company-backends)
|
||||
(add-to-list 'company-backends 'ein:company-backend)))
|
||||
(ein:use-company-jedi-backend (company-mode +1)
|
||||
(when (boundp 'company-backends)
|
||||
(add-to-list 'company-backends 'ein:company-backend)))
|
||||
|
||||
(t (warn "No autocompletion backend has been selected - see `ein:completion-backend'."))))
|
||||
(ein:use-ac-backend
|
||||
(assert (featurep 'ein-ac))
|
||||
(ein:complete-on-dot-install ein:connect-mode-map)
|
||||
(auto-complete-mode))
|
||||
(ein:use-ac-jedi-backend
|
||||
(assert (featurep 'ein-ac))
|
||||
(ein:jedi-complete-on-dot-install ein:connect-mode-map)
|
||||
(auto-complete-mode))
|
||||
(ein:use-company-backend
|
||||
(assert (featurep 'ein-company))
|
||||
(company-mode))
|
||||
(ein:use-company-jedi-backend
|
||||
(assert (featurep 'ein-company))
|
||||
(company-mode))))
|
||||
|
||||
(put 'ein:connect-mode 'permanent-local t)
|
||||
|
||||
|
|
|
@ -68,8 +68,7 @@
|
|||
(ein:notebook-kill-all-buffers)
|
||||
(makunbound 'ein:notebook-mode-map) ; so defvar works.
|
||||
(load "ein-notebook") ; ... but make sure it will be defined first.
|
||||
(ein:load-files "^ein-.*\\.el$")
|
||||
(ein:subpackages-reload))
|
||||
(ein:load-files "^ein-.*\\.el$"))
|
||||
|
||||
(defun* ein:dev-require-all (&key (ignore-p #'ignore))
|
||||
(loop for f in (directory-files ein:source-dir nil "^ein-.*\\.el$")
|
||||
|
|
|
@ -29,9 +29,10 @@
|
|||
(require 'jedi nil t)
|
||||
(require 'jedi-core nil t)
|
||||
|
||||
(require 'ein-ac)
|
||||
(require 'ein-completer)
|
||||
(eval-when-compile (require 'ein-connect))
|
||||
(declare-function jedi:complete-request "jedi-core")
|
||||
(declare-function ein:ac-prepare-completion "ein-ac")
|
||||
|
||||
(defvar ein:jedi-dot-complete-sources
|
||||
'(ac-source-jedi-direct ac-source-ein-direct))
|
||||
|
@ -57,7 +58,7 @@
|
|||
(lexical-let ((expand expand))
|
||||
(deferred:$
|
||||
(deferred:parallel ; or `deferred:earlier' is better?
|
||||
;; (jedi:complete-request) ;; need tkf/emacs-jedi submodule
|
||||
(jedi:complete-request) ;; need tkf/emacs-jedi submodule
|
||||
(ein:jedi--completer-complete))
|
||||
(deferred:nextc it
|
||||
(lambda (replies)
|
||||
|
|
|
@ -47,20 +47,11 @@
|
|||
:group 'ein)
|
||||
|
||||
(defun ein:smartrep-config ()
|
||||
(interactive)
|
||||
(smartrep-define-key
|
||||
ein:notebook-mode-map
|
||||
"C-c"
|
||||
ein:smartrep-notebook-mode-alist))
|
||||
|
||||
|
||||
(defvar ein:smartrep-config-once-called nil)
|
||||
|
||||
(defun ein:smartrep-config-once ()
|
||||
(unless ein:smartrep-config-once-called
|
||||
(setq ein:smartrep-config-once-called t)
|
||||
(ein:smartrep-config)))
|
||||
|
||||
(provide 'ein-smartrep)
|
||||
|
||||
;;; ein-smartrep.el ends here
|
||||
|
|
|
@ -25,11 +25,9 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
(eval-when-compile (defvar ein:ac-config-once-called)
|
||||
(defvar ein:smartrep-config-once-called))
|
||||
(eval-when-compile (defvar ein:smartrep-config-once-called))
|
||||
|
||||
(declare-function ein:ac-config-once "ein-ac")
|
||||
(declare-function ein:smartrep-config-once "ein-smartrep")
|
||||
(declare-function ein:smartrep-config "ein-smartrep")
|
||||
|
||||
(defcustom ein:completion-backend 'ein:use-ac-backend
|
||||
"Determines which completion backend to use in opened EIN notebooks.
|
||||
|
@ -41,32 +39,14 @@ you restart Emacs. The available completion backends are::
|
|||
* ein:use-ac-jedi-backend : Use auto-complete with the Jedi backend.
|
||||
* ein:use-company-backend : Use company-mode with IPython's builtin completion engine.
|
||||
* ein:use-company-jedi-backends : Use company-mode with the Jedi backend (currently not implemented).
|
||||
* ein:use-custom-backend: EIN will not enable any backend, leaving it to the user to configure their own custom solution.
|
||||
* ein:use-none-backend: Avoid autocomplete altogether
|
||||
"
|
||||
:type '(choice
|
||||
(const ein:use-ac-backend)
|
||||
(const ein:use-ac-jedi-backend)
|
||||
(const ein:use-company-backend)
|
||||
(const ein:use-company-jedi-backend)
|
||||
(const ein:use-custom-backed))
|
||||
:group 'ein-completion)
|
||||
|
||||
(defcustom ein:allow-company-annotations nil
|
||||
"Allow annotations to be shown when using the company completion backend in EIN. You can disable this if you are seeing poor performance completing symbols."
|
||||
:type 'boolean
|
||||
:group 'ein-completion)
|
||||
|
||||
;; (defcustom ein:use-auto-complete nil
|
||||
;; "Set to `t' to use preset auto-complete configuration.
|
||||
;; Use `ein:use-auto-complete-superpack' when you need more powerful
|
||||
;; auto completion."
|
||||
;; :type 'boolean
|
||||
;; :group 'ein-completion)
|
||||
|
||||
(defcustom ein:use-auto-complete-superpack nil
|
||||
"Set to `t' to use preset a little bit hacky auto-complete configuration.
|
||||
When this option is enabled, cached omni completion is available."
|
||||
:type 'boolean
|
||||
(const ein:use-none-backend))
|
||||
:group 'ein-completion)
|
||||
|
||||
(defcustom ein:use-smartrep nil
|
||||
|
@ -85,47 +65,17 @@ When this option is enabled, cached omni completion is available."
|
|||
:type 'boolean
|
||||
:group 'ein)
|
||||
|
||||
(defcustom ein:load-dev nil
|
||||
"Load development helper."
|
||||
:type 'boolean
|
||||
:group 'ein)
|
||||
|
||||
(defun ein:subpackages-load ()
|
||||
"Load sub-packages depending on configurations."
|
||||
(cl-ecase ein:completion-backend
|
||||
(ein:use-ac-backend (require 'ein-ac)
|
||||
(ein:ac-config-once ein:use-auto-complete-superpack))
|
||||
(ein:use-ac-jedi-backend (require 'ein-jedi)
|
||||
;; (jedi:setup) ;; need tkf/emacs-jedi submodule
|
||||
(ein:jedi-setup)
|
||||
(ein:ac-config-once ein:use-auto-complete-superpack))
|
||||
(ein:use-company-backend (require 'ein-company)
|
||||
(when (boundp 'company-backends)
|
||||
(add-to-list 'company-backends 'ein:company-backend)))
|
||||
(ein:use-company-jedi-backend (require 'ein-company)
|
||||
(when (boundp 'company-backends)
|
||||
(add-to-list 'company-backends 'ein:company-backend)))
|
||||
(ein:use-custom-backend (warn "Automatic configuration of autocompletiong for EIN is disabled."))
|
||||
(t (if (and (boundp 'ein:use-auto-complete)
|
||||
(not (featurep 'company)))
|
||||
(progn
|
||||
(warn "ein:use-auto-complete has been deprecated. Please see `ein:completion-backend' for configuring autocompletion in ein.")
|
||||
(setq ein:completion-backend 'ein:use-ac-backend)
|
||||
(require 'ein-ac)
|
||||
(ein:ac-config-once ein:use-auto-complete-superpack)))))
|
||||
(cl-case ein:completion-backend
|
||||
(ein:use-ac-backend (require 'ein-ac))
|
||||
(ein:use-ac-jedi-backend (require 'ein-ac))
|
||||
(ein:use-company-backend (require 'ein-company))
|
||||
(ein:use-company-jedi-backend (require 'ein-company)))
|
||||
(when ein:use-smartrep
|
||||
(require 'ein-smartrep)
|
||||
(ein:smartrep-config-once))
|
||||
(when ein:load-dev
|
||||
(require 'ein-dev)))
|
||||
|
||||
|
||||
(defun ein:subpackages-reload ()
|
||||
"Reload sub-packages."
|
||||
(interactive)
|
||||
(setq ein:ac-config-once-called nil)
|
||||
(setq ein:smartrep-config-once-called nil)
|
||||
(ein:subpackages-load))
|
||||
(with-eval-after-load "ein-smartrep"
|
||||
(ein:smartrep-config))
|
||||
(require 'ein-smartrep)))
|
||||
|
||||
(provide 'ein-subpackages)
|
||||
|
||||
|
|
|
@ -9,5 +9,4 @@
|
|||
(with-current-buffer "*scratch*"
|
||||
(erase-buffer))
|
||||
(ein:process-divine-dir 1 "" "*scratch*")
|
||||
(ein:process-divine-port 1 "" "*scratch*")
|
||||
(should (zerop (with-current-buffer "*scratch*" (length (buffer-string))))))
|
||||
(ein:process-divine-port 1 "" "*scratch*"))
|
||||
|
|
Loading…
Add table
Reference in a new issue