2

I'm working with Emacs on windows, I usually work locally, but I want to disable magit when I'm working on a remote file.

I'm trying to add a hook that disables magit when it detects that the file is on a remote server. I tried this snippet but it freezes tramp everytime I try to open a remote file:

(use-package magit
    :ensure t
    
    :init
    (add-hook
       'magit-mode-hook
       (lambda () (when (file-remote-p default-directory) (magit-mode -1)))))
3
  • 1
    What exactly are you trying to disable? magit-mode is a major mode for magit buffers, not something that is enabled in specific source files. – Jordon Biondo Jan 21 at 13:37
  • I don't want magit to run git on the remote server everytime I open a file with Tramp. I just want it to work if I'm working with a file on my local machine. I don't know if that's possible really. – Fabman Jan 21 at 14:57
  • I'm not sure if this is an answer or not for you, but Magit mentions a fix for bad performance when using TRAMP in it's docs here: you might try their snippet out. magit.vc/manual/magit/Performance.html – Jordon Biondo Jan 21 at 18:21
1

I don't think Magit will be responsible for that; but vc might?

See whether vc-ignore-dir-regexp helps. That has a default value of:

"\\`\\(?:[\\/][\\/][^\\/]+[\\/]\\|/\\(?:net\\|afs\\|\\.\\.\\.\\)/\\)\\'"

For ease of editing and reading, let's use rx syntax. The excellent xr package on GNU ELPA gives me the following rx syntax for the default vc-ignore-dir-regexp value:

(seq bos (or (seq (any "/\\") (any "/\\")
                  (one-or-more (not (any "/\\")))
                  (any "/\\"))
             (seq "/" (or "net" "afs" "...") "/"))
     eos)))

So let's try the following. I'm using tramp-methods to establish the remote path syntax possibilities.

(with-eval-after-load "tramp"
  (setq vc-ignore-dir-regexp
        (rx (seq bos
                 (or (seq (any "/\\") (any "/\\")
                          (one-or-more (not (any "/\\")))
                          (any "/\\"))
                     (seq "/" (or "net" "afs" "...") "/")
                     ;; Ignore all tramp paths.
                     (seq "/"
                          (eval (cons 'or (mapcar #'car tramp-methods)))
                          ":"
                          (zero-or-more anything)))
                 eos))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.