在elisp中使用expand-file-name中的通配符?

时间:2017-05-29 02:32:43

标签: emacs filenames glob completion

是否可以在elisp中使用*等通配符来扩展文件名?

例如,我看到了

(expand-file-name "~/.emacs.d/elpa/babel-repl-20160504.1501")

扩展为/home/username/.emacs.d/elpa/babel-repl-20160504.1501

是否还有一个函数来扩展包含通配符的文件名,以便我们可以这样做:

(expand-file-name "~/.emacs.d/elpa/babel-repl*")

(如果存在多个匹配,则取第一个文件名)?

我尝试了上述内容,但expand-file-name似乎无法识别*(来自Ubuntu 16.04的Emacs 24.5)

- 编辑 -

@Drew我尝试了(byte-recompile-directory (file-expand-wildcards "~/.emacs.d/elpa/babel-repl*/") 0),但收到了错误Wrong type argument: stringp, nil

我不熟悉elisp和stringp类型(我想是一个字符串列表)。我尝试在(car )的返回值上使用file-expand-wildcards以获取第一个匹配的文件名。但Emacs仍能正常启动。

任何指针?

1 个答案:

答案 0 :(得分:1)

尝试file-expand-wildcards

  

file-expand-wildcards files.el中已编译的Lisp函数。

     

(file-expand-wildcards PATTERN &optional FULL)

     

展开通配符模式PATTERN

     

这将返回与模式匹配的文件名列表。

     

如果将PATTERN写为绝对文件名,   价值也是绝对的。

     

如果将PATTERN写为相对文件名,则会对其进行解释   相对于当前默认目录default-directory

     

返回的文件名通常也与当前文件名相关   默认目录。但是,如果FULL为非零,则它们是绝对的。

这会为您提供扩展列表。选择第一个或任何你想要的。

相关问题