I like to use ido for completing file paths and helm for all other things. I have tried setting magit-completing-read-function to magit-ido-completing-read. This doesn't change magit-status behaviour which calls read-directory-name. Here is what I have set for ido and helm:

(use-package ido
  :doc "I like `ido' for file paths' completion. Currently, the
  vector syntax [remap ..] is broken and using strings there is a
  workaround: https://github.com/jwiegley/use-package/issues/166"
  :ensure t
  :bind (("<remap> <read-file-name>" . ido-read-file-name)
         ("<remap> <read-directory-name>" . ido-read-directory-name))
  (ido-mode 1)
  (setq ido-enable-flex-matching t
        ido-auto-merge-work-directories-length -1
        ido-save-directory-list-file (expand-file-name "ido.last"
        ido-ignore-buffers '("\\` "  "^#.*" ".*freenode\.net.*"
                             ".*irc\.slack\.com.*" "\\*helm.*")
        ido-decorations '("\n-> " "" "\n   " "\n   ..." "[" "]" " [No match]"
                          " [Matched]" " [Not readable]" " [Too big]"
                          " [Confirm]")))

(use-package helm
  :doc "Helm for everything except file paths."
  :ensure t
  :diminish helm-mode
  :bind (("M-x" . helm-M-x)
         ("M-y" . helm-show-kill-ring)
         ("C-. C-r" . helm-grep-it))

  (helm-mode 1)

  ;; For some reason, this doesn't work. For example, `magit-status'
  ;; always uses `helm' for `read-file-name'.
  (add-to-list 'helm-completing-read-handlers-alist
               '(find-file . ido))
  (add-to-list 'helm-completing-read-handlers-alist
               '(dired . ido))
  (add-to-list 'helm-completing-read-handlers-alist
               '(read-file-name . ido-read-file-name)))
  • ido-ubiquitous? – npostavs Feb 22 '17 at 23:21
  • By the way, your <remap>s don't do anything because read-file-name and read-directory-name are not interactive commands so they can't have any bindings. – npostavs Feb 22 '17 at 23:23
  • No, I don't want to use ido-ubiquitous as I have mentioned. I am using helm for most of the things and ido only for files and directories. – narendraj9 Feb 22 '17 at 23:26

Magit only used magit-completing-read when reading "magit-specific" things. When reading things that other packages also need to read, then it uses the specialized functions provided by Emacs instead. For files and directories the work is ultimately done by read-file-name-default.

I like to use ido for completing file paths and helm for all other things.

So this doesn't really have anything to do with Magit. Unless you meant "use ido for completing file paths if and only if that is needed by Magit", which the following suggests:

I have tried setting magit-completing-read-function to magit-ido-completing-read.

However, I don't think that it would make sense for Magit to support reading file/directory names using a framework different from what every other package uses. I assume nearly everyone would want to use the same mechanism for reading files across all of Emacs. So if you meant that, then you are out of luck.

Using a different completion mechanism for files (regardless of what packages needs the user to select a file) than for anything else does make some sense though.

That appears to be supported. From helm-completing-read-handlers-alist's doc-string:

Ido is also supported, you can use `ido-completing-read' and
`ido-read-file-name' as value of an entry or just 'ido.
Note that you don't need to enable `ido-mode' for this to work.
  • If you see carefully, I have already set helm-completing-read-handers-alist. It doesn't work as has been written in the documentation. And if I do not enable ido-mode, I don't get ido-completing-read for file paths. That is all I want -- Ido for file paths and helm for everything else, e.g. describe-symbol – narendraj9 Feb 24 '17 at 18:25
  • I overlooked that, sorry. – tarsius Feb 24 '17 at 20:08

Finally, I found the solution to my problem. magit-status ultimately calls read-file-name. The read-file-name function uses read-file-name-function variable to find the function that it can call for reading a file path. helm-mode sets it to helm--generic-read.. and it doesn't respect the value of helm-completing-read-handlers for me somehow.

The only way I could make it use ido was with:

(setq read-file-name-function 'ido-read-file)
  • 1
    You should probably open a bug report against helm. – tarsius Feb 24 '17 at 20:10
  • You may be able to use let to make that setting temporary. – Cheeso May 10 '17 at 21:51

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.