Skip to content

Commit

Permalink
simplify yasnippet setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen Bin committed May 16, 2015
1 parent 5de663e commit d09f578
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions lisp/init-yasnippet.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(require 'yasnippet-autoloads)
;; loading yasnippet will slow the startup
;; but it's necessary cost
(require 'yasnippet)
(yas-global-mode 1)

(defun my-yas-reload-all ()
(interactive)
Expand Down Expand Up @@ -32,22 +35,7 @@

(defun my-yas-expand ()
(interactive)
(unless (featurep 'yasnippet)
(require 'yasnippet)
(yas-global-mode 1))

(if (buffer-file-name)
(let ((ext (car (cdr (split-string (buffer-file-name) "\\."))) )
(old-yas-flag yas-indent-line))
(if (or (string= ext "ftl") (string= ext "jsp"))
(setq yas-indent-line nil))
(yas-expand)
;; restore the flag
(setq yas-indent-line old-yas-flag))
(yas-expand)))

;; default TAB key is occupied by auto-complete
(global-set-key (kbd "C-c k") 'my-yas-expand)
(yas-expand))

(autoload 'snippet-mode "yasnippet" "")
(add-to-list 'auto-mode-alist '("\\.yasnippet\\'" . snippet-mode))
Expand All @@ -60,7 +48,6 @@
(setq my-yasnippets (expand-file-name "~/my-yasnippets"))
(if (and (file-exists-p my-yasnippets) (not (member my-yasnippets yas-snippet-dirs)))
(add-to-list 'yas-snippet-dirs my-yasnippets))
(message "yas-snippet-dirs=%s" yas-snippet-dirs)
;; (message "yas-snippet-dirs=%s" (mapconcat 'identity yas-snippet-dirs ":"))

;; default hotkey `C-c C-s` is still valid
Expand Down

0 comments on commit d09f578

Please sign in to comment.