ang*_*ixd 11 emacs elisp yasnippet
我喜欢yasnippet,但需要时间记忆.我想做的是当我处于可以扩展宏的点时(当没有宏时再次返回),更改光标颜色.但是,从我记忆中yasnippet如何工作,这可能不完全是高性能的.
一位朋友建议我在这里想要的是一个yasnippet-can-fire-p,但我仍然不确定这样做的最好方法.实现这一目标最干净的道路是什么,不会让我的系统停止运转?
Pas*_*ten 13
花了一些时间来找到检查它是否可以扩展的功能,但是"幸运"足以最终找到它.
关键是该函数通常会扩展或以其他方式执行回退行为.我克隆了这个函数,并在那些地方设置光标颜色.
而且,令人惊讶的是,它实际上并没有减速.
;; 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)
Run Code Online (Sandbox Code Playgroud)
将此添加到我的lisp集合中(我实际上认为这也很有用).
更新:在最新版本的yasnippet [从2014年8月起,来自0.8.1
],yas--current-key
功能已重命名为yas--templates-for-key-at-point
.cf 问题