├── LICENSE ├── README.md ├── elixir-yasnippets-pkg.el ├── elixir-yasnippets.el └── snippets └── elixir-mode ├── application ├── behaviour ├── case ├── cond ├── def ├── defimpl ├── defmacro ├── defmacrop ├── defmodule ├── defp ├── defprotocol ├── do ├── doc ├── fn ├── for ├── genevent ├── genserver ├── if ├── mdoc ├── pry ├── receive ├── supervisor ├── test └── unless /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Yinghai Zhao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | elixir-yasnippets 2 | ================= 3 | 4 | ### package.el installation via MELPA 5 | 6 | It can be more convenient to use Emacs's package manager to handle 7 | installation for you if you use many elisp libraries. If you have 8 | package.el but haven't added Marmalade, the community package source, 9 | yet, add this to ~/.emacs.d/init.el: 10 | 11 | ```lisp 12 | (require 'package) 13 | (add-to-list 'package-archives 14 | '("melpa" . "http://melpa.milkbox.net/packages/") t) 15 | (package-initialize) 16 | ``` 17 | 18 | Then do this to load the package listing: 19 | 20 | * M-x eval-buffer 21 | * M-x package-refresh-contents 22 | 23 | If you use a version of Emacs prior to 24 that doesn't include 24 | package.el, you can get it from http://bit.ly/pkg-el23. 25 | 26 | If you have an older ELPA package.el installed from tromey.com, you 27 | should upgrade in order to support installation from multiple sources. 28 | The ELPA archive is deprecated and no longer accepting new packages, 29 | so the version there (1.7.1) is very outdated. 30 | 31 | From there you can install `elixir-snippets` or any other modes by choosing 32 | them from a list: 33 | 34 | * M-x package-list-packages 35 | 36 | Now, to install packages, move your cursor to them and press i. This 37 | will mark the packages for installation. When you're done with 38 | marking, press x, and ELPA will install the packages for you (under 39 | ~/.emacs.d/elpa/). 40 | 41 | * or using M-x package-install elixir-yasnippets 42 | -------------------------------------------------------------------------------- /elixir-yasnippets-pkg.el: -------------------------------------------------------------------------------- 1 | (define-package "elixir-yasnippets" "0.0.2" 2 | "Yasnippets for Elixir" 3 | '((yasnippet "0.8.0"))) 4 | -------------------------------------------------------------------------------- /elixir-yasnippets.el: -------------------------------------------------------------------------------- 1 | ;;; elixir-yasnippets.el --- Yasnippets for Elixir 2 | 3 | ;; Copyright (C) 2013 Yinghai ZHAO 4 | 5 | ;; Author: Yinghai Zhao 6 | ;; Keywords: snippets 7 | ;; Version: 0.0.1 8 | ;; Package-Requires: ((yasnippet "0.8.0")) 9 | 10 | ;;; Code: 11 | 12 | (setq elixir-snippets-dir (file-name-directory (or (buffer-file-name) 13 | load-file-name))) 14 | 15 | ;;;###autoload 16 | (defun elixir-snippets-initialize () 17 | (let ((snip-dir (expand-file-name "snippets" elixir-snippets-dir))) 18 | (add-to-list 'yas-snippet-dirs snip-dir t) 19 | (yas/load-directory snip-dir))) 20 | 21 | ;;;###autoload 22 | (eval-after-load 'yasnippet 23 | '(elixir-snippets-initialize)) 24 | 25 | (require 'yasnippet) 26 | 27 | (provide 'elixir-yasnippets) 28 | 29 | ;;; elixir-yasnippets.el ends here 30 | -------------------------------------------------------------------------------- /snippets/elixir-mode/application: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Application 3 | # key: Application 4 | # -- 5 | defmodule ${1:MyApp} do 6 | use Application 7 | 8 | def start(_type, _args) do 9 | $1.Supervisor.start_link()$0 10 | end 11 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/behaviour: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Behaviour 3 | # key: Behaviour 4 | # -- 5 | defmodule ${1:MyBehaviour} do 6 | use Behaviour 7 | 8 | defcallback ${0:${2:function} :: ${3:any}} 9 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/case: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: case 3 | # key: case 4 | # -- 5 | case ${1:true} do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/cond: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: cond 3 | # key: cond 4 | # -- 5 | cond do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/def: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: def 3 | # key: def 4 | # -- 5 | def ${1:function}${2:(${3:args})} do 6 | $0 7 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/defimpl: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: defimpl 3 | # key: defimpl 4 | # -- 5 | defimpl ${1:Type}, for: ${2:Protocol} do 6 | def ${0:callback(args)} 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/defmacro: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: defmacro 3 | # key: defmacro 4 | # -- 5 | defmacro ${1:Macro()} do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/defmacrop: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: defmacrop 3 | # key: defmacrop 4 | # -- 5 | defmacrop ${1:Macro()} do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/defmodule: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: defmodule 3 | # key: defmodule 4 | # -- 5 | defmodule ${1:Module} do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/defp: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: defp 3 | # key: defp 4 | # -- 5 | defp ${1:function}${2:(${3:args})} do 6 | $0 7 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/defprotocol: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: defprotocol 3 | # key: defprotocol 4 | # -- 5 | defprotocol ${1:Protocol} do 6 | def ${0:callback(args)} 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/do: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: do 3 | # key: do 4 | # -- 5 | do 6 | $0 7 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/doc: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: doc 3 | # key: doc 4 | # expand-env: ((yas-indent-line 'fixed)) 5 | # -- 6 | @doc """ 7 | $0 8 | """ 9 | -------------------------------------------------------------------------------- /snippets/elixir-mode/fn: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: fn 3 | # key: fn 4 | # -- 5 | fn ${1:x} -> $1$0 end 6 | -------------------------------------------------------------------------------- /snippets/elixir-mode/for: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for 3 | # key: for 4 | # -- 5 | for ${2:x} <- ${1:Enumeration}, do: $2$0 6 | -------------------------------------------------------------------------------- /snippets/elixir-mode/genevent: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: GenEvent 3 | # key: GenEvent 4 | # -- 5 | defmodule ${1:EventHandler} do 6 | use GenEvent 7 | 8 | def handle_event(event, parent) do 9 | ${2:send parent, event}$0 10 | {:ok, parent} 11 | end 12 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/genserver: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: GenServer 3 | # key: GenServer 4 | # -- 5 | defmodule ${1:Module} do 6 | use GenServer 7 | 8 | # Client API 9 | def start_link(default) do 10 | GenServer.start_link(__MODULE__, default) 11 | end 12 | 13 | # Server callbacks 14 | def init(state) do 15 | {:ok, state} 16 | end 17 | 18 | $0 19 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/if: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: if 3 | # key: if 4 | # -- 5 | if ${1:true} do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/mdoc: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: moduledoc 3 | # key: mdoc 4 | # expand-env: ((yas-indent-line 'fixed)) 5 | # -- 6 | @moduledoc """ 7 | $0 8 | """ 9 | -------------------------------------------------------------------------------- /snippets/elixir-mode/pry: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: pry 3 | # key: pry 4 | # -- 5 | require IEx; IEx.pry -------------------------------------------------------------------------------- /snippets/elixir-mode/receive: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: receive 3 | # key: receive 4 | # -- 5 | receive do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/supervisor: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Supervisor 3 | # key: Supervisor 4 | # -- 5 | defmodule ${1:Module}.Supervisor do 6 | use Supervisor 7 | 8 | def start_link do 9 | Supervisor.start_link(__MODULE__, :ok) 10 | end 11 | 12 | def init(:ok) do 13 | children = [ 14 | $0 15 | ] 16 | supervise(children, strategy: :one_for_one) 17 | end 18 | 19 | end -------------------------------------------------------------------------------- /snippets/elixir-mode/test: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: test 3 | # key: test 4 | # -- 5 | test "$1" do 6 | $0 7 | end 8 | -------------------------------------------------------------------------------- /snippets/elixir-mode/unless: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: unless 3 | # key: unless 4 | # -- 5 | unless ${1:false} do 6 | $0 7 | end 8 | --------------------------------------------------------------------------------