0

我将 LaTeX 与 Emacs 一起使用,并希望能够将我写的内容传递给 shell 命令。(作为我使用的例子xargs echo。)

为此,我定义了一个交互式 elisp 函数:

(defun echo () 
  (interactive)
  (let ((bnds  (bounds-of-thing-at-point 'word)))
    (shell-command-on-region (car bnds) (cdr bnds) "xargs echo")))

这适用于大多数缓冲区,但不适用于使用 AUCTeX 字体锁定的 LaTeX 缓冲区。大多数单词都可以正常工作,但在单词边界处带有引号的单词却不行。

一个最小的例子:

\documentclass{article}
\usepackage{german}

\begin{document}
test "`Test"'
\end{document}

首先,作为概念证明:如果点test在我的 LaTeX 缓冲区中并且我尝试我的命令 ( echo),我会test在 minibuffer 中得到结果。(正如预期的那样。)

现在的问题:如果 point 是 onTest而我使用我的命令 xargs 抱怨不匹配的双引号。

原因是 shell-command-on-region 不会传递Test给 shell 命令,而是Test"'. 我可以通过在我的 elisp 代码中使用来验证这一点xargs -0。然后我在 minibuffer 中得到结果:

测试”'

问题来自 AUCTeXs 字体锁定。(我想使用它!)如果我设置font-latex-quotesnil,我的命令可以正常工作(它Test在迷你缓冲区中返回),但引用的内容当然不会被字体化......

有什么想法可以更改我的 elisp 代码以使其也与 AUCTeX 一起使用,或者自定义 AUCTeX 以使其字体化引用的内容但保留正确的单词边界?

4

1 回答 1

0
(defun echo ()
  (interactive)
  (let ((bnds (bounds-of-thing-at-point 'word)))
    (shell-command-on-region (car bnds) (cdr bnds) "xargs echo")
    (display-buffer "*Shell Command Output*")))

WRT 您的评论,使用函数临时更改语法表modify-syntax-entry或使用另一个这样的:

(defun echo ()
  (interactive)
  (with-syntax-table text-mode-syntax-table
    (let ((bnds (bounds-of-thing-at-point 'word)))
      (shell-command-on-region (car bnds) (cdr bnds) "xargs echo")
      (display-buffer "*Shell Command Output*"))))
于 2014-01-29T10:05:54.163 回答