Skip to content

Latest commit

 

History

History
54 lines (45 loc) · 1.94 KB

starter-kit-yasnippet.org

File metadata and controls

54 lines (45 loc) · 1.94 KB

Starter Kit Eshell

This is part of the Emacs Starter Kit.

Starter Kit Eshell

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))))))

Load the yasnippet bundle.

(add-to-list 'load-path
             (expand-file-name  "yasnippet"
                                (expand-file-name "src"
                                                  starter-kit-dir)))
(require 'yasnippet)
(yas-global-mode 1)

Load the snippets defined in the ./snippets/ directory.

(yas/load-directory (expand-file-name "snippets" starter-kit-dir))

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)