1

我正在尝试设置一个速度模板,当使用 Cu 前缀调用该模板时,它将用标签 \begin{environment} 和 \end{environment} 包围该区域,并在每行的开头插入标签 \item地区。但是它给出了“保存游览:Args 超出范围:2247、2312”错误。

(require 'tempo)
(setq tempo-interactive t)

(tempo-define-template "env"
'("\\begin{" (p "Environment: " environment) "}" > n>
r> n>
"\\end{" (s environment) "}" > n
(save-excursion
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward "^" nil t) (replace-match "\\item " nil t))
(widen)
))
"env"
"Insert a LaTeX environment.")

(defun item (start end)
(interactive "r")
(save-excursion 
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward "^" nil t) (replace-match "\\item " nil t))
(widen)
)) 

item 函数本身在区域上运行良好。我尝试在 tempo-template 中调用 elisp 函数项:

(tempo-define-template "env"
'("\\begin{" (p "Environment: " environment) "}" > n>
r> n>
"\\end{" (s environment) "}" > n
(item point-min point-max)
)
"env"
"Insert a LaTeX environment.")

但是,这会给出“eval:符号的值作为变量是 void:point-min”错误。任何解决问题的指针表示赞赏。

4

2 回答 2

2

point-minpoint-max是函数,所以你应该调用它们(item (point-min) (point-max))

(tempo-define-template
 "env"
 '("\\begin{" (p "Environment: " environment) "}" > n>
   r> n>
   "\\end{" (s environment) "}" > n
   (item (point-min) (point-max))) ; HERE
 "env"
 "Insert a LaTeX environment.")
于 2012-08-08T07:15:41.890 回答
0

@Deokhwan Kim:感谢您对此进行调查。在模板中使用 (item (point-min) (point-max)) 会替换整个缓冲区。使用 (item (region-beginning) (region-end)) 修改后的模板现在可以工作:

(require 'tempo)
(setq tempo-interactive t)

(tempo-define-template
 "list"
'("\\begin{" (p "List environment: " environment) "}" > n>
r> (item (region-beginning) (region-end)) 
"\\end{" (s environment) "}" > n>
)
"list"
"Insert a LaTeX list environment.")

(defun item (start end)
(interactive "r")
(save-excursion
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward "^[^\\]" (point-max) t) (replace-match "\\item " nil t))
(widen)
))
于 2012-08-09T01:58:07.450 回答