I'm making some functions to interact with Mercurial. Many Mercurial commands take a repository as an argument, and that argument can be specified either by a path to the root of the repository or by a repo name. These repo names can be configured in the user's .hgrc file, and it is easy to get a list of the names that are defined.

I'd like to make a completing read function that dynamically completes a path to a directory or an item from a list. I'd like it to work just like ido-read-directory-name, but with the items from a list also offered as options.

I've been digging through the documentation, and also through mini_buffer.el and ido.el. The only hint I have so far is that I can override the variable read-file-name-function, but it seems like I'd end up reimplementing a lot of functionality for dynamically completing directory names.

Does anyone have any guidance for me? Or perhaps an example?

1 Answer 1


You can try something like:

(let* ((dir-table (apply-partially #'completion-table-with-predicate
        (completion-table-in-turn <reponamesfromhg> dir-table)))
  (completing-read "Foo:" my-table))
  • Very cool, thanks! How can I make this only complete directories? And how can I get this to work with ido? Mar 30, 2016 at 14:35
  • 1
    See updated code to constrain the completion to directories. As for IDO, I do not know why it wouldn't work with it, but it might be difficult to fix it (IOW you might be better off trying to get the standard completion to look more like IDO, e.g. by enabling icomplete-mode).
    – Stefan
    Mar 30, 2016 at 14:58
  • Should it be apply-partially? Mar 30, 2016 at 15:02
  • Thanks for getting me this far, Stefan! I use ido-vertical-mode, so unfortunately icomplete-mode isn't quite what I want. I would still love for this to work basically the same as ido-read-directory-name, if anyone else has any ideas. Mar 30, 2016 at 15:37
  • There's no good reason why you couldn't have an icomplete-vertical-mode.
    – Stefan
    Mar 31, 2016 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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