在emacs中调用(buffer-file-name)时转义空格

Sea*_*mus 2 emacs perl latex auctex

所以,我有一个关于让字数统计在emacs LaTeX模式中正常工作的问题(实际上是auctex,但没关系.)这个答案很好.然后我发现我在(buffer-file-name)包含空格时遇到了麻烦.这让它搞得一团糟.这个问题也得到了解决.现在问题是当没有任何空格时解决方案会中断.

所以目前我有两个emacs命令:

(defun latex-word-count ()
  (interactive)
  (shell-command (concat "/usr/local/bin/texcount.pl "
                         "-inc "
                     (shell-quote-argument (concat "'" (buffer-file-name) "'")))))
Run Code Online (Sandbox Code Playgroud)

这在包含文件夹中有空格时有效.

(defun latex-word-c-nospace ()
  (interactive)
  (shell-command (concat "/usr/local/bin/texcount.pl "
             "-inc "
             (shell-quote-argument (buffer-file-name)))))
Run Code Online (Sandbox Code Playgroud)

当包含文件夹名称中没有空格时,此方法有效.(好吧所以缩进有点screwey,但无论如何)

我的问题:是否有某种方法可以在两种情况下使用相同的功能?这个答案表明问题在于texcount而不是emacs.有没有办法做到这一点,而不用乱搞texcount.pl?或者,我最好的选择是以Chris Johnsen在SU上提出的方式来戳戳texcount.pl?

Sea*_*ean 5

无论文件名中是否有空格,您的第二个例程都应该有效.例如,我创建了这个小命令:

(defun ls-l ()
  (interactive)
  (shell-command (concat "ls -l "
                         (shell-quote-argument
                          (buffer-file-name)))))
Run Code Online (Sandbox Code Playgroud)

它在我编辑调用的文件foo.txt和编辑调用的文件时调用它时有效foo bar.txt.