所以,我有一个关于让字数统计在emacs LaTeX模式下正常工作的问题(实际上,auctex,但没关系。)That was answered fine。然后我发现我在(buffer-file-name)
包含的空格时遇到了麻烦。这让它搞得一团糟。 This problem was got around too。现在问题是当没有任何空格时解决方案会中断。
所以目前我有两个emacs命令:
(defun latex-word-count ()
(interactive)
(shell-command (concat "/usr/local/bin/texcount.pl "
"-inc "
(shell-quote-argument (concat "'" (buffer-file-name) "'")))))
当包含文件夹中有空格时,这是有效的。
(defun latex-word-c-nospace ()
(interactive)
(shell-command (concat "/usr/local/bin/texcount.pl "
"-inc "
(shell-quote-argument (buffer-file-name)))))
当包含文件夹名称中没有空格时,此方法有效。 (好吧所以缩进有点screwey,但无论如何)
我的问题:是否有某种方法可以在两种情况下都使用相同的功能? This answer表明问题出在texcount而不是emacs上。有没有办法做到这一点,而不用乱搞texcount.pl?或者我最好用Chris Johnsen在SU上建议的方式戳texcount.pl?
答案 0 :(得分:5)
无论文件名中是否有空格,您的第二个例程都应该有效。例如,我创建了这个小命令:
(defun ls-l ()
(interactive)
(shell-command (concat "ls -l "
(shell-quote-argument
(buffer-file-name)))))
当我在编辑名为foo.txt
的文件时以及编辑名为foo bar.txt
的文件时调用它时,它会起作用。
答案 1 :(得分:1)
您始终可以选择让emacs确定文件名是否有空格:
(defun latex-word-count ()
(interactive)
(let* ((has-space (string-match " " buffer-file-name))
(quoted-name (shell-quote-argument
(if has-space
(concat "'" buffer-file-name "'")
buffer-file-name))))
(shell-command (concat "/usr/local/bin/texcount.pl "
"-inc "
quoted-name))))
答案 2 :(得分:1)