30

Particularly, what is the best snippets package out there?

Features:

  • 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

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

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

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 _.

jfs
  • 399,953
  • 195
  • 994
  • 1,670

6 Answers6

23

TextMate's snippets is the most closest match but it is not a cross-platform solution and not for 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.

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

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
jfs
  • 399,953
  • 195
  • 994
  • 1,670
5

Personally, I've been using Dmacro for years (ftp://ftp.sgi.com/other/dmacro/dmacro.tar.gz).

Here's a review of it that also mentions some alternatives: http://linuxgazette.net/issue39/marsden.html

cjm
  • 61,471
  • 9
  • 126
  • 175
4

The EmacsWiki has a page of template engines.

Of these, I've used tempo in the (distant) past to add table support to html-helper-mode, but don't know how it has progressed in the last 15 years.

Joe Hildebrand
  • 10,354
  • 2
  • 38
  • 48
3

I'd add my vote for tempo snippets ... easy to setup, powerful (you can run arbitrary elisp in your template - so that you can downcase things, lookup filenames & classes, count things, etc), set the indentation, integrate with abbrevs ... I use it a lot ;)

l0st3d
  • 2,860
  • 1
  • 27
  • 29
2

I vote for http://cedet.sourceforge.net/srecode.shtml

It has very clean syntax and has access to code environment through Semantic.

Also it is a part of a large well supported CEDET distribution (which was built into Emacs for 24.x version series).

UPDATE YASnippet is also a powerful template engine. But it uses an ugly file naming schema (your file name === template name) for you can't put several templates into a single file and have issues with national character sets...

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
1

You can try a lightweight solution muban.el

It is written completely in Elisp and has a very simple syntax.

Jiahao
  • 19
  • 1