Skip to content

MiniApollo/snippy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

173 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snippy.el

VSCode/LSP snippet support for Emacs with Yasnippet.

main-demo.mp4

Table of Contents

Introduction

Snippy is a snippet translation and completion engine that uses YASnippet under the hood.

This package translates LSP/VSCode-style snippets into YASnippet format, allowing you to use all modern, external snippets seamlessly.

Since YASnippet doesn't fully support the entire LSP specification.

It can optionally fix LSP snippets that Eglot retrieves from servers (e.g., Java), working alongside YASnippet so you can use both simultaneously.

The Default Snippets collection is Friendly Snippets.

Features

Specification

Automatic mode detection

autodetection.mp4

Tabstops

tabstops.mp4

Placeholders

placeholders.mp4

Choices

choices.mp4

Variables

vars.mp4

Fix LSP server snippets

Enable: snippy-fix-lsp-snippet-mode

Installation

(use-package snippy
  :vc (:url "https://github.com/MiniApollo/snippy.git"
            :branch "main"
            :rev :newest) ; To get the latest updates
  :hook (after-init . global-snippy-minor-mode)
  :custom
  (snippy-global-languages '("global")) ; Recommended
  ;; Optional
  ;; (snippy-install-dir (expand-file-name <Your location>))
  ;; Use different snippet collections
  ;; (snippy-source '("Your git repo" . "my-snippets-dir"))
  :config
  (snippy-install-or-update-snippets) ; Autoupdate git repo
  ;; (snippy-fix-lsp-snippet-mode) ; Fixes lsp server snippets (e.g java lsp)
  (add-hook 'completion-at-point-functions #'snippy-capf)) ; Or merge them with Yasnippet or eglot capf

Using special characters for snippets like !,@

Prefix characters like !, @ don't work with yasnippet out of the box.

With Snippy it does work, but if you are merging completion backends make sure snippy is the first capf that dictates boundaries for the completion.

Other completion backends do not include special characters in the prefix.

If you want to use special characters in Yasnippet-snippets use this to fix it:

;; This is not needed for Snippy.el
(setq yas-key-syntaxes '("w_" "w_." "^ ")) ; Fixes Yasnippet-snippets special character usage.

Now you can use snippets like !cdr which is defined in yasnippet-snippets package.

Configuration

Package Variables

  • snippy-install-dir: Directory where to install/clone snippets.
  • snippy-source: The source details for downloading snippets (Both needed).
    • Repository URL
    • Directory Name (Cloned repo dir name)
  • snippy-global-languages: List of languages to enable globally across all major modes.

You can use any language you like.

;; Global Variable names
(setq snippy-global-languages '("global" "license"))

snippy-emacs-to-vscode-lang-alist:

Alist mapping for Emacs major modes to VSCode language names.

You can see all the languages inside the package.json file in the Friendly Snippets repository. There are some language snippets that are optional. To use them add it to the list.

You can also add more remaps if any language is missing from the list (or you can just make a pull request). When adding language remaps the first is the only one that is used in the list.

You also need to include all vscode snippet names not just the new one's name.

Optional remap names:

  • (c++-mode . "unreal")
  • (c++-ts-mode . "unreal")
  • (csharp-mode . "unity")
  • (csharp-ts-mode . "unity")
  • (html-mode . "djangohtml")
  • (html-mode . "htmldjango")
  • (web-mode . "angular")
  • (web-mode . "twig")
  • (python-mode . "django")
  • (python-mode . "django-rest")
  • (python-ts-mode . "django")
  • (python-ts-mode . "django-rest")

Modes that don't have a specific major-mode:

  • blade
  • eelixir
  • rmd
;; Choose the remaps you want to use
(add-to-list 'snippy-emacs-to-vscode-lang-alist '(super-cool-mode "coolang" "cool-doc")) ;  Example new dummy-mode

;; Add to an existing mode (You need to include all vscode snippet names not just the new one)
(add-to-list 'snippy-emacs-to-vscode-lang-alist '(c++-mode "cpp" "cppdoc" "unreal"))
(add-to-list 'snippy-emacs-to-vscode-lang-alist '(c++-ts-mode "cpp" "cppdoc" "unreal"))

Functions

  • snippy-install-or-update-snippets: Install or update snippet git repo in snippy-install-dir.
  • snippy-refresh-snippets: Force an update on the snippets for the current buffer.
  • snippy-expand: Expand snippet by prefix.
  • snippy-expand-snippet: Expand VSCode snippet body.
  • snippy-capf: Complete with snippy at point.

Modes

  • snippy-minor-mode: Toggle snippy in the current buffer.
  • global-snippy-minor-mode: Toggle snippy in all buffers.
  • snippy-fix-lsp-snippet-mode: Toggle LSP server snippet fix globally.

About

VSCode/LSP snippet support for Emacs with Yasnippet.

Topics

Resources

License

Stars

13 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors