簡體   English   中英

作用於區域的速度模式 elisp 函數

[英]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-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.")

@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM