refactor code, put some code as functions in .yas-setup.el

This commit is contained in:
sh-ow 2016-04-13 22:53:48 +02:00
parent 6652d25288
commit 29e0a872de
3 changed files with 56 additions and 4 deletions

View file

@ -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))))))

View file

@ -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

View file

@ -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