我正在尝试做一些看似简单的事情:创建一个 Emacs 函数来为我创建一个 TAGS 文件。这里有执行此操作的简单说明
(defun create-tags (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(eshell-command
(format "find %s -type f -name \"*.[ch]\" | etags -" dir-name)))
问题是我需要“cpp”文件而不是“c”。这意味着我的 find 命令必须更改为:
find %s -type f -iname "*.cpp" -or -iname "*.h"
这在命令行上效果很好。我遇到的问题是 eshell 似乎根本不喜欢那样。当我执行此功能时,我不断收到:
File not found - "*.h": Invalid argument
.
这个问题的答案表明,正确使用shell-quote-argument
可能会解决这类问题,但我无法破解出有效的解决方案。例如,这会产生相同的错误:
(format "find %s -type f -iname %s -or -iname %s | etags -"
dir-name
(shell-quote-argument "*.cpp")
(shell-quote-argument "*.h"))