emacs lisp使用glob扩展列出文件

pyg*_*iel 27 lisp elisp

是否有任何库或函数为emacs lisp执行类似bash的glob扩展?

例如:

(directory-files-glob "~/Desktop/*")
> ("/home/user/Desktop/file1" "/home/user/Desktop/file2")
Run Code Online (Sandbox Code Playgroud)

如果没有这样的功能,是否有任何关于如何实施它的提示/建议?

编辑:

我在文档中发现了一个非常有用的函数:

file-expand-wildcards:此函数扩展通配符模式模式,返回与其匹配的文件名列表.

Tre*_*son 20

查看以下文档directory-files:

(directory-files "~/Desktop" nil ".")
Run Code Online (Sandbox Code Playgroud)

注意:第三个参数是正则表达式 - 不是通配符.

将globbing模式转换为正则表达式是很简单的. eshell附带一个翻译包,您可以使用:

(require 'em-glob)
(defun directory-files-glob (path)
   (directory-files (file-name-directory path) 
                    nil 
                    (eshell-glob-regexp (file-name-nondirectory path))))
Run Code Online (Sandbox Code Playgroud)

并且,如果你想完全接触eshell的globbing(带目录),那么可能有办法实现.以上假设globbing部分位于路径的非目录部分.


Pee*_*ger 15

不知道为什么这个被忽略了也许它不是在2010年的emacs中但是在当前的emacs中至少有功能文件 - 扩展 - 通配符

(file-expand-wildcards "~/Desktop/*")
Run Code Online (Sandbox Code Playgroud)

这正是你想要做的......


Mir*_*lov 5

f在一致的命名方案下添加了大量的文件和文件路径操作功能。它有一个函数f-glob可以做到这一点:

(f-glob "~/doc/*.org") ; returns a list of files ending with ".org"
(f-glob "*.org" "~/doc/") ; they all behave the same
(f-glob "*.org" "~/doc")
Run Code Online (Sandbox Code Playgroud)