aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* Don't misindent 'else:' after 'if re.match:' in PythonDmitry Gutov2023-03-081-1/+3
| | | | | | | | | | | * lisp/progmodes/python.el (python-info-dedenter-opening-block-positions): Check that the supposed block start is not a method call (bug#62031). * test/lisp/progmodes/python-tests.el (python-indent-after-re-match): New test. Co-authored-by: Lele Gaifax <lele@metapensiero.it>
* 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).
* python-ts-mode: Fix single-quote string fontificationDmitry Gutov2023-02-261-1/+1
| | | | | * lisp/progmodes/python.el (python--treesit-fontify-string): Look for ', not just ", as opening delimiter (bug#61796).
* Add more/finer faces for tree-sitterDmitry Gutov2023-02-251-15/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * doc/lispref/modes.texi (Faces for Font Lock): Update the list of faces (bug#61655). * etc/NEWS: Update the list of new faces. * lisp/cus-theme.el (custom-theme--listed-faces): Update. * lisp/font-lock.el (font-lock-function-call-face) (font-lock-variable-ref-face, font-lock-property-ref-face): New faces. (font-lock-property-name-face): Rename from 'font-lock-property-face'. * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Use new faces. More 'enumerator' query to 'definition' feature. (c-ts-mode--fontify-declarator, c-ts-mode--fontify-variable): Use new faces. * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode--font-lock-settings): Use new faces. * lisp/progmodes/csharp-mode.el (csharp-ts-mode--font-lock-settings): Use new faces. * lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings): Use new faces. * lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings): Use new faces. * lisp/progmodes/js.el (js--treesit-fontify-assignment-lhs) (js--treesit-font-lock-settings): Use new faces. Highlight variable definitions inside array and object destructuring patterns. * lisp/progmodes/python.el (python--treesit-variable-p): Exclude identifiers in parameters. (python--treesit-settings): Use new faces. Highlight function parameters. Move 'keyword' up to still highlight 'self' as keyword. * lisp/progmodes/ruby-ts-mode.el (ruby-ts--font-lock-settings): Use new faces. * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--font-lock-settings): Use new faces. * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--font-lock-settings): Use new faces. * lisp/textmodes/css-mode.el (css--treesit-settings): Use font-lock-property-ref-face. * lisp/textmodes/toml-ts-mode.el (toml-ts-mode--font-lock-settings): Use font-lock-property-ref-face. * lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode--font-lock-settings): Same.
* * lisp/progmodes/python.el (python--import-sources): Fix regexp (bug#61648)Augusto Stoffel2023-02-221-1/+1
|
* Fix point moving when calling python-shell-send-regionkobarity2023-02-181-12/+14
| | | | | | | | | | * lisp/progmodes/python.el (python-shell-buffer-substring): Add `save-excursion' to prevent the point from moving. * test/lisp/progmodes/python-tests.el (python-tests-should-not-move): New helper function to assert that point does not move while calling a function. (python-shell-buffer-substring-*): Use `python-tests-should-not-move'. (Bug#61463)
* python.el: Use correct regexp when enabling python-ts-modeBrian Leung2023-01-281-2/+2
| | | | | * lisp/progmodes/python.el: Use "python[0-9.]*" regexp for 'interpreter-mode-alist', and not 'auto-mode-alist'. (Bug#61090)
* Make tree-sitter based modes optionalEli Zaretskii2023-01-201-1/+4
| | | | | | | | | | | | | | | | | | | | | * lisp/progmodes/c-ts-mode.el: Update Commentary. Make 'auto-mode-alist' update conditional on the tree-sitter and grammar libraries being available. * lisp/progmodes/cmake-ts-mode.el: * lisp/progmodes/csharp-mode.el: * lisp/progmodes/dockerfile-ts-mode.el: * lisp/progmodes/go-ts-mode.el: * lisp/progmodes/java-ts-mode.el: * lisp/progmodes/js.el: * lisp/progmodes/json-ts-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/ruby-ts-mode.el: * lisp/progmodes/typescript-ts-mode.el: * lisp/textmodes/css-mode.el: * lisp/textmodes/toml-ts-mode.el: * lisp/textmodes/yaml-ts-mode.el: Make 'auto-mode-alist' update for tree-sitter based modes be conditional on the tree-sitter and grammar libraries being available. (Bug#60559)
* Fix string fontification on python-ts-mode (bug#60599)Yuan Fu2023-01-071-2/+5
| | | | | | * lisp/progmodes/python.el: (python--treesit-fontify-string): Generalize and skip anything before the first quote character.
* Fix string-interpolation feature of python-ts-mode (bug#60599)Yuan Fu2023-01-071-2/+18
| | | | | | | * lisp/progmodes/python.el: (python--treesit-fontify-string-interpolation): New function. (python--treesit-settings): Use the new function for string-interpolation.
* Fix 'python-shell-buffer-substring' when START is in middle of 1st linekobarity2023-01-071-4/+5
| | | | | | | | * lisp/progmodes/python.el (python-shell-buffer-substring): Instead of checking whether START is point-min, check whether START is in the first line. (Bug#60466) * test/lisp/progmodes/python-tests.el (python-shell-buffer-substring-18): New test.
* ; Add 2023 to copyright years.Eli Zaretskii2023-01-011-1/+1
|
* ; Fix typosStefan Kangas2022-12-311-1/+1
|
* Fix python-shell-buffer-substring when retrieving a single statementkobarity2022-12-311-14/+31
| | | | | | | | | | | * lisp/progmodes/python.el (python-shell-buffer-substring): Do not add "if True:" line when retrieving a single statement. (python-shell-send-region): Add a reference to `python-shell-buffer-substring' in docstring. * test/lisp/progmodes/python-tests.el (python-shell-buffer-substring-13) (python-shell-buffer-substring-14, python-shell-buffer-substring-15) (python-shell-buffer-substring-16, python-shell-buffer-substring-17): New tests. (Bug#60142)
* (python--treesit-settings): Remove duplicate matcherDmitry Gutov2022-12-281-3/+1
| | | | | | * lisp/progmodes/python.el (python--treesit-settings): Remove duplicate matcher (which found itself under 'function' in addition to 'definition').
* Clean up python-ts-mode font-lock featuresYuan Fu2022-12-261-9/+30
| | | | | | | | | * 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.
* ; Fix typosStefan Kangas2022-12-261-1/+1
| | | | (cherry picked from commit a5d39e11443fa30c8e8bc58254a1a59550dcd99e)
* Support treesit-defun-name in tree-sitter major modesYuan Fu2022-12-241-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Add "function" feature to python-ts-mode (bug#59977)Yuan Fu2022-12-151-3/+11
| | | | | | * 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.
* Add basic support for hideshow in python-ts-mode (bug#60044)Yuan Fu2022-12-151-13/+15
| | | | | * lisp/progmodes/python.el (python-base-mode): Add setup for python-ts-mode.
* Fix syntax tables of tree-sitter modes (bug#59807)Kai Ma2022-12-131-0/+1
| | | | | | | | | | | | | | 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
* Add "->" to python--treesit-operators (bug#59968)Daniel Martín2022-12-121-1/+2
| | | | | * lisp/progmodes/python.el (python--treesit-operators): Add "->", used to specify the return types of functions in Python.
* Improve treesit-fontify-with-overrideYuan Fu2022-12-041-1/+1
| | | | | | | | | | | | | | | | | | | | | 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.
* Add case and match to python--treesit-keywords (bug#59720)Daniel Martín2022-12-011-2/+2
| | | | | * lisp/progmodes/python.el (python--treesit-keywords): Add "case" and "match" keywords.
* Add highlighting Python operators (bug#59629)kobarity2022-12-011-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Sink python indent offset guessing to avoid test failureMattias Engdegård2022-11-301-5/+9
| | | | | | | | | | | | 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.
* Reorganize treesit-font-lock-feaure-list's to the new level schemeYuan Fu2022-11-261-5/+5
| | | | | | | | | | | * 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.
* Partially fix some python tests (bug#59477)Yuan Fu2022-11-261-1/+3
| | | | | | | | | | | | | | | | | | | 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.
* ; * lisp/progmodes/python.el (treesit-node-prev-sibling): Declare.Eli Zaretskii2022-11-251-1/+1
|
* Improve python-ts-mode fontification (bug#59534)Yuan Fu2022-11-241-5/+20
| | | | | * lisp/progmodes/python.el (python--treesit-operators): Add operators. (python--treesit-fontify-string): Fontify BOF docstrings.
* Don't skip nested defuns in python-ts-mode defun navigationYuan Fu2022-11-231-52/+2
| | | | | | | | | | | | 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.
* ; Fix typosStefan Kangas2022-11-231-1/+1
|
* Tweak python-ts-mode fontification (bug#59470)Yuan Fu2022-11-221-1/+3
| | | | | | * lisp/progmodes/python.el (python--treesit-settings): Only fontify the @ and the identifier of a decorator, not the argument list (if there is any).
* Merge remote-tracking branch 'savannah/master' into feature/tree-sitterYuan Fu2022-11-211-21/+53
|\
| * Fix indentation for multi-line block start in Python modekobarity2022-11-101-0/+1
| | | | | | | | | | | | | | | | * 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)
| * Disable completion/ElDoc/FFAP when Python program is runningkobarity2022-10-271-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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)
| * Fix invalid search bound error in python-shell-completion-at-pointkobarity2022-10-161-9/+12
| | | | | | | | | | | | | | | | * 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).
| * Disable completion when PDB is active in Python Shell bufferkobarity2022-10-161-1/+4
| | | | | | | | | | | | | | * lisp/progmodes/python.el (python-shell-completion-at-point): Disable completion in Python buffer when PDB is active in Python Shell buffer. * test/lisp/progmodes/python-tests.el (python-shell-completion-pdb-1): New test (bug#58562).
| * Fix Python completion when point in shell buffer is before promptkobarity2022-10-121-2/+4
| | | | | | | | | | | | | | * lisp/progmodes/python.el (python-shell-completion-at-point): Limit prompt boundaries check to shell buffer. * test/lisp/progmodes/python-tests.el (python-shell-completion-2): (python-shell-completion-native-2): New tests (bug#58441).
| * Fix Python completion failure under certain conditionskobarity2022-10-111-8/+18
| | | | | | | | | | | | | | | | | | | | | | * lisp/progmodes/python.el (python-shell-send-string-no-output): Save and restore `comint-last-prompt-overlay' or `comint-last-prompt'. * test/lisp/progmodes/python-tests.el (python-tests-shell-wait-for-prompt): New helper function. (python-tests-with-temp-buffer-with-shell): New helper macro. (python-shell-completion-1, python-shell-completion-native-1) (python-shell-completion-native-with-ffap-1) (python-shell-completion-native-with-eldoc-1): New tests (bug#58389).
* | ; Silence byte-compiler warningsEli Zaretskii2022-11-211-0/+9
| | | | | | | | | | | | | | | | | | | | * 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.
* | Add separate keymaps for js/python/css-ts-modeYuan Fu2022-11-211-1/+4
| | | | | | | | | | | | * 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.
* | Tweak python-ts-mode fontificationYuan Fu2022-11-211-4/+10
| | | | | | | | | | * lisp/progmodes/python.el (python--treesit-fontify-string): Make the matching condition for docstrings more specific.
* | Limit recursion level for tree-sitter imenu functionsYuan Fu2022-11-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 recently-modified documentationEli Zaretskii2022-11-201-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | * 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-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | * 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.
* | 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.
* | 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-171-6/+35
| | | | | | | | | | | | | | | | | | | | | | * 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.