init
This commit is contained in:
36
snippets/prog-mode/.yas-setup.el
Normal file
36
snippets/prog-mode/.yas-setup.el
Normal file
@@ -0,0 +1,36 @@
|
||||
(require 'yasnippet)
|
||||
|
||||
;; whitespace removing functions from Magnar Sveen ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun yas-s-trim-left (s)
|
||||
"Remove whitespace at the beginning of S."
|
||||
(if (string-match "\\`[ \t\n\r]+" s)
|
||||
(replace-match "" t t s)
|
||||
s))
|
||||
|
||||
(defun yas-s-trim-right (s)
|
||||
"Remove whitespace at the end of S."
|
||||
(if (string-match "[ \t\n\r]+\\'" s)
|
||||
(replace-match "" t t s)
|
||||
s))
|
||||
|
||||
(defun yas-s-trim (s)
|
||||
"Remove whitespace at the beginning and end of S."
|
||||
(yas-s-trim-left (yas-s-trim-right s)))
|
||||
|
||||
|
||||
(defun yas-string-reverse (str)
|
||||
"Reverse a string STR manually to be compatible with emacs versions < 25."
|
||||
(apply #'string
|
||||
(reverse
|
||||
(string-to-list str))))
|
||||
|
||||
(defun yas-trimmed-comment-start ()
|
||||
"This function returns `comment-start' trimmed by whitespaces."
|
||||
(yas-s-trim comment-start))
|
||||
|
||||
(defun yas-trimmed-comment-end ()
|
||||
"This function returns `comment-end' trimmed by whitespaces if `comment-end' is not empty.
|
||||
Otherwise the reversed output of function `yas-trimmed-comment-start' is returned."
|
||||
(if (eq (length comment-end) 0)
|
||||
(yas-string-reverse (yas-trimmed-comment-start))
|
||||
(yas-s-trim comment-end)))
|
||||
6
snippets/prog-mode/comment
Normal file
6
snippets/prog-mode/comment
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- mode: snippet -*-
|
||||
# contributor: sh-ow <sh-ow@users.noreply.github.com>
|
||||
# name: comment
|
||||
# key: co
|
||||
# --
|
||||
`(yas-trimmed-comment-start)` ${1:comment}`(unless (eq (length comment-end) 0) (concat " " (yas-trimmed-comment-end)))`$0
|
||||
36
snippets/prog-mode/commentblock
Normal file
36
snippets/prog-mode/commentblock
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- mode: snippet -*-
|
||||
# contributor: sh-ow <sh-ow@users.noreply.github.com>
|
||||
# name: commentblock
|
||||
# key: cob
|
||||
# --
|
||||
${1:$(let* ((col (current-column))
|
||||
(str "")
|
||||
(lastcom (substring (yas-trimmed-comment-start) -1))
|
||||
(start (yas-trimmed-comment-start))
|
||||
(end (yas-trimmed-comment-end))
|
||||
(over (- (+ (string-width yas-text) (length start) (length end) col) 77)))
|
||||
(while (< (length str) (+ (- 79 (length start) (length end) col) (if (> over 0) over 0)))
|
||||
(setq str (concat str lastcom)))
|
||||
(concat start str end))}
|
||||
${1:$(let* ((col (current-column))
|
||||
(str "")
|
||||
(start (yas-trimmed-comment-start))
|
||||
(end (yas-trimmed-comment-end)))
|
||||
(while (< (length str) (ffloor (/ (- 78.0 (+ col (length start) (string-width yas-text) (length end))) 2.0)))
|
||||
(setq str (concat str " ")))
|
||||
(concat start str))} ${1:comment} ${1:$(let* ((col (current-column))
|
||||
(str "")
|
||||
(start (yas-trimmed-comment-start))
|
||||
(end (yas-trimmed-comment-end)))
|
||||
(while (< (length str) (- 79.0 (if (eq (mod (string-width yas-text) 2) 1) (- col 1) col) (length end)))
|
||||
(setq str (concat str " ")))
|
||||
(concat str end))}
|
||||
${1:$(let* ((col (current-column))
|
||||
(str "")
|
||||
(lastcom (substring (yas-trimmed-comment-start) -1))
|
||||
(start (yas-trimmed-comment-start))
|
||||
(end (yas-trimmed-comment-end))
|
||||
(over (- (+ (string-width yas-text) (length start) (length end) col) 77)))
|
||||
(while (< (length str) (+ (- 79 (length start) (length end) col) (if (> over 0) over 0)))
|
||||
(setq str (concat str lastcom)))
|
||||
(concat start str end))}$0
|
||||
11
snippets/prog-mode/commentline
Normal file
11
snippets/prog-mode/commentline
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- mode: snippet -*-
|
||||
# contributor: sh-ow <sh-ow@users.noreply.github.com>
|
||||
# name: commentline
|
||||
# key: col
|
||||
# --
|
||||
`(yas-trimmed-comment-start)` ${1:comment} ${1:$(let* ((start (yas-trimmed-comment-start))
|
||||
(lastcom (aref start (1- (length start))))
|
||||
(end (yas-trimmed-comment-end))
|
||||
(endpadlen (- 79 (+ (current-column) (length end)))))
|
||||
(concat (make-string (max endpadlen 0) lastcom)
|
||||
end))}$0
|
||||
6
snippets/prog-mode/fixme
Normal file
6
snippets/prog-mode/fixme
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- mode: snippet -*-
|
||||
# name: fixme
|
||||
# key: fi
|
||||
# condition: (not (eq major-mode 'sh-mode))
|
||||
# --
|
||||
`comment-start`FIXME: $0`comment-end`
|
||||
5
snippets/prog-mode/todo
Normal file
5
snippets/prog-mode/todo
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- mode: snippet -*-
|
||||
# name: todo
|
||||
# key: t
|
||||
# --
|
||||
`comment-start`TODO: $0`comment-end`
|
||||
5
snippets/prog-mode/xxx
Normal file
5
snippets/prog-mode/xxx
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- mode: snippet -*-
|
||||
# name: xxx
|
||||
# key: x
|
||||
# --
|
||||
`comment-start`XXX: $0`comment-end`
|
||||
Reference in New Issue
Block a user