Open PythonNut opened 9 years ago
Hmm, doing this in a backward-compatible way may be difficult. Using two :
would definitely cause issues, because currently yatemplate is documented to specifically throw away everything before the first :
.
It could be something like 00-major-mode:c++-mode
, since that wouldn't break ordering constraints, but that would still be a breaking change (albeit one that is unlikely to collide with anything). Have you ever had any thoughts about this @mineo?
Right now I just have Doom's template system copied in my config file. I'd like to switch to something that's actually packaged, but the functionality of yatemplate seems limited by comparison. For example, Doom's template system supports this:
(setq doom-+file-templates-alist
`((,(rx ".org" eol)
:when noct-blog-dir-p
:trigger "__post"
:mode org-mode)
(emacs-lisp-mode :trigger "__package")))
Going entirely by file naming seems too basic to handle more complex cases.
I've ultimately decided that doing this in file names is probably a bad idea to begin with. It makes it much more likely that my emacs config will fail on some more exotic filesystems (or, i don't know, an OS that uses \
as a path separator, but who would want to use such a thing?), and it makes things awkward to type if you want your regexes to be a little robust. It also indeed prevents using the really, really nice rx
macro.
The code for doing it with just autoinsert
isn't a significant amount of boilerplate anyway (or any if you don't want to write regexes in your file names), so I don't think that a package is actually necessary for the basics.
autoinsert
supports file name regexes and modes, I don't know by what sorcery the :when
thing works for doom (but perhaps arbitrary functions are accepted and undocumented, or doom does regex manipulation?), but I find I don't need that for my config currently.
The only slight annoyance is that it feels like the template names are duplicating information, which is why I used yasnippet in the first place. I think ideally yasnippet
itself would be extended to have a template
pragma instead, where you can record these regexes/mode names. I looked a little into doing that, but it's a bit much effort for what I want to do. Upstream hasn't seen much maintenance lately either, and I'm not too interested in trying to work on something that will never be merged anyway.
I don't know by what sorcery the :when thing works for doom
Doom doesn't use autoinsert at all; it uses find-file-hook
. It has a couple other useful keywords as well.
I think ideally yasnippet itself would be extended to have a template pragma instead, where you can record these regexes/mode names. I looked a little into doing that, but it's a bit much effort for what I want to do. Upstream hasn't seen much maintenance lately either, and I'm not too interested in trying to work on something that will never be merged anyway.
Yeah, it would be nice if yasnippet just had this functionality built in. I would package an alternative myself, but I don't really want to maintain it. I'll just keep the code in my config for now.
See #32 for a possible solution
See #32 for a possible solution
Very cool! Hope it lands, last I looked upstream wasn't really accepting PRs because they're working on a more-or-less full rework of the codebase that in turn has stalled. Maybe I'll switch to your branch in the mean time :)
auto-insert-mode
can define insertions by major mode (in addition to regex matching the filename). It would be great ifyatemplate
also supported this. Perhaps something-like:To define a snippet for
c++-mode
.