Question

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

Was it helpful?

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 ))))

OTHER TIPS

The package uniquify does something similar to what you want. When you have two buffers visiting files with the same filename it will add a string at then end to differentiate the two.

For example if you have files /etc/foo/bar/a and /mnt/a it will call the buffers something like a <bar> and a <mnt>. Then when you use ido to switch buffers you do not have to select from the full filename but you end up in the right buffer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top