Search code examples
emacselispido

Masking the output of completing-read in Emacs Lisp


I'm doing completing-read with a list of filesystem paths, eg. ("~/parent/child" "/parent/child").

I would like to mask the output of completing-read/ido-completing-read so that it would show only child, but would still return the compelete path.

Is this possible at all?

Best regards, Rat


Solution

  • Answer: no, it is not possible, because completing-read does not keep into account any semantics of the strings.

    This is possible, but with multiple calls of completing-list.

    The idea is that this function is passed a list of strings, and it helps you chose a string from that list.

    Completing-list has no control over what the strings contain. It does not care about the semantics of strings, as paths. It sees only list of strings.

    So, in order to make how you want, you call it once with the list of files from the current directory, and if you select a directory, first you change tto that directory, and then you call it once again with the list of files from that directory, etc.

    If you want to keep pwd the same as initial, then when it returns , you change again to the original dir.

    (cd (concat default-directory
                (completing-read "> " (directory-files default-directory ))))