I have a set of directories. For each directory I have a set of relative file names. I would like to select any of these relative filenames using completion, and then later reconstruct the absolute path of the filename. (The relative filenames can be assumed to be unique). The following code works:
(let ((lst '(("a/b" . "dir1") ("a/c" . "dir2"))) (select nil)) (setq select (completing-read "Enter file name: " lst nil t "")) (cdr (assoc select lst)))
cdr of the cons cells represents (absolute) directory names (simplified to
"dir2" for this question) for the given relative path. But it feels like I have missed something. It should be possible to avoid using
completing-read just could return the whole
cons cell instead of just the
car of the cons cell, but I could not find information about how to achieve that in the manual.
Is it possible to tell
completing-read to return more information (i.e. the cons cell)?