|
39 | 39 | (let (result |
40 | 40 | pos) |
41 | 41 | (if (<= 0 arg) |
42 | | - (while (< 0 arg) |
43 | | - (setq result (swift-mode:beginning-of-defun-1 |
44 | | - #'swift-mode:backward-token-or-list)) |
45 | | - (setq arg (1- arg))) |
| 42 | + (progn |
| 43 | + (setq pos (point)) |
| 44 | + ;; Special handling for the case that the cursor is between the |
| 45 | + ;; beginning of the defun and the open curly brace of the defun. |
| 46 | + (when (< (save-excursion |
| 47 | + (swift-mode:beginning-of-statement) |
| 48 | + (point)) |
| 49 | + (point)) |
| 50 | + ;; Searches forward { or end of a statement. |
| 51 | + (while (not |
| 52 | + (memq |
| 53 | + (swift-mode:token:type (swift-mode:forward-token-or-list)) |
| 54 | + '({} implicit-\; \; } outside-of-buffer)))) |
| 55 | + (when (eq (char-before) ?}) |
| 56 | + (backward-list)) |
| 57 | + ;; Skips implicit ; |
| 58 | + (forward-comment (point-max)) |
| 59 | + (if (swift-mode:is-point-before-body-of-defun) |
| 60 | + (progn |
| 61 | + (swift-mode:beginning-of-statement) |
| 62 | + (setq result t) |
| 63 | + (setq arg (1- arg))) |
| 64 | + (goto-char pos))) |
| 65 | + (while (< 0 arg) |
| 66 | + (setq result (swift-mode:beginning-of-defun-1 |
| 67 | + #'swift-mode:backward-token-or-list)) |
| 68 | + (setq arg (1- arg)))) |
46 | 69 | (while (< arg 0) |
| 70 | + ;; If the cursor is on a defun, ensure the cursor is after the open |
| 71 | + ;; curly brace of defun. |
47 | 72 | (setq pos (point)) |
48 | | - |
49 | 73 | (swift-mode:beginning-of-statement) |
50 | | - |
| 74 | + ;; swift-mode:beginning-of-statement may forward the cursor if the |
| 75 | + ;; cursor is on a comment or whitespace. In that case, does not skip |
| 76 | + ;; the defun. |
51 | 77 | (when (<= (point) pos) |
52 | 78 | (while (not |
53 | 79 | (memq |
54 | 80 | (swift-mode:token:type (swift-mode:forward-token-or-list)) |
55 | | - '({} outside-of-buffer))))) |
| 81 | + '({} } outside-of-buffer))))) |
56 | 82 |
|
57 | 83 | (setq result (swift-mode:beginning-of-defun-1 |
58 | 84 | (lambda () |
|
109 | 135 | Intended for internal use." |
110 | 136 | (let ((parent (swift-mode:backward-sexps-until |
111 | 137 | swift-mode:statement-parent-tokens))) |
112 | | - (forward-comment (point-max)) |
113 | | - (swift-mode:goto-non-comment-bol) |
114 | | - (when (< (point) (swift-mode:token:end parent)) |
115 | | - (goto-char (swift-mode:token:end parent))) |
116 | | - (swift-mode:skip-whitespaces))) |
117 | | - |
| 138 | + (if (and |
| 139 | + (eq (swift-mode:token:type parent) 'implicit-\;) |
| 140 | + (save-excursion |
| 141 | + (goto-char (swift-mode:token:end parent)) |
| 142 | + (eq |
| 143 | + (swift-mode:token:type (swift-mode:forward-token)) |
| 144 | + '{))) |
| 145 | + (progn |
| 146 | + (forward-comment (- (point))) |
| 147 | + (swift-mode:beginning-of-statement)) |
| 148 | + (goto-char (swift-mode:token:end parent)) |
| 149 | + (setq parent (save-excursion (swift-mode:backward-token))) |
| 150 | + (forward-comment (point-max)) |
| 151 | + (swift-mode:goto-non-comment-bol) |
| 152 | + (when (< (point) (swift-mode:token:end parent)) |
| 153 | + (goto-char (swift-mode:token:end parent))) |
| 154 | + (swift-mode:skip-whitespaces)))) |
118 | 155 |
|
119 | 156 | (defun swift-mode:end-of-defun (&optional arg) |
120 | 157 | "Move forward to the end of a defun." |
|
0 commit comments