Search code examples
emacselispyasnippet

Prevent HAML snippets loading when using sass-mode and yasnippet


I'm using Emacs with sass-mode and yasnippet to edit .sass files. This is all working great and the snippets are expanding. But since sass-mode requires haml-mode the haml snippets are also loaded when editing sass files. This is rather annoying since the haml snippets are useless in sass.

I've checked my snippets directory for a .yas-parents file and didn't find one. And I've searched through the documentation and elisp code but a setting or function didn't jump out at me. When I run M-x yas-describe-table within a sass buffer I'm showon the expantion tables for both sass and haml.

Ideally I'd like to prevent the haml snippets from loading when opening when working on a sass buffer. But if I could setup some sort of hook to remove the haml table of snippets when sass buffers are loaded that would be good too.

Thanks!


Solution

  • There does not seem to be a way in yasnippets to do what you want. So you should open issue on yasnippet github repo requesting this feature.

    As a temporary solution you can disable loading of haml-mode snippets in sass-mode by advising yas--modes-to-activate as follows. Remember this is NOT recommended

    (eval-after-load "yasnippet"
      '(progn (defadvice yas--modes-to-activate (after my-simple-advise)
               (when (eq major-mode 'sass-mode)
                 (setq ad-return-value (remove 'haml-mode ad-return-value))))
    
             (ad-activate 'yas--modes-to-activate)))
    

    The above advises yas--modes-to-activate so that haml-mode is not returned as a mode to load when in sass-mode.