Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support to hide/override snippets #270

Open
sheijk opened this Issue · 5 comments

3 participants

@sheijk

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:

snippets/
  text-mode/
    hl <- creating something like --------
    c++-mode/
      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"
            comment-start
            (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

Also see discussion in the forum

@lifelike

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.

@capitaomorte

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?

@lifelike

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)?

@capitaomorte

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
Something went wrong with that request. Please try again.