mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
Gee, what're we gonna do tonight, Brain?
This commit is contained in:
@ -1,41 +1,45 @@
|
||||
(provide 'init-snippets)
|
||||
|
||||
(use-package yasnippet
|
||||
:mode (("emacs.+/snippets/" . snippet-mode))
|
||||
:pre-load
|
||||
(progn
|
||||
;; Fix yasnippet keymaps so they only work in insert mode (why they
|
||||
;; had to make this so complicated I don't know); must be defined
|
||||
;; BEFORE we include yasnippet.
|
||||
(defvar yas-minor-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(imap map [(tab)] 'yas-expand)
|
||||
(imap map (kbd "TAB") 'yas-expand)
|
||||
map)))
|
||||
:config
|
||||
(progn
|
||||
(defadvice evil-force-normal-state (before evil-esc-quit-yasnippet activate)
|
||||
(shut-up (yas-exit-all-snippets)))
|
||||
:mode (("emacs\\.d/.+/snippets/" . snippet-mode))
|
||||
:pre-load
|
||||
(progn
|
||||
;; Fix yasnippet keymaps so they only work in insert mode (why they
|
||||
;; had to make this so complicated I don't know); must be defined
|
||||
;; BEFORE we include yasnippet.
|
||||
(defvar yas-minor-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(bind 'insert map [(tab)] 'yas-expand)
|
||||
(bind 'insert map (kbd "TAB") 'yas-expand)
|
||||
(bind 'visual map (kbd "<backtab>") 'yas-insert-snippet)
|
||||
map)))
|
||||
:config
|
||||
(progn
|
||||
(defadvice evil-force-normal-state (before evil-esc-quit-yasnippet activate)
|
||||
(shut-up (yas-exit-all-snippets)))
|
||||
|
||||
;; Only load personal snippets
|
||||
(setq yas-snippet-dirs `(,*snippets-dir))
|
||||
(setq yas-prompt-functions '(yas-ido-prompt yas-no-prompt))
|
||||
;; Only load personal snippets
|
||||
(setq yas-snippet-dirs `(,*snippets-dir))
|
||||
(setq yas-prompt-functions '(yas-ido-prompt yas-no-prompt))
|
||||
(setq yas-also-auto-indent-first-line t)
|
||||
|
||||
(after auto-complete
|
||||
(add-hook! 'yas-before-expand-snippet-hook (auto-complete-mode -1))
|
||||
(add-hook! 'yas-after-exit-snippet-hook (auto-complete-mode t))
|
||||
(defadvice ac-expand (before advice-for-ac-expand activate)
|
||||
(when (yas-expand) (ac-stop))))
|
||||
(after auto-complete
|
||||
;; (add-hook! 'yas-before-expand-snippet-hook (auto-complete-mode -1))
|
||||
;; (add-hook! 'yas-after-exit-snippet-hook (auto-complete-mode t))
|
||||
(defadvice ac-expand (before advice-for-ac-expand activate)
|
||||
(when (yas-expand) (ac-stop))))
|
||||
|
||||
(defmap yas-keymap (kbd "DEL") 'my/yas-clear-field)
|
||||
(bind yas-keymap (kbd "DEL") 'my/yas-clear-field)
|
||||
|
||||
(yas-reload-all))
|
||||
:init
|
||||
(progn
|
||||
(add-hook 'prog-mode-hook 'yas-minor-mode)
|
||||
(add-hook 'snippet-mode-hook 'yas-minor-mode)
|
||||
(add-hook 'markdown-mode-hook 'yas-minor-mode)
|
||||
(add-hook 'org-mode-hook 'yas-minor-mode)))
|
||||
(yas-reload-all))
|
||||
:init
|
||||
(progn
|
||||
(add-hook 'snippet-mode-hook 'disable-final-newline)
|
||||
(add-hook 'text-mode-hook 'yas-minor-mode)
|
||||
(add-hook 'prog-mode-hook 'yas-minor-mode)
|
||||
(add-hook 'snippet-mode-hook 'yas-minor-mode)
|
||||
;; (add-hook 'markdown-mode-hook 'yas-minor-mode)
|
||||
(add-hook 'org-mode-hook 'yas-minor-mode)))
|
||||
|
||||
;; Prevents Yas from stepping on my toes when I use backspace
|
||||
(defun my/yas-clear-field (&optional field)
|
||||
@ -49,3 +53,10 @@
|
||||
(eq (point) (marker-position (yas--field-start field))))
|
||||
(yas--skip-and-clear field))
|
||||
(t (delete-char -1)))))
|
||||
|
||||
;; yas snippet helpers
|
||||
(defvaralias '% 'yas-selected-text)
|
||||
(defun %! () (if % (s-trim-right %)))
|
||||
(defun !% () (if % (s-trim-left %)))
|
||||
(defun !%! () (if % (s-trim %)))
|
||||
(defun --newline-maybe () (if % "\n"))
|
||||
|
Reference in New Issue
Block a user