|
28 | 28 | (eval-when-compile (require 'cl))
|
29 | 29 | (require 'json)
|
30 | 30 |
|
| 31 | +;; Optional dependency on tramp: |
| 32 | +(declare-function tramp-make-tramp-file-name "tramp") |
| 33 | +(declare-function tramp-file-name-localname "tramp") |
| 34 | +(declare-function tramp-dissect-file-name "tramp") |
| 35 | + |
31 | 36 | (defgroup ein nil
|
32 | 37 | "IPython notebook client in Emacs"
|
33 | 38 | :group 'applications
|
@@ -442,22 +447,42 @@ NOTE: This function creates new list."
|
442 | 447 | (funcall it filename)
|
443 | 448 | filename))
|
444 | 449 |
|
445 |
| -(defun ein:make-tramp-filename-translation (prefix) |
| 450 | +(defun ein:make-tramp-file-name (username remote-host python-filename) |
| 451 | + "Old (with multi-hops) tramp compatability function. |
| 452 | +Adapted from `slime-make-tramp-file-name'." |
| 453 | + (if (boundp 'tramp-multi-methods) |
| 454 | + (tramp-make-tramp-file-name nil nil |
| 455 | + username |
| 456 | + remote-host |
| 457 | + python-filename) |
| 458 | + (tramp-make-tramp-file-name nil |
| 459 | + username |
| 460 | + remote-host |
| 461 | + python-filename))) |
| 462 | + |
| 463 | +(defun ein:tramp-create-filename-translator (remote-host &optional username) |
446 | 464 | "Generate a pair of TO-PYTHON and FROM-PYTHON for
|
447 | 465 | `ein:filename-translations'.
|
448 | 466 |
|
449 | 467 | Usage::
|
450 | 468 |
|
451 | 469 | (setq ein:filename-translations
|
452 | 470 | `((8888
|
453 |
| - . ,(ein:make-tramp-filename-translation \"/scpc:MY-HOSTNAME:\")))) |
| 471 | + . ,(ein:tramp-create-filename-translator \"MY-HOSTNAME\")))) |
454 | 472 |
|
455 | 473 | This setting assumes that the IPython server which can be
|
456 | 474 | connected using the port 8888 in localhost is actually running in
|
457 |
| -the host named MY-HOSTNAME." |
458 |
| - (lexical-let ((prefix prefix)) |
459 |
| - (list (lambda (filename) (substring filename (length prefix))) |
460 |
| - (lambda (filename) (concat prefix filename))))) |
| 475 | +the host named MY-HOSTNAME. |
| 476 | +
|
| 477 | +Adapted from `slime-create-filename-translator'." |
| 478 | + (require 'tramp) |
| 479 | + (lexical-let ((remote-host remote-host) |
| 480 | + (username (or username (user-login-name)))) |
| 481 | + (list (lambda (emacs-filename) |
| 482 | + (tramp-file-name-localname |
| 483 | + (tramp-dissect-file-name emacs-filename))) |
| 484 | + (lambda (python-filename) |
| 485 | + (ein:make-tramp-file-name username remote-host python-filename))))) |
461 | 486 |
|
462 | 487 |
|
463 | 488 | ;;; utils.js compatible
|
|
0 commit comments