在 elisp 的扩展文件名中使用通配符?
using wildcards in expand-file-name in elisp?
是否可以在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
似乎无法识别 *
(Emacs 24.5 来自 Ubuntu 16.04)
-- 编辑 --
@Drew 我试过 (byte-recompile-directory (file-expand-wildcards "~/.emacs.d/elpa/babel-repl*/") 0)
但出现错误 Wrong type argument: stringp, nil
。
我不太熟悉 elisp 和 stringp
类型(我猜是字符串列表)。我试图在 file-expand-wildcards
的返回值上使用 (car )
以获得第一个匹配的文件名。但是 Emacs 仍然可以正常启动。
有什么指点吗?
尝试 file-expand-wildcards
:
file-expand-wildcards
is a compiled Lisp function in files.el
.
(file-expand-wildcards PATTERN &optional FULL)
Expand wildcard pattern PATTERN
.
This returns a list of file names which match the pattern.
If PATTERN
is written as an absolute file name,
the values are absolute also.
If PATTERN
is written as a relative file name, it is interpreted
relative to the current default directory, default-directory
.
The file names returned are normally also relative to the current
default directory. However, if FULL
is non-nil, they are absolute.
这为您提供了扩展列表。选择第一个或您想要的任何一个。
是否可以在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
似乎无法识别 *
(Emacs 24.5 来自 Ubuntu 16.04)
-- 编辑 --
@Drew 我试过 (byte-recompile-directory (file-expand-wildcards "~/.emacs.d/elpa/babel-repl*/") 0)
但出现错误 Wrong type argument: stringp, nil
。
我不太熟悉 elisp 和 stringp
类型(我猜是字符串列表)。我试图在 file-expand-wildcards
的返回值上使用 (car )
以获得第一个匹配的文件名。但是 Emacs 仍然可以正常启动。
有什么指点吗?
尝试 file-expand-wildcards
:
file-expand-wildcards
is a compiled Lisp function infiles.el
.
(file-expand-wildcards PATTERN &optional FULL)
Expand wildcard pattern
PATTERN
.This returns a list of file names which match the pattern.
If
PATTERN
is written as an absolute file name, the values are absolute also.If
PATTERN
is written as a relative file name, it is interpreted relative to the current default directory,default-directory
.The file names returned are normally also relative to the current default directory. However, if
FULL
is non-nil, they are absolute.
这为您提供了扩展列表。选择第一个或您想要的任何一个。