我正在尝试增强 etags-select 功能,以便如果 find-tag 点失败,它将回退到正常的 find-tag 。我试过的代码是:
(defun my-etags-find-tag ()
"Find at point or fall back"
(interactive)
(unless (etags-select-find-tag-at-point)
(etags-select-find-tag)))
(global-set-key (kbd "C-f") 'my-etags-find-tag)
但是,当点不在有效标签上时,这会失败。相反,我收到了 etags-select-find-tag-at-point 引发的错误:
etags-select-find-tag-at-point: Wrong type argument: char-or-string-p, nil
在这种情况下,我只需要重复etags-select-find-tag-at-point完成的测试:
(defun my-etags-find-tag ()
"Find at point or fall back"
(interactive)
(if (find-tag-default)
(etags-select-find-tag-at-point)
(etags-select-find-tag)))
但这似乎有点多余。是否可以在 elisp 中捕获异常并进行替代处理?