节奏模式elisp函数作用于区域

时间:2012-08-08 04:29:43

标签: emacs elisp

我正在尝试设置一个速度模板,当使用Cu前缀调用时,将使用标记\ begin {environment}和\ end {environment}包围区域,并在每个开头插入标记\ item该地区的线路。然而它给出了'save-excursion: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)
)) 

项目功能本身可以在某个区域上正常工作。我尝试在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'错误。 任何解决问题的方法都表示赞赏。

2 个答案:

答案 0 :(得分: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.")

答案 1 :(得分: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)
))