|
67 | 67 | (rassoc next smie-closer-alist)))) |
68 | 68 | (smie-indent-calculate)))))))) |
69 | 69 |
|
| 70 | +(defun elixir-smie-looking-around (back at) |
| 71 | + "Check if looking backwards at BACK and forward at AT." |
| 72 | + (and (looking-at-p at) (looking-back back))) |
| 73 | + |
70 | 74 | ;; Declare variable that we need from the smie package |
71 | 75 | (defvar smie--parent) |
72 | 76 |
|
|
271 | 275 | ;; the beginning of a new line. Keep that in mind. |
272 | 276 | (if (elixir-smie--semi-ends-match) |
273 | 277 | "MATCH-STATEMENT-DELIMITER" |
274 | | - ";")) |
| 278 | + (if (and (looking-at ".+,$") |
| 279 | + (not (> (nth 0 (syntax-ppss)) 0))) |
| 280 | + "COMMA"";"))) |
275 | 281 | ((looking-at elixir-smie--block-operator-regexp) |
276 | 282 | (goto-char (match-end 0)) |
277 | 283 | "->") |
|
296 | 302 | (elixir-smie--implicit-semi-p)) |
297 | 303 | (if (elixir-smie--semi-ends-match) |
298 | 304 | "MATCH-STATEMENT-DELIMITER" |
299 | | - ";")) |
| 305 | + (if (and (looking-back ",$" (- (point) 2) t) |
| 306 | + (not (> (nth 0 (syntax-ppss)) 0))) |
| 307 | + "COMMA" |
| 308 | + ";"))) |
300 | 309 | ((looking-back elixir-smie--oneline-def-operator-regexp (- (point) 3) t) |
301 | 310 | (goto-char (match-beginning 0)) |
302 | 311 | ";") |
|
330 | 339 | -4) |
331 | 340 | (`(:elem . args) |
332 | 341 | -4) |
| 342 | + (`(:before . "COMMA") |
| 343 | + (cond |
| 344 | + ((and (smie-rule-parent-p ";") |
| 345 | + (smie-rule-hanging-p)) |
| 346 | + (smie-rule-parent (- elixir-smie-indent-basic))) |
| 347 | + ((smie-rule-parent-p "(") |
| 348 | + (smie-rule-parent)) |
| 349 | + ((smie-rule-parent-p "->") |
| 350 | + (smie-rule-parent (- elixir-smie-indent-basic))))) |
| 351 | + (`(:after . "COMMA") |
| 352 | + (cond |
| 353 | + ((and (smie-rule-parent-p ";") |
| 354 | + (smie-rule-hanging-p)) |
| 355 | + (smie-rule-parent elixir-smie-indent-basic)) |
| 356 | + ((and (smie-rule-parent-p "{") |
| 357 | + (smie-rule-hanging-p)) |
| 358 | + (smie-rule-parent elixir-smie-indent-basic)) |
| 359 | + ((and (smie-rule-parent-p "[") |
| 360 | + (smie-rule-hanging-p)) |
| 361 | + 0) |
| 362 | + ((smie-rule-parent-p "->") |
| 363 | + (smie-rule-parent elixir-smie-indent-basic)) |
| 364 | + (t (smie-rule-parent elixir-smie-indent-basic)))) |
333 | 365 | (`(:before . "OP") |
334 | 366 | (cond |
| 367 | + ((smie-rule-parent-p "for") |
| 368 | + (smie-rule-parent)) |
335 | 369 | ((and (not (smie-rule-hanging-p)) |
336 | 370 | (elixir-smie-current-line-start-with-pipe-operator-p) |
337 | 371 | (elixir-smie-last-line-is-assignment-p)) |
|
341 | 375 | (cons 'column (elixir-smie--previous-line-indentation))) |
342 | 376 | ((and (not (smie-rule-hanging-p)) |
343 | 377 | (smie-rule-prev-p "OP")) |
344 | | - -2) |
| 378 | + (- elixir-smie-indent-basic)) |
345 | 379 | ((smie-rule-parent-p "def" "defp" "defmacro" "defmacrop") |
346 | 380 | (smie-rule-parent)) |
347 | 381 | (t (smie-rule-parent)))) |
348 | | - (`(:before . "def") |
349 | | - (cond |
350 | | - (t |
351 | | - (smie-rule-parent)))) |
352 | | - (`(:before . "defp") |
353 | | - (cond |
354 | | - (t |
355 | | - (smie-rule-parent)))) |
356 | | - (`(:before . "defmacro") |
357 | | - (cond |
358 | | - (t |
359 | | - (smie-rule-parent)))) |
360 | | - (`(:before . "defmacrop") |
361 | | - (cond |
362 | | - (t |
363 | | - (smie-rule-parent)))) |
364 | 382 | (`(:after . "OP") |
365 | 383 | (cond |
366 | 384 | ((smie-rule-sibling-p) nil) |
367 | | - ((smie-rule-hanging-p) (smie-rule-parent elixir-smie-indent-basic)) |
| 385 | + ((smie-rule-hanging-p) |
| 386 | + (smie-rule-parent elixir-smie-indent-basic)) |
368 | 387 | ((and (not (smie-rule-sibling-p)) |
369 | 388 | (not (smie-rule-hanging-p)) |
370 | 389 | (smie-rule-parent-p "do:")) |
371 | 390 | ;; Dedent the line after an OP if it's after a "do:" token, which implies |
372 | 391 | ;; a one-line function. |
373 | 392 | (smie-rule-parent |
374 | 393 | (- (+ elixir-smie-indent-basic elixir-smie-indent-basic)))) |
375 | | - (t (smie-rule-parent)))) |
| 394 | + ((smie-rule-parent-p ";") |
| 395 | + (smie-rule-parent )) |
| 396 | + (t (smie-rule-parent (- elixir-smie-indent-basic))))) |
376 | 397 | (`(:before . "MATCH-STATEMENT-DELIMITER") |
377 | 398 | (cond |
378 | 399 | ((and (smie-rule-parent-p "do") |
|
426 | 447 | (t |
427 | 448 | (smie-rule-parent)))) |
428 | 449 | (`(:before . "fn") |
429 | | - (smie-rule-parent)) |
| 450 | + (cond |
| 451 | + ((smie-rule-parent-p "(") |
| 452 | + (smie-rule-parent)) |
| 453 | + (t (smie-rule-parent)))) |
430 | 454 | (`(:before . "for") |
431 | 455 | (cond |
432 | 456 | ((elixir-smie-last-line-end-with-block-operator-p) |
433 | 457 | (smie-rule-parent elixir-smie-indent-basic)) |
434 | | - (t (smie-rule-parent)))) |
| 458 | + ((smie-rule-prev-p "OP") |
| 459 | + (smie-rule-parent)))) |
435 | 460 | (`(:before . "do:") |
436 | 461 | (cond |
437 | 462 | ((smie-rule-parent-p "def" "if" "defp" "defmacro" "defmacrop") |
438 | 463 | (smie-rule-parent)) |
439 | 464 | ((and (smie-rule-parent-p ";") |
440 | 465 | (not (smie-rule-hanging-p))) |
441 | | - (smie-rule-parent)) |
| 466 | + (smie-rule-parent (+ elixir-smie-indent-basic elixir-smie-indent-basic))) |
442 | 467 | ;; Example |
443 | 468 | ;; |
444 | 469 | ;; hi = for i <- list, do: i |
|
451 | 476 | (smie-rule-parent)) |
452 | 477 | ((and (smie-rule-parent-p "OP") |
453 | 478 | (not (smie-rule-hanging-p))) |
454 | | - (smie-rule-parent)))) |
| 479 | + (smie-rule-parent elixir-smie-indent-basic)))) |
455 | 480 | (`(:before . "do") |
456 | 481 | (cond |
457 | 482 | ((and (smie-rule-parent-p "case") |
|
476 | 501 | (smie-rule-parent elixir-smie-indent-basic)) |
477 | 502 | (t elixir-smie-indent-basic))) |
478 | 503 | (`(:before . "end") |
479 | | - (smie-rule-parent)) |
| 504 | + (cond |
| 505 | + ((smie-rule-parent-p "(") |
| 506 | + (smie-rule-parent)) |
| 507 | + (t (smie-rule-parent)))) |
| 508 | + (`(:before . "else:") |
| 509 | + (cond |
| 510 | + ((smie-rule-parent-p ";") |
| 511 | + (smie-rule-parent)) |
| 512 | + (t (smie-rule-parent)))) |
480 | 513 | ;; Closing paren on the other line |
481 | 514 | (`(:before . "(") |
482 | 515 | (cond |
|
491 | 524 | ;; ..... |
492 | 525 | ((smie-rule-parent-p "do") |
493 | 526 | (smie-rule-parent)) |
| 527 | + ((smie-rule-parent-p "OP") |
| 528 | + (smie-rule-parent)) |
| 529 | + ((smie-rule-parent-p ";") |
| 530 | + (smie-rule-parent)) |
494 | 531 | (t (smie-rule-parent)))) |
495 | 532 | (`(:before . "[") |
496 | 533 | (cond |
497 | 534 | ((smie-rule-hanging-p) |
498 | 535 | (smie-rule-parent)))) |
499 | 536 | (`(:before . "{") |
500 | 537 | (cond |
| 538 | + ((smie-rule-parent-p "COMMA") |
| 539 | + (smie-rule-parent)) |
501 | 540 | ;; Example |
502 | 541 | ;; |
503 | 542 | ;; case parse do |
|
523 | 562 | (if (elixir-smie-last-line-end-with-block-operator-p) |
524 | 563 | (smie-rule-parent elixir-smie-indent-basic) |
525 | 564 | (if (elixir-smie-last-line-start-with-block-operator-p) |
526 | | - (smie-rule-parent -2) |
| 565 | + (smie-rule-parent (- elixir-smie-indent-basic)) |
527 | 566 | (smie-rule-parent)))) |
528 | 567 | ((and (smie-rule-parent-p "OP") |
529 | 568 | (smie-rule-hanging-p)) |
|
536 | 575 | (if (save-excursion |
537 | 576 | (move-end-of-line 1) |
538 | 577 | (looking-back elixir-smie--block-operator-regexp (- (point) 3) t)) |
539 | | - (smie-rule-parent -2) |
| 578 | + (smie-rule-parent (- elixir-smie-indent-basic)) |
540 | 579 | elixir-smie-indent-basic)) |
541 | 580 | ((smie-rule-parent-p ";") |
542 | 581 | (if (save-excursion |
543 | 582 | (move-end-of-line 1) |
544 | 583 | (looking-back elixir-smie--block-operator-regexp (- (point) 3) t)) |
545 | | - (smie-rule-parent -2) |
546 | | - elixir-smie-indent-basic)) |
| 584 | + (smie-rule-parent (- elixir-smie-indent-basic)) |
| 585 | + (smie-rule-parent))) |
547 | 586 | (t (smie-rule-parent elixir-smie-indent-basic)))) |
548 | 587 | (`(:after . "{") |
549 | 588 | (cond |
|
680 | 719 | ((and (smie-rule-parent-p "else") |
681 | 720 | (smie-rule-hanging-p)) |
682 | 721 | (smie-rule-parent elixir-smie-indent-basic)) |
683 | | - ((smie-rule-parent-p "after" "catch" "def" "defmodule" "defp" "do" "else" |
| 722 | + ((smie-rule-parent-p "catch" "def" "defmodule" "defp" "do" "else" |
684 | 723 | "fn" "if" "rescue" "try" "unless" "defmacro" "defmacrop") |
685 | 724 | (smie-rule-parent)) |
| 725 | + ((smie-rule-parent-p "after") |
| 726 | + (smie-rule-parent elixir-smie-indent-basic)) |
686 | 727 | ;; Example |
687 | 728 | ;; |
688 | 729 | ;; case parse do |
|
702 | 743 | (smie-rule-hanging-p) |
703 | 744 | (elixir-smie-line-starts-with-do-colon-p)) |
704 | 745 | (smie-rule-parent (- elixir-smie-indent-basic))) |
705 | | - |
| 746 | + ((and (smie-rule-parent-p ";") |
| 747 | + (smie-rule-hanging-p) |
| 748 | + (save-excursion |
| 749 | + (forward-line 1) |
| 750 | + (looking-at "*.do:.*"))) |
| 751 | + (smie-rule-parent (- elixir-smie-indent-basic))) |
| 752 | + ((and (smie-rule-parent-p ";") |
| 753 | + (save-excursion |
| 754 | + (forward-line -1) |
| 755 | + (move-end-of-line 1) |
| 756 | + (looking-back ",$")) |
| 757 | + (not (smie-rule-hanging-p))) |
| 758 | + (smie-rule-parent elixir-smie-indent-basic)) |
| 759 | + ((and (smie-rule-parent-p ";") |
| 760 | + (smie-rule-hanging-p)) |
| 761 | + (if (save-excursion |
| 762 | + (forward-line 1) |
| 763 | + (looking-at "^.+do:.+$")) |
| 764 | + (cons 'column elixir-smie-indent-basic) |
| 765 | + (smie-rule-parent))) |
706 | 766 | ((elixir-smie-current-line-start-with-pipe-operator-p) |
707 | 767 | (smie-rule-parent)) |
708 | 768 | ((smie-rule-parent-p "(") |
|
0 commit comments