summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Avoid usage of intern_c_string in treesit.cPo Lu2022-11-211-4/+8
| | | | | | * src/treesit.c (Ftreesit_pattern_expand): Use DEFSYM'd symbols when the naming makes sense. (syms_of_treesit): Add new defsyms QCanchor, QCequal, QCmatch.
* Stylistic fixes to treesit.cPo Lu2022-11-211-6/+6
| | | | | * src/treesit.c (treesit_make_ranges): (Ftreesit_parser_set_included_ranges): Fix coding style.
* Fix MS-DOS buildPo Lu2022-11-211-0/+2
| | | | * msdos/sed1v2.inp: Edit out tree-sitter stuff.
* Add another heuristic to speed up tree-sitter fontificationYuan Fu2022-11-201-29/+39
| | | | | * lisp/treesit.el (treesit-font-lock-fontify-region): Use treesit--children-covering-range to reduce the node size.
* Limit recursion level for tree-sitter imenu functionsYuan Fu2022-11-206-14/+17
| | | | | | | | | | | | | | Generating imenu index doesn't require going down to the bottom of the tree (defun's are usually top-level). Add limit so we don't go too far down on very large buffers. * lisp/progmodes/c-ts-mode.el (c-ts-mode--imenu) * lisp/progmodes/java-ts-mode.el (java-ts-mode--imenu) * lisp/progmodes/js.el (js--treesit-imenu) * lisp/progmodes/json-ts-mode.el (json-ts-mode--imenu) * lisp/progmodes/python.el (python-imenu-treesit-create-index) * lisp/textmodes/css-mode.el (css--treesit-imenu): Add limit to treesit-induce-sparse-tree.
* Improve tree-sitter fontification on large buffersYuan Fu2022-11-201-8/+52
| | | | | | | | | | * lisp/treesit.el (treesit--children-covering-range) (treesit--children-covering-range-recurse): New functions. They are not currently used but could be useful in the future, so I left them in place. (treesit-font-lock-fontify-region): * lisp/treesit.el (treesit-font-lock-fontify-region): Use the result of treesit-node-on instead of the root node.
* ; Improve recently-modified documentationEli Zaretskii2022-11-205-26/+28
| | | | | | | | | | | | * lisp/progmodes/python.el (python-base-mode) (python--treesit-fontify-string): * lisp/textmodes/css-mode.el (css-base-mode): * lisp/treesit.el (treesit-ready-p, treesit-comment-end) (treesit-simple-indent-presets): Fix typos and wording in doc strings. * doc/lispref/parsing.texi (Tree-sitter major modes): * doc/lispref/modes.texi (Parser-based Indentation): Fix wording and add cross-references.
* Fix uses of treesit-ready-pYuan Fu2022-11-197-8/+8
| | | | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode) (c++-ts-mode) * lisp/progmodes/java-ts-mode.el (java-ts-mode) * lisp/progmodes/js.el (js-ts-mode) * lisp/progmodes/json-ts-mode.el (json-ts-mode) * lisp/progmodes/python.el (python-ts-mode) * lisp/progmodes/sh-script.el (sh-mode) * lisp/progmodes/ts-mode.el (ts-mode): Remove the MODE argument.
* Remove treesit-settingsYuan Fu2022-11-192-116/+40
| | | | | | | | | | Remove it since we are using separate major modes for tree-sitter and native variant now. * doc/lispref/parsing.texi (Tree-sitter major modes): Update manual. * lisp/treesit.el (treesit-settings): Remove option. (treesit--setting-for-mode): Remove function. (treesit-ready-p): Don't check for user preference in treesit-settings.
* Remove tree-sitter setup from js-json-modeYuan Fu2022-11-191-38/+1
| | | | | | * lisp/progmodes/js.el (js-json--treesit-font-lock-settings) (js--json-treesit-indent-rules): Remove variables. (js-json-mode): Remove tree-sitter setup.
* Fix tree-sitter comment indentation for C-like languagesYuan Fu2022-11-197-4/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | The goal is to indent like this: /* comment comment --> This line aligns with the beginning of the first line */ --> This line aligns with the opening comment token * lisp/treesit.el (treesit-comment-start) (treesit-comment-end): New variables. (treesit-simple-indent-presets): New preset comment-end, comment-start, comment-start-skip * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles) (c-ts-mode) * lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules) (java-ts-mode) * lisp/progmodes/js.el (js--treesit-indent-rules) (js-ts-mode) * lisp/progmodes/ts-mode.el (ts-mode--indent-rules) (ts-mode): Add identical indent rules to each mode, and set identical treesit-comment-start/end's. * doc/lispref/modes.texi (Parser-based Indentation) * doc/lispref/parsing.texi (Tree-sitter major modes): Update manual.
* Separate native and tree-sitter variant of js-modeYuan Fu2022-11-191-21/+47
| | | | | | | | * lisp/progmodes/js.el (js-base-mode): New mode. (js-mode): Return to before tree-sitter setup is added, change to inherit from js-base-mode. (js-ts-mode): New mode. Now it doesn't use any cc-mode feature, meaning it looses comment filling.
* Merge function/class-name features in python-modeYuan Fu2022-11-191-7/+4
| | | | | | | | To keep consistency with other tree-sitter major modes. * lisp/progmodes/python.el (python--treesit-settings) (python-ts-mode): Merge function-name and class-name features into definition.
* Split python-mode into native and tree-sitter variantYuan Fu2022-11-191-20/+29
| | | | | | | * lisp/progmodes/python.el (python-base-mode): New virtual mode that contains most of the setup. (python-mode): Change to inherit from python-base-mode. (python-ts-mode): New mode that sets up tree-sitter.
* Expand css-ts-mode and merge it into css-modeYuan Fu2022-11-192-146/+151
| | | | | | | | | | | | | * lisp/progmodes/css-ts-mode.el: Deleted. * lisp/textmodes/css-mode.el (css--treesit-indent-rules) (css--treesit-settings): New variables. (css--treesit-imenu-1) (css--treesit-imenu): New functions. * lisp/textmodes/css-mode.el (css-base-mode): New mode inherited by both css-mode and css-ts-mode. (css-ts-mode): New mode. (css-mode): Inherit from css-base-mode, and move some setup to css-base-mode.
* Change tree-sitter indent preset 'match' to count on all nodesYuan Fu2022-11-191-2/+2
| | | | | | | | I changed other presets to count all nodes a while ago, but forgot to change 'match' too. * lisp/treesit.el (treesit-simple-indent-presets): Change to count on both named and anonymous nodes.
* Use keyword-face for declaration commands in tree-sitter sh-modeYuan Fu2022-11-191-1/+1
| | | | * lisp/progmodes/sh-script.el: Change builtin to keyword.
* ; * lisp/treesit.el (treesit--font-lock-notifier): Add messaging.Yuan Fu2022-11-191-0/+3
|
* Fix python-mode tree-sitter fontificationYuan Fu2022-11-191-10/+8
| | | | | | | | | | Forgot to update python-mode's code when I added the tree-sitter notifier facility. Now it doesn't need any special treatment anymore. Leaving it as is causes some incorrect fontification. * lisp/progmodes/python.el (python--treesit-fontify-string): Accept the string node rather than the quote node. (python--treesit-settings): Capture string node.
* Utilize new font-lock faces for C/C++ and Python tree-sitter useRandy Taylor2022-11-172-23/+66
| | | | | | | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Use new escape, number, property, operator, bracket, and delimiter font-lock faces. (c-ts-mode--base-mode): Add them to the feature list. (c-ts-mode): Fix typo. * lisp/progmodes/python.el (python--treesit-settings): Use new number, property, operator, bracket, and delimiter font-lock faces. (python-mode): Add them to the feature list.
* Improvements to the tree-sitter setup in sh-script.elYuan Fu2022-11-171-38/+22
| | | | | | | | | * lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Add defvar. (sh-mode): Change feature names. (sh-mode--treesit-fontify-decl-command): Remove function. (sh-mode--treesit-declaration-commands): New variable. (sh-mode--treesit-settings): Change feature names. Simplify declaration-command feature.
* ; Minor stylistic fix for previous change on sh-script.elYuan Fu2022-11-171-19/+32
| | | | * lisp/progmodes/sh-script.el: Stylistic change.
* Initial fontification in sh-mode with tree-sitterJoão P. L. de Carvalho2022-11-171-9/+139
| | | | | | | | | | * lisp/progmodes/sh-script.el (sh-mode): Add tree-sitter setup. Move setup of font-lock-defaults into branch. (sh-mode--treesit-operators) (sh-mode--treesit-keywords) (sh-mode--treesit-settings): New variables. (sh-mode--treesit-other-keywords) (sh-mode--treesit-fontify-decl-command): New functions.
* ; Elaborate on tree-sitter fontification features documentationYuan Fu2022-11-172-10/+19
| | | | | | * doc/lispref/modes.texi (Parser-based Font Lock) * lisp/treesit.el (treesit-font-lock-feature-list): Explain in more detail, and change some features.
* Fix documentation of recent treesit changesEli Zaretskii2022-11-172-41/+45
| | | | | | | | | | * src/treesit.c (Ftreesit_parser_notifiers) (Ftreesit_parser_add_notifier, Ftreesit_parser_remove_notifier): Doc string fixes. * doc/lispref/parsing.texi (Accessing Node Information): Fix wording and punctuation. (Using Parser): Improve indexing and wording.
* Fix treesit-search-forward not matching leaf nodesYuan Fu2022-11-161-0/+9
| | | | * src/treesit.c: Match against NODE at start of the loop.
* Tweaks on c-ts-mode fontification rulesYuan Fu2022-11-161-67/+70
| | | | | | | | | | | | | | | | | | | | Changes: 1. Remove some :override flags 2. Fontify "!" in font-lock-negation-char-face 3. Use some new faces like font-lock-escape-face and font-lock-property-face 4. Move all type fontification into 'type' feature. Previously some are in 'definition' feature. 5. Simplify definition feature, and fontify identifiers in definitions recursively. 6. Change 'statement' feature to 'label' 7. New feature 'assignment' 8. Remove some rules from 'expression' feature * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): See above. (c-ts-mode--fontify-declarator): New function. (c-ts-mode): Update feature-list.
* Fix c-ts-mode-imenuYuan Fu2022-11-161-26/+29
| | | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--imenu-1): If cannot find its name, ignore the node. (c-ts-mode--imenu): Don't include a category if it's empty.
* Allow checking for outdated nodes in tree-sitterYuan Fu2022-11-163-8/+27
| | | | | | | | | Now you can run (treesit-node-check node 'outdated). * doc/lispref/parsing.texi (Accessing Node Information): Update manual. * src/treesit.c (Ftreesit_node_check): Add new property 'outdated'. * test/src/treesit-tests.el (treesit-node-check): Add tests.
* ; Add documentation for tree-sitter parser after-change notifiersYuan Fu2022-11-163-3/+55
| | | | | | * doc/lispref/parsing.texi (Using Parser): Update manual. * lisp/treesit.el (treesit): Add shordocs. * src/treesit.c: Augment docstrings.
* Add treesit-explore-modeYuan Fu2022-11-162-0/+295
| | | | | | | | | | | | | | | | | | | | | | | | This mode is basically the tree-sitter playground[1] in Emacs: displays the syntax tree with the source side-by-side, kept in sync in real-time. [1] https://tree-sitter.github.io/tree-sitter/playground * doc/lispref/parsing.texi (Language Definitions): Mention in manual. * lisp/treesit.el (treesit--explorer-buffer) (treesit--explorer-source-buffer) (treesit--explorer-language) (treesit--explorer-refresh-timer) (treesit--explorer-highlight-overlay) (treesit--explorer-last-node): New variables. * lisp/treesit.el (treesit--explorer--nodes-to-highlight) (treesit--explorer-refresh) (treesit--explorer-post-command) (treesit--explorer-jump) (treesit--explorer-highlight-node) (treesit--explorer-draw-node): New functions. (treesit--explorer-tree-mode) (treesit-explore-mode): New modes.
* Add emacs-devel-specific font-lock rules to c-ts-modeYuan Fu2022-11-151-1/+48
| | | | | | | | This rule corrects the fontification for DEFUN macros. * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Additional font-lock rules. (c-ts-mode--fontify-defun): New function.
* ; * src/treesit.c: Minor stylistic changes.Yuan Fu2022-11-151-13/+8
|
* Fix the MS-Windows build due to use of a new TS functionEli Zaretskii2022-11-151-4/+5
| | | | | * src/treesit.c (ts_tree_get_changed_ranges) [WINDOWSNT]: Define, load from the library, and call through a function pointer.
* ; Enable highlighting error in c-ts-mode--base-modeYuan Fu2022-11-151-1/+1
| | | | | | | I expect this to be turned off by default. but turn this on for demonstration for now. * lisp/progmodes/c-ts-mode.el (c-ts-mode--base-mode): Enable error.
* Make tree-sitter fontification automatically updateYuan Fu2022-11-152-2/+17
| | | | | | | | | | | | | Now nodes that are affected and changed during re-parse will be correctly refontified. Nodes can change even if it corresponding text wasn't edited: additional text can complete the parse tree and resolve error nodes, for example. * lisp/progmodes/python.el (python-mode): Create Python parser before calling treesit-major-mode-setup. * lisp/treesit.el (treesit--font-lock-notifier): New function. (treesit-major-mode-setup): Register fontifier with every existing parser.
* Remove the contextual hack in tree-sitter fontificationYuan Fu2022-11-155-81/+3
| | | | | | | | | | | | | | | | We now have a better facility that can replace the contextual hack. The C part is in the previous commit, and the Lisp part work will be in the next commit. * doc/lispref/modes.texi (Parser-based Font Lock): Update manual. * lisp/progmodes/js.el (js--treesit-font-lock-settings) * lisp/progmodes/python.el (python--treesit-settings) * lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings): Stop marking contextual nodes. * lisp/treesit.el (treesit-font-lock-contextual-post-process): Remove function. (treesit-font-lock-fontify-region): Remove code processing contextual nodes.
* Allow tree-sitter to notify parse-tree changesYuan Fu2022-11-152-1/+89
| | | | | | | | | | | * src/treesit.c (treesit_call_after_change_functions): New function. (treesit_ensure_parsed): Call treesit_call_after_change_functions right after re-parse. (make_treesit_parser): Initialize after_change_functions. (Ftreesit_parser_notifiers) (Ftreesit_parser_add_notifier) (Ftreesit_parser_remove_notifier): New functions. * src/treesit.h (Lisp_TS_Parser): New field after_change_functions.
* Extract out treesit_make_rangesYuan Fu2022-11-151-17/+27
| | | | | * src/treesit.c (treesit_make_ranges): New function. (Ftreesit_parser_included_ranges): Use treesit_make_ranges.
* Don't highlight syntax error in c-ts-modeYuan Fu2022-11-141-1/+1
| | | | | * lisp/progmodes/c-ts-mode.el (c-ts-mode--base-mode): Remove error feature.
* ; Remove some tree-sitter testsYuan Fu2022-11-141-5/+1
| | | | | | * test/src/treesit-tests.el (treesit-parser-supplemental): Remove treesit-set-ranges, and treesit-get-ranges, as these functions are removed.
* Fix some inconsistencies in *-ts-modesTheodor Thornhill2022-11-145-33/+89
| | | | | | | | | | | | | | | | | | | | (c-ts-mode--base-mode): Extract comment-* so that we can separate between C and C++. (c-ts-mode, c++-ts-mode): Set comment-* variables. * lisp/progmodes/css-ts-mode.el (css-ts-mode): Add electric-indent. * lisp/progmodes/java-ts-mode.el (java-ts-mode--imenu): Add categories. Only display categories that exist in the file. (java-ts-mode): Add electric-indent. * lisp/progmodes/json-ts-mode.el (json-ts-mode): Add electric-indent. * lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings): Whitespace cleanup. (ts-mode): Add electric-indent.
* ; * test/src/treesit-tests.el (treesit-node-check): New test.Yuan Fu2022-11-141-0/+18
|
* Remove feature that checks whether tree-sitter node "has changes"Yuan Fu2022-11-142-16/+5
| | | | | | | | | | | | | | First of all, we signal error on using an outdated node, so if a node has changes, calling treesit-node-check would only raise an error. Besides, in order to properly answer whether a node has changed, we would have to update the node as the buffer is edited, which we don't do right now. * doc/lispref/parsing.texi (Accessing Node Information): Remove relevant manual text. * src/treesit.c (Ftreesit_node_check): Remove docstring mentions, remove the branch for "has-changes". (syms_of_treesit): Remove has-changes.
* Fix crash on MS-Windows due to memory-allocation problem in treesit.cEli Zaretskii2022-11-131-2/+2
| | | | | | | | * src/treesit.c (treesit_load_language): Use 'xstrdup'/'xfree' instead of 'strdup'/'free', to prevent crashes on MS-Windows, where we must use our own implementation of 'malloc'/'free', whereas 'strdup' uses the default implementation in the MS-Windows C runtime library.
* Improve tree-sitter imenu for c-mode and js-modeYuan Fu2022-11-122-40/+46
| | | | | | | | | | | | | Instead of a flat list, now categorize imenu entries into categories like "Function", "Variable", "Class", etc. * lisp/progmodes/c-ts-mode.el (c-ts-mode--imenu-1): Handle more edge cases. (c-ts-mode--imenu): Categorize menu entries. * lisp/progmodes/js.el (js--treesit-imenu-type-alist): Remove variable. (js--treesit-imenu-label): Remove function. (js--treesit-imenu-1): Use the name alone for labels. (js--treesit-imenu): Categorize menu entries.
* ; Minor typo fixes for tree-sitter modesYuan Fu2022-11-125-27/+27
| | | | | | | | | * etc/NEWS: Fix typos. Change Tree-sitter to tree-sitter. * lisp/progmodes/c-ts-mode.el * lisp/progmodes/css-ts-mode.el * lisp/progmodes/java-ts-mode.el * lisp/progmodes/json-ts-mode.el: Change Tree Sitter to tree-sitter. Fix typo.
* Add tree-sitter modes for C-like languagesTheodor Thornhill2022-11-125-4/+1043
| | | | | | | | | * etc/NEWS: Mention the new modes * lisp/progmodes/c-ts-mode.el: New major mode with tree-sitter support for C and C++. * lisp/progmodes/java-ts-mode.el: New major mode with tree-sitter support. * lisp/progmodes/json-ts-mode.el: New major mode with tree-sitter support. * lisp/progmodes/css-ts-mode.el: New major mode with tree-sitter support.
* Fix recent changes in documentationEli Zaretskii2022-11-123-22/+19
| | | | | | | | | | * lisp/treesit.el (treesit-node-at): Doc fix. * doc/lispref/parsing.texi (Language Definitions): Add cross-reference. (Retrieving Nodes): Renamed from "Retrieving Node"; all references changed. (Retrieving Nodes): Fix wording and markup.
* ; * lisp/treesit.el (treesit--indent-1): Fix treesit-node-at usage.Yuan Fu2022-11-111-1/+1
|