Skip to content

Commit 4a5f577

Browse files
committed
Tweak comments and style
1 parent e9e493e commit 4a5f577

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

swift-mode-beginning-of-defun.el

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -312,23 +312,27 @@ Intended for internal use."
312312
(previous-token (save-excursion (swift-mode:backward-token)))
313313
next-token)
314314
(cond
315+
;; Already at the end of statement. Returns next token.
315316
((and
316317
(memq (swift-mode:token:type previous-token)
317318
'(\; anonymous-function-parameter-in))
318319
(eq (swift-mode:token:end previous-token) pos))
319-
;; Already at the end of statement. Returns next token.
320320
(save-excursion (swift-mode:forward-token)))
321+
322+
;; Between statements, or before the first statement.
321323
((memq (swift-mode:token:type previous-token)
322324
'(implicit-\; outside-of-buffer))
323-
;; Between statements, or before the first statement.
324325
(swift-mode:forward-statement))
326+
327+
;; Already at the end of statement. Returns next token.
325328
((progn
326329
(setq next-token (save-excursion (swift-mode:forward-token)))
327330
(and (memq (swift-mode:token:type next-token)
328331
'(implicit-\; } outside-of-buffer))
329332
(eq (swift-mode:token:end previous-token) pos)))
330-
;; Already at the end of statement. Returns next token.
331333
next-token)
334+
335+
;; Inside a statement.
332336
(t
333337
(swift-mode:forward-statement)))))
334338

@@ -362,18 +366,28 @@ Intended for internal use."
362366
'\;)
363367
(setq token (swift-mode:forward-token)))
364368
(cond
369+
;; The statement is the last one in the buffer.
370+
;; Goes back to the end of the statement unless we were between the end of
371+
;; the statement and the end of the buffer.
365372
((eq (swift-mode:token:type token) 'outside-of-buffer)
366373
(forward-comment (- (point)))
367374
(when (<= (point) pos)
368375
(goto-char (swift-mode:token:end token)))
369376
token)
377+
378+
;; We were inside of a block.
379+
;; Goes back to the end of the statement unless we were between the end of
380+
;; the statement and the close bracket.
381+
;; Otherwise, goes to the end of the parent statement.
370382
((eq (swift-mode:token:type token) '})
371383
(forward-comment (- (point)))
372384
(if (<= (point) pos)
373385
(progn
374386
(goto-char (swift-mode:token:end token))
375387
(swift-mode:end-of-statement))
376388
token))
389+
390+
;; Otherwise, we have finished.
377391
(t token))))
378392

