tags:

views:

74

answers:

3

I have a template I use when creating a ruby script.

Currently when I rename a copy of that template and load it in emacs and get to coding.

I think emacs can load a template for me though. Ideally I could do this.

  • Ctrl X Ctrl F to open a file.
  • Type in name of file that doesn't exist (aka my new file).
  • Emacs recognizes the file doesn't exist and loads my template (right now it loads a blank screen).

Anyone done this?

Thanks!

+3  A: 
(add-hook 'find-file-hooks 'maybe-load-template)
(defun maybe-load-template ()
  (interactive)
  (when (and 
         (string-match "\\.rb$" (buffer-file-name))
         (eq 1 (point-max)))
    (insert-file "C:/Home/template.rb")))
Kilian Foth
+2  A: 

You probably want something like the 'template' package. Or, alternatively, if you are comfortable with emacs-lisp to define the template you can use the built-in skeleton functionality in emacs 22 and above.

Peter Hart
+2  A: 

There are lots of ways to do it on the Emacs wiki.

scottfrazer
Also check out http://www.emacswiki.org/emacs/CategoryTemplates
Noufal Ibrahim