gpt4 book ai didi

emacs - 当 Yasnippet 宏可以触发时,如何触发事件?

转载 作者:行者123 更新时间:2023-12-04 02:02:52 24 4
gpt4 key购买 nike

我喜欢 yasnippet,但它需要时间来内存。我想要做的是在可以扩展宏的时候更改光标颜色(当没有宏时再返回)。但是,根据我对 yasnippet 的工作方式的内存,这可能并不完全有效。

一位 friend 建议我在这里想要的是 yasnippet-can-fire-p,但我仍然不确定这样做的最佳方法。实现这一点的最干净的方法是什么,不会使我的系统陷入停顿?

最佳答案

花了一些时间来找到检查它是否可以扩展的函数,但最终“幸运”地找到了它。

关键是这个函数通常会扩展,或者以其他方式执行回退行为。我克隆了这个函数并在这些地方设置了光标颜色。

而且,令人惊讶的是,它实际上根本没有减速。

;; It will test whether it can expand, if yes, cursor color -> green.
(defun yasnippet-can-fire-p (&optional field)
(interactive)
(setq yas--condition-cache-timestamp (current-time))
(let (templates-and-pos)
(unless (and yas-expand-only-for-last-commands
(not (member last-command yas-expand-only-for-last-commands)))
(setq templates-and-pos (if field
(save-restriction
(narrow-to-region (yas--field-start field)
(yas--field-end field))
(yas--current-key))
(yas--current-key))))

(set-cursor-color (if (and templates-and-pos (first templates-and-pos))
"green" "red"))))

; As pointed out by Dmitri, this will make sure it will update color when needed.
(add-hook 'post-command-hook 'yasnippet-can-fire-p)

将此添加到我的 lisp 集合中(我实际上认为这也很有用)。

更新:在最新版本的 yasnippet [从 2014 年 8 月开始,来自 0.8.1 ], yas--current-key函数已重命名为 yas--templates-for-key-at-point .参见 Issue

关于emacs - 当 Yasnippet 宏可以触发时,如何触发事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14264228/

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