mineo / yatemplate

File templates for Emacs with YASnippet
https://github.com/mineo/yatemplate
GNU General Public License v3.0
70 stars 11 forks source link

support lazy loading of yasnippet #3

Closed fommil closed 6 years ago

fommil commented 9 years ago

thanks for this! I had written something similar myself, but I'm moving over to use your library.

One thing I'd like is to be able to load yasnippet lazily (it's a really heavy package because of all the snippets that need to be parsed), but it seems that filling the alist will force the load of yasnippet.

Is there any chance you could please make your use of yasnippet lazy loading (i.e. no require) and/or assume its loaded already? (you might still need to load some parts of yasnippet to be able to do the alist filling)

fommil commented 9 years ago

workaround is to use deferred loading, but this is far from ideal.

(use-package yatemplate
  :defer 2
  :config
  (auto-insert-mode)
  (yatemplate-fill-alist))
mineo commented 9 years ago

It's not the alist filling that needs yasnippet, it's only required in yatemplate-expand-yas-buffer (to expand content that was inserted into the buffer) and find-file-hook--yatemplate (to enable snippet-mode for editing). It should be possible to simply move require calls into both of these functions (the emacs lisp manual does this in the first example with comint).

AFAIK simply requiring yasnippet also doesn't actually load all the snippets, it's the call to either yas-global-mode or yas-reload-all. However, not calling them (or enabling yas-minor-mode) makes yas-expand-snippet complain about missing mode setup.

But I think what's best is for me to open a feature request over at the yasnippet repo to provide a function for expanding a string without consulting the snippet table. Then we could even keep the (require 'yasnippet) at the top of the file (or does that already trigger use-package blocks defined for yasnippet?) and just not care about the snippet table at all :-)

mineo commented 9 years ago

On second thought and a little bit of trying, yas-minor-mode is required for the tabstop fields to work…

fommil commented 9 years ago

yes exactly, you don't actually need to require yasnippet to be able to do the filling, but because its declared in that file, it loads it aggressively.

fommil commented 9 years ago

re: loading snippets, but I have use-package set up to load all the snippets when yasnippet is loaded :-)