@@ -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
559573block.
560574Both 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."
885895In 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."
926941In 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
0 commit comments