summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsh-ow <sh-ow@users.noreply.github.com>2016-04-13 22:53:48 +0200
committersh-ow <sh-ow@users.noreply.github.com>2016-04-13 22:53:48 +0200
commit29e0a872dec37cff3c3e8325056e5fc7020e4562 (patch)
tree3dd0d2ed72ebe1eda10052e913763441ade055c2
parent6652d252883d4fed79678ec4bcc86d61be8f413b (diff)
refactor code, put some code as functions in .yas-setup.el
-rw-r--r--prog-mode/.yas-setup.el16
-rw-r--r--prog-mode/commentblock34
-rw-r--r--prog-mode/commentline10
3 files changed, 56 insertions, 4 deletions
diff --git a/prog-mode/.yas-setup.el b/prog-mode/.yas-setup.el
index 03d07cf..c006d05 100644
--- a/prog-mode/.yas-setup.el
+++ b/prog-mode/.yas-setup.el
@@ -1,2 +1,18 @@
(defun yas-with-comment (str)
(format "%s%s%s" comment-start str comment-end))
+
+(defun yas-get-comment-start ()
+ (substring comment-start 0
+ (dotimes (i (length comment-start))
+ (unless (or (eq (aref (reverse comment-start) i) nil)
+ (eq (aref (reverse comment-start) i) 32))
+ (return (- (length comment-start) i))))))
+
+(defun yas-get-comment-end ()
+ (if (eq (length comment-end) 0)
+ (reverse start)
+ (substring comment-end
+ (dotimes (i (length comment-end))
+ (unless (or (eq (aref comment-end i) nil)
+ (eq (aref comment-end i) 32))
+ (return i))))))
diff --git a/prog-mode/commentblock b/prog-mode/commentblock
index 06d607c..57eb46b 100644
--- a/prog-mode/commentblock
+++ b/prog-mode/commentblock
@@ -3,7 +3,35 @@
# name: commentblock
# key: com
# --
-${1:$(let* ((col (current-column)) (lastcom (dolist (ch (append (reverse comment-start) nil)) (unless (or (eq ch nil) (eq ch 32)) (return (string ch))))) (str "") (start (substring comment-start 0 (dotimes (i (length comment-start)) (unless (or (eq (aref (reverse comment-start) i) nil) (eq (aref (reverse comment-start) i) 32)) (return (- (length comment-start) i)))))) (end (if (eq (length comment-end) 0) (reverse start) (substring comment-end (dotimes (i (length comment-end)) (unless (or (eq (aref comment-end i) nil) (eq (aref comment-end i) 32)) (return i)))))) (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 (substring comment-start 0 (dotimes (i (length comment-start)) (unless (or (eq (aref (reverse comment-start) i) nil) (eq (aref (reverse comment-start) i) 32)) (return (- (length comment-start) i)))))) (end (if (eq (length comment-end) 0) (reverse start) (substring comment-end (dotimes (i (length comment-end)) (unless (or (eq (aref comment-end i) nil) (eq (aref comment-end i) 32)) (return i))))))) (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 (substring comment-start 0 (dotimes (i (length comment-start)) (unless (or (eq (aref (reverse comment-start) i) nil) (eq (aref (reverse comment-start) i) 32)) (return (- (length comment-start) i)))))) (end (if (eq (length comment-end) 0) (reverse start) (substring comment-end (dotimes (i (length comment-end)) (unless (or (eq (aref comment-end i) nil) (eq (aref comment-end i) 32)) (return i))))))) (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)) (lastcom (dolist (ch (append (reverse comment-start) nil)) (unless (or (eq ch nil) (eq ch 32)) (return (string ch))))) (str "") (start (substring comment-start 0 (dotimes (i (length comment-start)) (unless (or (eq (aref (reverse comment-start) i) nil) (eq (aref (reverse comment-start) i) 32)) (return (- (length comment-start) i)))))) (end (if (eq (length comment-end) 0) (reverse start) (substring comment-end (dotimes (i (length comment-end)) (unless (or (eq (aref comment-end i) nil) (eq (aref comment-end i) 32)) (return i)))))) (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 "")
+ (lastcom (substring (yas-get-comment-start) -1))
+ (start (yas-get-comment-start))
+ (end (yas-get-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-get-comment-start))
+ (end (yas-get-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-get-comment-start))
+ (end (yas-get-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-get-comment-start) -1))
+ (start (yas-get-comment-start))
+ (end (yas-get-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
diff --git a/prog-mode/commentline b/prog-mode/commentline
index aa789e6..c794f7c 100644
--- a/prog-mode/commentline
+++ b/prog-mode/commentline
@@ -3,5 +3,13 @@
# name: commentline
# key: co
# --
-${1:$(let* ((start (substring comment-start 0 (dotimes (i (length comment-start)) (unless (or (eq (aref (reverse comment-start) i) nil) (eq (aref (reverse comment-start) i) 32)) (return (- (length comment-start) i))))))) start)} ${1:comment} ${1:$(let* ((str "") (curr (current-column)) (start (substring comment-start 0 (dotimes (i (length comment-start)) (unless (or (eq (aref (reverse comment-start) i) nil) (eq (aref (reverse comment-start) i) 32)) (return (- (length comment-start) i)))))) (lastcom (substring start -1)) (end (if (eq (length comment-end) 0) (reverse start) (substring comment-end (dotimes (i (length comment-end)) (unless (or (eq (aref comment-end i) nil) (eq (aref comment-end i) 32)) (return i))))))) (while (< (length str) (- 79 (+ curr (length end)))) (setq str (concat str lastcom))) (concat str end))}
+${1:$(let* ((start (yas-get-comment-start)))
+ start)} ${1:comment} ${1:$(let* ((str "")
+ (curr (current-column))
+ (start (yas-get-comment-start))
+ (lastcom (substring start -1))
+ (end (yas-get-comment-end)))
+ (while (< (length str) (- 79 (+ curr (length end))))
+ (setq str (concat str lastcom)))
+ (concat str end))}
$0