|
173 | 173 | (not (or (memq (char-before) '(?\{ ?\[))
|
174 | 174 | (looking-back elixir-smie--operator-regexp (- (point) 3) t))))
|
175 | 175 |
|
| 176 | +(defun elixir-smie-last-line-end-with-block-operator-p () |
| 177 | + "Return non-nil if the previous line ends with a `->' operator." |
| 178 | + (save-excursion |
| 179 | + (forward-line -1) |
| 180 | + (move-end-of-line 1) |
| 181 | + (looking-back elixir-smie--block-operator-regexp (- (point) 3) t))) |
| 182 | + |
176 | 183 | (defun elixir-smie--semi-ends-match ()
|
177 | 184 | "Return non-nil if the current line concludes a match block."
|
178 | 185 | (when (not (eobp))
|
|
292 | 299 | (t (smie-rule-parent))))
|
293 | 300 | (`(:before . "MATCH-STATEMENT-DELIMITER")
|
294 | 301 | (cond
|
295 |
| - ((smie-rule-parent-p "MATCH-STATEMENT-DELIMITER") |
| 302 | + ((and (smie-rule-parent-p "do") |
| 303 | + (smie-rule-hanging-p)) |
296 | 304 | (smie-rule-parent))
|
297 | 305 | ((and (not (smie-rule-sibling-p))
|
298 | 306 | (nth 2 smie--parent)
|
|
302 | 310 | (not (nth 2 smie--parent))
|
303 | 311 | (smie-rule-hanging-p))
|
304 | 312 | (smie-rule-parent))))
|
| 313 | + (`(:after . "MATCH-STATEMENT-DELIMITER") |
| 314 | + (cond |
| 315 | + ((and (smie-rule-parent-p "MATCH-STATEMENT-DELIMITER") |
| 316 | + (smie-rule-hanging-p) |
| 317 | + (smie-rule-sibling-p)) |
| 318 | + (if (elixir-smie-last-line-end-with-block-operator-p) |
| 319 | + (smie-rule-parent) |
| 320 | + 0)) |
| 321 | + (t |
| 322 | + (smie-rule-parent)))) |
305 | 323 | (`(:before . "fn")
|
306 | 324 | (smie-rule-parent))
|
307 | 325 | (`(:before . "do:")
|
308 | 326 | (cond
|
309 | 327 | ((smie-rule-parent-p "def" "if")
|
310 | 328 | (smie-rule-parent))))
|
| 329 | + (`(:before . "do") |
| 330 | + (cond |
| 331 | + ((and (smie-rule-parent-p "case") |
| 332 | + (smie-rule-hanging-p)) |
| 333 | + (smie-rule-parent elixir-smie-indent-basic)) |
| 334 | + (t |
| 335 | + elixir-smie-indent-basic))) |
311 | 336 | (`(:before . "end")
|
312 | 337 | (smie-rule-parent))
|
313 | 338 | ;; Closing paren on the other line
|
|
323 | 348 | ;; ()
|
324 | 349 | ;; .....
|
325 | 350 | ((smie-rule-parent-p "do")
|
326 |
| - (smie-rule-parent elixir-smie-indent-basic)) |
| 351 | + (smie-rule-parent)) |
327 | 352 | (t (smie-rule-parent))))
|
328 | 353 | (`(:before . "[")
|
329 | 354 | (cond
|
330 | 355 | ((smie-rule-hanging-p)
|
331 | 356 | (smie-rule-parent))))
|
| 357 | + (`(:before . "{") |
| 358 | + (cond |
| 359 | + ;; Example |
| 360 | + ;; |
| 361 | + ;; case parse do |
| 362 | + ;; { [ help: true ], _, _ } |
| 363 | + ;; -> :help |
| 364 | + ;; { _, [ user, project, count ], _ } |
| 365 | + ((and (not (smie-rule-hanging-p)) |
| 366 | + (smie-rule-parent-p "do")) |
| 367 | + (smie-rule-parent)) |
| 368 | + ((and (smie-rule-parent-p "MATCH-STATEMENT-DELIMITER") |
| 369 | + (not (smie-rule-hanging-p))) |
| 370 | + (if (elixir-smie-last-line-end-with-block-operator-p) |
| 371 | + (smie-rule-parent elixir-smie-indent-basic) |
| 372 | + (smie-rule-parent -2))))) |
332 | 373 | (`(:after . "{")
|
333 | 374 | (cond
|
334 | 375 | ((smie-rule-hanging-p)
|
|
346 | 387 | (`(:before . "->")
|
347 | 388 | (cond
|
348 | 389 | ((smie-rule-hanging-p)
|
349 |
| - (smie-rule-parent elixir-smie-indent-basic)))) |
| 390 | + (smie-rule-parent elixir-smie-indent-basic)) |
| 391 | + ;; Example |
| 392 | + ;; |
| 393 | + ;; case parse do |
| 394 | + ;; { [ help: true ], _, _ } |
| 395 | + ;; -> :help |
| 396 | + ;; ... |
| 397 | + ((and (not (smie-rule-hanging-p)) |
| 398 | + (smie-rule-parent-p "do")) |
| 399 | + elixir-smie-indent-basic) |
| 400 | + ((and (not (smie-rule-hanging-p)) |
| 401 | + (smie-rule-parent-p "MATCH-STATEMENT-DELIMITER")) |
| 402 | + (smie-rule-parent) |
| 403 | + ) |
| 404 | + )) |
350 | 405 | (`(:after . "->")
|
351 | 406 | (cond
|
352 | 407 | ;; This first condition is kind of complicated so I'll try to make this
|
|
372 | 427 | ;; Otherwise, if just indent by two.
|
373 | 428 | ((smie-rule-hanging-p)
|
374 | 429 | (cond
|
375 |
| - ((smie-rule-parent-p "after" "catch" "do" "rescue" "try") |
376 |
| - elixir-smie-indent-basic) |
| 430 | + ((smie-rule-parent-p "catch" "rescue") |
| 431 | + (smie-rule-parent (+ elixir-smie-indent-basic |
| 432 | + elixir-smie-indent-basic))) |
| 433 | + ((smie-rule-parent-p "after" "do" "try") |
| 434 | + (smie-rule-parent elixir-smie-indent-basic)) |
377 | 435 | (t (smie-rule-parent elixir-smie-indent-basic))))))
|
378 | 436 | (`(:before . ";")
|
379 | 437 | (cond
|
|
390 | 448 | ((and (smie-rule-parent-p "if")
|
391 | 449 | (smie-rule-hanging-p))
|
392 | 450 | (smie-rule-parent))
|
| 451 | + ((and (smie-rule-parent-p "else") |
| 452 | + (smie-rule-hanging-p)) |
| 453 | + (smie-rule-parent elixir-smie-indent-basic)) |
393 | 454 | ((smie-rule-parent-p "after" "catch" "def" "defmodule" "defp" "do" "else"
|
394 | 455 | "fn" "if" "rescue" "try" "unless")
|
395 |
| - (smie-rule-parent elixir-smie-indent-basic)) |
| 456 | + (smie-rule-parent)) |
| 457 | + ;; Example |
| 458 | + ;; |
| 459 | + ;; case parse do |
| 460 | + ;; { [ help: true ], _, _ } |
| 461 | + ;; -> :help |
| 462 | + ;; { _, [ user, project, count ], _ } |
| 463 | + ;; -> { user, project, count } |
| 464 | + ;; ... |
| 465 | + ((and (smie-rule-parent-p "->") |
| 466 | + (smie-rule-hanging-p)) |
| 467 | + (smie-rule-parent)) |
396 | 468 | ))
|
397 | 469 | (`(:after . ";")
|
398 | 470 | (cond
|
399 | 471 | ((smie-rule-parent-p "def")
|
400 | 472 | (smie-rule-parent))
|
401 | 473 | ((smie-rule-parent-p "if")
|
402 | 474 | (smie-rule-parent))
|
| 475 | + ((smie-rule-parent-p "after") |
| 476 | + (smie-rule-parent elixir-smie-indent-basic)) |
403 | 477 | ((and (smie-rule-parent-p "(")
|
404 | 478 | (boundp 'smie--parent)
|
405 | 479 | (save-excursion
|
|
0 commit comments