Change cursor color when Yasnippet can be fired
This commit is contained in:
parent
61a95107de
commit
74176aa6a5
32
init.el
32
init.el
@ -1210,3 +1210,35 @@
|
|||||||
(file-directory-p (helm-get-selection)))
|
(file-directory-p (helm-get-selection)))
|
||||||
(helm-execute-persistent-action)
|
(helm-execute-persistent-action)
|
||||||
(insert "/")))
|
(insert "/")))
|
||||||
|
|
||||||
|
(setq default-cursor-color (frame-parameter nil 'cursor-colbxuor))
|
||||||
|
(setq yasnippet-can-fire-cursor-color "purple")
|
||||||
|
|
||||||
|
;; It will test whether it can expand, if yes, cursor color -> purple.
|
||||||
|
(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--templates-for-key-at-point))
|
||||||
|
(yas--templates-for-key-at-point))))
|
||||||
|
(and templates-and-pos (first templates-and-pos))))
|
||||||
|
|
||||||
|
;; Taken from http://pages.sachachua.com/.emacs.d/Sacha.html
|
||||||
|
(defun sachachua/change-cursor-color-when-can-expand (&optional field)
|
||||||
|
(interactive)
|
||||||
|
(when (eq last-command 'self-insert-command)
|
||||||
|
(set-cursor-color (if (sachachua/can-expand)
|
||||||
|
yasnippet-can-fire-cursor-color
|
||||||
|
default-cursor-color))))
|
||||||
|
|
||||||
|
(defun sachachua/can-expand ()
|
||||||
|
"Return true if right after an expandable thing."
|
||||||
|
(or (abbrev--before-point) (yasnippet-can-fire-p)))
|
||||||
|
|
||||||
|
(add-hook 'post-command-hook 'sachachua/change-cursor-color-when-can-expand)
|
||||||
|
Loading…
Reference in New Issue
Block a user