aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/oni-yasnippet.el
blob: 06e6d18402e3c8b7fe6a352a9140fad85515fb12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;; Start of oni-yasnippet

(use-package yasnippet
  :init
  (yas-global-mode)
  :config
  (require 'diminish)

  (defun oni-yasnippet-remove-snippet-by-name (name mode)
    "Remove the snippet NAME from MODE's snippet tables."
    (and-let* ((mode-table (gethash mode yas--tables))
               (uuidhash-table (yas--table-uuidhash mode-table))
               (hash-table (yas--table-hash mode-table))
               (snippet (gethash name uuidhash-table))
               (key (yas--template-key snippet)))
      (remhash key hash-table)
      (remhash name uuidhash-table)))

  (defun oni-yasnippet-cleanup-snippets ()
    "Remove some snippets that I don't like."
    (oni-yasnippet-remove-snippet-by-name "defun" 'lisp-interaction-mode))

  (with-eval-after-load 'yasnippet (diminish 'yas-minor-mode))

  (setq-default yas-buffer-local-condition yas-not-string-or-comment-condition)

  (define-key yas-minor-mode-map (kbd "<tab>") nil)
  (define-key yas-minor-mode-map (kbd "C-\\") 'yas-expand)
  (define-key yas-minor-mode-map (kbd "SPC") yas-maybe-expand)
  (define-key yas-minor-mode-map (kbd "TAB") nil)

  (add-hook 'yas-after-reload-hook #'oni-yasnippet-cleanup-snippets))

;; End of oni-yasnippet