From 71eae252acaa425edb020b475f89e7f68ca53f4b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 14 Sep 2025 21:25:04 -0400 Subject: [PATCH] module: add :emacs tramp --- lisp/doom-editor.el | 17 +++------- modules/emacs/tramp/README.org | 61 ++++++++++++++++++++++++++++++++++ modules/emacs/tramp/config.el | 50 ++++++++++++++++++++++++++++ static/init.example.el | 1 + 4 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 modules/emacs/tramp/README.org create mode 100644 modules/emacs/tramp/config.el diff --git a/lisp/doom-editor.el b/lisp/doom-editor.el index 7f8b6cccb..cbc37f68c 100644 --- a/lisp/doom-editor.el +++ b/lisp/doom-editor.el @@ -104,8 +104,7 @@ possible." delete-old-versions t ; clean up after itself kept-old-versions 5 kept-new-versions 5 - backup-directory-alist (list (cons "." (concat doom-cache-dir "backup/"))) - tramp-backup-directory-alist backup-directory-alist) + backup-directory-alist (list (cons "." (concat doom-cache-dir "backup/")))) ;; But turn on auto-save, so we have a fallback in case of crashes or lost data. ;; Use `recover-file' or `recover-session' to recover them. @@ -116,12 +115,8 @@ possible." auto-save-include-big-deletions t ;; Keep it out of `doom-emacs-dir' or the local directory. auto-save-list-file-prefix (concat doom-cache-dir "autosave/") - tramp-auto-save-directory (concat doom-cache-dir "tramp-autosave/") auto-save-file-name-transforms - (list (list "\\`/[^/]*:\\([^/]*/\\)*\\([^/]*\\)\\'" - ;; Prefix tramp autosaves to prevent conflicts with local ones - (concat auto-save-list-file-prefix "tramp-\\2") t) - (list ".*" auto-save-list-file-prefix t))) + (list (list ".*" auto-save-list-file-prefix t))) (add-hook! 'after-save-hook (defun doom-guess-mode-h () @@ -417,13 +412,9 @@ files, so this replace calls to `pp' with the much faster `prin1'." (server-start))) -(after! tramp - (setq remote-file-name-inhibit-cache 60 - tramp-completion-reread-directory-timeout 60 - tramp-verbose 1 - vc-ignore-dir-regexp (format "%s\\|%s\\|%s" +(after! vc-hooks + (setq vc-ignore-dir-regexp (format "%s\\|%s" vc-ignore-dir-regexp - tramp-file-name-regexp "[/\\\\]node_modules"))) diff --git a/modules/emacs/tramp/README.org b/modules/emacs/tramp/README.org new file mode 100644 index 000000000..03fb526a9 --- /dev/null +++ b/modules/emacs/tramp/README.org @@ -0,0 +1,61 @@ +:PROPERTIES: +:ID: 68a51608-e252-421a-bb79-bb1f038fbf5b +:END: +#+title: :emacs tramp +#+subtitle: Remote files at your arthritic fingertips +#+created: September 14, 2025 +#+since: 25.10.0 + +* Description :unfold: +This module provides sensible and performant defaults for TRAMP, a built-in +Emacs packages that provides remote file editing over various protocols like +SSH, SCP, FTP, and more. + +#+begin_quote +  The performance enhancements in this module have the greatest effects in + later versions of Emacs (at least 30.1 is recommended). +#+end_quote + +** Maintainers +- [[doom-user:][@hlissner]] + +[[doom-contrib-maintainer:][Become a maintainer?]] + +** Module flags +/This module has no flags./ + +** Packages +/This module doesn't install any packages./ + +** Hacks +#+begin_quote +󱌣 This module's hacks haven't been documented yet. [[doom-contrib-module:][Document them?]] +#+end_quote + +** TODO Changelog +# This section will be machine generated. Don't edit it by hand. +/This module does not have a changelog yet./ + +* Installation +[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] + +* Usage +#+begin_quote +󱌣 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] +#+end_quote + +* TODO Configuration +#+begin_quote +󱌣 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] +#+end_quote + +* Troubleshooting +/There are no known problems with this module./ [[doom-report:][Report one?]] + +* Frequently asked questions +/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]] + +* TODO Appendix +#+begin_quote +󱌣 This module has no appendix yet. [[doom-contrib-module:][Write one?]] +#+end_quote diff --git a/modules/emacs/tramp/config.el b/modules/emacs/tramp/config.el new file mode 100644 index 000000000..415a60352 --- /dev/null +++ b/modules/emacs/tramp/config.el @@ -0,0 +1,50 @@ +;;; emacs/tramp/config.el -*- lexical-binding: t; -*- + +;; Prefix tramp autosaves to prevent conflicts with local ones +(cl-pushnew (list "\\`/[^/]*:\\([^/]*/\\)*\\([^/]*\\)\\'" + (concat auto-save-list-file-prefix "tramp-\\2") t) + auto-save-file-name-transforms + :test #'equal) + + +(after! tramp + (setq remote-file-name-inhibit-cache 60 + remote-file-name-inhibit-locks t + tramp-copy-size-limit (* 1024 1024) ; 1mb + tramp-use-scp-direct-remote-copying t + tramp-completion-reread-directory-timeout 60 + tramp-backup-directory-alist backup-directory-alist + tramp-auto-save-directory (concat doom-cache-dir "tramp-autosave/")) + + ;; the ssh method is faster tha nthe default ssh on Windows + (unless (featurep :system 'windows) + (setq tramp-default-method "ssh"))) + + +;; PERF: When creating a new process in Emacs, you have two options: synchronous +;; or asynchronous. Async processes have historically been really slow over +;; TRAMP, because it has to create a new connection for every async process. +;; However recent version of TRAMP have added a feature called direct async +;; process that makes this significantly faster. This feature alone will take +;; many packages (like magit or git-gutter) from completely unusable to +;; bearable over TRAMP. Here is how you configure it with TRAMP 2.7. +(connection-local-set-profile-variables + 'remote-direct-async-process + '((tramp-direct-async-process . t))) + +(connection-local-set-profiles + `(:application tramp :protocol "scp") + 'remote-direct-async-process) + + +;; See magit/magit#5220 +(after! magit + (setq magit-tramp-pipe-stty-setings 'pty)) + + +;; PERF: Newer versions of TRAMP will use SSH connection sharing for much faster +;; connections. These don’t require you to reenter your password each time you +;; connect. The compile command disables this feature, so we want to turn it +;; back on. +(after! (tramp compile) + (remove-hook 'compilation-mode-hook #'tramp-compile-disable-ssh-controlmaster-options)) diff --git a/static/init.example.el b/static/init.example.el index eafbb7f36..00ad1dd17 100644 --- a/static/init.example.el +++ b/static/init.example.el @@ -72,6 +72,7 @@ electric ; smarter, keyword-based electric-indent ;;eww ; the internet is gross ;;ibuffer ; interactive buffer management + tramp ; remote files at your arthritic fingertips undo ; persistent, smarter undo for your inevitable mistakes vc ; version-control and Emacs, sitting in a tree