-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-yasnippet.el
68 lines (59 loc) · 1.99 KB
/
my-yasnippet.el
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;;; my-yasnippet.el --- customisation and helper functions
;;
;;; Commentary:
;;
;; There isn't much here but I do want to add more Lisp type stuff.
;;
;;; Code:
(require 'use-package)
(require 'my-libs)
(defun my-disable-yas-if-no-snippets ()
(when (and yas-minor-mode (null (yas--get-snippet-tables)))
(yas-minor-mode -1)))
;; YASnippet itself
(use-package yasnippet
:ensure t
:commands (snippet-mode yas-global-mode)
:defer 60
:hook (yas-minor-mode . my-disable-yas-if-no-snippets)
:config (progn
(when (file-exists-p "~/.emacs.d/my-snippets")
(add-to-list 'yas-snippet-dirs "~/.emacs.d/my-snippets"))
(yas-global-mode 1)
(setq yas-prompt-functions
'(yas-ido-prompt yas-completing-prompt yas-no-prompt))))
;; Helper functions
(defvar my-yas-emails
(mapc
(lambda (elt)
(cons (purecopy (car elt)) (cdr elt)))
'(
(".*/src/.*" . "[email protected]")
(".*/lsrc/.*" . "[email protected]")
(".*/mysrc/.*" . "[email protected]")))
"A mapping from source location to email address.")
(defun my-yas-expand-email ()
"Return the right email for the current source file."
(cond
((derived-mode-p 'mail-mode 'mu4e-compose-mode)
user-mail-address)
(t "[email protected]")))
(defun my-yas-expand-copyright ()
"Like `my-yas-expand-email' except just return the company name if
I'm in a work for hire directory."
(if (s-contains-p "lsrc" (buffer-file-name))
"Linaro Ltd"
(my-yas-expand-email)))
(defun my-yas-pull-req-helper ()
"Return a pull request string from a given directory."
(interactive)
(let ((base "origin/master")
(repo "https://gitlab.com/stsquad/qemu.git")
(head (shell-command-to-string "git describe")))
(shell-command-to-string
(format "git request-pull %s %s %s" base repo head))))
(defun my-yas-local-disable ()
"Disable yas-snippet-mode in this local buffer"
(yas-minor-mode -1))
(provide 'my-yasnippet)
;;; my-yasnippet.el ends here