Skip to content

Commit eae9327

Browse files
committed
Add docstrings to API functions
1 parent e2c6cf4 commit eae9327

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

doom-snippets-lib.el

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,29 @@ always in front of the word that triggered this snippet."
2222
(backward-word))
2323
,@body))
2424

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-
3625
(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'."
3830
(let ((text (or yas-selected-text default "")))
3931
(if trim
4032
(string-trim text)
4133
text)))
4234

4335
(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."
4548
(let* ((text (or yas-selected-text default ""))
4649
(text (if trim (string-trim text) text)))
4750
(format-spec format
@@ -50,8 +53,18 @@ one line."
5053
(?> . ,(if (eolp) "" "\n"))
5154
))))
5255

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+
5366
(defun doom-snippets-newline-or-eol ()
54-
"Used in snippets. Insert newline here if at `eolp'."
67+
"Return newline, unless at `eolp'."
5568
(doom-snippets-format "%>"))
5669

5770
(defun doom-snippets-count-lines (str)

0 commit comments

Comments
 (0)