I've just discovered "yasnippet" when I'm looking for a powerful minor
mode to handle code snippets. (Actually I've heavily used "msf-abbrev"
until now, but I began to miss more powerful mechanisms to handle
variable parts of snippets. Thus I was looking for something else that
let me write snippets easily and provide powerful building blocks for
them at once. "yasnippet" seems to satisfy both needs.)
I suggest a tiny reorganization of `yasnippet.el's code: Function `yas/
reload-all' contains code that loads the directory in `yas/root-
directory' - or all directories in `yas/root-directory' if this
variable is a list. I would factor out that code into a separate
function, say `yas/load-root-directory'. Than loading snippets during
"yasnippet"'s initialization would be a little more convenient: You
can just call `(yas/load-root-directory)', and it does not matter
whether `yas/root-directory's value is single directory or a list.
Below you will find a patch for the current SVN revision's
"yasnippet.el" doing this changes.
Dirk
--------------------------------------8<---------------------------------------------------
--- a/yasnippet.el Mon Dec 21 12:48:58 2009 +0100
+++ b/yasnippet.el Mon Dec 21 17:11:11 2009 +0100
@@ -1,4 +1,4 @@
-;;; Yasnippet.el --- Yet another snippet extension for Emacs.
+;;; yasnippet.el --- Yet another snippet extension for Emacs.
;; Copyright 2008 pluskid
;; 2009 pluskid, joaotavora
@@ -1515,6 +1515,17 @@
(when (interactive-p)
(message "[yas] Loaded snippets from %s." directory)))
+(defun yas/load-root-directory ()
+ "Reload the directories listed in `yas/root-directory' or
+ prompt the user to select one."
+ (if yas/root-directory
+ (if (listp yas/root-directory)
+ (dolist (directory yas/root-directory)
+ (yas/load-directory directory))
+ (yas/load-directory yas/root-directory))
+ (call-interactively 'yas/load-directory))
+ )
+
(defun yas/reload-all (&optional reset-root-directory)
"Reload all snippets and rebuild the YASnippet menu. "
(interactive "P")
@@ -1541,12 +1552,7 @@
;; Reload the directories listed in `yas/root-directory' or
prompt
;; the user to select one.
;;
- (if yas/root-directory
- (if (listp yas/root-directory)
- (dolist (directory yas/root-directory)
- (yas/load-directory directory))
- (yas/load-directory yas/root-directory))
- (call-interactively 'yas/load-directory))
+ (yas/load-root-directory)
;; Reload the direct keybindings
;;
(yas/direct-keymaps-reload)
--------------------------------------8<---------------------------------------------------
I try to add this and enhacement of issue 117 in the following weeks.
Bye,
João