Skip to content

Commit 2e85ac2

Browse files
committed
Add new Tramp method "flatpak"
* doc/misc/tramp.texi (Inline methods): Add flatpak. * etc/NEWS: Add new Tramp method "flatpak". Fix typos. * lisp/net/tramp-container.el (tramp-flatpak-program): New defcustom. (tramp-flatpak-method): New defconst. (tramp-flatpak--completion-function): New defun. Set it for "flatpak". (tramp-methods) <flatpak>: Add. (tramp-container-connection-local-default-flatpak-variables): New defconst. Set respective connection-local variables.
1 parent 3badd23 commit 2e85ac2

File tree

4 files changed

+106
-17
lines changed

4 files changed

+106
-17
lines changed

doc/misc/tramp.texi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,16 @@ be used.
938938

939939
This method does not support user names.
940940

941+
@item @option{flatpak}
942+
@cindex method @option{flatpak}
943+
@cindex @option{flatpak} method
944+
945+
Integration of Flatpak sandboxes. The host name may be either an
946+
application ID, a sandbox instance ID, or a PID, as returned by
947+
@samp{flatpak ps}.
948+
949+
This method does not support user names.
950+
941951
@end table
942952

943953

etc/NEWS

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ This is used for displaying the time and date components of
6767
'display-time-mode'.
6868

6969
---
70-
** New icon images for general use
71-
Several symbolic icons are added to etc/images/symbols, including
70+
** New icon images for general use.
71+
Several symbolic icons are added to "etc/images/symbols", including
7272
plus, minus, check-mark, start, etc.
73+
7374

7475
* Editing Changes in Emacs 30.1
7576

