mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 01:21:38 -05:00
Refactor ein:filename-to/from-python functions
This commit is contained in:
parent
d2c8c5eee6
commit
c4924efdbd
3 changed files with 18 additions and 11 deletions
|
@ -495,6 +495,14 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete
|
|||
|
||||
;;; Utility functions
|
||||
|
||||
(defun ein:kernel-filename-to-python (kernel filename)
|
||||
"See: `ein:filename-to-python'."
|
||||
(ein:filename-to-python (ein:$kernel-url-or-port kernel) filename))
|
||||
|
||||
(defun ein:kernel-filename-from-python (kernel filename)
|
||||
"See: `ein:filename-from-python'."
|
||||
(ein:filename-from-python (ein:$kernel-url-or-port kernel) filename))
|
||||
|
||||
(defun ein:kernel-construct-defstring (content)
|
||||
"Construct call signature from CONTENT of ``:object_info_reply``.
|
||||
Used in `ein:cell-finish-tooltip', etc."
|
||||
|
@ -548,9 +556,7 @@ When no such directory exists, `default-directory' will not be changed."
|
|||
"__import__('sys').stdout.write(__import__('os').getcwd())"
|
||||
(lambda (path kernel buffer)
|
||||
(with-current-buffer buffer
|
||||
(setq path (ein:filename-from-python
|
||||
path
|
||||
(ein:$kernel-url-or-port kernel)))
|
||||
(setq path (ein:kernel-filename-from-python kernel path))
|
||||
(if (file-accessible-directory-p path)
|
||||
(progn
|
||||
(setq default-directory path)
|
||||
|
@ -584,9 +590,7 @@ When no such directory exists, `default-directory' will not be changed."
|
|||
kernel
|
||||
"__import__('sys').stdout.write(__import__('os').getcwd())"
|
||||
(lambda (cwd kernel kernelinfo buffer)
|
||||
(setq cwd (ein:filename-from-python
|
||||
cwd
|
||||
(ein:$kernel-url-or-port kernel)))
|
||||
(setq cwd (ein:kernel-filename-from-python kernel cwd))
|
||||
(setf (ein:$kernelinfo-ccwd kernelinfo) cwd)
|
||||
;; sync buffer's `default-directory' with CWD
|
||||
(when (buffer-live-p buffer)
|
||||
|
|
|
@ -121,9 +121,8 @@ If OTHER-WINDOW is non-`nil', open the file in the other window."
|
|||
(destructuring-bind (filename &optional lineno &rest ignore)
|
||||
(split-string it "\n")
|
||||
(setq lineno (string-to-number lineno))
|
||||
(setq filename (ein:filename-from-python
|
||||
filename
|
||||
(ein:$kernel-url-or-port kernel)))
|
||||
(setq filename
|
||||
(ein:kernel-filename-from-python kernel filename))
|
||||
(ein:goto-file filename lineno other-window)
|
||||
(when (and notebook-buffer (not ein:@connect))
|
||||
(ein:connect-to-notebook-buffer notebook-buffer))
|
||||
|
|
|
@ -434,15 +434,19 @@ NOTE: This function creates new list."
|
|||
|
||||
;;; File name translation
|
||||
|
||||
;; Probably it's better to define `ein:filename-translations-get' as
|
||||
;; an EIEIO method so that I don't have to re-define functions such as
|
||||
;; `ein:kernel-filename-to-python' and `ein:kernel-filename-from-python'.
|
||||
|
||||
(defun ein:filename-translations-get (url-or-port)
|
||||
(ein:choose-setting 'ein:filename-translations url-or-port))
|
||||
|
||||
(defun ein:filename-to-python (filename url-or-port)
|
||||
(defun ein:filename-to-python (url-or-port filename)
|
||||
(ein:aif (car (ein:filename-translations-get url-or-port))
|
||||
(funcall it filename)
|
||||
filename))
|
||||
|
||||
(defun ein:filename-from-python (filename url-or-port)
|
||||
(defun ein:filename-from-python (url-or-port filename)
|
||||
(ein:aif (cadr (ein:filename-translations-get url-or-port))
|
||||
(funcall it filename)
|
||||
filename))
|
||||
|
|
Loading…
Add table
Reference in a new issue