diff options
| author | Yuan Fu | 2024-12-01 16:19:01 -0800 |
|---|---|---|
| committer | Yuan Fu | 2024-12-01 17:53:23 -0800 |
| commit | 994258f55675baa8473e6cff9aab7ecb31338580 (patch) | |
| tree | ecac00a56039e0a9c5f9b015743457b6558657b2 | |
| parent | 44fcd37a486399be048fb03b9456497af78632fe (diff) | |
| download | emacs-994258f55675baa8473e6cff9aab7ecb31338580.tar.gz emacs-994258f55675baa8473e6cff9aab7ecb31338580.zip | |
Remove unused functions in c-ts-mode
Remove functions that became unused due to the previous change.
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--standalone-grandparent):
(c-ts-mode--else-heuristic):
(c-ts-mode--first-sibling):
(c-ts-mode--parent-is-not-top-compound):
(c-ts-mode--indent-styles):
(c-ts-mode--top-level-label-matcher): Remove functions.
(c-ts-mode--simple-indent-rules): Move two label rules into
c-ts-mode--label-indent-rules.
(c-ts-mode--label-indent-rules): Add rules
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 236 |
1 files changed, 25 insertions, 211 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 3059898f6d5..54617e20eba 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el | |||
| @@ -357,42 +357,6 @@ PARENT is the parent of the current node." | |||
| 357 | (line-beginning-position))))) | 357 | (line-beginning-position))))) |
| 358 | t)))) | 358 | t)))) |
| 359 | 359 | ||
| 360 | (defun c-ts-mode--standalone-grandparent (_node parent bol &rest args) | ||
| 361 | "Like the standalone-parent anchor but pass it the grandparent. | ||
| 362 | NODE, PARENT, BOL, ARGS are the same as in other anchors." | ||
| 363 | (apply (alist-get 'standalone-parent treesit-simple-indent-presets) | ||
| 364 | parent (treesit-node-parent parent) bol args)) | ||
| 365 | |||
| 366 | (defun c-ts-mode--else-heuristic (node parent bol &rest _) | ||
| 367 | "Heuristic matcher for when \"else\" is followed by a closing bracket. | ||
| 368 | PARENT is NODE's parent, BOL is the beginning of non-whitespace | ||
| 369 | characters of the current line." | ||
| 370 | (and (null node) | ||
| 371 | (save-excursion | ||
| 372 | (forward-line -1) | ||
| 373 | (looking-at (rx (* whitespace) "else" (* whitespace) eol))) | ||
| 374 | (let ((next-node (treesit-node-first-child-for-pos parent bol))) | ||
| 375 | (equal (treesit-node-type next-node) "}")))) | ||
| 376 | |||
| 377 | (defun c-ts-mode--first-sibling (node parent &rest _) | ||
| 378 | "Matches when NODE is the \"first sibling\". | ||
| 379 | \"First sibling\" is defined as: the first child node of PARENT | ||
| 380 | such that it's on its own line. NODE is the node to match and | ||
| 381 | PARENT is its parent." | ||
| 382 | (let ((prev-sibling (treesit-node-prev-sibling node t))) | ||
| 383 | (or (null prev-sibling) | ||
| 384 | (save-excursion | ||
| 385 | (goto-char (treesit-node-start prev-sibling)) | ||
| 386 | (<= (line-beginning-position) | ||
| 387 | (treesit-node-start parent) | ||
| 388 | (line-end-position)))))) | ||
| 389 | |||
| 390 | (defun c-ts-mode--parent-is-not-top-compound (_n parent &rest _) | ||
| 391 | "Matches when PARENT is not the top level compound statement. | ||
| 392 | The top-level compound is the {} that immediately follows the function | ||
| 393 | signature." | ||
| 394 | (not (equal "function_definition" (treesit-node-type (treesit-node-parent parent))))) | ||
| 395 | |||
| 396 | (defun c-ts-mode--for-loop-indent-rule (node parent &rest _) | 360 | (defun c-ts-mode--for-loop-indent-rule (node parent &rest _) |
| 397 | "Indentation rule for the for-loop. | 361 | "Indentation rule for the for-loop. |
| 398 | 362 | ||
| @@ -519,11 +483,6 @@ MODE can be `c' or `c++'. STYLE can be `gnu', `k&r', `linux', `bsd'." | |||
| 519 | 1) | 483 | 1) |
| 520 | ((parent-is "comment") prev-adaptive-prefix 0) | 484 | ((parent-is "comment") prev-adaptive-prefix 0) |
| 521 | 485 | ||
| 522 | ;; Labels. | ||
| 523 | ((node-is "labeled_statement") standalone-parent 0) | ||
| 524 | ((parent-is "labeled_statement") | ||
| 525 | c-ts-mode--standalone-grandparent c-ts-mode-indent-offset) | ||
| 526 | |||
| 527 | ;; Preproc directives | 486 | ;; Preproc directives |
| 528 | ((node-is "preproc_arg") no-indent) | 487 | ((node-is "preproc_arg") no-indent) |
| 529 | ((node-is "preproc") column-0 0) | 488 | ((node-is "preproc") column-0 0) |
| @@ -554,155 +513,6 @@ MODE can be `c' or `c++'. STYLE can be `gnu', `k&r', `linux', `bsd'." | |||
| 554 | ('c `((c . ,rules))) | 513 | ('c `((c . ,rules))) |
| 555 | ('c++ `((cpp . ,rules)))))) | 514 | ('c++ `((cpp . ,rules)))))) |
| 556 | 515 | ||
| 557 | (defun c-ts-mode--indent-styles (mode) | ||
| 558 | "Indent rules supported by `c-ts-mode'. | ||
| 559 | MODE is either `c' or `cpp'." | ||
| 560 | (let ((common | ||
| 561 | `((c-ts-mode--for-each-tail-body-matcher prev-line c-ts-mode-indent-offset) | ||
| 562 | ;; If the user types "else" and hits RET, they expect point | ||
| 563 | ;; on the empty line to be indented; this rule does that. | ||
| 564 | ;; This heuristic is intentionally very specific because | ||
| 565 | ;; more general heuristic is very error-prone, see | ||
| 566 | ;; discussion in bug#67417. | ||
| 567 | (c-ts-mode--else-heuristic prev-line c-ts-mode-indent-offset) | ||
| 568 | |||
| 569 | ((parent-is "translation_unit") column-0 0) | ||
| 570 | ((query "(ERROR (ERROR)) @indent") column-0 0) | ||
| 571 | ((node-is ")") parent 1) | ||
| 572 | ((node-is "]") parent-bol 0) | ||
| 573 | ((node-is "else") parent-bol 0) | ||
| 574 | ((node-is "case") parent-bol 0) | ||
| 575 | ((node-is "preproc_arg") no-indent) | ||
| 576 | ;; `c-ts-common-looking-at-star' has to come before | ||
| 577 | ;; `c-ts-common-comment-2nd-line-matcher'. | ||
| 578 | ((and (parent-is "comment") c-ts-common-looking-at-star) | ||
| 579 | c-ts-common-comment-start-after-first-star -1) | ||
| 580 | (c-ts-common-comment-2nd-line-matcher | ||
| 581 | c-ts-common-comment-2nd-line-anchor | ||
| 582 | 1) | ||
| 583 | ((parent-is "comment") prev-adaptive-prefix 0) | ||
| 584 | |||
| 585 | ;; Labels. | ||
| 586 | ((node-is "labeled_statement") standalone-parent 0) | ||
| 587 | ((parent-is "labeled_statement") | ||
| 588 | c-ts-mode--standalone-grandparent c-ts-mode-indent-offset) | ||
| 589 | |||
| 590 | ;; Preproc directives | ||
| 591 | ((node-is "preproc") column-0 0) | ||
| 592 | ((node-is "#endif") column-0 0) | ||
| 593 | ((match "preproc_call" "compound_statement") column-0 0) | ||
| 594 | |||
| 595 | ;; Top-level things under a preproc directive. Note that | ||
| 596 | ;; "preproc" matches more than one type: it matches | ||
| 597 | ;; preproc_if, preproc_elif, etc. | ||
| 598 | ((n-p-gp nil "preproc" "translation_unit") column-0 0) | ||
| 599 | ;; Indent rule for an empty line after a preproc directive. | ||
| 600 | ((and no-node (parent-is ,(rx (or "\n" "preproc")))) | ||
| 601 | c-ts-mode--standalone-parent-skip-preproc c-ts-mode--preproc-offset) | ||
| 602 | ;; Statement under a preproc directive, the first statement | ||
| 603 | ;; indents against parent, the rest statements indent to | ||
| 604 | ;; their prev-sibling. | ||
| 605 | ((match nil ,(rx "preproc_" (or "if" "elif")) nil 3 3) | ||
| 606 | c-ts-mode--standalone-parent-skip-preproc c-ts-mode-indent-offset) | ||
| 607 | ((match nil "preproc_ifdef" nil 2 2) | ||
| 608 | c-ts-mode--standalone-parent-skip-preproc c-ts-mode-indent-offset) | ||
| 609 | ((match nil "preproc_else" nil 1 1) | ||
| 610 | c-ts-mode--standalone-parent-skip-preproc c-ts-mode-indent-offset) | ||
| 611 | ((parent-is "preproc") c-ts-mode--anchor-prev-sibling 0) | ||
| 612 | |||
| 613 | ((parent-is "function_definition") parent-bol 0) | ||
| 614 | ((parent-is "pointer_declarator") parent-bol 0) | ||
| 615 | ((parent-is ,(rx bos "declaration" eos)) parent-bol 0) | ||
| 616 | ((parent-is "conditional_expression") first-sibling 0) | ||
| 617 | ((parent-is "assignment_expression") parent-bol c-ts-mode-indent-offset) | ||
| 618 | ((parent-is "concatenated_string") first-sibling 0) | ||
| 619 | ((parent-is "comma_expression") first-sibling 0) | ||
| 620 | ((parent-is "init_declarator") parent-bol c-ts-mode-indent-offset) | ||
| 621 | ((parent-is "parenthesized_expression") first-sibling 1) | ||
| 622 | ((parent-is "argument_list") first-sibling 1) | ||
| 623 | ((parent-is "parameter_list") first-sibling 1) | ||
| 624 | ((parent-is "binary_expression") parent 0) | ||
| 625 | ((query "(for_statement initializer: (_) @indent)") parent-bol 5) | ||
| 626 | ((query "(for_statement condition: (_) @indent)") parent-bol 5) | ||
| 627 | ((query "(for_statement update: (_) @indent)") parent-bol 5) | ||
| 628 | ((query "(call_expression arguments: (_) @indent)") parent c-ts-mode-indent-offset) | ||
| 629 | ((parent-is "call_expression") parent 0) | ||
| 630 | ;; Closing bracket. This should be before initializer_list | ||
| 631 | ;; (and probably others) rule because that rule (and other | ||
| 632 | ;; similar rules) will match the closing bracket. (Bug#61398) | ||
| 633 | ((and (node-is "}") c-ts-mode--parent-is-not-top-compound) parent-bol 0) | ||
| 634 | ((node-is "}") standalone-parent 0) | ||
| 635 | ,@(when (eq mode 'cpp) | ||
| 636 | '(((node-is "access_specifier") parent-bol 0) | ||
| 637 | ;; Indent the body of namespace definitions. | ||
| 638 | ((parent-is "declaration_list") parent-bol c-ts-mode-indent-offset) | ||
| 639 | ((parent-is "template_declaration") parent-bol 0))) | ||
| 640 | |||
| 641 | |||
| 642 | ;; int[5] a = { 0, 0, 0, 0 }; | ||
| 643 | ((match nil "initializer_list" nil 1 1) parent-bol c-ts-mode-indent-offset) | ||
| 644 | ((parent-is "initializer_list") c-ts-mode--anchor-prev-sibling 0) | ||
| 645 | ;; Statement in enum. | ||
| 646 | ((match nil "enumerator_list" nil 1 1) standalone-parent c-ts-mode-indent-offset) | ||
| 647 | ((parent-is "enumerator_list") c-ts-mode--anchor-prev-sibling 0) | ||
| 648 | ;; Statement in struct and union. | ||
| 649 | ((match nil "field_declaration_list" nil 1 1) standalone-parent c-ts-mode-indent-offset) | ||
| 650 | ((parent-is "field_declaration_list") c-ts-mode--anchor-prev-sibling 0) | ||
| 651 | |||
| 652 | ;; Statement in {} blocks. | ||
| 653 | ((and (parent-is "compound_statement") c-ts-mode--parent-is-not-top-compound) | ||
| 654 | parent-bol c-ts-mode-indent-offset) | ||
| 655 | ((or (and (parent-is "compound_statement") | ||
| 656 | ;; If the previous sibling(s) are not on their | ||
| 657 | ;; own line, indent as if this node is the first | ||
| 658 | ;; sibling (Bug#67357) | ||
| 659 | c-ts-mode--first-sibling) | ||
| 660 | (match null "compound_statement")) | ||
| 661 | standalone-parent c-ts-mode-indent-offset) | ||
| 662 | ((parent-is "compound_statement") c-ts-mode--anchor-prev-sibling 0) | ||
| 663 | ;; Opening bracket. | ||
| 664 | ((node-is "compound_statement") standalone-parent c-ts-mode-indent-offset) | ||
| 665 | ;; Bug#61291. | ||
| 666 | ((match "expression_statement" nil "body") standalone-parent c-ts-mode-indent-offset) | ||
| 667 | ;; These rules are for cases where the body is bracketless. | ||
| 668 | ;; Tested by the "Bracketless Simple Statement" test. | ||
| 669 | ((parent-is "if_statement") standalone-parent c-ts-mode-indent-offset) | ||
| 670 | ((parent-is "else_clause") standalone-parent c-ts-mode-indent-offset) | ||
| 671 | ((parent-is "for_statement") standalone-parent c-ts-mode-indent-offset) | ||
| 672 | ((match "while" "do_statement") parent-bol 0) ; (do_statement "while") | ||
| 673 | ((parent-is "while_statement") standalone-parent c-ts-mode-indent-offset) | ||
| 674 | ((parent-is "do_statement") standalone-parent c-ts-mode-indent-offset) | ||
| 675 | |||
| 676 | ((parent-is "case_statement") standalone-parent c-ts-mode-indent-offset) | ||
| 677 | |||
| 678 | ,@(when (eq mode 'cpp) | ||
| 679 | `(((node-is "field_initializer_list") parent-bol ,(* c-ts-mode-indent-offset 2))))))) | ||
| 680 | `((gnu | ||
| 681 | ;; Prepend rules to set highest priority | ||
| 682 | ((match "while" "do_statement") parent 0) | ||
| 683 | (c-ts-mode--top-level-label-matcher column-0 1) | ||
| 684 | ,@common) | ||
| 685 | (k&r ,@common) | ||
| 686 | (linux | ||
| 687 | ;; Reference: | ||
| 688 | ;; https://www.kernel.org/doc/html/latest/process/coding-style.html, | ||
| 689 | ;; and script/Lindent in Linux kernel repository. | ||
| 690 | ((node-is "labeled_statement") column-0 0) | ||
| 691 | ,@common) | ||
| 692 | (bsd | ||
| 693 | ((node-is "}") parent-bol 0) | ||
| 694 | ((node-is "labeled_statement") parent-bol c-ts-mode-indent-offset) | ||
| 695 | ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset) | ||
| 696 | ((parent-is "compound_statement") parent-bol c-ts-mode-indent-offset) | ||
| 697 | ((match "compound_statement" "if_statement") standalone-parent 0) | ||
| 698 | ((match "compound_statement" "else_clause") standalone-parent 0) | ||
| 699 | ((match "compound_statement" "for_statement") standalone-parent 0) | ||
| 700 | ((match "compound_statement" "while_statement") standalone-parent 0) | ||
| 701 | ((match "compound_statement" "switch_statement") standalone-parent 0) | ||
| 702 | ((match "compound_statement" "case_statement") standalone-parent 0) | ||
| 703 | ((match "compound_statement" "do_statement") standalone-parent 0) | ||
| 704 | ,@common)))) | ||
| 705 | |||
| 706 | (defun c-ts-mode--parenthesized-expression-indent-rule (_node parent &rest _) | 516 | (defun c-ts-mode--parenthesized-expression-indent-rule (_node parent &rest _) |
| 707 | "Indent rule that indents aprenthesized expression. | 517 | "Indent rule that indents aprenthesized expression. |
| 708 | 518 | ||
| @@ -732,9 +542,9 @@ NODE, PARENT are the same as other indent rules." | |||
| 732 | (treesit-node-child parent 0 'named)) | 542 | (treesit-node-child parent 0 'named)) |
| 733 | 0)))) | 543 | 0)))) |
| 734 | 544 | ||
| 735 | (defun c-ts-mode--label-indent-rules (node parent &rest _) | 545 | (defun c-ts-mode--label-indent-rules (node parent bol &rest args) |
| 736 | "Handles indentation around labels. | 546 | "Handles indentation around labels. |
| 737 | NODE, PARENT are as usual." | 547 | NODE, PARENT, BOL, ARGS are as usual." |
| 738 | (cond | 548 | (cond |
| 739 | ;; Matches the top-level labels for GNU-style. | 549 | ;; Matches the top-level labels for GNU-style. |
| 740 | ((and (eq c-ts-mode-indent-style 'gnu) | 550 | ((and (eq c-ts-mode-indent-style 'gnu) |
| @@ -742,6 +552,18 @@ NODE, PARENT are as usual." | |||
| 742 | (treesit-node-match-p (treesit-node-parent parent) | 552 | (treesit-node-match-p (treesit-node-parent parent) |
| 743 | "function_definition")) | 553 | "function_definition")) |
| 744 | (cons (pos-bol) 1)) | 554 | (cons (pos-bol) 1)) |
| 555 | ;; Indent the label itself. | ||
| 556 | ((treesit-node-match-p node "labeled_statement") | ||
| 557 | (cons (apply (alist-get 'standalone-parent | ||
| 558 | treesit-simple-indent-presets) | ||
| 559 | node parent bol args) | ||
| 560 | 0)) | ||
| 561 | ;; Indent the statement below the label. | ||
| 562 | ((treesit-node-match-p parent "labeled_statement") | ||
| 563 | (cons (apply (alist-get 'standalone-parent | ||
| 564 | treesit-simple-indent-presets) | ||
| 565 | parent (treesit-node-parent parent) bol args) | ||
| 566 | c-ts-mode-indent-offset)) | ||
| 745 | ;; If previous sibling is a labeled_statement, align to it's | 567 | ;; If previous sibling is a labeled_statement, align to it's |
| 746 | ;; children, which is the previous statement. | 568 | ;; children, which is the previous statement. |
| 747 | ((and (not (treesit-node-match-p node "}")) | 569 | ((and (not (treesit-node-match-p node "}")) |
| @@ -753,14 +575,6 @@ NODE, PARENT are as usual." | |||
| 753 | 0)) | 575 | 0)) |
| 754 | (t nil))) | 576 | (t nil))) |
| 755 | 577 | ||
| 756 | (defun c-ts-mode--top-level-label-matcher (node parent &rest _) | ||
| 757 | "A matcher that matches a top-level label. | ||
| 758 | NODE should be a labeled_statement. PARENT is its parent." | ||
| 759 | (and (equal (treesit-node-type node) | ||
| 760 | "labeled_statement") | ||
| 761 | (equal "function_definition" | ||
| 762 | (treesit-node-type (treesit-node-parent parent))))) | ||
| 763 | |||
| 764 | ;;; Font-lock | 578 | ;;; Font-lock |
| 765 | 579 | ||
| 766 | (defvar c-ts-mode--feature-list | 580 | (defvar c-ts-mode--feature-list |
| @@ -991,17 +805,17 @@ MODE is either `c' or `cpp'." | |||
| 991 | :feature 'delimiter | 805 | :feature 'delimiter |
| 992 | '((["," ":" ";"]) @font-lock-delimiter-face) | 806 | '((["," ":" ";"]) @font-lock-delimiter-face) |
| 993 | 807 | ||
| 994 | :language mode | 808 | :language mode |
| 995 | :feature 'emacs-devel | 809 | :feature 'emacs-devel |
| 996 | :override t | 810 | :override t |
| 997 | `(((call_expression | 811 | `(((call_expression |
| 998 | (call_expression function: (identifier) @fn) | 812 | (call_expression function: (identifier) @fn) |
| 999 | @c-ts-mode--fontify-DEFUN) | 813 | @c-ts-mode--fontify-DEFUN) |
| 1000 | (:match "\\`DEFUN\\'" @fn)) | 814 | (:match "\\`DEFUN\\'" @fn)) |
| 1001 | 815 | ||
| 1002 | ((function_definition type: (_) @for-each-tail) | 816 | ((function_definition type: (_) @for-each-tail) |
| 1003 | @c-ts-mode--fontify-for-each-tail | 817 | @c-ts-mode--fontify-for-each-tail |
| 1004 | (:match ,c-ts-mode--for-each-tail-regexp @for-each-tail))))) | 818 | (:match ,c-ts-mode--for-each-tail-regexp @for-each-tail))))) |
| 1005 | 819 | ||
| 1006 | ;;; Font-lock helpers | 820 | ;;; Font-lock helpers |
| 1007 | 821 | ||