GithubHelp home page GithubHelp logo

andreacrotti / yasnippet-snippets Goto Github PK

View Code? Open in Web Editor NEW
1.1K 35.0 461.0 1.42 MB

a collection of yasnippet snippets for many languages

License: GNU General Public License v3.0

Emacs Lisp 2.30% YASnippet 96.15% Clojure 1.55%
yasnippet emacs emacs-lisp

yasnippet-snippets's Introduction

Yasnippet official snippet collections

MELPA Stable NonGNU ELPA MELPA

This repository contains the official collection of snippets for yasnippet.

How to install

From melpa

You can install this package from melpa, by first ensuring that you have the melpa source in your package-archives.

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
(package-initialize)

Once that is done, then just refresh the packages and install it with.

  • M-x package-refresh-contents
  • M-x package-install yasnippet-snippets

Now all the snippets will load automatically, as soon as yasnippet loads.

On Debian ≥10 and derivatives such as Ubuntu ≥ 18.10

sudo apt install elpa-yasnippet-snippets

Contributing

If you have any useful snippets for any language or framework, then please feel free to contribute, by opening a PR or an issue if you have any suggestions.

To study the current snippets, I suggest that you use M-x yas-describe-tables, which will show a table representation of all the snippets that are available in the current mode.

Guidelines

Snippets need to be generic enough to be useful for everyone, and not contain anything specific to your own system.

Various notes

HTML snippets

Until September 1st 2014 there were a lot of HTML snippets in the repository, which sometimes were useful, but I came to the conclusion that yasnippet was not the right tool for them, so they were removed in this pull request: #49

To everyone writing a lot of HTML I suggest using emmet mode instead, which is a much more powerful mode for writing HTML tags.

yasnippet-snippets's People

Contributors

andersontorres avatar andreacrotti avatar bgamari avatar dakling avatar dgutov avatar equwal avatar gbalats avatar grafov avatar jaigupta avatar jferguson-gnubio avatar julienpalard avatar magnetophon avatar npostavs avatar olivia5k avatar picosushi avatar quazgar avatar r-darwish avatar rrooij avatar s9gf4ult avatar sei40kr avatar sh-ow avatar spacecowboy avatar sshaw avatar sten0 avatar unhammer avatar vedvyas avatar wyuenho avatar ybiquitous avatar yorkz avatar zbeekman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yasnippet-snippets's Issues

[Python] pyplot pl vs plt

It seems like the standard way to import pyplot from matplotlib is:

import matplotlib.pyplot as plt

instead of:

import matplotlib.pyplot as pl

I believe that the pl snippet should be changed to reflect that.

I am basing this off of the documentation and other general documentation. What do people think of this change?

text-mode snippets

Emacs v24.3
yasnippet a0c2217
snippets c8b6d19

mode and localvar are broken (or my installation is). localvar fails because it uses ca-with-comment rather than the yas-with-comment swapped in af6fa9a. Tab-completing mode results in

;-*- mode: ${1:mode} -*-?

where point is denoted by ?.

js-mode function

function${1: ${2:name}}(${3:arg}) { $0 }
maybe add a space is better
function ${1: ${2:name}}(${3:arg}) { $0 }

cc-mode once does not expand correctly

Hello. Thank you for the collection of snippets.
I am having a bug with cc-mode once: when I try to complete the snippet with C-S-i (see configuration below), I get the following:

#ifndefY_H}
#define 



#endif /*  */

And I see the following line in the Messages buffer
yas--snippet-parse-create: Wrong type argument: char-or-string-p, (stringp nil)

I looked into the snippet, and tried to debug. So, I went to scratch, and I get an error with this:
(file-name-sans-extension (buffer-file-name))

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  file-name-nondirectory(nil)
  file-name-sans-extension(nil)
  eval((file-name-sans-extension (buffer-file-name)) nil)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

Which seems to be relevant only when the buffer is not saved. When the file is saved, the name does appear next to ifndef (without space in between), but it is not expanded in the rest of the snippet, and hitting tab does not move the mark to the next tag.

I also have this in Warnings

Warning (yasnippet): Couldn't find: "[[:space:]
]*#ifndef[[:space:]
]*TEST_H}[[:space:]
]*#define[[:space:]
]*#endif[[:space:]
]*/\\*[[:space:]
]*\\*/[[:space:]
]*\\(\\)[[:space:]
]*#endif[[:space:]
]*/\\*[[:space:]
]*\\*/"

