From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.devel Subject: [GNU ELPA] New package: tramp-locproc Date: Mon, 30 Dec 2024 17:22:57 +0100 Message-ID: <87r05p3ztq.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6335"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 30 17:23:55 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tSIYd-0001VW-Jc for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Dec 2024 17:23:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tSIXp-0006Tc-CO; Mon, 30 Dec 2024 11:23:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tSIXn-0006TQ-Q9 for emacs-devel@gnu.org; Mon, 30 Dec 2024 11:23:03 -0500 Original-Received: from mout.gmx.net ([212.227.17.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tSIXk-0007Qi-Sj for emacs-devel@gnu.org; Mon, 30 Dec 2024 11:23:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1735575778; x=1736180578; i=michael.albinus@gmx.de; bh=adgLpqAFRd49IsoOosFGa9eNvnf+dc6B/2UsOYm6H2U=; h=X-UI-Sender-Class:From:To:Subject:Date:Message-ID:MIME-Version: Content-Type:cc:content-transfer-encoding:content-type:date:from: message-id:mime-version:reply-to:subject:to; b=hcxZMkhkrWLmwHIUDNVJcV1FETLzDKyZvdYm0m4ueqsX561X/kPOmBGRLGwTd7ED GVhNcvuhwKLjGggRdMhL2LMfJKJy9q6x+oHph1C1DrX4Zax4NzDrIPJqZY/lcIzh8 X7tAxxXAa+K+aN5/FPGyId7Ftxgq1ifkA3/aFPuT4fBmZsHCa30JSceszvQ/38jUO zOGh8JtB/4GPhSdtZ5ddpFSD4c1iTP7pjfa3sOw4EyPiLD4Ag1jWQEIqWVajMhVE/ wuRBufu+ZgV3eiDRSJyRWk2iDKvijViRpNGKD69hw/ao1cA6lk8tEAUg9xU7QVEbp FncBtnksmxmfg8DTlw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from gandalf.gmx.de ([185.89.38.155]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MpUUm-1trVPi2dLQ-00nT2R for ; Mon, 30 Dec 2024 17:22:58 +0100 X-Provags-ID: V03:K1:zcQvyRyNLkvCMuwgU9DwM/ayPpDss1lHfI+kJPqOR56cuhDrDT7 m5ICxIZRireqZWQ5o9DKNJD55+++hAXEIH6w5/YyCIt46oGnHc2GdVy1QTiXDU9BPieXA4v BVJ2sUVQRxrnyKvvBo8LSeiDQfWiSCJ6e4gHTX9UkQc56JeKS7eWbIH67iqMUYug6NY7mgn wLkAGkNBoxKuvkxmfhoqw== UI-OutboundReport: notjunk:1;M01:P0:gmRbI2SwBBc=;3C8p4CMPcDoCPHoOUWcujNg/bMU OCFFADaCyorNBmzPMu00GeNHX8TB3Cn1YMLzHe06ZyVNMXNmbOdkWSmSH1BLUsHmNCGDwnlXN CsMc4HK6VUU8Cn5bvO5hHRqiHzpmYwgC+tG4pMiFOJD/089iUXh+8rdpapnodmF5uwfaxp087 sfe/FJ/hN9NUWjw2x352ciYnptlPLMnHKPPmJfpHXCq5CzR1oCUzExFsW8sz3AEasSaOfXefc CsOlG2Zjg5uy2cIlwgwwP09/IUCHuTRs3YVIXwHsR66RI7ObJvyHx0hG+h5JSughsKWz03+hQ eBmNiO837va3i+pz9qWbUGUV7P5RAbbgJP2OeKpMbmA3Y2SsZP1g1d2Cg1d9GrCbyOzWacZ81 dQ+qlHi9PCu38GoQTWr/3UaH2pMUvyGUNF7Mt5SLa9YkZhI+Lfuum15ispfzLOhZPJ0Kqa9RD hKdaHH/9tB5RrqGc9wHNx10lgy37B8aOhclDtYux3Bd+mj11t91ZOmMnsXbVLe66uA7l9L0nw XzhGAh4NkEfNDKrZlAMhgbl4hpdKeeyhYQ/8qKxP6S6c0z8eib7NIfvrNvyPk1q1lonBS1AqX b13f0Mnad4y8dBHo+gj3PVvJ8HxA5/ZcheDMBHKFLQT1WmwdkWJmCUKxwKGwjiF6+G3aiN3bP sSSnJrL4d7hZqwSR2Np5bcXa2iRSBwRN29DP0rSIQw7nUD968xCvt8w55fFCEdoH3GPykv8cB Y8uX9wpqCBZLi7rwdzxYz12O/nq9PwT6qDlVBYKk8uGArB+In9+iYFSSf/auHYHCC/H8luvy Received-SPF: pass client-ip=212.227.17.21; envelope-from=michael.albinus@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327446 Archived-At: --=-=-= Content-Type: text/plain Hi, I would like to submit a new package to GNU ELPA: tramp-locproc. It extends the possibility to run local processes for remote files, which are mounted by Tramp using FUSE, and which do not have an implementation of remote processes, like Tramp's "rclone" method and all Tramp methods implemented in tramp-gvfs.el ("ftp", "nextcloud", and alike). It also adds local processes for Tramp's "sshfs" method, although it has an own remote processes implementation. Even files in file archives, implemented by tramp-archive.el, profit from this new feature. Beside the obvious advantage to run local processes over remote files, there is also the disadvantage that file names are adapted in order to reflect their local mount location. Therefore, I would appreciate to get feedback, whether people find this useful. Thanks, and best regards, Michael. --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename=tramp-locproc.el Content-Transfer-Encoding: quoted-printable ;;; tramp-locproc.el --- Tramp local processes for FUSE mounts -*- lexical= -binding:t -*- ;; Copyright (C) 2025 Free Software Foundation, Inc. ;; Author: Michael Albinus ;; Keywords: comm, processes ;; Package: tramp-locproc ;; Version: 0 ;; Package-Requires: ((tramp "2.7.2")) ;; This file is not part of GNU Emacs. ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; This package adds process support for "sshfs", "rclone" and all ;; methods defined in `tramp-gvfs-methods'. It overwrites the remote ;; process support in "sshfs"; the other methods have no process ;; support otherwise. ;; A remote process runs as a local process, using the local mount ;; name of `default-directory'. The program name is used literally, ;; after piping through `file-local-name'. As a consequence, programs ;; on the local host are called, which might not exist on the remote ;; host. ;; Arguments of the process, which are an absolute file name, are ;; transformed to the respective local mount name. That is, a file ;; name "/path/to/file" is located on the local host as ;; "/mount_point/path/to/file". This is suppressed if user option ;; `tramp-locproc-extend-arguments' is nil. ;; Although not strictly remote, Tramp archive files are also ;; supported. That is, a local process can run over the file system ;; which is defined by a file archive, see (info "(tramp) Archive file ;; names") . ;; If this package is unloaded via `M-x unload-feature RET tramp-locproc', ;; the original implementation of the different Tramp backends is restored. ;;; Code: (require 'tramp) (defvar tramp-locproc-unload-file-name-handler-alist nil "Variable keeping unload information.") (defun tramp-locproc-massage-file-name-handler-alist (fnha) "Adapt FNHA to the needs of `tramp-locproc'. FNHA is the variable symbol, collecting handler functions for a Tramp backe= nd." (let ((val (symbol-value fnha))) ;; Prepare unloading. This must be performed prior modifying FNHA. (unless (assq fnha tramp-locproc-unload-file-name-handler-alist) (add-to-list 'tramp-locproc-unload-file-name-handler-alist `(,fnha ,(copy-tree (assq 'exec-path val)) ,(copy-tree (assq 'make-process val)) ,(copy-tree (assq 'process-file val)) ,(copy-tree (assq 'shell-command val)) ,(copy-tree (assq 'start-file-process val)))) (add-hook 'tramp-locproc-unload-hook (lambda () (dolist (entry (alist-get fnha tramp-locproc-unload-file-name-handler-alist)) (setcdr (assq (car entry) (symbol-value fnha)) (cdr entry)))))) ;; Replace handler functions. (setcdr (assq 'exec-path val) #'tramp-locproc-handle-exec-path) (setcdr (assq 'make-process val) #'tramp-locproc-handle-make-process) (setcdr (assq 'process-file val) #'tramp-locproc-handle-process-file) (setcdr (assq 'shell-command val) #'tramp-locproc-handle-shell-command) (setcdr (assq 'start-file-process val) #'tramp-handle-start-file-proces= s))) ;; `tramp-archive-local-file-name' is introduced in Tramp 2.7.2. (with-eval-after-load 'tramp-archive (when (fboundp 'tramp-archive-local-file-name) (tramp-locproc-massage-file-name-handler-alist 'tramp-archive-file-name-handler-alist))) ;; `tramp-gvfs-local-file-name' is introduced in Tramp 2.7.2. (with-eval-after-load 'tramp-gvfs (when (fboundp 'tramp-gvfs-local-file-name) (tramp-locproc-massage-file-name-handler-alist 'tramp-gvfs-file-name-handler-alist))) (with-eval-after-load 'tramp-rclone (tramp-locproc-massage-file-name-handler-alist 'tramp-rclone-file-name-handler-alist)) (with-eval-after-load 'tramp-sshfs (tramp-locproc-massage-file-name-handler-alist 'tramp-sshfs-file-name-handler-alist)) (declare-function tramp-archive-local-file-name 'tramp-arechive) (declare-function tramp-fuse-local-file-name 'tramp-fuse) (declare-function tramp-gvfs-local-file-name 'tramp-gvfs) (defun tramp-locproc-local-file-name (filename) "Return local mount name of remote FILENAME." (funcall (cond ((tramp-archive-file-name-p filename) #'tramp-archive-local-file-name) ((tramp-gvfs-file-name-p filename) #'tramp-gvfs-local-file-name) (t #'tramp-fuse-local-file-name)) filename)) (defun tramp-locproc-mount-point (filename) "Return mount point of remote FILENAME." (tramp-locproc-local-file-name (funcall (cond ((tramp-archive-file-name-p filename) (lambda (string) (file-name-as-directory (tramp-archive-file-name-archive string)))) (t #'file-remote-p)) filename))) (defun tramp-locproc-file-name-p (filename) "Check if it=E2=80=99s a FILENAME handled by local processes." ;; FIXME: Check, that it is activated for the repective backend. (or (tramp-archive-file-name-p filename) (tramp-gvfs-file-name-p filename) (tramp-rclone-file-name-p filename) (tramp-sshfs-file-name-p filename))) (defcustom tramp-locproc-extend-arguments t "Whether to prefix arguments of remote processes by the mount-point." :group 'tramp :type 'boolean) (defun tramp-locproc-extend-arguments (mount-point args) "Return ARGS, a list of local file names, prefixed with MOUNT-POINT. This can be suppressed by setting user option `tramp-locproc-extend-arguments' to nil." (if tramp-locproc-extend-arguments (mapcar (lambda (file) (if (and (stringp file) (file-name-absolute-p file)) (concat mount-point file) file)) args) args)) (defun tramp-locproc-handle-exec-path () "Like `exec-path' for Tramp files." exec-path) (defun tramp-locproc-handle-make-process (&rest args) "An alternative `make-process' implementation for Tramp files." (let ((mount-point (tramp-locproc-mount-point default-directory)) (default-directory (tramp-locproc-local-file-name default-directory)) (command (plist-get args :command))) ;; The car in COMMAND is the program name. We don't manipulate it. (setcdr command (tramp-locproc-extend-arguments mount-point (cdr comman= d))) (apply #'make-process (plist-put args :command command)))) (defun tramp-locproc-handle-process-file (program &optional infile buffer display &rest args) "Like `process-file' for Tramp files." (let ((mount-point (tramp-locproc-mount-point default-directory)) (default-directory (tramp-locproc-local-file-name default-directory))) (apply #'process-file (file-local-name program) infile buffer display (tramp-locproc-extend-arguments mount-point args)))) (defun tramp-locproc-handle-shell-command (command &optional output-buffer error-buffer) "An alternative `shell-command' implementation for Tramp files." (let ((mount-point (tramp-locproc-mount-point default-directory)) (default-directory (tramp-locproc-local-file-name default-directory)) (command (split-string command))) ;; The first word in COMMAND is the program name. We don't ;; manipulate it. (setcdr command (tramp-locproc-extend-arguments mount-point (cdr comman= d))) (setq command (mapconcat #'identity command " ")) (shell-command command output-buffer error-buffer))) ;;; Integration of compile.el: (defun tramp-locproc-compilation-mode-function () "Setup compilation buffer properly." (when (and (compilation-buffer-p (current-buffer)) (tramp-locproc-file-name-p default-directory)) (trace-values (current-buffer) default-directory comint-file-name-prefi= x) (setq default-directory (tramp-locproc-local-file-name default-director= y)) (setq-local comint-file-name-prefix ""))) (with-eval-after-load 'compile (trace-function-background 'compilation-setup) (trace-function-background 'compilation-get-file-structure) (add-hook 'compilation-mode-hook #'tramp-locproc-compilation-mode-function) (add-hook 'tramp-locproc-unload-hook (lambda () (remove-hook 'compilation-mode-hook #'tramp-locproc-compilation-mode-function)))) ;;; Integration of shell.el: (defun tramp-locproc-shell-function (&rest args) (let ((default-directory (tramp-locproc-local-file-name default-directory= ))) (apply args))) (with-eval-after-load 'shell (trace-function-background 'shell) (advice-add #'shell :around #'tramp-locproc-shell-function) (add-hook 'tramp-locproc-unload-hook (lambda () (advice-remove #'shell :around #'tramp-locproc-shell-function)))) ;; FIXME: Do we need this? ;;; Integration of comint.el: ;; (defun tramp-locproc-comint-mode-function () ;; "Setup comint mode properly." ;; (trace-values (current-buffer) default-directory comint-file-name-pref= ix) ;; (setq default-directory (tramp-locproc-local-file-name default-directo= ry)) ;; (setq-local comint-file-name-prefix "")) ;; (with-eval-after-load 'comint ;; (add-hook 'comint-mode-hook ;; #'tramp-locproc-comint-mode-function) ;; (add-hook 'tramp-locproc-unload-hook ;; (lambda () ;; (remove-hook 'comint-mode-hook ;; #'tramp-locproc-comint-mode-function)))) ;; Development settings. (require 'trace) (mapc #'trace-function-background (mapcar #'intern (all-completions "tramp-locproc-" obarray #'functionp))) (add-hook 'tramp-unload-hook (lambda () (unload-feature 'tramp-locproc 'force))) (provide 'tramp-locproc) ;;; tramp-locproc.el ends here --=-=-=--