379393
(defun swift-mode:end-of-defun (&optional arg)
@@ -559,7 +573,6 @@ MOVE-BACKWARD is a function moving the cursor to the previous beginning of
559573
block.
560574
Both functions return t if succeeded, return nil otherwise."
561575
(setq arg (or arg 1))
562-
563576
(let ((reversed (< arg 0))
564577
(count (abs arg))
565578
(direction
@@ -587,10 +600,8 @@ Both functions return t if succeeded, return nil otherwise."
587600
((eq direction 'containing) 'containing)
588601
((eq direction 'preceding) 'following)
589602
((eq direction 'following) 'preceding))))
590-
591603
(setq new-region original-region)
592604
(setq new-direction direction)
593-
594605
(while (and new-region (< 0 count))
595606
(let ((new-region-and-direction
596607
(swift-mode:extend-region-to-be-marked
@@ -604,16 +615,13 @@ Both functions return t if succeeded, return nil otherwise."
604615
(when new-region
605616
(setq last-successful-region new-region))
606617
(setq count (1- count)))
607-
608618
(setq new-region (or new-region last-successful-region))
609619
(setq swift-mode:last-mark-direction new-direction)
610-
611620
(and
612621
new-region
613622
(progn
614623
(goto-char (car new-region))
615624
(push-mark (cdr new-region) nil t)
616-
617625
(if (eq (car original-region) (cdr original-region))
618626
(when (eq new-direction 'preceding)
619627
(exchange-point-and-mark))
@@ -838,9 +846,11 @@ Both functions return t if succeeded, return nil otherwise."
838846
(nth 0 (swift-mode:containing-generic-block-region
839847
(cons (point) (point))
840848
move-forward move-backward)))
849+
841850
((eq swift-mode:mark-defun-preference 'preceding)
842851
(swift-mode:preceding-generic-block-region
843852
move-forward move-backward))
853+
844854
((eq swift-mode:mark-defun-preference 'following)
845855
(swift-mode:following-generic-block-region
846856
move-forward move-backward))))
@@ -885,27 +895,30 @@ Return t if a sentence is found. Return nil otherwise."
885895
In comments or strings, skip a sentence. Otherwise, skip a statement."
886896
(let ((chunk (swift-mode:chunk-after)))
887897
(cond
898+
;; Inside a comment.
888899
((swift-mode:chunk:comment-p chunk)
889900
(swift-mode:forward-sentence-inside-comment
890901
(swift-mode:chunk:single-line-comment-p chunk)))
902+
903+
;; Inside a string.
891904
((swift-mode:chunk:string-p chunk)
892905
(swift-mode:forward-sentence-inside-string))
906+
893907
;; Spaces at the beginning of 2nd and following lines.
908+
;; Between the beginning of the line and "ccc" and "ddd" bellow:
894909
;;
895910
;; class Foo {
896911
;; // aaa
897912
;;
898913
;; // bbb
899-
;; // ccc ← spaces before //
900-
;; // ddd ← spaces before //
914+
;; // ccc
915+
;; // ddd
901916
;; func foo() { // eee
902917
;; }
903918
;; }
904919
;;
905-
;; Not including spaces before the first line of blocks.
920+
;; Not including spaces before the first line of blocks ("bbb").
906921
((save-excursion
907-
(skip-syntax-backward " ")
908-
(skip-chars-backward "/")
909922
(skip-syntax-backward " ")
910923
(and (bolp)
911924
(looking-at "[ \t]*//")
@@ -917,6 +930,8 @@ In comments or strings, skip a sentence. Otherwise, skip a statement."
917930
(skip-syntax-forward " ")
918931
(forward-char 2)
919932
(swift-mode:forward-sentence-inside-comment t))
933+
934+
;; Otherwise
920935
(t
921936
(swift-mode:forward-sentence-inside-code)))))
922937

@@ -926,36 +941,43 @@ In comments or strings, skip a sentence. Otherwise, skip a statement."
926941
In comments or strings, skip a sentence. Otherwise, skip a statement."
927942
(let ((chunk (swift-mode:chunk-after)))
928943
(cond
944+
;; Inside a comment.
929945
((swift-mode:chunk:comment-p chunk)
930946
(swift-mode:backward-sentence-inside-comment
931947
(swift-mode:chunk:single-line-comment-p chunk)))
948+
949+
;; Inside a string.
932950
((swift-mode:chunk:string-p chunk)
933951
(swift-mode:backward-sentence-inside-string))
952+
934953
;; Spaces at the beginning of 2nd and following lines.
954+
;; Between the beginning of the line and "ccc" and "ddd" bellow:
935955
;;
936956
;; class Foo {
937957
;; // aaa
938958
;;
939959
;; // bbb
940-
;; // ccc ← spaces before //
941-
;; // ddd ← spaces before //
960+
;; // ccc
961+
;; // ddd
942962
;; func foo() { // eee
943963
;; }
944964
;; }
945965
;;
946-
;; Not including spaces before the first line of blocks.
966+
;; Not including spaces before the first line of blocks ("bbb").
947967
((save-excursion
948968
(skip-syntax-backward " ")
949969
(and (bolp)
950970
(looking-at "[ \t]*//")
951971
(not (bobp))
952972
(progn
953973
(backward-char)
954-
(nth 4 (syntax-ppss)))))
974+
(swift-mode:chunk:comment-p (swift-mode:chunk-after)))))
955975
(forward-line 0)
956976
(skip-syntax-forward " ")
957977
(forward-char 2)
958978
(swift-mode:backward-sentence-inside-comment t))
979+
980+
;; Otherwise
959981
(t
960982
(swift-mode:backward-sentence-inside-code)))))
961983

@@ -1210,8 +1232,10 @@ of lines. Empty lines split blocks. Example:
12101232
(skip-chars-forward "\"")
12111233
(skip-syntax-forward " >")
12121234
t)
1235+
12131236
((eq (char-after) ?\))
12141237
(swift-mode:backward-sentence-inside-interpolated-expression))
1238+
12151239
(t
12161240
(swift-mode:backward-sentence-inside-code t)))))))
12171241

swift-mode-indent.el

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ declaration and its offset is `swift-mode:basic-offset'."
152152
(defun swift-mode:calculate-indent ()
153153
"Return the indentation of the current line."
154154
(back-to-indentation)
155-
156155
(let ((parser-state (syntax-ppss)))
157156
(cond
158157
((nth 4 parser-state)
@@ -1616,7 +1615,6 @@ See `indent-new-comment-line' for SOFT."
16161615
(comment-beginning-position (swift-mode:chunk:start chunk)))
16171616
(if soft (insert-and-inherit ?\n) (newline 1))
16181617
(delete-horizontal-space)
1619-
16201618
;; Inserts a prefix and indents the line.
16211619
(cond
16221620
((not (swift-mode:chunk:comment-p chunk))
@@ -1646,7 +1644,6 @@ See `indent-new-comment-line' for SOFT."
16461644

16471645
(t
16481646
(swift-mode:format-multiline-comment-line-after-newline chunk soft)))
1649-
16501647
;; Cleans up the previous line.
16511648
(save-excursion
16521649
(forward-line 0)
@@ -1750,7 +1747,6 @@ See `indent-new-comment-line' for SOFT."
17501747
(t
17511748
;; Uses the default indentation.
17521749
(indent-according-to-mode)))
1753-
17541750
;; Closes incomplete multiline comment.
17551751
(when (and swift-mode:auto-close-multiline-comment
17561752
(swift-mode:incomplete-comment-p chunk))
@@ -1760,7 +1756,6 @@ See `indent-new-comment-line' for SOFT."
17601756
(if soft (insert-and-inherit ?\n) (newline 1)))
17611757
(insert-and-inherit "*/")
17621758
(indent-according-to-mode)))
1763-
17641759
;; Make sure the closing delimiter is on its own line.
17651760
(when swift-mode:break-line-before-comment-close
17661761
(save-excursion
@@ -1839,12 +1834,9 @@ See `indent-new-comment-line' for SOFT."
18391834
swift-mode:anchor-overlay
18401835
(swift-mode:indentation:point indentation)
18411836
(1+ (swift-mode:indentation:point indentation)))
1842-
18431837
(overlay-put swift-mode:anchor-overlay 'face 'highlight)
1844-
18451838
(when swift-mode:anchor-overlay-timer
18461839
(cancel-timer swift-mode:anchor-overlay-timer))
1847-
18481840
(let ((buffer (current-buffer)))
18491841
(setq swift-mode:anchor-overlay-timer
18501842
(run-at-time

swift-mode-lexer.el

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ Intended for `syntax-propertize-function'."
243243
((swift-mode:chunk:comment-p chunk)
244244
(goto-char (swift-mode:chunk:start chunk))
245245
(forward-comment (point-max)))))
246-
247246
(swift-mode:syntax-propertize:scan end 0))
248247

249248
(defun swift-mode:syntax-propertize:scan (end nesting-level)
@@ -317,6 +316,7 @@ pound signs."
317316
(put-text-property (1- (point)) (point)
318317
'syntax-table
319318
(string-to-syntax "|")))
319+
320320
((and (equal "(" (match-string-no-properties 0))
321321
(swift-mode:escaped-p (match-beginning 0) pound-count))
322322
;; Found an interpolated expression. Skips the expression.
@@ -352,6 +352,7 @@ pound signs."
352352
(1- (point)))
353353
(swift-mode:syntax-propertize:end-of-string
354354
end quotation pound-count))))
355+
355356
(t
356357
(swift-mode:syntax-propertize:end-of-string end quotation pound-count)))
357358
(goto-char end)))
@@ -700,7 +701,6 @@ Return nil otherwise."
700701
nil
701702
(save-excursion
702703
(setq swift-mode:in-recursive-call-of-case-colon-p t)
703-
704704
(unwind-protect
705705
(member
706706
;; FIXME:
@@ -1419,14 +1419,19 @@ If PARSER-STATE is given, it is used instead of (syntax-ppss)."
14191419
(looking-at "#*\"\"\""))
14201420
(swift-mode:chunk 'multiline-string (nth 8 parser-state))
14211421
(swift-mode:chunk 'single-line-string (nth 8 parser-state))))
1422+
14221423
((eq (nth 4 parser-state) t)
14231424
(swift-mode:chunk 'single-line-comment (nth 8 parser-state)))
1425+
14241426
((nth 4 parser-state)
14251427
(swift-mode:chunk 'multiline-comment (nth 8 parser-state)))
1428+
14261429
((and (eq (char-before) ?/) (eq (char-after) ?/))
14271430
(swift-mode:chunk 'single-line-comment (1- (point))))
1431+
14281432
((and (eq (char-before) ?/) (eq (char-after) ?*))
14291433
(swift-mode:chunk 'multiline-comment (1- (point))))
1434+
14301435
(t
14311436
nil))))
14321437

0 commit comments

Comments
 (0)