Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/elisp/slime/contrib/slime-tramp.el
990 views
1
2
(define-slime-contrib slime-tramp
3
"Filename translations for tramp"
4
(:authors "Marco Baringer <[email protected]>")
5
(:license "GPL")
6
(:slime-dependencies tramp)
7
(:on-load
8
(setq slime-to-lisp-filename-function #'slime-tramp-to-lisp-filename)
9
(setq slime-from-lisp-filename-function #'slime-tramp-from-lisp-filename)))
10
11
(defcustom slime-filename-translations nil
12
"Assoc list of hostnames and filename translation functions.
13
Each element is of the form (HOSTNAME-REGEXP TO-LISP FROM-LISP).
14
15
HOSTNAME-REGEXP is a regexp which is applied to the connection's
16
slime-machine-instance. If HOSTNAME-REGEXP maches then the
17
corresponding TO-LISP and FROM-LISP functions will be used to
18
translate emacs filenames and lisp filenames.
19
20
TO-LISP will be passed the filename of an emacs buffer and must
21
return a string which the underlying lisp understandas as a
22
pathname. FROM-LISP will be passed a pathname as returned by the
23
underlying lisp and must return something that emacs will
24
understand as a filename (this string will be passed to
25
find-file).
26
27
This list will be traversed in order, so multiple matching
28
regexps are possible.
29
30
Example:
31
32
Assuming you run emacs locally and connect to slime running on
33
the machine 'soren' and you can connect with the username
34
'animaliter':
35
36
(push (list \"^soren$\"
37
(lambda (emacs-filename)
38
(subseq emacs-filename (length \"/ssh:animaliter@soren:\")))
39
(lambda (lisp-filename)
40
(concat \"/ssh:animaliter@soren:\" lisp-filename)))
41
slime-filename-translations)
42
43
See also `slime-create-filename-translator'."
44
:type '(repeat (list :tag "Host description"
45
(regexp :tag "Hostname regexp")
46
(function :tag "To lisp function")
47
(function :tag "From lisp function")))
48
:group 'slime-lisp)
49
50
(defun slime-find-filename-translators (hostname)
51
(cond ((and hostname slime-filename-translations)
52
(or (cdr (assoc-if (lambda (regexp) (string-match regexp hostname))
53
slime-filename-translations))
54
(error "No filename-translations for hostname: %s" hostname)))
55
(t (list #'identity #'identity))))
56
57
(defun slime-make-tramp-file-name (username remote-host lisp-filename)
58
"Old (with multi-hops) tramp compatability function"
59
(if (boundp 'tramp-multi-methods)
60
(tramp-make-tramp-file-name nil nil
61
username
62
remote-host
63
lisp-filename)
64
(tramp-make-tramp-file-name nil
65
username
66
remote-host
67
lisp-filename)))
68
69
(defun* slime-create-filename-translator (&key machine-instance
70
remote-host
71
username)
72
"Creates a three element list suitable for push'ing onto
73
slime-filename-translations which uses Tramp to load files on
74
hostname using username. MACHINE-INSTANCE is a required
75
parameter, REMOTE-HOST defaults to MACHINE-INSTANCE and USERNAME
76
defaults to (user-login-name).
77
78
MACHINE-INSTANCE is the value returned by slime-machine-instance,
79
which is just the value returned by cl:machine-instance on the
80
remote lisp. REMOTE-HOST is the fully qualified domain name (or
81
just the IP) of the remote machine. USERNAME is the username we
82
should login with.
83
The functions created here expect your tramp-default-method or
84
tramp-default-method-alist to be setup correctly."
85
(lexical-let ((remote-host (or remote-host machine-instance))
86
(username (or username (user-login-name))))
87
(list (concat "^" machine-instance "$")
88
(lambda (emacs-filename)
89
(tramp-file-name-localname
90
(tramp-dissect-file-name emacs-filename)))
91
`(lambda (lisp-filename)
92
(slime-make-tramp-file-name
93
,username
94
,remote-host
95
lisp-filename)))))
96
97
(defun slime-tramp-to-lisp-filename (filename)
98
(funcall (if (slime-connected-p)
99
(first (slime-find-filename-translators (slime-machine-instance)))
100
'identity)
101
(expand-file-name filename)))
102
103
(defun slime-tramp-from-lisp-filename (filename)
104
(funcall (second (slime-find-filename-translators (slime-machine-instance)))
105
filename))
106
107
(provide 'slime-tramp)
108
109