YASnippets
Table of Contents
1 This is not the file you are looking for…
If you want to configure yasnippets for the emagicians starter kit, you want to go into the "editing" section. This file is actually for generating the snippets.
2 Building build
(emagician/expect-dir "./assets/snippets")
2.1 Execute this during development
(defun emagician/snippet-tangle-and-reload ()
"Helper function to automagickally tangle and reload snippets after the snippet file is saved"
(org-babel-tangle nil)
(yas-recompile-all)
(yas-reload-all))
(add-hook 'after-save-hook 'emagician/snippet-tangle-and-reload t t)
3 Text modes
3.1 Org org
(emagician/expect-dir "./assets/snippets/org-mode")
3.1.1 Source blocks. A majority of mine are elisp and snippets
# name: source block
# key: src
# --
#+begin_src $1 $2
$0
#+end_src
# name: emacs-lisp
# key: lisp
# --
#+begin_src emacs-lisp $1
$0
#+end_src
# name: sh
# key: sh
# --
#+begin_src sh $1
$0
#+end_src
# name: sql
# key: sql
# --
#+begin_src sql $1
$0
#+end_src
3.1.2 So meta! Such Wow!
This is so fucking cool.
This is a snippet to build a snippet in an org mode file.
# name: yasnippet
# key: snippet
# expand-env: ((yas-indent-line 'never) (yas-wrap-around-region 'nil))
# --
#+begin_src yasnippet :tangle assets/snippets/$1/$2
# name: $2
# key: $2
# --
$0
#+end_src
3.1.3 David Allen's Natural Project Planning model.
# name: project
# key: project
# --
** PROJECT $1
- Purpose - 50K :: $2
- Success Looks Like - 40K :: $3
- Brainstorming - 30K
- $4
- Organize the brainstorming and come up with next actions (20K)
*** TODO $5
4 Programming modes
4.1 Javascript
(emagician/expect-dir "./assets/snippets/js-mode")
text-mode
# name: function(...) { ... }
# key: function
# --
function(${1:args}) {
$0
}
# name: var (declare)
# key: var
# --
var $0;
# name: var (assign)
# key: var
# --
var $1 = $0;
# name: var (assign)
# key: var
# --
describe("$1", function(done) {
$0
});
# name: var (assign)
# key: var
# --
it("$1", function(done) {
$0
});
4.2 Coffeescript
(emagician/expect-dir "./assets/snippets/coffee-mode")
# name: if
# key: if
# --
if $1
$0
# name: if
# key: if
# --
if $1
$2
else
$0
4.3 Emacs Lisp
(emagician/expect-dir "./assets/snippets/emacs-lisp-mode")
# name: defun
# key: defun
#--
defun $1 ($2)
"$3"
$0
# name: use-package
# key: use-package
#--
use-package ${name-no-quote}
$0
4.4 Ruby
(emagician/expect-dir "./assets/snippets/ruby-mode")
# -*- mode: snippet -*-
# name: class
# key: class
# --
class `(s-upper-camel-case (file-name-base))`
$0
end
# -*- mode: snippet -*-
# name: def
# key: def
# --
def $1($2)
$0
end
# -*- mode: snippet -*-
# name: if
# key: if
# --
if ($1)
$0
end
Note that the end is already inserted by the if snippet
# -*- mode: snippet -*-
# name: elsif
# key: elsif
# --
elsif ($1)
$0
# -*- mode: snippet -*-
# name: do-block
# key: do
# --
do ${1:|$2|}
$0
end
4.4.1 Unit Testing
# name: describe
# key: describe
# --
describe "$1" do
$0
end
# name: context
# key: context
# --
context "$1" do
$0
end
# name: it
# key: it
# --
it "$1" do
$0
end
# name: let
# key: let
# --
let (:$1) { $2 }
$0
# name: let!
# key: let!
# --
let! (:$1) { $2 }
$0
4.5 SQL
(emagician/expect-dir "./assets/snippets/sql-mode")
# name: select
# key: select
#--
select $1 from $2 as
# name: left join
# key: left
# --
left join ${1} as ${2:`(s-left 1 yas-text)`} on ${1:.id} = $0