@@ -104,7 +105,7 @@ If you want to get back the old behavior, set the user option to the value
104105
(setopt gdb-locals-table-row-config
105106
`((type . 0) (name . 0) (value . ,gdb-locals-value-limit)))
106107

107-
** Compile
108+
** Grep
108109

109110
*** New user option 'grep-use-headings'.
110111
When non-nil, the output of Grep is split into sections, one for each
@@ -203,16 +204,18 @@ point is not in a comment or a string. It is by default bound to
203204
** Tramp
204205

205206
+++
206-
*** New connection method "toolbox".
207-
This allows accessing system containers provided by Toolbox.
207+
*** New connection methods "toolbox" and "flatpak".
208+
They allow accessing system containers provided by Toolbox or
209+
sandboxes provided by Flatpak.
208210

209211
+++
210-
*** Rename 'tramp-use-ssh-controlmaster-options' to 'tramp-use-connection-share.
211-
The old name still exists as defvaralias. This user option controls
212-
now connection sharing for both ssh-based and plink-based methods. It
213-
allows the values t, nil, and 'suppress'. The latter suppresses
214-
also "ControlMaster" settings in the user's "~/.ssh/config" file,
215-
or connection share configuration in PuTTY sessions, respectively.
212+
*** Rename 'tramp-use-ssh-controlmaster-options' to 'tramp-use-connection-share'.
213+
The old name still exists as obsolete variable alias. This user
214+
option controls now connection sharing for both ssh-based and
215+
plink-based methods. It allows the values t, nil, and 'suppress'.
216+
The latter suppresses also "ControlMaster" settings in the user's
217+
"~/.ssh/config" file, or connection share configuration in PuTTY
218+
sessions, respectively.
216219

217220
** EWW
218221

@@ -280,7 +283,7 @@ distracting and easily confused with actual code, or a significant
280283
early aid that relieves you from moving the buffer or reaching for the
281284
mouse to consult an error message.
282285

283-
** Python mode
286+
** Python Mode
284287

285288
---
286289
*** New user option 'python-indent-block-paren-deeper'.

lisp/net/tramp-adb.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ connection if a previous connection has died for some reason."
13111311
(tramp-set-connection-property p "connected" t)))))))
13121312

13131313
;;; Default connection-local variables for Tramp.
1314+
13141315
(defconst tramp-adb-connection-local-default-shell-variables
13151316
'((shell-file-name . "/system/bin/sh")
13161317
(shell-command-switch . "-c"))

lisp/net/tramp-container.el

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
;; C-x C-f /kubernetes:POD:/path/to/file
4848
;;
4949
;; Where:
50-
;; POD is the pod to connect to.
51-
;; By default, the first container in that pod will be
52-
;; used.
50+
;; POD is the pod to connect to.
51+
;; By default, the first container in that pod will be
52+
;; used.
5353
;;
5454
;; Completion for POD and accessing it operate in the current
5555
;; namespace, use this command to change it:
@@ -58,7 +58,7 @@
5858
;;
5959
;;
6060
;;
61-
;; Open a file on an existing toolbox container via Toolbox:
61+
;; Open a file on an existing Toolbox container:
6262
;;
6363
;; C-x C-f /toolbox:CONTAINER:/path/to/file
6464
;;
@@ -67,6 +67,16 @@
6767
;;
6868
;; If the container is not running, it is started. If no container is
6969
;; specified, the default Toolbox container is used.
70+
;;
71+
;;
72+
;;
73+
;; Open a file on a running Flatpak sandbox:
74+
;;
75+
;; C-x C-f /flatpak:SANDBOX:/path/to/file
76+
;;
77+
;; Where:
78+
;; SANDBOX is the running sandbox to connect to.
79+
;; It could be an application ID, an instance ID, or a PID.
7080

7181
;;; Code:
7282

@@ -104,6 +114,14 @@
104114
:type '(choice (const "toolbox")
105115
(string)))
106116

117+
;;;###tramp-autoload
118+
(defcustom tramp-flatpak-program "flatpak"
119+
"Name of the Flatpak client program."
120+
:group 'tramp
121+
:version "30.1"
122+
:type '(choice (const "flatpak")
123+
(string)))
124+
107125
;;;###tramp-autoload
108126
(defconst tramp-docker-method "docker"
109127
"Tramp method name to use to connect to Docker containers.")
@@ -120,6 +138,10 @@
120138
(defconst tramp-toolbox-method "toolbox"
121139
"Tramp method name to use to connect to Toolbox containers.")
122140

141+
;;;###tramp-autoload
142+
(defconst tramp-flatpak-method "flatpak"
143+
"Tramp method name to use to connect to Flatpak sandboxes.")
144+
123145
;;;###tramp-autoload
124146
(defun tramp-container--completion-function (program)
125147
"List running containers available for connection.
@@ -195,6 +217,30 @@ see its function help for a description of the format."
195217
lines)))
196218
(mapcar (lambda (name) (list nil name)) (delq nil names))))
197219

220+
;;;###tramp-autoload
221+
(defun tramp-flatpak--completion-function (&rest _args)
222+
"List Flatpak sandboxes available for connection.
223+
It returns application IDs or, in case there is no application
224+
ID, instance IDs.
225+
226+
This function is used by `tramp-set-completion-function', please
227+
see its function help for a description of the format."
228+
(when-let ((default-directory tramp-compat-temporary-file-directory)
229+
(raw-list
230+
(shell-command-to-string
231+
(concat tramp-flatpak-program
232+
" ps --columns=instance,application")))
233+
(lines (split-string raw-list "\n" 'omit))
234+
(names (mapcar
235+
(lambda (line)
236+
(when (string-match
237+
(rx bol (* space) (group (+ (not space)))
238+
(? (+ space) (group (+ (not space)))) eol)
239+
line)
240+
(or (match-string 2 line) (match-string 1 line))))
241+
lines)))
242+
(mapcar (lambda (name) (list nil name)) (delq nil names))))
243+
198244
;;;###tramp-autoload
199245
(defvar tramp-default-remote-shell) ;; Silence byte compiler.
200246

@@ -253,6 +299,17 @@ see its function help for a description of the format."
253299

254300
(add-to-list 'tramp-default-host-alist `(,tramp-toolbox-method nil ""))
255301

302+
(add-to-list 'tramp-methods
303+
`(,tramp-flatpak-method
304+
(tramp-login-program ,tramp-flatpak-program)
305+
(tramp-login-args (("enter")
306+
("%h")
307+
("%l")))
308+
(tramp-direct-async (,tramp-default-remote-shell "-c"))
309+
(tramp-remote-shell ,tramp-default-remote-shell)
310+
(tramp-remote-shell-login ("-l"))
311+
(tramp-remote-shell-args ("-c"))))
312+
256313
(tramp-set-completion-function
257314
tramp-docker-method
258315
`((tramp-container--completion-function
@@ -269,7 +326,25 @@ see its function help for a description of the format."
269326

270327
(tramp-set-completion-function
271328
tramp-toolbox-method
272-
'((tramp-toolbox--completion-function ""))))
329+
'((tramp-toolbox--completion-function "")))
330+
331+
(tramp-set-completion-function
332+
tramp-flatpak-method
333+
'((tramp-flatpak--completion-function "")))
334+
335+
;; Default connection-local variables for Tramp.
336+
337+
(defconst tramp-container-connection-local-default-flatpak-variables
338+
`((tramp-remote-path . ,(cons "/app/bin" tramp-remote-path)))
339+
"Default connection-local variables for remote flatpak connections.")
340+
341+
(connection-local-set-profile-variables
342+
'tramp-container-connection-local-default-flatpak-profile
343+
tramp-container-connection-local-default-flatpak-variables)
344+
345+
(connection-local-set-profiles
346+
`(:application tramp :protocol ,tramp-flatpak-method)
347+
'tramp-container-connection-local-default-flatpak-profile))
273348

274349
(add-hook 'tramp-unload-hook
275350
(lambda ()

0 commit comments

Comments
 (0)