summaryrefslogtreecommitdiff
path: root/lisp/progmodes/c-ts-mode.el
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix c-ts-mode comment indentYuan Fu2023-01-091-4/+5
| | | | | | * lisp/progmodes/c-ts-mode.el: (c-ts-mode--comment-2nd-line-matcher): Also make sure PARENT is a comment node.
* Fix c-ts-mode indentation for 2nd line in block comment (bug#60270)Yuan Fu2023-01-091-5/+33
| | | | | | | | | | | | | | | | | | | | If the first line is "/*" or "/* ", indent like this: /* aaa If the first line is "/* some text", indent like this: /* some text aaa * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): (c-ts-mode--looking-at-star): Minor refactor. (c-ts-mode--comment-2nd-line-matcher) (c-ts-mode--comment-2nd-line-anchor): New functions. * lisp/treesit.el (treesit-simple-indent-presets): prev-adaptive-prefix doesn't handle the comment-start-skip case (i.e, 2nd line) anymore. (Handled by the new matcher.)
* Fix label indent of GNU and Linux style in c-ts-mode (bug#60543)Yuan Fu2023-01-081-1/+16
| | | | | | | | | The previous fix isn't correct. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--indent-styles): New indent rule. Fix the rule for Linux style. (c-ts-mode--top-level-label-matcher): New function.
* Revert "Add c-or-c++-ts-mode (bug#59613)"Yuan Fu2023-01-081-44/+0
| | | | | | This reverts commit 1df2826639c912396fac0af108301533dac71406. I forgot about the feature freeze, sorry :-)
* Add indentation rule for concatenated_string (bug#60572)Theodor Thornhill2023-01-071-0/+1
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Indent to parent-bol.
* Fix label indentation for Linux style in c-ts-mode (bug#60543)Yuan Fu2023-01-071-1/+3
| | | | | | | | | | | | Reference: 1. https://www.gnu.org/software/indent/manual/indent/Common-styles.html 2. https://www.gnu.org/software/indent/manual/indent/Option-Summary.html The GNU indent manual says Linux style should use -il1 flag, which means "indent labels to column 1". * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Indent label to column 1 in Linux style.
* Remove duplicate entries in c-ts-mode's ImenuYuan Fu2023-01-071-1/+18
| | | | | | | | | | Right now the Class subindex includes top-level functions, which is wrong. This change ensures the Class subindex only contain classes and functions nested in those classes. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--defun-for-class-in-imenu-p): New function. * lisp/progmodes/c-ts-mode.el (c-ts-base-mode): Use the new function.
* Fix use of treesit-ready-p in c/c++-ts-modeYuan Fu2023-01-071-30/+22
| | | | | | * lisp/progmodes/c-ts-mode.el: (c-ts-mode) (c++-ts-mode): Put setup code in a when form.
* Add documentation for c/c++-ts-mode (bug#60443)Yuan Fu2023-01-071-2/+10
| | | | | | | | Explain that tree-sitter c modes and cc-mode c modes don't share config variables. * lisp/progmodes/c-ts-mode.el (c-ts-mode) (c++-ts-mode): Update docstring.
* Optionally include the namespace in c-ts-mode--declarator-identifierYuan Fu2023-01-071-8/+18
| | | | | | | | This is an additional fix for bug#60397. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--declarator-identifier): New parameter QUALIFIED. (c-ts-mode--defun-name): Use qualified identifier.
* Support namespaces in c++-ts-mode (bug#60397)Yuan Fu2023-01-071-3/+7
| | | | | | | | | Not a complete fix. See the next commit. * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Add rules. (c-ts-mode--defun-name): Add namespace_definition. (c-ts-base-mode): Add namespace_definition to treesit-defun-type-regexp.
* Fix c-ts-mode--looking-at-starYuan Fu2023-01-071-2/+4
| | | | | | | | Not the topic of bug#60270 but reported in one of the replies. * lisp/progmodes/c-ts-mode.el (c-ts-mode--looking-at-star): Check not the character after point but character after BOL. Otherwise indentation is wrong when point is not at BOL.
* Add c-or-c++-ts-mode (bug#59613)Yuan Fu2023-01-071-0/+44
| | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--c-or-c++-regexp): New variable. (c-or-c++-ts-mode): New mode. * etc/NEWS: Mention c-or-c++-ts-mode.
* ; Fix function reference in comment in c-ts-mode.el (bug#60514)Daniel Martín2023-01-041-1/+1
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Fix reference.
* Fontify C++ function definitions in c-ts-mode (bug#60529)Daniel Martín2023-01-041-1/+11
| | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--declarator-identifier): Teach the code how to extract the declarator of a node of type "qualified_identifier". (c-ts-mode--fontify-declarator): Consider the case where the identifier in a function declarator is buried inside "qualifier_identifier" nodes.
* Fix fontification of C++ reference return types (bug#60441)Daniel Martín2023-01-011-1/+1
| | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-fontify-error): Treat reference_declarator nodes the same as pointer_declarator nodes when calculating the identifier to fontify.
* ; Add 2023 to copyright years.Eli Zaretskii2023-01-011-1/+1
|
* ; * lisp/progmodes/c-ts-mode.el (c-ts-mode--fill-paragraph): Fix.Yuan Fu2022-12-301-1/+3
|
* Fix c-ts-mode bracket indentation (bug#60398)Yuan Fu2022-12-291-2/+18
| | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Use new anchor. (c-ts-mode--bracket-children-anchor): New anchor function.
* ; * lisp/progmodes/c-ts-mode.el (c-ts-mode--fill-paragraph): Fix.Yuan Fu2022-12-281-2/+13
|
* Fix syntax for < and > in c++-ts-mode (bug#60351)Yuan Fu2022-12-281-8/+25
| | | | | | | | | | | < and > are usually punctuation, e.g., in ->. But when used for templates, they should be considered pairs. Right now we always consider them as pairs which is incorrect. * lisp/progmodes/c-ts-mode.el (c++-ts-mode--syntax-table): Remove variable. (c-ts-mode--syntax-propertize): New function. (c++-ts-mode): Remove syntax table. Setup syntax-propertize-function.
* Update tree-sitter major modes to use the new Imenu facilityYuan Fu2022-12-271-43/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | See previous commit for more explanation. * lisp/progmodes/c-ts-mode.el (c-ts-mode--defun-name): Handle more types. (c-ts-mode--imenu-1) (c-ts-mode--imenu): Remove functions. (c-ts-base-mode): Setup Imenu. * lisp/progmodes/csharp-mode.el (csharp-ts-mode--imenu-1) (csharp-ts-mode--imenu): Remove functions. (csharp-ts-mode): Setup Imenu. * lisp/progmodes/java-ts-mode.el (java-ts-mode--imenu-1) (java-ts-mode--imenu): Remove functions. (java-ts-mode): Setup Imenu. * lisp/progmodes/js.el (js--treesit-imenu-1) (js--treesit-imenu): Remove functions. (js--treesit-valid-imenu-entry): New function. (js-ts-mode): Setup Imenu. * lisp/progmodes/json-ts-mode.el (json-ts-mode--defun-name): Trim the quotes. (json-ts-mode--imenu-1) (json-ts-mode--imenu): Remove functions. (json-ts-mode): Setup Imenu. * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--imenu) (rust-ts-mode--imenu-1): Remove functions. (rust-ts-mode): Setup Imenu. * lisp/progmodes/typescript-ts-mode.el: (typescript-ts-base-mode): Remove treesit-defun-prefer-top-level, it's not used anymore. Setup Imenu. Setup treesit-defun-name-function. * lisp/textmodes/css-mode.el (css--treesit-imenu-1) (css--treesit-imenu): Remove functions. (css-ts-mode): Setup Imenu. * lisp/textmodes/toml-ts-mode.el (toml-ts-mode--defun-name): Fix it and add a fallback. (toml-ts-mode--imenu-1) (toml-ts-mode--imenu): Remove functions. (toml-ts-mode): Setup Imenu.
* Fix imenu for c-ts-mode (bug#60296)Yuan Fu2022-12-261-24/+27
| | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--imenu-1): Use c-ts-mode--defun-valid-p to filter out nested matches. (c-ts-mode--defun-valid-p): Handle more types of nodes.
* Add comment indent and filling to other tree-sitter major modesYuan Fu2022-12-261-48/+55
| | | | | | | | | | | | | | | | | | | | | | | | Extract the setup into a function, and use it in other major modes. * lisp/progmodes/c-ts-mode.el (c-ts-mode-comment-setup): New function. (c-ts-base-mode): Extract out. (c-ts-mode) (c++-ts-mode): Remove old setup. * lisp/progmodes/csharp-mode.el (csharp-ts-mode--indent-rules): New indent rules. (csharp-ts-mode): Use new setup function. * lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules): New indent rules. (java-ts-mode): Use new setup function. * lisp/progmodes/js.el (js--treesit-indent-rules): New indent rules. (js-ts-mode): Use new setup function. * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--indent-rules): New indent rules. (rust-ts-mode): Use new setup function. * lisp/progmodes/typescript-ts-mode.el: (typescript-ts-mode--indent-rules): New indent rules. (typescript-ts-base-mode): Use new setup function.
* ; Remove unused function in c-ts-modeYuan Fu2022-12-261-23/+2
| | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--end-of-defun): Remove. (c-ts-mode) (c++-ts-mode): Remove setup.
* ; Restore ARGS argument in c-ts-mode--fontify-declaratorJuanma Barranquero2022-12-251-1/+1
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--fontify-declarator): Restore argument name referenced in the docstring.
* ; Fix byte-copmiler warning in c-ts-mode--fontify-declaratorYuan Fu2022-12-251-1/+1
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--fontify-declarator): Ignore the rest args.
* Fix c-ts-mode imenu defun name (bug#60296)Yuan Fu2022-12-241-26/+24
| | | | | | | | | | Extract out c-ts-mode--declarator-identifier from c-ts-mode--fontify-declarator. * lisp/progmodes/c-ts-mode.el (c-ts-mode--declarator-identifier): New function. (c-ts-mode--fontify-defun): Extract out. (c-ts-mode--defun-name): Use the new function.
* Add treesit-defun-name and friendsYuan Fu2022-12-241-16/+21
| | | | | | | | | | | | | | | | | | | | 1. We now have treesit-defun-name, powered by treesit-defun-name-function. 2. We now have treesit-add-log-current-defun, which powers add-log-current-defun. 3. c-ts-mode updates its code to take advantage of these new features. 4. Manual updates. * doc/lispref/parsing.texi (Tree-sitter major modes): Add manual for new functions. * lisp/progmodes/c-ts-mode.el (c-ts-mode--defun-name): New function. (c-ts-mode--imenu-1): Extract out into c-ts-mode--defun-name. (c-ts-base-mode): Setup treesit-defun-name-function. * lisp/treesit.el (treesit-defun-name-function) (treesit-add-log-defun-delimiter): New variables. (treesit-defun-at-point) (treesit-defun-name): New functions. (treesit-major-mode-setup): Setup add-log-current-defun-function.
* ; * lisp/progmodes/c-ts-mode.el: quote literal string in regexpMattias Engdegård2022-12-241-1/+1
|
* ; * lisp/progmodes/c-ts-mode.el: Add outline section headers.Yuan Fu2022-12-241-0/+14
|
* Improve c-ts-mode block comment indent (bug#60270)Yuan Fu2022-12-241-1/+20
| | | | | | | | | | | | | | Now it handles stuff like /** * @some_func: * @arg1: */ * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Use new matcher and anchor. (c-ts-mode--looking-at-star): New matcher. (c-ts-mode--comment-start-after-first-star): New anchor.
* Fix block comment indent and filling for c-ts-mode (bug#59763)Yuan Fu2022-12-241-0/+96
| | | | | | | | | | | | | | | Now indent and filling works like in c-mode. The only noticeable missing piece is that the "*/" is not attached to the last sentence when filling. c-mode does it by replacing whitespaces between the "*/" and the end of the last sentence with xxx, fill it, then change the xxx back. I don't know if we should do that in c-ts-mode's filling. * doc/lispref/modes.texi (Parser-based Indentation): Add new preset. * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Add new indent rule. (c-ts-mode--fill-paragraph): New function. (c-ts-base-mode): Setup paragraph-start, adaptive-fill, etc. * lisp/treesit.el (treesit-simple-indent-presets): Add new preset.
* Add treesit-defun-at-point and fix c-ts-mode-indent-defunYuan Fu2022-12-221-7/+4
| | | | | | * lisp/treesit.el (treesit-defun-at-point): New function. * lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-defun): Implement with treesit-defun-at-point.
* Remove comment-start-skip preset in tree-sitter indentation engineYuan Fu2022-12-181-1/+0
| | | | | | | | | | | | | | | Comment indentation should use a adaptive-fill-based indent, rather than comment-start-skip. Also remove manual description of removed variables in treesit.el and add documentation for n-p-gp upon request. * doc/lispref/modes.texi (Parser-based Indentation) * lisp/treesit.el (treesit-simple-indent-presets): Add n-p-gp, remove treesit-comment-start/end, remove comment-start-skip. * doc/lispref/parsing.texi (Tree-sitter major modes): Remove treesit-comment-start/end.
* Use the new tree-sitter commandsYuan Fu2022-12-151-6/+29
| | | | | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--defun-valid-p) (c-ts-mode--defun-skipper): New functions. (c-ts-base-mode): Setup defun navigation. * lisp/progmodes/sh-script.el (bash-ts-mode): Setup defun navigation. * lisp/treesit.el (treesit-beginning-of-defun) (treesit-end-of-defun): Change to new implementation, which is intended to be used as commands. (treesit-major-mode-setup): Setup remap for beginning/end-of-defun commands.
* Treat C++ classes as defuns in C Tree-sitter mode (bug#60047)Daniel Martín2022-12-141-1/+2
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-base-mode): Add "class_specifier" as a node of type "defun".
* Add < and > to the syntax table in c++-ts-mode (bug#60049)Daniel Martín2022-12-141-0/+9
| | | | | | | * lisp/progmodes/c-ts-mode.el (c++-ts-mode--syntax-table): Add a specific syntax table for C++. Consider "<" and ">" open/close delimiters (C++ templates). (c++-ts-mode): Use the new syntax table.
* Align C++ access specifiers to their enclosing class/struct/unionDaniel Martín2022-12-121-0/+2
| | | | | | | | | | | | (bug#59966) The default style in c++-mode aligns access specifiers like "private", "public" or "protected" to their enclosing class, struct, or union. The "ellemtel" style indents access specifiers, but this C++ style is not supported by c++-ts-mode yet. * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Align access specifiers to their enclosing class/struct/union.
* Tweak various ts-mode's indent and fontification (bug#59931)Theodor Thornhill2022-12-121-1/+3
| | | | | | | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Add raw string literal font-locking. * lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules): Add text_block indent rule. (java-ts-mode--font-lock-settings): Add text_block font-locking. * lisp/progmodes/js.el (js-ts-mode): Prefer top-level navigation. * lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings): Add comment feature. (json-ts-mode): Use comment feature. * lisp/progmodes/typescript-ts-mode.el (typescript-ts-base-mode): Prefer top-level navigation.
* Fontify "this" as a keyword in c++-ts-mode (bug#59924)Brian Leung2022-12-091-3/+3
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Following c++-mode, fontify as a keyword instead of a constant.
* ; Normalize GPLv3 license statements in new filesStefan Kangas2022-12-091-4/+3
|
* Add c-ts-mode-indent-defun (bug#59662)Theodor Thornhill2022-12-071-1/+22
| | | | | | | Add in this function to mimic 'c-indent-defun'. * lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-defun): New function. (c-ts-mode-map): New mode map that uses said function.
* Fix syntax-table for tree-sitter modesTheodor Thornhill2022-12-071-0/+2
| | | | | | | | | | | | | | | | | | When adapting the 'c-populate-syntax-table' for tree-sitter, I misread the code, and thus some crucial entries were missing. For the relevant modes we use the same table as specified in the non-tree-sitter major mode. * lisp/progmodes/c-ts-mode.el (c-ts-mode--syntax-table): Add new entries. * lisp/progmodes/csharp-mode.el (csharp-ts-mode): Add new entries. * lisp/progmodes/java-ts-mode.el (java-ts-mode--syntax-table): Add new entries. * lisp/progmodes/json-ts-mode.el (json-ts-mode--syntax-table): Add new entries. * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--syntax-table): Add new entries. * lisp/textmodes/css-mode.el (css-ts-mode): Add new entries.
* c++-ts-mode: Highlight nullptr as a constantBrian Leung2022-12-071-1/+2
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Add nullptr.
* ; Rename c-ts-fontify-error to c-ts-mode--fontify-errorYuan Fu2022-12-061-2/+2
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings) (c-ts-fontify-error): Rename.
* ; Improve docstring of c-ts-mode--fontify-variableYuan Fu2022-12-061-2/+2
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--fontify-variable): Improve docstring.
* Fontify some keywords in type face in c-ts-modeYuan Fu2022-12-061-4/+9
| | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--keywords): Remove some keywords. (c-ts-mode--type-keywords): New variables. (c-ts-mode--font-lock-settings): New rule.
* Improve treesit-fontify-with-overrideYuan Fu2022-12-041-17/+11
| | | | | | | | | | | | | | | | | | | | | This also fixes fontification problem with c-ts-mode--fontify-defun. Now treesit-fontify-with-override clips the fontification region for the user, so no need for (max start node-start) shenanigans anymore. More importantly it doesn't fontify unless the region between node-start and node-end intersects with the region between start and end, which fixes the problem with c-ts-mode--fontify-defun. * lisp/treesit.el (treesit-fontify-with-override): Add optional parameter BOUND-START and BOUND-END. Wrap the function body in a when-form. * lisp/progmodes/c-ts-mode.el (c-ts-mode--fontify-declarator) (c-ts-mode--fontify-variable) (c-ts-mode--fontify-defun) (c-ts-fontify-error) * lisp/progmodes/js.el (js--fontify-template-string) * lisp/progmodes/python.el (python--treesit-fontify-string): Use the new signature.
* Fix comment-start-skip in tree-sitter modes (bug#59690)Yuan Fu2022-12-031-2/+4
| | | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode) (c++-ts-mode) * lisp/progmodes/csharp-mode.el (csharp-ts-mode) * lisp/progmodes/java-ts-mode.el (java-ts-mode) * lisp/progmodes/js.el (js-ts-mode) * lisp/progmodes/typescript-ts-mode.el (tsx-ts-mode): Remove the group from the regexp.