summaryrefslogtreecommitdiff
path: root/.emacs.d/snippets/prog-mode
diff options
context:
space:
mode:
authorSimeon Simeonov2016-09-06 07:39:30 +0200
committerSimeon Simeonov2016-09-06 07:39:30 +0200
commit6a3efe35bf8b20b0900dbbf7747b8b8d0d19bd04 (patch)
tree1d00039f67672be9e0f8abb48aaad663ab85a37b /.emacs.d/snippets/prog-mode
parent991f8ff925f51fd5598db72885f8cca1a1a79bed (diff)
Upgrade ports
Diffstat (limited to '.emacs.d/snippets/prog-mode')
-rw-r--r--.emacs.d/snippets/prog-mode/.yas-setup.el37
-rw-r--r--.emacs.d/snippets/prog-mode/comment6
-rw-r--r--.emacs.d/snippets/prog-mode/commentblock36
-rw-r--r--.emacs.d/snippets/prog-mode/commentline13
4 files changed, 92 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)))
diff --git a/.emacs.d/snippets/prog-mode/comment b/.emacs.d/snippets/prog-mode/comment
new file mode 100644
index 0000000..edd53e9
--- /dev/null
+++ b/.emacs.d/snippets/prog-mode/comment
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# contributor: sh-ow <sh-ow@users.noreply.github.com>
3# name: comment
4# key: co
5# --
6${1:$(yas-trimmed-comment-start)} ${1:comment}${1:$(unless (eq (length comment-end) 0) (concat " " (yas-trimmed-comment-end)))}$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/prog-mode/commentblock b/.emacs.d/snippets/prog-mode/commentblock
new file mode 100644
index 0000000..ba61f61
--- /dev/null
+++ b/.emacs.d/snippets/prog-mode/commentblock
@@ -0,0 +1,36 @@
1# -*- mode: snippet -*-
2# contributor: sh-ow <sh-ow@users.noreply.github.com>
3# name: commentblock
4# key: cob
5# --
6${1:$(let* ((col (current-column))
7 (str "")
8 (lastcom (substring (yas-trimmed-comment-start) -1))
9 (start (yas-trimmed-comment-start))
10 (end (yas-trimmed-comment-end))
11 (over (- (+ (string-width yas-text) (length start) (length end) col) 77)))
12 (while (< (length str) (+ (- 79 (length start) (length end) col) (if (> over 0) over 0)))
13 (setq str (concat str lastcom)))
14 (concat start str end))}
15${1:$(let* ((col (current-column))
16 (str "")
17 (start (yas-trimmed-comment-start))
18 (end (yas-trimmed-comment-end)))
19 (while (< (length str) (ffloor (/ (- 78.0 (+ col (length start) (string-width yas-text) (length end))) 2.0)))
20 (setq str (concat str " ")))
21 (concat start str))} ${1:comment} ${1:$(let* ((col (current-column))
22 (str "")
23 (start (yas-trimmed-comment-start))
24 (end (yas-trimmed-comment-end)))
25 (while (< (length str) (- 79.0 (if (eq (mod (string-width yas-text) 2) 1) (- col 1) col) (length end)))
26 (setq str (concat str " ")))
27 (concat str end))}
28${1:$(let* ((col (current-column))
29 (str "")
30 (lastcom (substring (yas-trimmed-comment-start) -1))
31 (start (yas-trimmed-comment-start))
32 (end (yas-trimmed-comment-end))
33 (over (- (+ (string-width yas-text) (length start) (length end) col) 77)))
34 (while (< (length str) (+ (- 79 (length start) (length end) col) (if (> over 0) over 0)))
35 (setq str (concat str lastcom)))
36 (concat start str end))}$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/prog-mode/commentline b/.emacs.d/snippets/prog-mode/commentline
new file mode 100644
index 0000000..0b0edff
--- /dev/null
+++ b/.emacs.d/snippets/prog-mode/commentline
@@ -0,0 +1,13 @@
1# -*- mode: snippet -*-
2# contributor: sh-ow <sh-ow@users.noreply.github.com>
3# name: commentline
4# key: col
5# --
6${1:$(yas-trimmed-comment-start)} ${1:comment} ${1:$(let* ((str "")
7 (curr (current-column))
8 (start (yas-trimmed-comment-start))
9 (lastcom (substring start -1))
10 (end (yas-trimmed-comment-end)))
11 (while (< (length str) (- 79 (+ curr (length end))))
12 (setq str (concat str lastcom)))
13 (concat str end))}$0 \ No newline at end of file