Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best code template facility for Emacs? [closed]

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

like image 780
jfs Avatar asked Sep 14 '08 16:09

jfs


2 Answers

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.

like image 84
jfs Avatar answered Sep 19 '22 13:09

jfs


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

like image 27
cjm Avatar answered Sep 20 '22 13:09

cjm