mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 09:31:39 -05:00
Merge branch 'ac-dont-expand-on-dot-complete'
Improve `ein:completer-dot-complete` and `ein:jedi-dot-complete`. Do not expand common part when inserting dot, to make typing code containing dots less surprising. Call signature of ein:completer-complete is changed. The CALLBACKS argument must be passed as a keyword argument now. It was a positional argument.
This commit is contained in:
commit
41c9f872df
6 changed files with 55 additions and 17 deletions
|
@ -543,6 +543,9 @@ Change Log
|
|||
v0.2
|
||||
----
|
||||
|
||||
* Improve :el:symbol:`ein:completer-dot-complete` and
|
||||
:el:symbol:`ein:jedi-dot-complete`. Do not expand common part when
|
||||
inserting dot, to make typing code containing dots less surprising.
|
||||
* Add support for Jedi.el_. See :el:symbol:`ein:jedi-setup`.
|
||||
* Add a simple org-mode link support.
|
||||
* Add built-in multiple language fontification for notebook:
|
||||
|
|
|
@ -114,7 +114,11 @@ Call this function before calling `auto-complete'."
|
|||
(setq ein:ac-cache-matches (append matches ein:ac-cache-matches))
|
||||
(run-with-idle-timer 1 nil #'ein:ac-clear-cache)))
|
||||
|
||||
(defun ein:completer-finish-completing-ac (matched-text matches)
|
||||
(defun* ein:completer-finish-completing-ac
|
||||
(-matched-text-not-used-
|
||||
matches
|
||||
&key (expand ac-expand-on-auto-complete)
|
||||
&allow-other-keys)
|
||||
"Invoke completion using `auto-complete'.
|
||||
Only the argument MATCHES is used. MATCHED-TEXT is for
|
||||
compatibility with `ein:completer-finish-completing-default'."
|
||||
|
@ -125,7 +129,8 @@ compatibility with `ein:completer-finish-completing-default'."
|
|||
matched-text matches)
|
||||
(ein:ac-prepare-completion matches)
|
||||
(when matches ; No auto-complete drop-down list when no matches
|
||||
(auto-complete '(ac-source-ein-direct))))
|
||||
(let ((ac-expand-on-auto-complete expand))
|
||||
(auto-complete '(ac-source-ein-direct)))))
|
||||
|
||||
(defun ein:ac-clear-cache ()
|
||||
(setq ein:ac-cache-matches
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
(declare-function ac-cursor-on-diable-face-p "auto-complete")
|
||||
|
||||
(eval-when-compile (require 'cl))
|
||||
|
||||
(require 'ein-core)
|
||||
(require 'ein-log)
|
||||
(require 'ein-subpackages)
|
||||
|
@ -48,15 +50,16 @@
|
|||
(save-excursion
|
||||
(re-search-backward (concat matched-text "\\="))))
|
||||
|
||||
(defun ein:completer-finish-completing (_dummy_ content -metadata-not-used-)
|
||||
(defun ein:completer-finish-completing (args content -metadata-not-used-)
|
||||
(ein:log 'debug "COMPLETER-FINISH-COMPLETING: content=%S" content)
|
||||
(let ((matched-text (plist-get content :matched_text))
|
||||
(matches (plist-get content :matches))
|
||||
(completer (ein:completer-choose)))
|
||||
(ein:log 'debug "COMPLETER-FINISH-COMPLETING: completer=%s" completer)
|
||||
(funcall completer matched-text matches)))
|
||||
(apply completer matched-text matches args)))
|
||||
|
||||
(defun ein:completer-finish-completing-default (matched-text matches)
|
||||
(defun ein:completer-finish-completing-default (matched-text matches
|
||||
&rest -ignore-)
|
||||
(let* ((end (point))
|
||||
(beg (ein:completer-beginning matched-text))
|
||||
(word (if (and beg matches)
|
||||
|
@ -67,13 +70,28 @@
|
|||
(insert word))))
|
||||
|
||||
(defun* ein:completer-complete
|
||||
(kernel
|
||||
&optional
|
||||
(callbacks (list :complete_reply
|
||||
(cons #'ein:completer-finish-completing nil))))
|
||||
"Request completion to KERNEL.
|
||||
CALLBACKS is passed to `ein:kernel-complete'."
|
||||
(kernel &rest args &key callbacks &allow-other-keys)
|
||||
"Start completion for the code at point.
|
||||
|
||||
.. It sends `:complete_request' to KERNEL.
|
||||
CALLBACKS is passed to `ein:kernel-complete'.
|
||||
|
||||
If you specify CALLBACKS explicitly (i.e., you are not using
|
||||
`ein:completer-finish-completing'), keyword argument will be
|
||||
ignored. Otherwise, ARGS are passed as additional arguments
|
||||
to completer callback functions. ARGS **must** be keyword
|
||||
arguments.
|
||||
|
||||
EXPAND keyword argument is supported by
|
||||
`ein:completer-finish-completing-ac'. When it is specified,
|
||||
it overrides `ac-expand-on-auto-complete' when calling
|
||||
`auto-complete'."
|
||||
(interactive (list (ein:get-kernel)))
|
||||
(unless callbacks
|
||||
(setq callbacks
|
||||
(list :complete_reply
|
||||
(cons #'ein:completer-finish-completing
|
||||
(ein:plist-exclude args '(:callbacks))))))
|
||||
(ein:kernel-complete kernel
|
||||
(thing-at-point 'line)
|
||||
(current-column)
|
||||
|
@ -86,7 +104,7 @@ CALLBACKS is passed to `ein:kernel-complete'."
|
|||
(ein:and-let* ((kernel (ein:get-kernel))
|
||||
((not (ac-cursor-on-diable-face-p)))
|
||||
((ein:kernel-live-p kernel)))
|
||||
(ein:completer-complete kernel)))
|
||||
(ein:completer-complete kernel :expand nil)))
|
||||
|
||||
(defcustom ein:complete-on-dot t
|
||||
"Start completion when inserting a dot. Note that
|
||||
|
@ -106,5 +124,4 @@ notebook buffers and connected buffers."
|
|||
|
||||
(provide 'ein-completer)
|
||||
|
||||
|
||||
;;; ein-completer.el ends here
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
((ein:kernel-live-p kernel)))
|
||||
(ein:completer-complete
|
||||
kernel
|
||||
:callbacks
|
||||
(list :complete_reply
|
||||
(cons (lambda (_ &rest args) (deferred:callback-post d args))
|
||||
nil))))
|
||||
|
|
|
@ -315,6 +315,7 @@ Adapted from twittering-mode.el's `case-string'."
|
|||
|
||||
(defun ein:plist-iter (plist)
|
||||
"Return list of (key . value) in PLIST."
|
||||
;; FIXME: this is not needed. See: `ein:plist-exclude'.
|
||||
(loop for p in plist
|
||||
for i from 0
|
||||
for key-p = (= (% i 2) 0)
|
||||
|
@ -322,6 +323,16 @@ Adapted from twittering-mode.el's `case-string'."
|
|||
if key-p do (setq key p)
|
||||
else collect `(,key . ,p)))
|
||||
|
||||
(defun ein:plist-exclude (plist keys)
|
||||
"Exclude entries specified by KEYS in PLIST.
|
||||
|
||||
Example::
|
||||
|
||||
(ein:plist-exclude '(:a 1 :b 2 :c 3 :d 4) '(:b :c))"
|
||||
(loop for (k v) on plist by 'cddr
|
||||
unless (memq k keys)
|
||||
nconc (list k v)))
|
||||
|
||||
(defun ein:hash-keys (table)
|
||||
(let (keys)
|
||||
(maphash (lambda (k v) (push k keys)) table)
|
||||
|
|
|
@ -13,10 +13,11 @@
|
|||
(let* ((matched-text 'dummy-matched-text-value) ; value can be anything
|
||||
(matches 'dummy-matches-value)
|
||||
(content (list :matched_text matched-text
|
||||
:matches matches)))
|
||||
:matches matches))
|
||||
(args '(:extend t)))
|
||||
(mocker-let
|
||||
((ein:completer-choose () ((:output 'completer)))
|
||||
(completer
|
||||
(matched-text matches)
|
||||
((:input (list matched-text matches)))))
|
||||
(ein:completer-finish-completing '-not-used- content '-not-used-))))
|
||||
(matched-text matches &rest args)
|
||||
((:input (list matched-text matches args)))))
|
||||
(ein:completer-finish-completing args content '-not-used-))))
|
||||
|
|
Loading…
Add table
Reference in a new issue