gpt4 book ai didi

emacs - 对 "wrong-type-argument"使用react

转载 作者:太空宇宙 更新时间:2023-11-03 18:42:18 25 4
gpt4 key购买 nike

所以我开始学习一些 lisp/elisp 来优化我的 emacs 环境,并且我已经开始制作一个简单的 emacs 库,主要障碍是能够判断输入的括号是否匹配.我一直在查看 emacs 源代码 (paren.el.gz) 并意识到我可以使用函数 show-paren-function 来确定它是否匹配。

这是我到目前为止所得到的:

(defun it-is-a-paren()
(interactive)
(insert ")")
(if (show-paren-function)
(message "%s" "it is a match")
(message "%s" "it is not")))

所以这是非常基本的,“它是一个匹配”按它应该的方式工作,但是当它应该抛出“它不是”时,它没有,而是给我“错误的类型参数:整数-或-标记-p, t"。

有没有足够熟悉的人建议使用不同的函数,或者我应该完全编写自己的函数而不是使用 show-paren-function。或者是否有解决此错误的方法(有点像异常处理)?

最佳答案

您正在寻找的类似于“异常处理”的结构是condition-case

(defun its-a-paren()
(interactive)
(insert ")")
(condition-case ex
(if (show-paren-function)
(message "its a match")
(message "its not"))
(error (message "its not"))))

编辑:查看show-paren-function 的代码,在我看来这个错误是一个错误,因为它来自表达式( goto-char pos) 其中 post

无论如何,show-paren-function 使用scan-sexps 来寻找匹配的paren。根据在 show-paren-function 中完成的方式进行改编,针对您的情况的简化函数将是:

(defun its-a-paren()
(interactive)
(insert ")")
(condition-case ()
(progn
(scan-sexps (point) -1)
(message "It's a match"))
(error (message "It's not a match"))))

关于emacs - 对 "wrong-type-argument"使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9862401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com