效果的视频欣赏
- emacs yasnippet—在线播放—优酷网,视频高清在线观看
http://v.youku.com/v_show/id_XMjMxNDg5MjQ4.html?from=s1.8-1-1.2&spm=a2h0k.8191407.0.0
yasnippet的安装及使用,参考文档:
- Emacs: How to Define Templates in YASnippet
http://ergoemacs.org/emacs/yasnippet_templates_howto.html
verilog-mode下的yasnippet
GitHub - dallingham/verilog-mode-snippets: A set of yasnippets for emacs that assist with SystemVerilog https://github.com/dallingham/verilog-mode-snippets
举例:spacemacs verilog语言的yasnippet操作
- 打开verilog的文件,使emacs处于verilog-mode下;
- 菜单,YASnippet->New snippet
2.1 输入name内容;“用户使用的时候,提示yasnippet的名称”
2.2 输入key内容; “用户使用的时候,输入匹配的key内容,然后TAB键,就可以得到对应的yasinppet代码模板。”
2.3 在# --
的下一行输入内容;语法参考emacs大神-李杀-的emacs手册
Emacs: How to Define Templates in YASnippet
http://ergoemacs.org/emacs/yasnippet_templates_howto.html - 生成文件名跟key一般是对应的;然后会默认保存在目录:
.emacs.d/private/snippets/verilog-mode/ - yasnippet的创建已完成;
- 使用:
5.1 在verilog文件里,(非spacemacs用户,可以输入yasnippet key内容,然后TAB键展开代码模板。但是spacemacs用户,不能采用相同方式。)
5.2 spacemacs用户,输入快捷键SPC i s
会提示当前verilog-mode下的所有yasnippet;然后可以根据单词扩展,选择需要的yasnippet。这里想讲一句,spacemacs的操作方式,比默认emacs的方式,要舒服很多,点赞。
tips
可以实现各种代码模板,包括注释模板。
可以参考emacs自带的yasnippet文档
命令是:
c-h f yas-minor-mode
可以利用emacs的elisp代码,实现功能命令输出。
You can also include lisp code in your template. For example, you might want to have a date stamp. Here’s a example that insert user’s email address and datestamp.
`user-mail-address`
`(current-time-string)`