Skip to content

Latest commit

 

History

History
76 lines (65 loc) · 2.35 KB

starter-kit-yasnippet.org

File metadata and controls

76 lines (65 loc) · 2.35 KB

Starter Kit Yasnippet

This is part of the Emacs Starter Kit.

Starter Kit Yasnippet

yasnippet is yet another snippet expansion system for Emacs. It is inspired by TextMate’s templating syntax.

Install Yasnippet

(starter-kit-install-if-needed 'yasnippet)

;; If `yasnippet-bundle' has previously been installed through ELPA,
;; delete it before installing the new `yasnippet'
(let ((yas-bundle-desc (assq 'yasnippet-bundle package-alist)))
  (when yas-bundle-desc
    (package-delete "yasnippet-bundle"
                    (package-version-join
                     (package-desc-vers (cdr yas-bundle-desc))))))

Put yasnippet directories on the load path

(add-to-list 'load-path
             (expand-file-name  "yasnippet"
                                (expand-file-name "src"
                                                  starter-kit-dir)))

Load Yasnippet

(require 'yasnippet)
(yas-global-mode 1)

Load Snippets Distributed with the Starter Kit

Load the snippets defined in the ./snippets/ directory.
(yas/load-directory (expand-file-name "snippets" starter-kit-dir))

Configure Yasnippets for Org Mode

The latest version of yasnippets doesn’t play well with Org-mode, the following function allows these two to play nicely together.

(defun yas/org-very-safe-expand ()
  (let ((yas/fallback-behavior 'return-nil)) (yas/expand)))

(defun yas/org-setup ()
  ;; yasnippet (using the new org-cycle hooks)
  (make-variable-buffer-local 'yas/trigger-key)
  (setq yas/trigger-key [tab])
  (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
  (define-key yas/keymap [tab] 'yas/next-field))

(add-hook 'org-mode-hook #'yas/org-setup)