@@ -22,26 +22,29 @@ always in front of the word that triggered this snippet."
22
22
(backward-word ))
23
23
,@body ))
24
24
25
-
26
- (defun doom-snippets-newline-selected-newline ()
27
- " Used in snippets. Shorthand defun to surround text with newlines if more than
28
- one line."
29
- (doom-snippets-format " %!%s%!" nil t ))
30
-
31
- (defun doom-snippets-newline-selected ()
32
- " Used in snippets. Shorthand defun for snippets: prepends a newline to
33
- `yas-selected-text' IF it contains more than one line."
34
- (doom-snippets-format " %!%s" nil t ))
35
-
36
25
(defun doom-snippets-text (&optional default trim )
37
- " TODO"
26
+ " Return `yas-selected-text' (or `default' ).
27
+
28
+ If TRIM is non-nil, trim leading and trailing whitespace from
29
+ `yas-selected-text'/`default' ."
38
30
(let ((text (or yas-selected-text default " " )))
39
31
(if trim
40
32
(string-trim text)
41
33
text)))
42
34
43
35
(defun doom-snippets-format (format &optional default trim )
44
- " TODO"
36
+ " Returns a formatted string.
37
+
38
+ Like `format' , but with a custom spec:
39
+
40
+ %s The contents of your current selection (`yas-selected-text`)
41
+ %! A newline, if your current selection spans more than a single line
42
+ %> A newline, unless the point is at EOL
43
+
44
+ If `yas-selected-text` is empty, `DEFAULT` is used.
45
+
46
+ If `TRIM` is non-nil, whitespace on the ends of `yas-selected-text` is
47
+ trimmed."
45
48
(let* ((text (or yas-selected-text default " " ))
46
49
(text (if trim (string-trim text) text)))
47
50
(format-spec format
@@ -50,8 +53,18 @@ one line."
50
53
(?> . ,(if (eolp ) " " " \n " ))
51
54
))))
52
55
56
+ (defun doom-snippets-newline-selected-newline ()
57
+ " Return `yas-selected-text' surrounded with newlines if it consists of more
58
+ than one line."
59
+ (doom-snippets-format " %!%s%!" nil t ))
60
+
61
+ (defun doom-snippets-newline-selected ()
62
+ " Return `yas-selected-text' prefixed with a newline if it consists of more
63
+ than one line."
64
+ (doom-snippets-format " %!%s" nil t ))
65
+
53
66
(defun doom-snippets-newline-or-eol ()
54
- " Used in snippets. Insert newline here if at `eolp' ."
67
+ " Return newline, unless at `eolp' ."
55
68
(doom-snippets-format " %>" ))
56
69
57
70
(defun doom-snippets-count-lines (str )
0 commit comments