Emacs 从文件名列表中打开文件

cra*_*sic 6 emacs

我有一个较大的 tex 项目,它被分成几个 tex 文件。每次我想处理它时,我都会打开 emacs 并手动打开C-x C-f所有我想处理的文件。

我想知道是否有办法从包含文件名列表的文件中打开文件(从命令行),例如

文件列表.txt:

file1.tex file2.tex file3.tex
Run Code Online (Sandbox Code Playgroud)

然后做

cat files | emacs -nw

除了 emacs 不支持使用的命令,因为它不喜欢重新分配 stdin。

有任何想法吗?

Col*_*lin 5

而是通过 xargs 传递它:

cat files | xargs emacs
Run Code Online (Sandbox Code Playgroud)

xargs从 stdin 获取文本并将其作为参数传递给指定的程序。将files文件放入管道会导致它调用 emacs,如下所示:

emacs file1.tex file2.tex file3.tex
Run Code Online (Sandbox Code Playgroud)


Ero*_*oen 5

Collin Hockey 建议的替代方法是在 shell 中使用命令替换。以下语法在 Bourne 中的作用类似于 shell ( sh, bash, zsh&c.)。

emacs $( cat files )
Run Code Online (Sandbox Code Playgroud)

或等效地(但可读性较差且更模棱两可)

emacs ` cat files `
Run Code Online (Sandbox Code Playgroud)

尽管如此,仍然不是一个优雅的解决方案。我通常不是emacs用户,但我想这里的一些答案可能是您真正想要的。看一看!

PS
如果文件名列表长于getconf ARG_MAX字节,无论是我的还是 Collin 的解决方案都无法正常工作。在我的系统上,大约为 2 MiB。