elisp错误的类型参数:integer-or-marker-p错误

时间:2013-04-12 19:41:01

标签: emacs elisp

我有下面的文字(实际标签而不是\ t),我需要在“描述”之后的标签之后,抓住所有文本,直到缓冲区结束。

key1\tval1      
key2\tval2
key3\tval3      
Description\tlots and lots and lots and lots and lots lots 
and lots and lots and lots and lots lots and lots and lots and 
lots and lots lots and lots and lots and lots and lots lots and 

lots lots and lots and lots and lots and lots lots and lots lots 

and lots and lots and lots and lots lots and lots lots and lots 

and lots and lots and lots lots and lots lots and lots and lots 
and lots and lots lots and lots lots and lots and lots and lots 
and lots lots and lots lots and lots and lots and lots and lots

这是lisp函数:

(defun find-description()
  (interactive) 
  (goto-char (point-min))
  (when (re-search-forward "Description\t")
    (setq myStr (buffer-substring (point) (end-of-line)))
    (goto-char (point-max))
    (insert "\n\n\ndescription=")
    (insert myStr)
   )
)

这在(setq行错误:

上失败了
Wrong type argument: integer-or-marker-p, nil

我认为在正则表达式搜索之后,该点将在Description \ t之后。那么为什么不设置变量呢?

1 个答案:

答案 0 :(得分:3)

end-of-line的值不是标记或位置,因此尝试在buffer-substring中使用该值是导致错误消息的原因。简单的解决方法是在移动到行尾之后获取缓冲区位置;

(let ((beg (point))
  (end-of-line)
  (setq myStr (buffer-substring beg (point)) )

另请注意https://stackoverflow.com/a/15974319/874188,它指出line-end-position是一个更简单的修复方法。

你也可以重构这个以避免临时变量,例如:通过搜索"Description\t\([^\n]*\)"并拉出匹配的子字符串,但我想无论哪种方式都没问题。

顺便说一句,通过将debug-on-error设置为真值来检查回溯,很快就会揭示出问题的原因。