Posted on Mon 14 December 2020 by alex in geek

magit-file-dispatch is my new favourite command since the recent removal of magit-file-mode. Rather than paper over the change and stick to the old way I tried the suggestions of launching with the dispatch commands. I discovered a few cool things including the ability to trace an individual functions changes over time which has completely replaced my old method of piping git log through less. In the end I found the fall-back of going to magit-dispatch a little too much friction given I've a lot of memory muscle to launch the status of git from various non-file backed yet still project orientated buffers. compilation-mode is one example but I also have my mail client set-up so I can quickly get to the code from the relevant mailing list. As everyone can have their own special snowflake settings in Emacs I finally went with:

(with-eval-after-load 'magit
  (defun my-magit-file-bindings ()
    "Setup my file bindings"
    (local-set-key (kbd "<f5>") 'my-counsel-git-grep))
  (add-hook 'magit-find-file-hook 'my-magit-file-bindings))

(defun my-magit-dispatch (&optional prefix)
  "My personal preference for magit-dispatch.
While magit-file-dispatch is cool, falling back to magit-dispatch is
not, I'd rather just go to magit-status. Lets make it so."
  (interactive "P")
  (if (or prefix
          (not (buffer-file-name))
          (not (functionp 'magit-file-dispatch)))

(use-package magit
  :bind (("C-x g" . my-magit-dispatch))