|
169 | 169 |
|
170 | 170 | (defun elixir-smie--semi-ends-match () |
171 | 171 | "Return non-nil if the current line concludes a match block." |
172 | | - (save-excursion |
173 | | - ;; Warning: Recursion. |
174 | | - ;; This is easy though. |
175 | | - |
176 | | - ;; 1. If we're at a blank line, move forward a character. This takes us to |
177 | | - ;; the next line. |
178 | | - ;; 2. If we're not at the end of the buffer, call this function again. |
179 | | - ;; (Otherwise, return nil.) |
180 | | - |
181 | | - ;; The point here is that we want to treat blank lines as a single semi- |
182 | | - ;; colon when it comes to detecting the end of match statements. This could |
183 | | - ;; also be handled by a `while' expression or some other looping mechanism. |
184 | | - (cl-flet ((self-call () |
185 | | - (if (< (point) (point-max)) |
186 | | - (elixir-smie--semi-ends-match) |
187 | | - nil))) |
188 | | - (cond |
189 | | - ((and (eolp) (bolp)) |
190 | | - (forward-char) |
191 | | - (self-call)) |
192 | | - ((looking-at elixir-smie--spaces-til-eol-regexp) |
193 | | - (move-beginning-of-line 2) |
194 | | - (self-call)) |
195 | | - ;; And if we're NOT on a blank line, move to the end of the line, and see |
196 | | - ;; if we're looking back at a block operator. |
197 | | - (t (move-end-of-line 1) |
198 | | - (looking-back elixir-smie--block-operator-regexp)))))) |
| 172 | + (when (not (eobp)) |
| 173 | + (save-excursion |
| 174 | + ;; Warning: Recursion. |
| 175 | + ;; This is easy though. |
| 176 | + |
| 177 | + ;; 1. If we're at a blank line, move forward a character. This takes us to |
| 178 | + ;; the next line. |
| 179 | + ;; 2. If we're not at the end of the buffer, call this function again. |
| 180 | + ;; (Otherwise, return nil.) |
| 181 | + |
| 182 | + ;; The point here is that we want to treat blank lines as a single semi- |
| 183 | + ;; colon when it comes to detecting the end of match statements. This could |
| 184 | + ;; also be handled by a `while' expression or some other looping mechanism. |
| 185 | + (cl-flet ((self-call () |
| 186 | + (if (< (point) (point-max)) |
| 187 | + (elixir-smie--semi-ends-match) |
| 188 | + nil))) |
| 189 | + (cond |
| 190 | + ((and (eolp) (bolp)) |
| 191 | + (forward-char) |
| 192 | + (self-call)) |
| 193 | + ((looking-at elixir-smie--spaces-til-eol-regexp) |
| 194 | + (move-beginning-of-line 2) |
| 195 | + (self-call)) |
| 196 | + ;; And if we're NOT on a blank line, move to the end of the line, and see |
| 197 | + ;; if we're looking back at a block operator. |
| 198 | + (t (move-end-of-line 1) |
| 199 | + (looking-back elixir-smie--block-operator-regexp))))))) |
199 | 200 |
|
200 | 201 | (defun elixir-smie--same-line-as-parent (parent-pos child-pos) |
201 | 202 | "Return non-nil if `child-pos' is on same line as `parent-pos'." |
|
211 | 212 | ((and (or (looking-at elixir-smie--comment-regexp) |
212 | 213 | (looking-at "[\n#]")) |
213 | 214 | (elixir-smie--implicit-semi-p)) |
214 | | - (if (eolp) (forward-char 1) (forward-comment 1)) |
| 215 | + (when (not (save-excursion |
| 216 | + (forward-comment 1) |
| 217 | + (eobp))) |
| 218 | + (if (eolp) (forward-char 1) (forward-comment 1))) |
215 | 219 | ;; Note: `elixir-smie--semi-ends-match' will be called when the point is at |
216 | 220 | ;; the beginning of a new line. Keep that in mind. |
217 | 221 | (if (elixir-smie--semi-ends-match) |
|
313 | 317 | (cond |
314 | 318 | ((smie-rule-parent-p "if") |
315 | 319 | (smie-rule-parent)) |
316 | | - |
317 | 320 | ((and (smie-rule-parent-p "(") |
318 | 321 | (save-excursion |
319 | 322 | (goto-char (cadr smie--parent)) |
|
0 commit comments