|
67 | 67 | (rassoc next smie-closer-alist))))
|
68 | 68 | (smie-indent-calculate))))))))
|
69 | 69 |
|
| 70 | +;; In Emacs 27, ppss became a structure and has proper accessors. |
| 71 | + |
| 72 | +(defalias 'elixir-ppss-depth |
| 73 | + (if (<= 27 emacs-major-version) |
| 74 | + 'ppss-depth |
| 75 | + (lambda (parse-data) (nth 0 parse-data)))) |
| 76 | + |
| 77 | +(defalias 'elixir-ppss-innermost-start |
| 78 | + (if (<= 27 emacs-major-version) |
| 79 | + 'ppss-innermost-start |
| 80 | + (lambda (parse-data) (nth 1 parse-data)))) |
| 81 | + |
| 82 | +(defalias 'elixir-ppss-last-complete-sexp-start |
| 83 | + (if (<= 27 emacs-major-version) |
| 84 | + 'ppss-last-complete-sexp-start |
| 85 | + (lambda (parse-data) (nth 2 parse-data)))) |
| 86 | + |
| 87 | +(defalias 'elixir-ppss-string-terminator |
| 88 | + (if (<= 27 emacs-major-version) |
| 89 | + 'ppss-string-terminator |
| 90 | + (lambda (parse-data) (nth 3 parse-data)))) |
| 91 | + |
| 92 | +(defalias 'elixir-ppss-comment-depth |
| 93 | + (if (<= 27 emacs-major-version) |
| 94 | + 'ppss-comment-depth |
| 95 | + (lambda (parse-data) (nth 4 parse-data)))) |
| 96 | + |
| 97 | +(defalias 'elixir-ppss-comment-or-string-start |
| 98 | + (if (<= 27 emacs-major-version) |
| 99 | + 'ppss-comment-or-string-start |
| 100 | + (lambda (parse-data) (nth 8 parse-data)))) |
| 101 | + |
70 | 102 | (defun elixir-smie-looking-around (back at)
|
71 | 103 | "Check if looking backwards at BACK and forward at AT."
|
72 | 104 | (and (looking-at-p at) (looking-back back)))
|
|
187 | 219 | (looking-back elixir-smie--operator-regexp (- (point) 3) t))))
|
188 | 220 |
|
189 | 221 | (defun elixir-smie-current-line-contains-built-in-keyword-p ()
|
190 |
| - "Return non-nil if the current line contains built in keywords with a `.'" |
| 222 | + "Return non-nil if the current line contains built in keywords with a \".\"." |
191 | 223 | (save-excursion
|
192 | 224 | (beginning-of-line)
|
193 | 225 | (looking-at ".+\\.\\(case\\|try\\|if\\|rescue\\)")))
|
|
260 | 292 | (not (looking-back ".+fn.+")))))))))
|
261 | 293 |
|
262 | 294 | (defun elixir-smie--same-line-as-parent (parent-pos child-pos)
|
263 |
| - "Return non-nil if `child-pos' is on same line as `parent-pos'." |
| 295 | + "Return non-nil if CHILD-POS is on same line as PARENT-POS." |
264 | 296 | (= (line-number-at-pos parent-pos) (line-number-at-pos child-pos)))
|
265 | 297 |
|
266 | 298 | (defun elixir-smie-forward-token ()
|
|
279 | 311 | (if (elixir-smie--semi-ends-match)
|
280 | 312 | "MATCH-STATEMENT-DELIMITER"
|
281 | 313 | (if (and (looking-at ".+,$")
|
282 |
| - (not (> (nth 0 (syntax-ppss)) 0))) |
| 314 | + (not (> (elixir-ppss-depth (syntax-ppss)) 0))) |
283 | 315 | "COMMA"
|
284 | 316 | ";")))
|
285 | 317 | ((looking-at elixir-smie--block-operator-regexp)
|
|
308 | 340 | (if (elixir-smie--semi-ends-match)
|
309 | 341 | "MATCH-STATEMENT-DELIMITER"
|
310 | 342 | (if (and (looking-back ",$" (- (point) 3) t)
|
311 |
| - (not (> (nth 0 (syntax-ppss)) 0))) |
| 343 | + (not (> (elixir-ppss-depth (syntax-ppss)) 0))) |
312 | 344 | "COMMA"
|
313 | 345 | ";")))
|
314 | 346 | ((looking-back elixir-smie--block-operator-regexp (- (point) 3) t)
|
|
446 | 478 | (not (smie-rule-hanging-p)))
|
447 | 479 | 0)
|
448 | 480 | ((and (not (smie-rule-sibling-p))
|
449 |
| - (nth 2 smie--parent) |
| 481 | + (elixir-ppss-last-complete-sexp-start smie--parent) |
450 | 482 | (smie-rule-hanging-p))
|
451 | 483 | (smie-rule-parent elixir-smie-indent-basic))
|
452 | 484 | ((and (not (smie-rule-sibling-p))
|
453 |
| - (not (nth 2 smie--parent)) |
| 485 | + (not (elixir-ppss-last-complete-sexp-start smie--parent)) |
454 | 486 | (smie-rule-hanging-p))
|
455 | 487 | (smie-rule-parent))))
|
456 | 488 | (`(:after . "MATCH-STATEMENT-DELIMITER")
|
|
512 | 544 | (save-excursion
|
513 | 545 | (move-beginning-of-line 1)
|
514 | 546 | (looking-at "^\s*do:.+$")))
|
515 |
| - (if (> (nth 0 (syntax-ppss)) 0) |
| 547 | + (if (> (elixir-ppss-depth (syntax-ppss)) 0) |
516 | 548 | (smie-rule-parent (- 3))
|
517 | 549 | (smie-rule-parent elixir-smie-indent-basic)))
|
518 | 550 | ((and (smie-rule-parent-p ";")
|
519 | 551 | (not (smie-rule-hanging-p)))
|
520 |
| - (if (> (nth 0 (syntax-ppss)) 0) |
| 552 | + (if (> (elixir-ppss-depth (syntax-ppss)) 0) |
521 | 553 | (smie-rule-parent (- elixir-smie-indent-basic))
|
522 | 554 | (smie-rule-parent)))
|
523 | 555 | ((and (smie-rule-parent-p "OP")
|
|
567 | 599 | (`(:before . "else:")
|
568 | 600 | (cond
|
569 | 601 | ((smie-rule-parent-p ";")
|
570 |
| - (if (> (nth 0 (syntax-ppss)) 0) |
| 602 | + (if (> (elixir-ppss-depth (syntax-ppss)) 0) |
571 | 603 | (smie-rule-parent elixir-smie-indent-basic)
|
572 | 604 | (smie-rule-parent)))
|
573 | 605 | ((smie-rule-parent-p "if")
|
|
724 | 756 | ;; ... then indent the line after the `->' aligned with the
|
725 | 757 | ;; parent, offset by `elixir-smie-indent-basic'."
|
726 | 758 | (if (and smie--parent (elixir-smie--same-line-as-parent
|
727 |
| - (nth 1 smie--parent) |
| 759 | + (elixir-ppss-innermost-start smie--parent) |
728 | 760 | (point)))
|
729 | 761 | (smie-rule-parent elixir-smie-indent-basic)
|
730 | 762 | elixir-smie-indent-basic))
|
|
845 | 877 | (defun elixir-smie--heredoc-at-current-point-p ()
|
846 | 878 | "Return non-nil if cursor is at a string."
|
847 | 879 | (save-excursion
|
848 |
| - (or (and (nth 3 (save-excursion |
849 |
| - (let ((pos (point))) |
850 |
| - (parse-partial-sexp 1 pos)))) |
851 |
| - (nth 8 (save-excursion |
852 |
| - (let ((pos (point))) |
853 |
| - (parse-partial-sexp 1 pos))))) |
| 880 | + (or (save-excursion |
| 881 | + (let ((parse-data (parse-partial-sexp 1 (point)))) |
| 882 | + (and (elixir-ppss-string-terminator parse-data) |
| 883 | + (elixir-ppss-comment-or-string-start parse-data)))) |
854 | 884 | (and (looking-at "\"\"\"")
|
855 | 885 | (match-beginning 0)))))
|
856 | 886 |
|
|
876 | 906 | Rules:
|
877 | 907 | 1. If the previous line is empty, indent as the basic indentation
|
878 | 908 | at the beginning of the heredoc.
|
879 |
| - 2. If the previous line is not empty, indent as the previous line. |
880 |
| -" |
| 909 | + 2. If the previous line is not empty, indent as the previous line." |
881 | 910 | (if (eq major-mode 'elixir-mode)
|
882 | 911 | (if (elixir-smie--heredoc-at-current-point-p)
|
883 | 912 | (let ((indent
|
|
0 commit comments