Skip to content

Commit ea77cf9

Browse files
committed
Add comments
1 parent 193de68 commit ea77cf9

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

swift-mode-beginning-of-defun.el

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
(require 'swift-mode-indent)
3434

3535
(defun swift-mode:beginning-of-defun (&optional arg)
36-
"Move backward to the beginning of a defun."
36+
"Move backward to the beginning of a defun.
37+
38+
See `beginning-of-defun' for ARG."
3739
(interactive)
3840
(setq arg (or arg 1))
3941
(let (result
@@ -88,6 +90,9 @@
8890
result))
8991

9092
(defun swift-mode:beginning-of-defun-1 (next-token-function)
93+
"Goto the beginning of a defun.
94+
95+
NEXT-TOKEN-FUNCTION skips the preceding/following token."
9196
(catch 'swift-mode:found-defun
9297
(while (not (eq (swift-mode:token:type (funcall next-token-function))
9398
'outside-of-buffer))
@@ -98,6 +103,9 @@
98103

99104

100105
(defun swift-mode:is-point-before-body-of-defun ()
106+
"Return t it the point is just before the body of a defun.
107+
108+
Return nil otherwise."
101109
(and
102110
(eq (char-after) ?{)
103111
(progn
@@ -154,7 +162,9 @@ Intended for internal use."
154162
(swift-mode:skip-whitespaces))))
155163

156164
(defun swift-mode:end-of-defun (&optional arg)
157-
"Move forward to the end of a defun."
165+
"Move forward to the end of a defun.
166+
167+
See `end-of-defun' for ARG."
158168
(interactive)
159169
(setq arg (or arg 1))
160170
(let (result)
@@ -173,6 +183,9 @@ Intended for internal use."
173183
result))
174184

175185
(defun swift-mode:end-of-defun-1 (next-token-function)
186+
"Goto the end of a defun.
187+
188+
NEXT-TOKEN-FUNCTION skips the preceding/following token."
176189
(catch 'swift-mode:found-defun
177190
(while (not (eq (swift-mode:token:type (funcall next-token-function))
178191
'outside-of-buffer))

swift-mode-indent.el

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"Parent tokens for expressions.")
9494

9595
(defun swift-mode:indent-line ()
96+
"Indent the current line."
9697
(let ((indent (save-excursion (swift-mode:calculate-indent)))
9798
(current-indent
9899
(save-excursion (back-to-indentation) (current-column))))
@@ -103,6 +104,7 @@
103104
(save-excursion (indent-line-to indent)))))
104105

105106
(defun swift-mode:calculate-indent ()
107+
"Return the indentation of the current line."
106108
(back-to-indentation)
107109

108110
(if (nth 4 (syntax-ppss))
@@ -115,6 +117,7 @@
115117
(swift-mode:calculate-indent-of-code)))
116118

117119
(defun swift-mode:calculate-indent-of-multiline-comment ()
120+
"Return the indentation of the current line inside a multiline comment."
118121
(back-to-indentation)
119122
(let ((comment-beginning-position (nth 8 (syntax-ppss))))
120123
(forward-line -1)
@@ -134,6 +137,7 @@
134137
(current-column)))))
135138

136139
(defun swift-mode:calculate-indent-of-code ()
140+
"Return the indentation of the current line outside multiline comments."
137141
(back-to-indentation)
138142
(let* ((previous-token (save-excursion (swift-mode:backward-token)))
139143
(previous-type (swift-mode:token:type previous-token))
@@ -591,8 +595,7 @@ If scanning stops at eol, align with the next token with BOL-OFFSET.
591595
If AFTER-ATTRIBUTES is nil, skip lines with only attributes at the start of
592596
the expression."
593597
(save-excursion
594-
(let* ((pos (point))
595-
(parent-of-previous-line
598+
(let* ((parent-of-previous-line
596599
(save-excursion
597600
(swift-mode:goto-non-comment-bol-with-same-nesting-level)
598601
(swift-mode:backward-token)))
@@ -1069,12 +1072,12 @@ with one of those token types.
10691072
STOP-AT-EOL-TOKEN-TYPES is a list of token types that if we skipped the end of
10701073
a line just after a token with one of given toke typen, the function returns.
10711074
Typically, this is a list of token types that separates list elements
1072-
\(e.g. ',', ';'). If STOP-AT-EOL-TOKEN-TYPES is the symbol `any', it matches
1075+
\(e.g. ',', ';'). If STOP-AT-EOL-TOKEN-TYPES is the symbol `any', it matches
10731076
all tokens.
10741077
STOP-AT-BOL-TOKEN-TYPES is a list of token types that if we hit
10751078
the beginning of a line just before a token with one of given token types,
1076-
the function returns. Typically, this is a list of token types that starts
1077-
list element (e.g. 'case' of switch statement body). If STOP-AT-BOL-TOKEN-TYPES
1079+
the function returns. Typically, this is a list of token types that starts
1080+
list element (e.g. 'case' of switch statement body). If STOP-AT-BOL-TOKEN-TYPES
10781081
is the symbol `any', it matches all tokens."
10791082
(let*
10801083
((parent (swift-mode:backward-token-or-list))
@@ -1128,6 +1131,7 @@ is the symbol `any', it matches all tokens."
11281131
parent))
11291132

11301133
(defun swift-mode:align-with-next-token (parent &optional offset)
1134+
"Return indentation with the PARENT and OFFSET."
11311135
(let ((parent-end (swift-mode:token:end parent)))
11321136
(goto-char parent-end)
11331137
(forward-comment (point-max))
@@ -1138,6 +1142,7 @@ is the symbol `any', it matches all tokens."
11381142
(+ (or offset 0) (current-column))))
11391143

11401144
(defun swift-mode:align-with-current-line (&optional offset)
1145+
"Return indentation of the current line with OFFSET."
11411146
(swift-mode:goto-non-comment-bol)
11421147
(swift-mode:skip-whitespaces)
11431148
(+ (or offset 0) (current-column)))
@@ -1275,6 +1280,11 @@ It is a Generic parameter list if:
12751280

12761281
(defun swift-mode:try-skip-generic-parameters
12771282
(skip-token-or-list-function matching-bracket-text unmatching-bracket-text)
1283+
"Skip generic parameters if the point is just before/after one.
1284+
1285+
SKIP-TOKEN-OR-LIST-FUNCTION skips forward/backward a token or a list.
1286+
MATCHING-BRACKET-TEXT is a text of the matching bracket.
1287+
UNMATCHING-BRACKET-TEXT is a text of the current bracket."
12781288
(let ((pos (point))
12791289
(prohibited-tokens (append
12801290
unmatching-bracket-text
@@ -1356,6 +1366,9 @@ Return nil otherwise."
13561366
(skip-syntax-forward " >"))
13571367

13581368
(defun swift-mode:incomplete-comment-p ()
1369+
"Return t if the point is inside an incomplete comment.
1370+
1371+
Return nil otherwise."
13591372
(and (nth 4 (syntax-ppss))
13601373
(save-excursion
13611374
(goto-char (nth 8 (syntax-ppss)))
@@ -1364,9 +1377,10 @@ Return nil otherwise."
13641377
(defun swift-mode:indent-new-comment-line (&optional soft)
13651378
"Break the line at the point and indent the new line.
13661379
1367-
If the point is inside a comment, continue the comment. If the comment is a
1380+
If the point is inside a comment, continue the comment. If the comment is a
13681381
multiline comment, close the previous comment and start new one if
1369-
`comment-multi-line' is nil."
1382+
`comment-multi-line' is nil.
1383+
See `indent-new-comment-line' for SOFT."
13701384
(interactive)
13711385
(let* ((parser-state (syntax-ppss))
13721386
(is-inside-comment (nth 4 parser-state))
@@ -1422,6 +1436,9 @@ multiline comment, close the previous comment and start new one if
14221436
(indent-according-to-mode)))))
14231437

14241438
(defun swift-mode:post-self-insert ()
1439+
"Miscellaneous logic for electric indentation."
1440+
;; Indents electrically and insert a space when "*" is inserted at the
1441+
;; beginning of a line inside a multiline comment.
14251442
(cond
14261443
((and
14271444
(= last-command-event ?*)
@@ -1430,6 +1447,8 @@ multiline comment, close the previous comment and start new one if
14301447
(when swift-mode:insert-space-after-asterisk-in-comment
14311448
(insert-before-markers-and-inherit " "))
14321449
(indent-according-to-mode))
1450+
1451+
;; Fixes "* /" at the end of a multiline comment to "*/".
14331452
((and
14341453
(= last-command-event ?/)
14351454
swift-mode:fix-comment-close

swift-mode-lexer.el

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@
4646
stop-at-bol-token-types))
4747

4848
(defun swift-mode:token (type text start end)
49-
"Construct and returns a token."
49+
"Construct and return a token.
50+
51+
TYPE is the type of the token such as `inix-operator' or {.
52+
TEXT is the text of the token.
53+
START is the start position of the token.
54+
END is the point after the token."
5055
(list type text start end))
5156

5257
(defun swift-mode:token:type (token)
@@ -448,7 +453,9 @@ That is supertype declaration or type declaration of let or var."
448453
'{)))
449454

450455
(defun swift-mode:fix-operator-type (token)
451-
"Return new operator token with proper token type."
456+
"Return new operator token with proper token type.
457+
458+
Other properties are the same as the TOKEN."
452459
;; Operator type (i.e. prefix, postfix, infix) is decided from spaces or
453460
;; comments around the operator.
454461
;; https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID410
@@ -491,7 +498,7 @@ That is supertype declaration or type declaration of let or var."
491498
(swift-mode:token type text start end)))
492499

493500
(defun swift-mode:backquote-identifier-if-after-dot (token)
494-
"Backquote identifiers including keywords if it is after dot.
501+
"Backquote identifier TOKEN, including keywords, if it is after a dot.
495502
496503
See SE-0071:
497504
https://github.com/apple/swift-evolution/blob/master/proposals/0071-member-keywords.md"
@@ -561,8 +568,9 @@ type `out-of-buffer'"
561568
token)))))
562569

563570
(defun swift-mode:forward-token-simple ()
564-
"Like `swift-mode:forward-token' without recursion, and never produces
565-
`implicit-;' or `type-:'."
571+
"Like `swift-mode:forward-token' without recursion.
572+
573+
This function does not return `implicit-;' or `type-:'."
566574
(forward-comment (point-max))
567575
(cond
568576
;; Outside of buffer
@@ -748,8 +756,9 @@ type `out-of-buffer'."
748756
token)))))
749757

750758
(defun swift-mode:backward-token-simple ()
751-
"Like `swift-mode:backward-token' without recursion, and never produces
752-
`implicit-;' or `type-:'."
759+
"Like `swift-mode:backward-token' without recursion.
760+
761+
This function does not return `implicit-;' or `type-:'."
753762
(forward-comment (- (point)))
754763
(cond
755764
;; Outside of buffer

swift-mode.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
;;; `foward-sexp-function'
7171

7272
(defun swift-mode:forward-sexp (&optional arg)
73+
"Move forward/backward a token or list.
74+
75+
See `forward-sexp for ARG."
7376
(setq arg (or arg 1))
7477
(if (< 0 arg)
7578
(while (< 0 arg)

0 commit comments

Comments
 (0)