Yasnippet: How to expand on “ or” but not on “-or”

谁说胖子不能爱 提交于 2019-12-12 18:46:55

问题


Title says it, is it possible to alter yasnippets behavior so that it is not possible to expand on "-or" but it is possible to expand on "[newline]or" or "[tab]or" only?

I would like this because I am trying to expand my yasnippets automatically when expansion is possible, and there is only ever confliction when I am writing variable names.


回答1:


I got the solution here: http://ergoemacs.org/emacs/emacs_tip_yasnippet_expand_whole_hyphenated_word.html

There is variable (defvar yas-key-syntaxes (list "w" "w_" "w_." "w_.()" "^ ")..), which controls kinds of expansions. "w" means that `"-or" is expanded as separate "or".

If

(setq yas-key-syntaxes '("w_" "w_." "w_.()" "^ "))

then "-or" is expanded as complex expression "<some>-or" only. But " or" is expanded as usually.

So, "buffer-substring" will be expanded only if there is file buffer-substring.yasnippet with content

# contributor: Xah Lee (XahLee.org)
# name: buffer-substring
# key: buffer-substring
# --
(buffer-substring START$0 END)

But with "w" keyword "buffer-substring" will be expanded as substring.yasnippet.

If there is additional string # key: bs in file buffer-substring.yasnippet then "buffer-substring" won't be expanded at all. (For Version: 0.8.0)



来源:https://stackoverflow.com/questions/14335142/yasnippet-how-to-expand-on-or-but-not-on-or

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!