Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support to hide/override snippets #270

sheijk opened this Issue Jul 26, 2012 · 5 comments


None yet
3 participants

sheijk commented Jul 26, 2012

In older yasnippet versions (at least 0.5.*) it was possible that a snippet would override/hide another one with the same name in a parent snippet directory. Since the move to the new non-hierarchical directory structure and use of .yas-parents files this does not work anymore. It would be nice to bring this back as an easy way to have a snippet that behaves differently in some modes.

My example for this would be a snippet that creates a comment line of fill-column characters length. For yasnippet 0.5.0 I had the following directory structure:

    hl <- creating something like --------
      hl <- creating something like //--------

I am working around this for current trunk with some code like this:

(defvar shk-hline-char ?- "Character from which horizontal comment line is made")

(defun shk-make-hline ()
  (if (not comment-start)
      (make-string fill-column shk-hline-char)
    (format "%s%s"
            (make-string (- fill-column (length comment-start)) shk-hline-char))))

(defun shk-set-hline-char-to-semicolon ()
  (set (make-local-variable 'shk-hline-char) ?\;))
(eval-after-load 'lisp-mode
  '(add-hook 'emacs-lisp-mode-hook 'shk-set-hline-char-to-semicolon))

Maybe instead of supporting hiding snippets explicitly it would be possible to automatically load code from .el files inside the snippet directories so such utilities could be included in a snippet library?

sheijk commented Jul 26, 2012

Also see discussion in the forum

I also just noticed this new behavior and google pointed me to this issue. Many of my snippets are modified versions of the snippets shipped with yasnippet and it used to work to override by simply using the same name, and it would be great to have that feature back.


joaotavora commented Aug 29, 2012

I'm not sure we're talking abou the same issue here: @sheijk is talking about snippets in derived modes overriding the paren't modes. But you can always override snippets by placing them in a directory that appears earlier in yas-snippet-dirs. Are you using more than one element in yas-snippet-dirs ? Can you explain clearly what your setup is. Where exactly is the snippet that you want overridden and where does the overriding snippet live?

Yes, I was confused. Just came back to say that.

However if I understand the issue correctly, it is also something I would like. I guess it is required when I want eg some default snippet in cc-mode, but slightly modify it for java-mode (having cc-mode set up as a parent)?


joaotavora commented Aug 30, 2012

Yes that's a more reasonable use case. I'll have a look at this when I find the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment