在 Emacs 中直接从 ido 启动 magit

Launch magit directly from ido in Emacs

我想启动 magit directly from ido。即,我想用 ido-find-file 启动 ido,导航到我想要 运行 magit 的目录,按一些组合键,例如 C-x g,然后让 ido退出并在该目录中打开 magit。

我目前只是在目录下按C-d打开dired,然后按C-x g打开magit,不过我想避免额外的 C-d.

我成功地向 ido-completion-map 添加了一个新的组合键:

(add-hook 'ido-minibuffer-setup-hook
          (lambda () (interactive)
            (define-key ido-completion-map (kbd "C-x g") 'arvid-ido-enter-magit-status)
            ))

但是下面的功能好像不起作用,只是打开dired with instead of magit:

(defun arvid-ido-enter-magit-status ()
  "Drop into `dired' from file switching."
  (interactive)
  (setq ido-exit 'dired)
  (magit-status default-directory)
  (exit-minibuffer))

Magit已经自带了这样的功能:

(defun ido-enter-magit-status ()
  "Drop into `magit-status' from file switching.

To make this command available use something like:

  (add-hook 'ido-setup-hook
            (lambda ()
              (define-key ido-completion-map
                (kbd \"C-x g\") 'ido-enter-magit-status)))

Starting with Emacs 25.1 the Ido keymaps are defined just once
instead of every time Ido is invoked, so now you can modify it
like pretty much every other keymap:

  (define-key ido-common-completion-map
    (kbd \"C-x g\") 'ido-enter-magit-status)"
  (interactive)
  (with-no-warnings ; FIXME these are internal variables
    (setq ido-exit 'fallback fallback 'magit-status))
  (exit-minibuffer))