mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 01:21:38 -05:00
Refactor ein:kernel-sync-directory
This commit is contained in:
parent
6dde09196a
commit
30011e7de6
1 changed files with 25 additions and 18 deletions
|
@ -446,30 +446,37 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete
|
||||||
|
|
||||||
;;; Utility functions
|
;;; Utility functions
|
||||||
|
|
||||||
|
(defun ein:kernel-request-stream (kernel code func &optional args)
|
||||||
|
(ein:kernel-execute
|
||||||
|
kernel
|
||||||
|
code
|
||||||
|
(list :output (cons (lambda (packed msg-type content)
|
||||||
|
(let ((func (car packed))
|
||||||
|
(args (cdr packed)))
|
||||||
|
(when (equal msg-type "stream")
|
||||||
|
(ein:aif (plist-get content :data)
|
||||||
|
(apply func it args)))))
|
||||||
|
(cons func args)))))
|
||||||
|
|
||||||
(defun ein:kernel-sync-directory (kernel buffer)
|
(defun ein:kernel-sync-directory (kernel buffer)
|
||||||
"Sync `default-directory' of BUFFER with cwd of KERNEL.
|
"Sync `default-directory' of BUFFER with cwd of KERNEL.
|
||||||
When no such directory exists, `default-directory' will not be changed."
|
When no such directory exists, `default-directory' will not be changed."
|
||||||
(ein:log 'info "Syncing directory of %s with kernel..." buffer)
|
(ein:log 'info "Syncing directory of %s with kernel..." buffer)
|
||||||
(ein:kernel-execute
|
(ein:kernel-request-stream
|
||||||
kernel
|
kernel
|
||||||
"__import__('sys').stdout.write(__import__('os').getcwd())"
|
"__import__('sys').stdout.write(__import__('os').getcwd())"
|
||||||
(list
|
(lambda (path buffer)
|
||||||
:output
|
(with-current-buffer buffer
|
||||||
(cons
|
(if (file-accessible-directory-p path)
|
||||||
(lambda (buf msg-type content)
|
(progn
|
||||||
(when (equal msg-type "stream")
|
(setq default-directory path)
|
||||||
(ein:aif (plist-get content :data)
|
(ein:log 'info
|
||||||
(with-current-buffer buf
|
"Syncing directory of %s with kernel...DONE (%s)"
|
||||||
(if (file-accessible-directory-p it)
|
buffer path))
|
||||||
(progn
|
(ein:log 'info
|
||||||
(setq default-directory it)
|
"Syncing directory of %s with kernel...FAILED (no dir: %s)"
|
||||||
(ein:log 'info
|
buffer path))))
|
||||||
"Syncing directory of %s with kernel...DONE (%s)"
|
(list buffer)))
|
||||||
buf it))
|
|
||||||
(ein:log 'info
|
|
||||||
"Syncing directory of %s with kernel...FAILED (no dir: %s)"
|
|
||||||
buf it))))))
|
|
||||||
buffer))))
|
|
||||||
|
|
||||||
(provide 'ein-kernel)
|
(provide 'ein-kernel)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue