[英]tempo mode elisp function acting on region
我正在尝试设置一个速度模板,当使用 Cu 前缀调用时,它会用标签 \\begin{environment} 和 \\end{environment} 包围该区域,并在每行的开头插入标签 \\item地区。 然而,它给出了“save-excursion: Args out of range: 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: Symbol's value as variable is void: point-min”错误。 任何解决问题的指针都表示赞赏。
point-min
和point-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.")
@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)
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.