summaryrefslogtreecommitdiff
path: root/.emacs.d/snippets/prog-mode/.yas-setup.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/snippets/prog-mode/.yas-setup.el')
-rw-r--r--.emacs.d/snippets/prog-mode/.yas-setup.el37
1 files changed, 37 insertions, 0 deletions
diff --git a/.emacs.d/snippets/prog-mode/.yas-setup.el b/.emacs.d/snippets/prog-mode/.yas-setup.el
index 03d07cf..22a8168 100644
--- a/.emacs.d/snippets/prog-mode/.yas-setup.el
+++ b/.emacs.d/snippets/prog-mode/.yas-setup.el
@@ -1,2 +1,39 @@
1(require 'yasnippet)
2
1(defun yas-with-comment (str) 3(defun yas-with-comment (str)
2 (format "%s%s%s" comment-start str comment-end)) 4 (format "%s%s%s" comment-start str comment-end))
5
6;; whitespace removing functions from Magnar Sveen ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7(defun yas-s-trim-left (s)
8 "Remove whitespace at the beginning of S."
9 (if (string-match "\\`[ \t\n\r]+" s)
10 (replace-match "" t t s)
11 s))
12
13(defun yas-s-trim-right (s)
14 "Remove whitespace at the end of S."
15 (if (string-match "[ \t\n\r]+\\'" s)
16 (replace-match "" t t s)
17 s))
18
19(defun yas-s-trim (s)
20 "Remove whitespace at the beginning and end of S."
21 (yas-s-trim-left (yas-s-trim-right s)))
22
23
24(defun yas-string-reverse (str)
25 "Reverse a string STR manually to be compatible with emacs versions < 25."
26 (apply #'string
27 (reverse
28 (string-to-list str))))
29
30(defun yas-trimmed-comment-start ()
31 "This function returns `comment-start' trimmed by whitespaces."
32 (yas-s-trim comment-start))
33
34(defun yas-trimmed-comment-end ()
35 "This function returns `comment-end' trimmed by whitespaces if `comment-end' is not empty.
36Otherwise the reversed output of function `yas-trimmed-comment-start' is returned."
37 (if (eq (length comment-end) 0)
38 (yas-string-reverse (yas-trimmed-comment-start))
39 (yas-s-trim comment-end)))