If I knew how to fix it, I would propose a solution, but I am really not good with lisp. I tried with an actual file and a new c-mode buffer. Also, I don't know if this has to do with the snippet alone or yasnippet as a whole (may be related to joaotavora/yasnippet#784).

My configuration (running emacs -Q):
emacs GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2)
yasnippet-20170326.1030 from melpa

.emacs (init file)

(require 'package)
(package-initialize)
(require 'yasnippet)
(define-key yas-minor-mode-map (kbd "<tab>") nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "C-i") nil)
(define-key yas-minor-mode-map (kbd "C-S-i") 'yas-expand)

(add-hook 'prog-mode-hook 'yas-minor-mode)

(require 'function-args)
(add-hook 'c-mode-common-hook (lambda ()
                                (function-args-mode) ; Find definitions in current buffer
                                (setq tab-width 4) ; set tab width to 4
                                (auto-fill-mode) ; break long lines
                                (yas-minor-mode) ; activate yasnippet
                                ))

How to discard the eval result of elisp code in a snippet ?

Hi !

I'd like to do something like (require 'org-table) in before/after loading a snippet. For example, I want to lazily load the package org-table before/after loading a snippet like

`(require 'org-table)`
`(orgtbl-mode 1)`
% BEGIN RECEIVE ORGTBL ${1:table}
% END RECEIVE ORGTBL $1
#+ORGTBL: SEND $1 orgtbl-to-latex :splice nil :skip 0
|$0

which is from here.

Wrapping the elisp code in a `, the eval result will be inserted in to buffer which is unexpected. How can I achieve this besides the before insert and after expand hooks ?

Thanks !

Haskell-mode pragma snippet is a huge pain with autopairing braces

As someone who programs in several curly-brace languages as well as Haskell, the pragma snippet of '{' is really annoying for me to use, as I have autopair for curly braces on. Would it be possible to change it to something that doesn't clash with autopairing curly braces?

New mode for Fortran 77

Hi,
I wrote some snippets for Fortran 77 and put them in a folder next to the "F90-mode" folder calles "f-mode" and hoped that this would work .... It didn't! Is there anything i have to do in order to be able to execute these snippets?
Thanks!

cc/c++-mode overloaded keys

Leaving this here as a proposition and a request for comments.

Currently when you hit tab on inc in cc-mode it offers you both includes, system and local and you have to pick one. I fixed this for myself by changing them to incs and incl.
Same thing for f in c++-mode which stands for a function declaration or a member function definition. I would suggest replacing the member function definition key with mf.

There is no shortage of (meaningful) abbreviations in c/c++-mode so I dont think there is a need for these collisions. If I am not alone with this thought I get a patch ready of course.

adoc-mode snippets proposal

I just ported the asciidoctor snippets, as defined for the Atom editor, to YASnippet. I've created a seperate adoc-mode-yasnippet repo. The original snippets were defined here.

If this meet the criteria for inclusion, I'd be happy to convert it into a PR.

Using js2-mode in snippets for js-mode

Since I'm using emacs for React development, I don't use js2-mode (Because it contains many bugs for parsing JSX). But js-mode of yasnippet-snippets does not works on js-mode.
When I don't load js2-mode emacs prints

[yas] Error in condition evaluation: Symbol’s function definition is void: js2-node-type

And when I load js2-mode,

[yas] Error in condition evaluation: No JavaScript AST available

It works after I turn on js2-mode.

Thank you for providing great set of snippets!

most of the nxml-mode snippets should be in html-mode/web-mode or similar

nxml-mode is used for more than editing html. When using XML minor-modes that define their own snippets, nxml-mode may override the relevant snippets or clutter the menu with irrellevant snippets. Can the html-specific snippets either move into a html-mode or web-mode directory, or at the very least get a condition that looks for an element?

(An alternative would be if yasnippet could have a method for turning off major-mode-defaults, but joaotavora/yasnippet#496 )

org-mode's "code" snippet is outdated

In org-mode 8.2.10, code blocks are defined as follows:

 #+NAME: <name>
 #+BEGIN_SRC <language> <switches> <header arguments>
   <body>
 #+END_SRC

The code template still uses

#+begin_${1:lang} ${2:options}
$0
#+end_$1

However, I'm not sure either is necessary, since Org-mode has its own Easy Template (<s) that inserts:

#+BEGIN_SRC 

#+END_SRC

There should be no fundamental-mode snippet (or not under really common names)

[First submitted at https://github.com/joaotavora/yasnippet/issues/513]

I'd like the fundamental snippets to be removed from the distribution, or hidden under less common names than "!", "email", "var", "mode" and "time".

Indeed, for different reasons (freeing a bit the overloaded TAB key, discovering and using snippets all the time), I've opted to bind YASnippet expansion on SPC.

Though, when typing text in an email or a report, I obviously type many times things such as "mode" followed by SPC, or "!" followed by SPC. Now, it always break my typing flow, because it has been expanded into a snippet which I did not intend.

The problem is that:

  • fundamental mode is everywhere, and
  • these are way too common tokens which we daily type.

WDYT?

Add typescript snipets

Emacs (Spacemacs/develop) has decent typescript support. The only missing thing for me is snippeting(snipping?).

There should be no org-mode snippet using common names as key

For the exact same reason as the one developped in #52 (i.e., when one binds `yas-expand' to SPC -- that is the "abbrev-way"), there should be no standard word of the dictionary used as "snippet keys".

In Org-mode, there are quite a few: "code", "dot", "embedded", "entry", "figure", "latex", "matrix" and "verse".

Could these be replaced by "non-word" abbreviations, so that YASnippet does not pop up at unexpected times (when typing "you can see in the code that...", for example)?

Thanks!

js-mode function snippet does not generate canonical javascript function syntax for anonymous functions

The javascript function snippet introduced here 99e72dd

When the name snippet parameter is skipped, the function.el snippet will generate a function expression like so

function (one, two, three) {
//function body
}

but by far the most common style is to not have a space in between the function keyword and parameter list for anonymous functions:

function(one, two, three) {
}

Almost any example you'll find on the web uses this style found here at mozdev on the function statement documentation:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function

"for" loop snippet doesn't expand properly

The following is my snippet. It's basically a copy from the existing snippet
`for' with a new name "forr".

# -*- mode: snippet -*-
# name: forr
# key: forr
# --
for (${1:i = 0}; ${2:i < N}; ${3:i++}) { $0 }

In a C++ buffer, when typing "forr", it expands to the following:

for (|)i = 0; i < N; i++) {

}

`|' is the position of the point after expanding the snippet. Hitting TAB wouldn't goto the next field.

The problem won't show up if I either turn off auto-complete, or turn off smartparen. Therefore, this might not be a problem of yasnppet. If that's the case, my apology.

This problem is really painful, and I would appreciate any help.

Thanks

The perl-mode vanished

The perl-mode snippets could be found in yasnippets 0.6.1c or earlier version but vanished in this repo. Is it OK to bring the perl-mode snippets back? If positive, I can submit a pull request then.

Broken typerex-mode symlink

typerex-mode points to /home/andrea/Emacs-configuration/yasnippet-snippets/tuareg-mode

ln -s tuareg-mode typerex-mode fixes this.

Code snippets in text mode?

This is part-question-part-bugreport.
Is there a reason why there are code-related snippets in text-mode?

I keep accidentally activating them in markdown buffers.

scala snippets out of date

many of the scala snippets are only relevant for versions of scala that are no longer in common use (i.e. prior to 2.10, which itself is deprecated).

This is more of a note to self to go through and remove all the snippets that are no longer relevant.

Possible to make a function like init_docstring, only that it initializes variables?

When calling a constructor with many arguments, you need to set the private variables to the arguments.

def __init__(self, transcript_name, gene_name, chromosome, strand, start_position, end_position):
    self._transcript_name = transcript_name
    ...

This is the most boilerplate of boilerplate of boilerplate and exacty the kind of thing yasnippet was made for. Could you please make a modified version of your python_docstring method that does this? Something like an init_private_variables snippet?

Thanks for plenty of great snippets btw.

Indentation control and whitespace

Hi,

I am trying to setup the default snippet indentation (c++-mode). Yasnippet uses a default indentation based on tab-with 4 but my desired indentation is 2 spaces (I don't use tabs). In order to illustrate the problem, the indentation of two clases are shown below:
image

The first snippet class indentation insert 4 spaces. The second snippet class insert one tab at class declaration level and two tabs at method declaration level.
Default snippet indentations are marked using whitespaces package.

Questions:

  1. Is it possible to change the default snippet indentation to 2 spaces?
  2. How can I obtain the following desired indentation when inserting a snippet?

image

Thanks

python-mode snippets are expanded with wrong indentation if there is more than one level of indentation possible in the snippet

Please refer to joaotavora/yasnippet#485 for more background information and the discussion that happened there. The issue happens because of python snippets having more than 1 level of indentation not having # expand-env: ((yas-indent-line 'fixed)) as per the yasnippet maintainer. This causes the snippet to be expanded with wrong indentation and hence wrong code. He pointed me to this repository and told that the fix has to be made in this repository. I have tested the changes by manually editing the snippet to add the # expand-env: ((yas-indent-line 'fixed)) line and I can see that the expansion works fine after that.

This issue happens only with snippets with more than one possible level of indentation.

Should yasnippet point to yasnippet-snippets for a default collection

Hi Andrea,

I'm the maintainer of yasnippet and was thinking of making your collection of snippets (the snippets/ subdir) the default collection for yasnippet. I would do this using a git submodule. What do you think of the idea?

Also, can you give me a general idea of:

  1. How often do you update your repository
  2. What criteria, if any, do you have before you accept snippets (snippets that you like, snippets that your friends like)
  3. How "good" your snippet repo is and do you know of other similar ones?

Thanks,
João

Error when updating the yasnippet package from Melpa

I don't think this is really a bug with this package, but generally when a new version gets installed and you try to open a file you get an error like:

File mode specification error: (file-error Opening directory No such file or directory /home/andrea/.emacs.d/elpa/yasnippet-snippets-20170920.1234/snippets/js-mode)
yas--subdirs: Opening directory: No such file or directory, /home/andrea/.emacs.d/elpa/yasnippet-snippets-20170920.1234/snippets/js-mode```

After a yas-reload-all it's all sorted even though you still see this in Messages

[yas] Check your `yas-snippet-dirs': /home/andrea/.emacs.d/elpa/yasnippet-snippets-20170920.1234/snippets is not a directory

And looking at the yas-snipppet-dirs it contains both the hold and the new package paths.
I wonder if there is anything to alleviate this problem, the code I used for the discovery is basically the same used by the other snippet packages (even if I didn't notice the same issue there).
Any idea?

Licensing

Hi, I can't find any licensing information here. Can I use the snippets at work?

Trying to disable default YAS snippets

I am trying to disable the default snippets in YAS directory and only allow mine.

So I have this code in my init.el file:

  (use-package yasnippet
    :ensure t
    :diminish (yas-minor-mode)
    :config
    (setq yas-snippet-dirs `(,(concat user-emacs-directory "snippets")))
    (yas-reload-all)
    (add-hook 'prog-mode-hook #'yas-minor-mode)
    )

So I succeeded not enabling the default ones but can't load mine.

In the snippets directory I have cc-mode/struct only.
But doing struct"TAB" does nothing.

What am I doing wrong?

update: I noticed when editing a c file if I changed the directory name from cc-mode to c-mode then my struct snippet does load. But why? cc-mode should include c-mode by default!

multi key

Today used tr to start import pdb;..., idea would be to have tr and put another key as pdb

example:

# -*- mode: snippet -*-
# name: trace
# key: tr, pdb
# group: debug
# --
import pdb; pdb.set_trace()

or

# -*- mode: snippet -*-
# name: trace
# key: tr
# key: pdb
# group: debug
# --
import pdb; pdb.set_trace()

python-mode super doesn't insert ", self)"

Using emacs 24, yasnippet 0.8.0 (beta) and yasnippet-snippets from master. When I expand super I only get: super(MyClass.current_method() instead of: super(MyClass, self).current_method()

I used yas/describe-tables to make sure I'm using the right snippet. It's strange that it looks like the snippet contains the right ", self)." part, but I don't see it when expanding.

Happy to help with more debugging info.

License for snippets?

I was wondering if the snippets are also subject to the GPLv3 license. I'm usually the first to ask for the GPL compliance, but it might not be a good idea to license snippets as GPL.

Of course, I don't think anyone would come and enforce their theoretical rights for that, but it might clear some confusion in the future.

Can Personal Snippets Overriding Bundled Not Prompt on Expansion?

Currently when I override a bundled snippet I get a prompt on expansion that allows me to choose between my local version and the overridden version. The docs say:

Collections appearing earlier in the list override snippets with same names appearing in collections later in the list. yas-new-snippet always stores snippets in the first collection.

My snippets dir comes before the bundled dir in yas-snippet-dirs. Given this the docs imply that there would be no prompt.

Bug or feature? In ether case how to get rid of the prompt?

HTML Snippet Comments Incorrect

https://github.com/AndreaCrotti/yasnippet-snippets/blob/6b6dcd9eca4d6d3e982bbc241b51cd6562ef600e/snippets/html-mode/html

#contributor : Jimmy Wu <frozenthrone88@gmail.com>
    #name : <html>...</html>
    # --
    <html>
        
    </html>

https://github.com/AndreaCrotti/yasnippet-snippets/blob/6b6dcd9eca4d6d3e982bbc241b51cd6562ef600e/snippets/html-mode/form

#contributor : Jimmy Wu <frozenthrone88@gmail.com>
    #name :<form method="..." id="..." action="..."></form>
    # --
    <form method="" id="" action="">
        
    </form>

Surely there are others.

Issue in go-mode

I had updated yasnippet package couple of days back, today when I closed, and reopened Emacs, 💥 .

Debugger entered--Lisp error: (invalid-read-syntax "#")
  eval-buffer(#<buffer  *load*> nil "/Users/tdot/.emacs.d/elpa/yasnippet-20140911.312/snippets/go-mode/default" nil t)  ; Reading at buffer position 2
  load-with-code-conversion("/Users/tdot/.emacs.d/elpa/yasnippet-20140911.312/snippets/go-mode/default" "/Users/tdot/.emacs.d/elpa/yasnippet-20140911.312/snippets/go-mode/default" t t)
  load("default" t t)
  #[0 "�\205\262    \306=\203�\307�\310Q\202;   \311=\204�\307�\312Q\202;\313\307\314\315#\203*\316\202;\313\307\314\317#\203:\320\nB�\321\202;\316\322�\323�\322\211#\210�\322=\203a\324\325\326\307�\327Q!\"\323�\322\211#\210�\322=\203`��\210�\203\243\330�!\331\232\203\243\332�!\211\333P\334�!\203}\211\202\210\334�!\203\207�\202\210\314\262��\203\241\335��\"\203\237\336\337��#\210\340\341!\210��\266�\f?\205\260\314�\323\342\322\211#)\262�\207" [init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init inhibit-startup-screen ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" (initialization "`_emacs' init file is deprecated, please use `.emacs'") "~/_emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default"] 7 "\n\n(fn)"]()
  command-line()
  normal-top-level()

From the error message, seems like there is an issue in the file, default. Tried yas-compile-directory on /Users/tdot/.emacs.d/elpa/yasnippet-20140911.312/snippets but the error did not go away. Had to delete the file, default.

My emacs:

GNU Emacs 24.4.50.1 (x86_64-apple-darwin13.3.0, NS appkit-1265.21 Version 10.9.4 (Build 13E28)) of 2014-08-28 on iDot

Latest version from MELPA does not install on Windows emacs

Installation of the latest version from MELPA on Windows emacs fails with:

File error: Opening output file, Invalid argument, c:/Users/berhol/AppData/Roaming/.emacs.d/elpa/yasnippet-snippets-20170920.1234/snippets/php-mode/foreach=>

it seems foreach=> is not a valid file name.

yasnippet" Discovered there was already *load* in fundamental-mode

Hi,
The following problem appears when loading. I could not find any solution. How can I fix it?

[yas] Discovered there was already scratch in fundamental-mode
[yas] Discovered there was already code-conversion-work in fundamental-mode
[yas] Discovered there was already load in fundamental-mode
[yas] Discovered there was already Echo Area 0 in fundamental-mode
[yas] Discovered there was already Echo Area 1 in fundamental-mode
[yas] Discovered there was already load-275874 in fundamental-mode

Regards,

Levis

add applescript snippets

Currently, the best applescript mode for emacs is apples-mode. The repository contains applescript snippets that are not available here. I've created a pull request to add them to your applescript section that is currently empty.

#179

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.