我有一个函数用于确定 latex 中的计数,通常喜欢使用命令 brief
。我如何将其修改为输入选项而不是使用 "-inc""-brief"
运行。我可以在迷你缓冲区中输入我自己的一组参数,以使用命令 texcount 运行。如果命令用逗号分隔然后翻译成下面的格式,则最有可能是最好的。或者,如果需要,我可以自己输入整个内容 "-inc""-brief"
。
(defun latex-word-count ()
(interactive)
(let* ((this-file (buffer-file-name))
(word-count
(with-output-to-string
(with-current-buffer standard-output
(call-process "texcount" nil t nil "-inc" "-brief" this-file)))))
(string-match "\n$" word-count)
(message (replace-match "" nil nil word-count))))
最佳答案
未经测试:
(defun latex-word-count () (interactive) (let* ((this-file (buffer-file-name)) (options (let ((opts ()) opt) (while (not (equal (setq opt (read-string "Option: ")) "")) (push opt opts)) (nreverse opts))) (word-count (with-output-to-string (with-current-buffer standard-output (apply 'call-process "texcount" nil t nil (append options (list this-file))))))) (string-match "\n$" word-count) (message (replace-match "" nil nil word-count))))
这样您就可以按照您想要的顺序输入任意数量的选项。在没有输入的情况下按 RET 结束。
如果您知道texcount
可以接受哪些选项,那么您可以使用completing-read
而不是read-string
,提供一个列表这些选项作为其 COLLECTION
参数。 HTH.
关于emacs - 在 Emacs 中使用 texcount 来确定 Latex 或 tex 文件的字数(需要可选参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8507695/