Emacs 最好的代码模板工具是什么? [英] What is the best code template facility for Emacs?

查看:43
本文介绍了Emacs 最好的代码模板工具是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

特别是,最好的代码片段包是什么?

Particularly, what is the best snippets package out there?

特点:

  • 易于定义新的片段(纯文本、带有默认值的自定义输入)
  • 代码段中预定义位置之间的简单导航
  • 多次插入相同的自定义输入
  • 接受当前选择的文本作为自定义输入
  • 跨平台(Windows、Linux)
  • 用简洁的编程语言(Perl、Python、Ruby 是首选)编写的动态计算表达式(嵌入式代码)
  • 与 Emacs 中的其他软件包很好地共存
  • easy to define new snippets (plain text, custom input with defaults)
  • simple navigation between predefined positions in the snippet
  • multiple insertion of the same custom input
  • accepts currently selected text as a custom input
  • cross-platform (Windows, Linux)
  • dynamically evaluated expressions (embedded code) written in a concise programming language (Perl, Python, Ruby are preferred)
  • nicely coexists with others packages in Emacs

代码模板示例,C中一个简单的for循环:

Example of code template, a simple for loop in C:

for (int i = 0; i < %N%; ++i) {
  _
}

这样的通用代码需要大量输入.我想调用插入的代码模板或片段给我的样板代码.此外,它会在 %N%(我的输入替换它)处停止(在 TAB 或其他击键上)并且光标的最终位置是 _.

It is a lot of typing for such common code. I want to invoke a code template or snippet which inserts that boilerplate code for me. Additionally it stops (on TAB or other keystroke) at %N% (my input replaces it) and final position of the cursor is _.

推荐答案

TextMate 的片段是最接近的匹配,但它不是跨平台的解决方案,也不适用于 Emacs.

TextMate's snippets is the most closest match but it is not a cross-platform solution and not for Emacs.

第二接近的是 YASnippet(screencast 显示了主要功能).但它干扰了我设置中的 hippie-expand 包,并且嵌入式语言是 EmacsLisp,我在 .emacs 之外对它感到不舒服.

The second closest thing is YASnippet (screencast shows the main capabilities). But it interferes with hippie-expand package in my setup and the embedded language is EmacsLisp which I'm not comfortable with outside .emacs.

编辑:在此处发布我的答案以允许对 YASnippet 进行投票.

EDIT: Posted my answer here to allow voting on YASnippet.

这篇关于Emacs 最好的代码模板工具是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