summaryrefslogtreecommitdiff
path: root/lisp/progmodes/python.el
AgeCommit message (Collapse)Author
2022-12-28(python--treesit-settings): Remove duplicate matcherDmitry Gutov
* lisp/progmodes/python.el (python--treesit-settings): Remove duplicate matcher (which found itself under 'function' in addition to 'definition').
2022-12-26Clean up python-ts-mode font-lock featuresYuan Fu
* lisp/progmodes/python.el (python--treesit-settings): Remove unnecessary override flags, add function and variable feature, fix assignment feature. (python--treesit-variable-p) (python--treesit-fontify-variable): New functions. (python-ts-mode): Add function and variable feature.
2022-12-26; Fix typosStefan Kangas
(cherry picked from commit a5d39e11443fa30c8e8bc58254a1a59550dcd99e)
2022-12-24Support treesit-defun-name in tree-sitter major modesYuan Fu
* lisp/progmodes/csharp-mode.el (csharp-ts-mode--defun-name): New function. (csharp-ts-mode--imenu-1): Extract into new function. (csharp-ts-mode): Setup treesit-defun-name-function. * lisp/progmodes/java-ts-mode.el (java-ts-mode--defun-name): New function. (java-ts-mode--imenu-1): Extract into new function. (java-ts-mode): Setup treesit-defun-name-function. * lisp/progmodes/js.el (js-treesit-current-defun): Remove function. This function is not used (for a while already). (js--treesit-defun-name): New function. (js--treesit-imenu-1): Extract into new function. (js-ts-mode): Setup treesit-defun-name-function. * lisp/progmodes/json-ts-mode.el (json-ts-mode--defun-name): New function. (json-ts-mode--imenu-1): Extract into new function. (json-ts-mode): Setup treesit-defun-name-function. * lisp/progmodes/python.el (python--treesit-defun-name): New function. (python--imenu-treesit-create-index-1): Extract into new function. (python-ts-mode): Setup treesit-defun-name-function. * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--defun-name): New function. (rust-ts-mode--imenu-1): Extract into new function. (rust-ts-mode): Setup treesit-defun-name-function. * lisp/textmodes/css-mode.el (css--treesit-defun-name): New function. (css--treesit-imenu-1): Extract into new function. (css-ts-mode): Setup treesit-defun-name-function. * lisp/textmodes/toml-ts-mode.el (toml-ts-mode--get-table-name): Remove function. (toml-ts-mode--defun-name): New function. (toml-ts-mode--imenu-1): Extract into new function. (toml-ts-mode): Setup treesit-defun-name-function.
2022-12-15Add "function" feature to python-ts-mode (bug#59977)Yuan Fu
* lisp/progmodes/python.el (python--treesit-settings): Add feature. (python-ts-mode): Add feature. And fix indentation for the python-indent-guess-indent-offset code.
2022-12-15Add basic support for hideshow in python-ts-mode (bug#60044)Yuan Fu
* lisp/progmodes/python.el (python-base-mode): Add setup for python-ts-mode.
2022-12-13Fix syntax tables of tree-sitter modes (bug#59807)Kai Ma
Tree-sitter modes should use the same syntax table as the non-tree-sitter ones. * lisp/progmodes/js.el (js-mode-syntax-table) (js-ts-mode) * lisp/progmodes/python.el (python-ts-mode) * lisp/progmodes/sh-script.el (bash-ts-mode) Copyright-paperwork-exempt: yes xx
2022-12-12Add "->" to python--treesit-operators (bug#59968)Daniel Martín
* lisp/progmodes/python.el (python--treesit-operators): Add "->", used to specify the return types of functions in Python.
2022-12-04Improve treesit-fontify-with-overrideYuan Fu
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.
2022-12-01Add case and match to python--treesit-keywords (bug#59720)Daniel Martín
* lisp/progmodes/python.el (python--treesit-keywords): Add "case" and "match" keywords.
2022-12-01Add highlighting Python operators (bug#59629)kobarity
* lisp/progmodes/python.el (python-rx): Remove "is" and "not" from operator. (python-font-lock-keywords-maximum-decoration): Add highlighting operators. * test/lisp/progmodes/python-tests.el (python-font-lock-assignment-statement-1) (python-font-lock-assignment-statement-2) (python-font-lock-assignment-statement-3) (python-font-lock-assignment-statement-4) (python-font-lock-assignment-statement-5) (python-font-lock-assignment-statement-6) (python-font-lock-assignment-statement-7) (python-font-lock-assignment-statement-8) (python-font-lock-assignment-statement-9) (python-font-lock-assignment-statement-10) (python-font-lock-assignment-statement-11) (python-font-lock-assignment-statement-12) (python-font-lock-assignment-statement-13) (python-font-lock-assignment-statement-14) (python-font-lock-assignment-statement-15) (python-font-lock-assignment-statement-16) (python-font-lock-assignment-statement-17) (python-font-lock-assignment-statement-18) (python-font-lock-assignment-statement-multiline-1) (python-font-lock-assignment-statement-multiline-2) (python-font-lock-assignment-statement-multiline-3) (python-font-lock-assignment-statement-multiline-4) (python-font-lock-assignment-statement-multiline-5) (python-font-lock-assignment-statement-multiline-6) (python-font-lock-escape-sequence-multiline-string): Modify expectations to include faces for operators. (python-font-lock-operator-1, python-font-lock-operator-2): New tests.
2022-11-30Sink python indent offset guessing to avoid test failureMattias Engdegård
Call python-indent-guess-indent-offset late in the set-up of python-mode and python-ts-mode to make sure that the required other settings (of syntax-propetize-function in particular) have been carried out. This cures a python-test failure (bug#59477). * lisp/progmodes/python.el (python-base-mode): Move python-indent-guess-indent-offset call from here... (python-mode): ...to here... (python-ts-mode): ...and here.
2022-11-26Reorganize treesit-font-lock-feaure-list's to the new level schemeYuan Fu
* lisp/progmodes/c-ts-mode.el (c-ts-mode--base-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/python.el (python-ts-mode) * lisp/progmodes/sh-script.el (bash-ts-mode) * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode): Reorganized treesit-font-lock-feature-list.
2022-11-26Partially fix some python tests (bug#59477)Yuan Fu
This fixes python-font-lock-assignment-statement-multiline-1 python-font-lock-assignment-statement-multiline-2 python-font-lock-assignment-statement-multiline-3 python-font-lock-assignment-statement-multiline-4 python-font-lock-assignment-statement-multiline-5 python-font-lock-assignment-statement-multiline-6 but leaves python-tests--fill-long-first-line unfixed. * lisp/progmodes/python.el (python-mode): Add the missing setup.
2022-11-25; * lisp/progmodes/python.el (treesit-node-prev-sibling): Declare.Eli Zaretskii
2022-11-24Improve python-ts-mode fontification (bug#59534)Yuan Fu
* lisp/progmodes/python.el (python--treesit-operators): Add operators. (python--treesit-fontify-string): Fontify BOF docstrings.
2022-11-23Don't skip nested defuns in python-ts-mode defun navigationYuan Fu
This fixes bug#59495. Before this change, python tries to skip nested function definition. Now we don't skip any nested defun. * lisp/progmodes/python.el (python-treesit-beginning-of-defun) (python-treesit-end-of-defun): Remove functions. * lisp/progmodes/python.el (python-ts-mode): Use tree-sitter's default navigation function.
2022-11-23; Fix typosStefan Kangas
2022-11-22Tweak python-ts-mode fontification (bug#59470)Yuan Fu
* lisp/progmodes/python.el (python--treesit-settings): Only fontify the @ and the identifier of a decorator, not the argument list (if there is any).
2022-11-21Merge remote-tracking branch 'savannah/master' into feature/tree-sitterYuan Fu
2022-11-21; Silence byte-compiler warningsEli Zaretskii
* lisp/textmodes/css-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/json-ts-mode.el: * lisp/progmodes/js.el: * lisp/progmodes/java-ts-mode.el: * lisp/progmodes/c-ts-mode.el: Add declarations of tree-sitter functions.
2022-11-21Add separate keymaps for js/python/css-ts-modeYuan Fu
* lisp/progmodes/js.el (js-ts-mode-map) * lisp/progmodes/python.el (python-ts-mode-map) * lisp/textmodes/css-mode.el (css-ts-mode-map): New keymap.
2022-11-21Tweak python-ts-mode fontificationYuan Fu
* lisp/progmodes/python.el (python--treesit-fontify-string): Make the matching condition for docstrings more specific.
2022-11-20Limit recursion level for tree-sitter imenu functionsYuan Fu
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.
2022-11-20; Improve recently-modified documentationEli Zaretskii
* 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.
2022-11-19Fix uses of treesit-ready-pYuan Fu
* 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.
2022-11-19Merge function/class-name features in python-modeYuan Fu
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.
2022-11-19Split python-mode into native and tree-sitter variantYuan Fu
* 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.
2022-11-19Fix python-mode tree-sitter fontificationYuan Fu
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.
2022-11-17Utilize new font-lock faces for C/C++ and Python tree-sitter useRandy Taylor
* 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.
2022-11-15Make tree-sitter fontification automatically updateYuan Fu
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.
2022-11-15Remove the contextual hack in tree-sitter fontificationYuan Fu
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.
2022-11-10Utilize new face font-lock-escape-face in python-modeYuan Fu
* lisp/progmodes/python.el (python--treesit-settings): Use font-lock-escape-face rather than font-lock-constant-face.
2022-11-10Fix indentation for multi-line block start in Python modekobarity
* lisp/progmodes/python.el (python-info-dedenter-opening-block-positions): Fix for multi-line block start. * test/lisp/progmodes/python-tests.el (python-info-dedenter-opening-block-positions-6): New test. (Bug#59009)
2022-11-09Mimic existing python-mode beg/end-of-defun behavior betterYuan Fu
* lisp/progmodes/python.el (python-treesit-beginning-of-defun) (python-treesit-end-of-defun): New functions. * lisp/progmodes/python.el (python-mode): Use custom beg/end-of-defun functions.
2022-11-02Pass region start and end to tree-sitter fontification functionsYuan Fu
* doc/lispref/modes.texi (Parser-based Font Lock): Update manual. * lisp/progmodes/js.el (js--fontify-template-string) * lisp/progmodes/python.el (python--treesit-fontify-string): Update function to only fontify within the region. * lisp/treesit.el (treesit-font-lock-rules): Update docstring. (treesit-font-lock-fontify-region): Pass START and END to fontification functions.
2022-11-02Add handling of contextual entities in tree-sitter font-lockYuan Fu
* lisp/progmodes/python.el: Remove function. (python--treesit-settings): Capture contextual node. * lisp/treesit.el (treesit--set-nonsticky): (treesit-font-lock-contextual-post-process): New functions. (treesit-font-lock-fontify-region): Change local variable START and END to NODE-START and NODE-END, handle special capture name "contextual". * doc/lispref/modes.texi (Parser-based Font Lock): Update manual.
2022-11-02Change signature of tree-sitter font-lock functionsYuan Fu
Change from (START END NODE OVERRIDE &rest _) to (NODE OVERRIDE &rest _) START and END aren't used frequently enough to justify. If a fontification function needs them, it can get them from NODE. * doc/lispref/modes.texi (Parser-based Font Lock): Update manual. * lisp/progmodes/js.el (js--fontify-template-string) * lisp/progmodes/python.el (python--treesit-fontify-string) (python--treesit-fontify-string-end): Change signature. * lisp/treesit.el (treesit-font-lock-rules): Update docstring. (treesit-font-lock-fontify-region): Remove START and END arguments.
2022-11-01Fix string fontification for tree-sitter python-modeYuan Fu
Now when user inserts a ending quote, the whole string is ganranteed to be refontified and redisplayed. * lisp/progmodes/python.el (python--treesit-fontify-string): Change docstring, now it's called on the leading quote. (python--treesit-fontify-string-end): New function. (python--treesit-settings): Capture both leading and ending quote in a string.
2022-10-31Use treesit-fontify-with-override in tree-sitter functionsYuan Fu
* lisp/progmodes/js.el (js--fontify-template-string) * lisp/progmodes/python.el (python--treesit-fontify-string): Use treesit-fontify-with-override.
2022-10-31Add an argument OVERRIDE to tree-sitter font-lock functionsYuan Fu
* doc/lispref/modes.texi (Parser-based Font Lock): Reflect this change in manual. * lisp/progmodes/js.el (js--fontify-template-string): Add _OVERRIDE argument. * lisp/progmodes/python.el (python--treesit-fontify-string): Add _OVERRIDE argument. * lisp/treesit.el (treesit-font-lock-rules): Update docstring. (treesit-fontify-with-override): New function. (treesit-font-lock-fontify-region): Extract out into treesit-fontify-with-override.
2022-10-31Improve python tree-sitter's string fontificationYuan Fu
* lisp/progmodes/python.el (python--treesit-fontify-string): Handle not only f-strings, but also docstrings, and NODE is now the last quote rather than the whole string. (python--treesit-settings): Use python--treesit-fontify-string for every occasion.
2022-10-29Separate python tree-sitter fontification into featuresYuan Fu
Level 1: comment string function-name class-name Level 2: keyword builtin constant type Level 3: assignment decorator escape-sequence string-interpolation * lisp/progmodes/python.el (python--treesit-settings): Separate. (python-mode): Set features.
2022-10-27Disable completion/ElDoc/FFAP when Python program is runningkobarity
* lisp/progmodes/python.el (python-completion-at-point) (python-ffap-module-path, python-eldoc--get-doc-at-point): Add check using `python-util-comint-end-of-output-p'. (python-util-comint-end-of-output-p): New function. * test/lisp/progmodes/python-tests.el (python-tests-shell-wait-for-prompt): Use `python-util-comint-end-of-output-p'. (python-completion-at-point-while-running-1) (python-ffap-module-path-1) (python-ffap-module-path-while-running-1) (python-eldoc--get-doc-at-point-1) (python-eldoc--get-doc-at-point-while-running-1): New tests. (Bug#58713)
2022-10-26Add tree-sitter navigation support to python-modeYuan Fu
* lisp/progmodes/python.el (python-mode): Set treesit-defun-type-regexp.
2022-10-25New tree-sitter toggle schemeYuan Fu
This version: central variable, everything controlled by treesit-settings. Major mode sets up tree-sitter/non-tree-sitter in a conditional branch, based on the setting. * lisp/treesit.el (treesit-settings): New option. (treesit-defun-type-regexp): Change docstring. (treesit-mode-supported) (treesit-required-languages) (treesit--local-variable-backup): Remove variables. (treesit--backup-local-variable) (treesit-mode) (global-treesit-mode--turn-on) (global-treesit-mode): Remove functions. (treesit--setting-for-mode): New function. (treesit-ready-p): New argument MODE, changed REPORT to QUIET, and LANGUAGEs to LANGUAGE (now it can be a single symbol or a list of them). (treesit-major-mode-setup): New function. Mostly comes from treesit-mode. * test/src/treesit-tests.el (treesit-misc): New test. * lisp/progmodes/python.el (python-mode): Move some setup code into the conditional branch at the end. * lisp/progmodes/js.el (js-json-mode) (js-mode): Move some setup code into the conditional branch at the end. * lisp/progmodes/ts-mode.el: Move tree-sitter setup into the conditional branch.
2022-10-19Revise the toggle scheme of tree-sitter (again)Yuan Fu
Now instead of a toggle function (major-mode-backend-function), we let major mode set local variables like treesit-font-lock-settings, treesit-imenu-function, then treesit-mode takes care of activating those things (clearing font-lock-keywords, setting imenu-create-index-function to treesit-imenu-function, etc). js.el and python.el: I've returned js-mode and python-mode to exactly what they were before tree-sitter change, plus lines at the end setting up tree-sitter variables. Sorry about all these fuss :-D * lisp/treesit.el (treesit-mode-inhibit-message): Remove option. (major-mode-backend-function) (treesit-remapped-major-mode-alist): Remove variables. (treesit-mode): Move down to the end of buffer. Do more things. (global-treesit-mode): Move down to the end of buffer. Don't handle major-mode-remap-alist anymore. (global-treesit-mode--turn-on): Move down to the end of buffer. (treesit-ready-p): Move down to the end of buffer. Changed signature. (treesit-font-lock-enable): Remove function. (treesit-defun-type-regexp): New variable. (treesit-beginning-of-defun) (treesit-end-of-defun): New function. (treesit-imenu-function): New variable. (treesit-mode-supported) (treesit-required-languages) (treesit--local-variable-backup): New variables. (treesit--backup-local-variable): New function * lisp/progmodes/js.el (js-use-tree-sitter): Remove option. (js--treesit-defun-type-regexp): Remove variable. (Now set inline in js-mode.) (js--treesit-beginning-of-defun) (js--treesit-end-of-defun): Remove functions. (Now use treesit-beginning/end-of-defun.) (js--backend-toggle) (js--json-backend-toggle): Remove function. (js-mode) (js-json-mode): Restore back to before tree-sitter changes. Add tree-sitter setup at the end. * lisp/progmodes/python.el (python--backend-toggle): Remove function. (python-mode): Restore back to before tree-sitter changes. Add tree-sitter setup at the end. * lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings): Use js--fontify-template-string. (ts-mode--fontify-template-string): Remove function (because we can just use js--fontify-template-string). (ts-mode--defun-type-regexp): Remove variable (now set inline in ts-mode). (ts-mode--beginning-of-defun) (ts-mode--end-of-defun): Remove functions (now using treesit-beginning/end-of-defun). (ts-mode): Setup tree-sitter variables and then turn on treesit-mode or move to js-mode.
2022-10-18; * lisp/progmodes/python.el (python--backend-toggle): Use cond.Yuan Fu
2022-10-18Install new toggle scheme for tree-sitterYuan Fu
Basically we now have treesit-mode and global-treesit-mode. Major modes set major-mode-backend-function which treesit-mode calls to activate/deactivate tree-sitter. js.el needs a bit explanation: I'm so sorry for messing up the history, but basically now js-mode and js-json-mode should be exactly the same as before any tree-sitter change was introduced, sans some initialization code that are moved to js(-json)--backend-toggle. js-mode and js-json-mode now just sets major-mode-backend-function and initialize with js(-json)--backend-toggle. * lisp/treesit.el (treesit-mode-inhibit-message): New option. (treesit-can-enable-p): Remove function. (major-mode-backend-function) (treesit-remapped-major-mode-alist): New variables. (treesit-mode) (global-treesit-mode): New minor modes. (global-treesit-mode--turn-on) (treesit-ready-p): New functions. * lisp/progmodes/python.el: Remove option. (python--backend-toggle): New function. (python-mode): Remove the if-form, all the initialization code are moved to python--backend-toggle, python-mode now just sets major-mode-backend-function and initialize with python--backend-toggle. * lisp/progmodes/js.el (js--treesit-can-enable-p) (js--json-treesit-can-enable-p) (js--treesit-enable) (js--json-treesit-enable): Remove functions. (js--backend-toggle) (js-json--backend-toggle): New function. * lisp/progmodes/ts-mode.el (ts-mode): Use treesit-ready-p.
2022-10-16Fix invalid search bound error in python-shell-completion-at-pointkobarity
* lisp/progmodes/python.el (python-shell-completion-at-point): Add check if point is before line-start. * test/lisp/progmodes/python-tests.el (python-shell-completion-shell-buffer-1) (python-shell-completion-shell-buffer-native-1): New tests (bug#58548).