在 emacs 中调用 (buffer-file-name) 时转义空格
所以,我有一个关于让字数统计在 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) "'")))))
当包含文件夹中有空格时,此命令有效。
(defun latex-word-c-nospace ()
(interactive)
(shell-command (concat "/usr/local/bin/texcount.pl "
"-inc "
(shell-quote-argument (buffer-file-name)))))
当包含的文件夹名称中没有空格时,此方法有效。 (好吧,缩进有点奇怪,但无论如何)
我的问题:有没有办法让相同的功能在两种情况下都起作用? 这个答案表明问题出在 texcount 而不是 emacs 上。有没有办法做到这一点而不弄乱 texcount.pl ?或者我最好的选择是按照 Chris Johnsen 在 SU 上建议的方式戳 texcount.pl?
So, I had a question about getting word count to work properly in emacs LaTeX mode (auctex, actually, but never mind.) That was answered fine. Then I found I had trouble when the (buffer-file-name)
included spaces. This made it mess up. This problem was got around too. Now the problem is that the solution breaks when there AREN'T any spaces.
So currently I have two emacs commands:
(defun latex-word-count ()
(interactive)
(shell-command (concat "/usr/local/bin/texcount.pl "
"-inc "
(shell-quote-argument (concat "'" (buffer-file-name) "'")))))
this works when there is a space in the containing folder.
(defun latex-word-c-nospace ()
(interactive)
(shell-command (concat "/usr/local/bin/texcount.pl "
"-inc "
(shell-quote-argument (buffer-file-name)))))
This works when there is no space in the containing folder name.
(OK so the indenting is a little screwey, but whatever)
My question: is there some way to have the same function work in both cases? This answer suggests the problem is with texcount rather than emacs. Is there a way to do this without messing about with texcount.pl? Or is my best bet to poke texcount.pl in the way Chris Johnsen suggested on SU?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无论文件名中是否有空格,您的第二个例程都应该有效。例如,我创建了这个小命令:
当我在编辑名为
foo.txt
的文件和编辑名为foo bar.txt
的文件时调用它时,它会起作用。Your second routine should work whether there are spaces in the file name or not. For example, I created this little command:
It works when I invoke it while editing a file called
foo.txt
and when editing a file calledfoo bar.txt
.您始终可以选择让 emacs 确定文件名是否有空格:
You always have the option of having emacs determine if the file name has a space:
我是 TeXcount 的开发人员,不久前看到了这篇文章。
正如所指出的,问题出在 TeXcount 上,因此最好的解决方案是修复 TeXcount 而不是破解其他解决方案。我在 TeXcount 网页上提供了一个更新,希望问题能够得到解决:
http://folk.uio.no/einarro/TeXcount/download.html
注意:这是新网页的临时版本,如果我决定 TeXcount 的新地址,可能会稍后移动。
出现这个问题的原因是,为了在 Windows 下允许文件名中使用通配符,我使用了 <@files> 。获取所有文件,这不喜欢空格。在 Linux 中,您可以只使用 @files 而不使用 glob (<...>),但我希望 TeXcount 也能在 Windows 中工作,因此更好的解决方案是在将空格传递给 glob 之前转义空格。
希望这有帮助,如果没有帮助,请与我联系,我会看看是否可以提供帮助......我不是这里的常客,所以如果作为回复发布,我可能不会注意到问题。
埃纳尔
I'm the developer of TeXcount and came across this posting just a little while ago.
As is pointed out, the problem is with TeXcount, so the best solution is to fix TeXcount rather than hack some other solution. I have an update available on the TeXcount web page in which I hope the problem is solved:
http://folk.uio.no/einarro/TeXcount/download.html
NB: This is the temporary version of the new web pages, and may move later on if I decide to new address for TeXcount.
The problem came about because, in order to allow wildcards in file names under Windows, I had used <@files> to get all the files, and this didn't like the spaces. In Linux, you could just use @files without the glob (<...>), but I'd like TeXcount to work in Windows too, so a better solution was to escape the spaces before passing them to the glob.
Hope this helps, and if it doesn't please contact me and I'll see if I can help...I'm not a regular here, so I might not notice questions if posted as replies.
Einar