summaryrefslogtreecommitdiff
path: root/lisp/progmodes/c-ts-mode.el
Commit message (Collapse)AuthorAgeFilesLines
* Fix c++-ts-mode defun navigation (bug#65885)Yuan Fu2024-04-081-1/+3
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-base-mode): Add BOL and EOL marker in the regexp.
* ; Add 2024 to copyright yearsPo Lu2024-01-021-1/+1
|
* Fix c++-ts-mode indentation (bug#67975)Yuan Fu2023-12-221-1/+1
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Make indent rule match precise so it doesn't match declaration_list.
* Fix c-ts-mode bracketless indentation for BSD style (bug#66152)Yuan Fu2023-12-101-7/+7
| | | | | | | | | * lisp/progmodes/c-ts-mode.el: (c-ts-mode--indent-styles): Make sure the BSD rules only apply to opening bracket (compound_statement), then bracketless statements will fallback to common rules. * test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts: Copy the bracketless test from indent.erts to here.
* Add missing indent rules in c-ts-mode (bug#66152)Augustin Chéneau2023-12-101-0/+2
| | | | | | | | | Example: static myttype * variable_name; * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Add rules.
* ; * lisp/progmodes/c-ts-mode.el (c-ts-mode--else-heuristic): Doc fix.Eli Zaretskii2023-12-101-2/+2
|
* Fix c-ts-mode indent heuristic (bug#67417)Yuan Fu2023-12-101-15/+15
| | | | | | | | | | | This is a continuation of the first two patches for bug#67417. The c-ts-mode--prev-line-match heuristic we added is too broad, so for now we are just adding a very specific heuristic for the else case. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--prev-line-match): Remove function. (c-ts-mode--else-heuristic): New function. (c-ts-mode--indent-styles): Use c-ts-mode--else-heuristic.
* Fix c-ts-mode indentation (bug#67357)nverno2023-12-101-2/+21
| | | | | | | | | | | | | | | | | | | 1. In a compund_statement, we indent the first sibling against the parent, and the rest siblings against their previous sibling. But this strategy falls apart when the first sibling is not on its own line. We should regard the first sibling that is on its own line as the "first sibling"", and indent it against the parent. 2. In linux style, in a do-while statement, if the do-body is bracket-less, the "while" keyword is indented to the same level as the do-body. It should be indented to align with the "do" keyword instead. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--no-prev-standalone-sibling): New function. (c-ts-mode--indent-styles): Use c-ts-mode--no-prev-standalone-sibling. Add while keyword indent rule. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New tests.
* ; Fix typosStefan Kangas2023-12-031-1/+1
|
* ; Fix recent change in 'c-ts-mode'Eli Zaretskii2023-11-271-3/+3
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--prev-line-match) (c-ts-mode--indent-styles): Fix wording of strings and comments.
* Fix c-ts-mode indentation after if/else (bug#67417)Yuan Fu2023-11-261-0/+16
| | | | | | | * lisp/progmodes/c-ts-mode.el: (c-ts-mode--prev-line-match): New function. (c-ts-mode--indent-styles): Add a rule for the empty line after if/else/for/etc.
* Fix indentation for else clause in c-ts-mode (bug#67417)Yuan Fu2023-11-261-0/+1
| | | | | | | | | | * lisp/progmodes/c-ts-mode.el: (c-ts-mode--indent-styles): Add indentation for children of else_clause. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: (Name): Add test for else-break. Also make the test such that it needs to indent correctly from scratch (rather than maintaining the already correct indentation.)
* * lisp/progmodes/c-ts-mode.el (c++-ts-mode): Provide (bug#65895).Eli Zaretskii2023-09-121-0/+1
|
* Fix c-ts-mode BSD style indentationYuan Fu2023-09-071-0/+1
| | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Add else_clause. (cherry picked from commit d392a5d3c11b7e7479d31421f8237f29952c909e)
* Support defun navigation for DEFUN in c-ts-mode (bug#64442)Yuan Fu2023-08-191-55/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change, beginning/end-of-defun just ignores DEFUN in c-ts-mode. After this change, beginning/end-of-defun can recognize DEFUN, but a DEFUN definition is considered two defuns. Eg, beginning/end-of-defun will stop at (1) (2) and (3) in the following snippet: (1)DEFUN ("treesit-node-parser", Ftreesit_node_parser, Streesit_node_parser, 1, 1, 0, doc: /* Return the parser to which NODE belongs. */) (Lisp_Object node) (2){ CHECK_TS_NODE (node); return XTS_NODE (node)->parser; } (3) Ideally we want point to only stop at (1) and (3), but that'll be a lot harder to do. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--defun-valid-p): Refactor to take in account of DEFUN body. (c-ts-mode--emacs-defun-body-p): New function. (c-ts-base-mode): Add DEFUN and DEFUN body to recognized types. (c-ts-mode--emacs-defun-at-point): Now that we recognize both parts of a DEFUN as defun, c-ts-mode--emacs-defun-at-point needs to be updated to adapt to it.
* Remove nullptr named node from c++-ts-mode (bug#64818)Theodor Thornhill2023-07-241-3/+1
| | | | | | | | | | | | The nullptr node was changed from a named node to an unnamed node upstream[0], which caused font locking to break. As this is a small enough regression, no compat code is required. * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Remove node no longer in use. [0]: https://github.com/tree-sitter/tree-sitter-c/commit/c75868f8b508ae32a0c8490da91bb31b2b96430e
* Fix bol/bos anchors in tree-sitter :match regexpsBasil L. Contovounesios2023-06-131-1/+1
| | | | | | | | | | | | | | | | | Further regexp fixes to follow separately (bug#64019#29). * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode--font-lock-settings): * lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings): * lisp/progmodes/js.el (js--treesit-font-lock-settings): * lisp/progmodes/python.el (python--treesit-settings): * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--font-lock-settings): * lisp/progmodes/sh-script.el (sh-mode--treesit-settings): * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--font-lock-settings): * test/src/treesit-tests.el (treesit-query-api): Anchor :match regexps at beginning/end of string, not line.
* Fix c-ts-mode--top-level-declaratorYuan Fu2023-05-201-1/+1
| | | | | * lisp/progmodes/c-ts-mode.el: (c-ts-mode--top-level-declarator): Don't use treesit-node-match-p.
* Improve c-ts-mode font-lock for function names (bug#63390)Yuan Fu2023-05-191-0/+20
| | | | | | | | | | When a function definition has preproc directives in its body, it can't correctly parse into a function_definition. This fix tries to recognize this case and highlight the function_declarator correctly. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--font-lock-settings): New rule. (c-ts-mode--top-level-declarator): New function.
* Teach c-ts-mode about the 'restrict' keywordEli Zaretskii2023-05-061-2/+2
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--keywords): Add "restrict" and "_Atomic" type qualifiers. (Bug#63323)
* Fix c-ts-mode--emacs-c-range-queryMichael Albinus2023-04-301-7/+8
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--emacs-c-range-query): Check for (treesit-available-p).
* ; Doc fix in c-ts-mode.elEli Zaretskii2023-04-301-1/+1
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--fontify-for-each-tail): Doc fix.
* Fix FOR_EACH_TAIL fontification (bug#62951)Yuan Fu2023-04-291-8/+33
| | | | | | | | | | | | Fix the fontification inconsistency between different FOR_EACH_TAIL's. See the comment for more explanation. Also enable the emacs-devel feature automatically when c-ts-mode-emacs-sources-support is on. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--for-each-tail-regexp): Move up. (c-ts-mode--font-lock-settings): New font-lock rule for FOR_EACH_TAIL. (c-ts-mode--fontify-for-each-tail): New function. (c-ts-mode): Automatically enable emacs-devel feature.
* ; Fix byte-compilation warnings in c-ts-mode.elEli Zaretskii2023-04-281-0/+4
| | | | | | * lisp/progmodes/c-ts-mode.el (treesit-parser-set-included-ranges) (treesit-query-compile): Declare treesit.c functions. (treesit-load-name-override-list): Defvar it.
* ; * lisp/progmodes/c-ts-mode.el: Fix comments and doc strings (bug#62951).Eli Zaretskii2023-04-281-16/+17
|
* Fix FOR_EACH_TAIL in c-ts-mode (bug#62951)Yuan Fu2023-04-271-2/+97
| | | | | | | | | | | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): New indent rule. (c-ts-mode--for-each-tail-regexp) (c-ts-mode--for-each-tail-body-matcher) (c-ts-mode--emacs-c-range-query) (c-ts-mode--for-each-tail-ranges) (c-ts-mode--reverse-ranges) (c-ts-mode--emacs-set-ranges): New functions and variables. (c-ts-mode): Create a emacs-c parser. More setup for Emacs source support. * lisp/treesit.el (treesit-query-range): Ignore underscore-prefixed capture names.
* Add indentation style setting for c-ts-mode in .dir-locals.elEli Zaretskii2023-04-221-0/+5
| | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-indent-style-safep): New predicate. (c-ts-mode-indent-style): Use it to test the value for being safe. * .dir-locals.el (c-ts-mode): Set 'c-ts-mode-indent-style' to 'gnu'.
* Minor changes in c-ts-mode.el's support of DEFUNsEli Zaretskii2023-04-161-23/+36
| | | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--fontify-DEFUN): Renamed from 'c-ts-mode--fontify-defun'; all callers changed. (c-ts-mode-emacs-sources-support): Renamed from 'c-ts-mode-emacs-devel' and made into a defcustom; all users changed. (c-ts-mode--emacs-defun-p, c-ts-mode--emacs-defun-at-point) (c-ts-mode--emacs-current-defun-name): Doc fixes. (Bug#62825)
* ; * lisp/progmodes/c-ts-mode.el (treesit-node-next-sibling): Declare.Eli Zaretskii2023-04-151-0/+1
|
* Partial support for DEFUN in c-ts-mode (bug#62825)Yuan Fu2023-04-141-25/+101
| | | | | | | | | | | | | | | | The DEFUN is hard to incorporate because it's made of two nodes rather than one, and most tree-sitter functionalities assume a defun is one node. I fixed the indent-defun and add-log functionality, but beginning/end-of-defun and imenu still don't recognize DEFUN. * lisp/progmodes/c-ts-mode.el (c-ts-mode-emacs-devel): New variable. (c-ts-mode--defun-name): Support DEFUN. (c-ts-mode--defun-valid-p): Support DEFUN. (c-ts-mode--emacs-defun-p) (c-ts-mode--emacs-defun-at-point): New functions. (c-ts-mode-indent-defun): Use c-ts-mode--emacs-defun-at-point. (c-ts-mode--emacs-current-defun-name): New function. (c-ts-mode, c++-ts-mode): Optionally setup custom defun-name function.
* Add menu to 'c-ts-mode' and 'c++-ts-mode'Eli Zaretskii2023-04-111-0/+33
| | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode-menu): New menu.
* Fix some cases of incomplete code's indentation [c/c++-ts-mode]Dmitry Gutov2023-04-101-0/+17
| | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-base--before-indent): Try to guess when the parse tree is incomplete, and provide a better node to indent against (bug#62717). (c-ts-base-mode): Set up advice for local treesit-indent-function.
* ; * lisp/progmodes/c-ts-mode.el (c++-ts-mode): Add some notice.Yuan Fu2023-04-011-1/+5
|
* Align concatenated strings to the first sibling in c-ts-modeYuan Fu2023-03-211-1/+1
| | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Change rule.
* Add missing indent rule for c-ts-modeYuan Fu2023-03-211-0/+2
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): New rule for case. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New test.
* Fix visiting XBM/XPM files when 'c-ts-mode' is activeEli Zaretskii2023-03-191-4/+9
| | | | | * lisp/progmodes/c-ts-mode.el (treesit-ready-p): Fix association for XBM/XPM files in 'auto-mode-alist'. (Bug#62276)
* Fix enums and unions appearing as structs in c-ts-base-mode's imenuRandy Taylor2023-03-091-3/+3
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-base-mode): Separate enums and unions out from structs.
* Fix empty line indentation in c-ts-mode (bug#61997)Yuan Fu2023-03-071-1/+3
| | | | | | | | | | * lisp/progmodes/c-ts-mode.el: (c-ts-mode--indent-styles): Handle the empty line case. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New test. * doc/lispref/modes.texi (Parser-based Indentation): Update manual. * lisp/treesit.el (treesit-simple-indent-presets): Support null as a value for NODE-TYPE in the 'match' matcher.
* Fix c-ts-mode indentationYuan Fu2023-03-051-0/+3
| | | | | | | | | Mentioned in bug#61893. * lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling): Handle "#elif" and "#else". * test/lisp/progmodes/c-ts-mode-resources/indent-preproc.erts: Add an "#elif" to the test.
* Fix c-ts-mode indentationYuan Fu2023-03-051-1/+3
| | | | | | | | | | Mentioned in bug#61893, although not the subject of it. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--anchor-prev-sibling): Fix the child index for preproc_else and preproc_elif case. * test/lisp/progmodes/c-ts-mode-resources/indent-preproc.erts: New test.
* Fix c-ts-mode indentationYuan Fu2023-03-051-11/+19
| | | | | | | | Not the subject of it, but mentioned in bug#61893. * lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling): Skip the sibling if it doesn't start on it's own line. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New test.
* Fix c-ts-mode preproc directive indentationYuan Fu2023-03-041-2/+34
| | | | | | | | | | | | | | | Mentioned in bug#61893, although not the subject of that report. This change fixes indentation for nested directives. For example, when the directive involves elif and the like, the elif is nested in the if directive, so simply using grand-parent and great-grand-parent for anchor is insufficient, because the nesting can grow arbitrarily. The test added also covers the last preproc fix. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--standalone-parent-skip-preproc): New function. (c-ts-mode--indent-styles): New rules. * test/lisp/progmodes/c-ts-mode-resources/indent-preproc.erts: New test.
* Change tree-sitter indent anchor 'point-min' to 'column-0'Yuan Fu2023-03-041-8/+8
| | | | | | | | | | | | | | Point-min isn't necessarily at column 0, using line-beginning-position is better. column-0 is also more intuitive. * doc/lispref/modes.texi (Parser-based Indentation): Update manual. * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): * lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules): * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--indent-rules): * lisp/progmodes/typescript-ts-mode.el: (typescript-ts-mode--indent-rules): Change point-min to column-0. * lisp/treesit.el (treesit-simple-indent-presets): Change point-min to column-0.
* Fix c-ts-mode indentation for statement after preproc (bug#61893)Yuan Fu2023-03-021-6/+13
| | | | | | | | | | | | | | | | Originally our c-ts-mode--anchor-prev-sibling only specially handled labeled_statements, now we add special case for preproc in the similar fasion: instead of using the preproc directive as anchor, use the last statement in that preproc as the anchor. Thus effectively ignore the preproc. There should be an accompanying test, but there are some problem in the elif preproc directive indent so it would pass, we'll add the test when that is fixed. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--anchor-prev-sibling): Add special case for preproc directives.
* Fix c/c++-ts-mode's mode lighterEli Zaretskii2023-03-021-1/+2
| | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode-set-modeline): Remove trailing blank from comment-start when indicating the comment style on the mode line.
* ; Avoid byte-compilation warning in c-ts-mode.elEli Zaretskii2023-03-021-0/+1
| | | | | * lisp/progmodes/c-ts-mode.el (treesit-node-first-child-for-pos): Declare.
* Fix c-ts-mode empty line indentation (bug#61893)Yuan Fu2023-03-011-4/+4
| | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Make the "rest sibling" matchers catch the case where NODE is nil, when indenting an empty line. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New test.
* Improve tree-sitter's prev-sibling indent anchorYuan Fu2023-03-011-3/+9
| | | | | | | | | Now it handles the case where NODE is nil when indenting an empty line: it tries to get the previous sibling nonetheless. * lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling): * lisp/treesit.el (treesit-simple-indent-presets): Add an or form to handle more cases.
* Implement prefix arg for 'c-ts-mode-toggle-comment-style'Felix2023-02-281-9/+13
| | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode-toggle-comment-style): Actually implement the optional numeric arg mentioned in the docstring. Copyright-paperwork-exempt: yes
* Rename the newly added -ref- faces to -use-Dmitry Gutov2023-02-281-3/+3
| | | | | | * lisp/font-lock.el (font-lock-variable-use-face) (font-lock-property-use-face): Rename from font-lock-variable-ref-face and font-lock-property-ref-face. Update all references (bug#61655).