emacs - 在 Emacs 中使用 texcount 来确定 Latex 或 tex 文件的字数(需要可选参数)

标签 emacs latex lisp elisp auctex

我有一个函数用于确定 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/

相关文章:

Elisp 中的正则表达式以包含换行符

matlab2tikz 生成繁重的排版 tikz 代码

lisp - elisp 中的 Y 组合器

go - Emacs 编译忽略编译命令变量

emacs - 如何删除 Emacs 生成的所有以 ~ 结尾的文件

latex - 如何减少 latex 中图形之间的垂直间距?

scheme - 将数据写入方案中不存在的文件(通过程序创建后)

comments - Lisp 注释约定

ruby-on-rails - Rails 3.1 Assets 管道 : Ignore backup files from Emacs and other editors

emacs - 使用 auctex 跳转到下一个缺失的引用