load template in emacs when creating new file
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!
(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")))
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.
There are lots of ways to do it on the Emacs wiki.
精彩评论