Skip to content

Commit 3a31920

Browse files
committed
jupyter-tramp.el: Implement a file-exists-p handler
The default handler for `file-exists-p` relies on `tramp-connectable-p` which in turn checks the process associated with the buffer corresponding to `tramp-buffer-name` of the remote file. For Jupyter files there is no such process. * jupyter-tramp.el (jupyter-tramp-file-name-handler-alist): Register the new handler. (jupyter-tramp-connected-p): New function. (jupyter-tramp-file-remote-p): Use it. (jupyter-tramp-file-exists-p): New function.
1 parent 17d90ee commit 3a31920

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

jupyter-tramp.el

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ host, localname, ..., are all bound to values parsed from FILE."
102102
;; jupyter-tramp-expand-file-name
103103
;; jupyter-tramp-file-attributes
104104
;; jupyter-tramp-file-directory-p
105+
;; jupyter-tramp-file-exists-p
105106
;; jupyter-tramp-file-local-copy
106107
;; jupyter-tramp-file-name-all-completions
107108
;; jupyter-tramp-file-remote-p
@@ -135,7 +136,7 @@ host, localname, ..., are all bound to values parsed from FILE."
135136
(file-directory-p . jupyter-tramp-file-directory-p)
136137
(file-equal-p . tramp-handle-file-equal-p)
137138
(file-executable-p . tramp-handle-file-exists-p)
138-
(file-exists-p . tramp-handle-file-exists-p)
139+
(file-exists-p . jupyter-tramp-file-exists-p)
139140
(file-in-directory-p . tramp-handle-file-in-directory-p)
140141
(file-local-copy . jupyter-tramp-file-local-copy)
141142
(file-modes . tramp-handle-file-modes)
@@ -429,17 +430,23 @@ See `jupyter-tramp-get-file-model' for details on what a file model is."
429430

430431
(defvar url-http-open-connections)
431432

433+
(defun jupyter-tramp-connected-p (vec-or-filename)
434+
"Return non-nil if connected to a Jupyter based remote host."
435+
(let* ((vec (tramp-ensure-dissected-file-name vec-or-filename))
436+
(port (tramp-file-name-port-or-default vec))
437+
(key (cons (tramp-file-name-host vec)
438+
(if (numberp port) port
439+
(string-to-number port)))))
440+
(catch 'connected
441+
(dolist (conn (gethash key url-http-open-connections))
442+
(when (memq (process-status conn) '(run open connect))
443+
(throw 'connected t))))))
444+
432445
(defun jupyter-tramp-file-remote-p (file &optional identification connected)
433446
(when (file-name-absolute-p file)
434447
(with-parsed-tramp-file-name file nil
435448
(when (or (null connected)
436-
(let* ((port (or port (tramp-file-name-port-or-default v)))
437-
(key (cons host (if (numberp port) port
438-
(string-to-number port)))))
439-
(catch 'connected
440-
(dolist (conn (gethash key url-http-open-connections))
441-
(when (memq (process-status conn) '(run open connect))
442-
(throw 'connected t))))))
449+
(jupyter-tramp-connected-p v))
443450
(cl-case identification
444451
(method method)
445452
(host host)
@@ -448,6 +455,18 @@ See `jupyter-tramp-get-file-model' for details on what a file model is."
448455
(t (tramp-make-tramp-file-name
449456
method user domain host port "")))))))
450457

458+
;; Adapted from `tramp-handle-file-exists-p'
459+
(defun jupyter-tramp-file-exists-p (filename)
460+
;; `file-exists-p' is used as predicate in file name completion.
461+
;; We don't want to run it when `non-essential' is t, or there is
462+
;; no connection process yet.
463+
(when (or (jupyter-tramp-connected-p filename)
464+
(not non-essential))
465+
(with-parsed-tramp-file-name (expand-file-name filename) nil
466+
(with-tramp-file-property v localname "file-exists-p"
467+
(not (null (file-attributes filename)))))))
468+
469+
451470
;;; File name manipulation
452471

453472
(defun jupyter-tramp-expand-file-name (name &optional directory)

0 commit comments

Comments
 (0)