aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el (unfollow)
Commit message (Collapse)AuthorFilesLines
2025-10-16Check if treesit-major-mode-remap-alist is bound in ts-modes autoload formsJuri Linkov1-2/+1
* lisp/progmodes/c-ts-mode.el: * lisp/progmodes/cmake-ts-mode.el: * lisp/progmodes/csharp-mode.el: * lisp/progmodes/dockerfile-ts-mode.el: * lisp/progmodes/elixir-ts-mode.el: * lisp/progmodes/go-ts-mode.el: * lisp/progmodes/heex-ts-mode.el: * lisp/progmodes/java-ts-mode.el: * lisp/progmodes/js.el: * lisp/progmodes/json-ts-mode.el: * lisp/progmodes/lua-ts-mode.el: * lisp/progmodes/php-ts-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/ruby-ts-mode.el: * lisp/progmodes/rust-ts-mode.el: * lisp/progmodes/sh-script.el: * lisp/progmodes/typescript-ts-mode.el: * lisp/textmodes/css-mode.el: * lisp/textmodes/markdown-ts-mode.el: * lisp/textmodes/mhtml-ts-mode.el: * lisp/textmodes/toml-ts-mode.el: * lisp/textmodes/yaml-ts-mode.el: In autoload forms replace '(treesit-available-p)' with (boundp 'treesit-major-mode-remap-alist). Calling 'treesit-available-p' in loaddefs.el is too early since the tree-sitter library might not be loaded yet. Checking if 'treesit-major-mode-remap-alist' is bound is equivalent to checking if Emacs is compiled with tree-sitter support. (bug#79622)
2025-09-25; Avoid byte-compiler warnings in python.elEli Zaretskii1-0/+2
* lisp/progmodes/python.el (treesit-node-prev-sibling) (treesit-node-field-name-for-child): Declare.
2025-09-24Fix infloop in python-ts-mode string fontification (bug#79457)Yuan Fu1-6/+7
* lisp/progmodes/python.el (python--treesit-fontify-string): Make sure there's no infloop.
2025-09-22Fix python-ts-mode font-lock breakage by grammar change (bug#79457)Yuan Fu1-30/+37
* lisp/progmodes/python.el (python--treesit-fontify-string): Use new algorithm.
2025-09-06Fix command keys in doc string of 'inferior-python-mode'Eli Zaretskii1-1/+1
* lisp/progmodes/python.el (inferior-python-mode): Mention the correct mode-map in the doc string. (Bug#79386) (cherry picked from commit ab5e0f535939e7fa94c0770e6e21acb9efea2a32)
2025-09-06Fix command keys in doc string of 'inferior-python-mode'Eli Zaretskii1-1/+1
* lisp/progmodes/python.el (inferior-python-mode): Mention the correct mode-map in the doc string. (Bug#79386)
2025-08-29* lisp/progmodes/python.el: Use 'treesit-major-mode-remap-alist'.Juri Linkov1-2/+9
(python-ts-mode): Don't duplicate 'auto-mode-alist' and 'interpreter-mode-alist' settings in Emacs 31 (bug#79180). Add ts-mode mapping to 'treesit-major-mode-remap-alist'.
2025-08-07Fix Python PDB tracking for remote inferior Pythonkobarity1-8/+40
* lisp/progmodes/python.el (python-shell-local-prefix): New constant. (python-shell--convert-file-name-to-send): New function to add/remove prefix. (python-shell-send-string, python-shell-send-file): Changed to use 'python-shell--convert-file-name-to-send'. (python-pdbtrack-set-tracked-buffer): Changed to add/remove prefix. * test/lisp/progmodes/python-tests.el (python-shell--convert-file-name-to-send-1): New test. (Bug#79036)
2025-08-02Improve region deletion handling in python.elJakub Ječmínek1-3/+6
* lisp/progmodes/python.el (python-indent-dedent-line-backspace): Delete the text in the region if Transient Mark mode is enabled, the mark is active, and prefix arg is 1. (Bug#48695) * test/lisp/progmodes/python-tests.el (python-indent-dedent-line-backspace-4): Add new test.
2025-06-25Improve treesit settings for python-ts-mode (bug#73404).Juri Linkov1-8/+32
* lisp/progmodes/python.el (python--thing-settings): For the 'sexp' thing use all nodes except top-level grouping nodes, comments and parens. Add the 'list' thing. (python-ts-mode): Use setq-local for treesit-thing-settings. Modify 'forward-sexp-function' and 'treesit-sexp-thing' after calling 'treesit-major-mode-setup'.
2025-06-21; * lisp/progmodes/python.el (treesit-thing-settings): Defvar.Eli Zaretskii1-0/+1
2025-06-21python-ts-mode: Improve fontificationJostein Kjønigsen1-1/+6
python--treesit-settings: Fontification based on selectors & code-conventions - Constructor: Fontified as type, not function-call. - Typed default parameters - Fontify kwargs in function calls as property-use. Differentiate from variable-use (passed in arguments)
2025-06-20Use keyword :commit with full hashes for treesit-language-source-alist.Juri Linkov1-1/+2
* lisp/treesit.el (treesit-language-source-alist): Document the format that uses keywords. (treesit--install-language-grammar-1): Remove args 'revision', 'source-dir', 'cc', 'c++', 'commit'. Use 'args' to process the keywords, and use the remaining list as the previous list of arguments. (treesit--install-language-grammar-1): Let-bind 'treesit--install-language-grammar-full-clone' and 'treesit--install-language-grammar-blobless' to t when 'commit' is non-nil (bug#78542). * lisp/progmodes/c-ts-mode.el: * lisp/progmodes/cmake-ts-mode.el: * lisp/progmodes/csharp-mode.el: * lisp/progmodes/dockerfile-ts-mode.el: * lisp/progmodes/elixir-ts-mode.el: * lisp/progmodes/go-ts-mode.el: * lisp/progmodes/heex-ts-mode.el: * lisp/progmodes/java-ts-mode.el: * lisp/progmodes/js.el: * lisp/progmodes/json-ts-mode.el: * lisp/progmodes/php-ts-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/ruby-ts-mode.el: * lisp/progmodes/rust-ts-mode.el: * lisp/progmodes/sh-script.el: * lisp/progmodes/typescript-ts-mode.el: * lisp/textmodes/css-mode.el: * lisp/textmodes/html-ts-mode.el: * lisp/textmodes/markdown-ts-mode.el: * lisp/textmodes/toml-ts-mode.el: * lisp/textmodes/yaml-ts-mode.el: Use the keyword :commit with full hashes instead of tags in 'treesit-language-source-alist'. * lisp/treesit-x.el (define-treesit-generic-mode): Simplify the keyword :copy-queries. (gitattributes-generic-ts-mode, liquid-generic-ts-mode): Add keywords :commit and :copy-queries to :source. * admin/tree-sitter/treesit-admin.el (treesit-admin--unversioned-treesit-language-source-alist): Handle :revision and :commit as well. (treesit-admin--find-latest-compatible-revision): Process the keywords in the recipe.
2025-06-17Use treesit-thing-settings in python-ts-modeYuan Fu1-17/+19
* lisp/progmodes/python.el (python--thing-settings): New variable. (python-ts-mode): Setup treesit-thing-settings.
2025-06-12Add 'treesit-sexp-thing' to use instead of 'treesit-sexp-type-regexp'.Juri Linkov1-12/+14
* lisp/treesit.el (treesit-sexp-thing): New variable to use instead of 'treesit-sexp-type-regexp'. (treesit-sexp-thing-down-list): Rename from 'treesit-sexp-type-down-list'. (treesit-sexp-thing-up-list): Rename from 'treesit-sexp-type-up-list'. (treesit-forward-sexp, treesit--forward-list-with-default) (treesit-down-list, treesit-up-list): Update references to the above variables. (treesit-cycle-sexp-thing): Rename from 'treesit-cycle-sexp-type'. * lisp/progmodes/elixir-ts-mode.el (elixir-ts-mode): Update same variables. * lisp/progmodes/heex-ts-mode.el (heex-ts-mode): Set these variables instead of calling the function that sets them. * lisp/progmodes/python.el (python-ts-mode): Check if variables 'treesit-sentence-type-regexp' and 'treesit-sexp-type-regexp' are bound. https://lists.gnu.org/archive/html/emacs-devel/2025-06/msg00182.html
2025-05-05Fix test-regressions in python-ts-modeJostein Kjønigsen1-1/+3
* lisp/progmodes/python.el (python--treesit-settings): Use more specific selectors for constants. * test/lisp/progmodes/python-tests.el (python-ts-mode-nested-types-face-1) (python-ts-mode-union-types-face-1) (python-ts-mode-union-types-face-2): None is now a constant.
2025-05-01Improve python-ts-mode fontification (bug#78129)Jostein Kjønigsen1-5/+18
Fontification based on selectors & code-conventions: - Lambda parameters: variable declarations - For in statements: variable declarations - Import statements: variable declerations - Constants: All upper case alphanumerical identifiers - Types: CamelCase alphanumerical identifiers - Enums: Enum-values as constants. * lisp/progmodes/python.el: (python--treesit-settings): Improve queries.
2025-04-30Add python tree-sitter grammar data to 'treesit-language-source-alist'.Juri Linkov1-1/+8
* lisp/progmodes/python.el (python-ts-mode): Use 'treesit-ensure-installed' when it's fboundp.
2025-04-26Fix filename completion in Python shell (bug#77853)Liu Hui1-0/+2
'comint-filename-completion' may complete the filename at wrong locations. Users who want proper filename completion should use specialized completion backends (e.g. Jedi). * lisp/progmodes/python.el (inferior-python-mode): Remove 'comint-filename-completion' in 'comint-dynamic-complete-functions'.
2025-04-26Add cache to Python block navigation functionskobarity1-0/+52
* lisp/progmodes/python.el (python-nav-cache) (python-nav-cache-tick): New variables. (python-nav-cache-get, python-nav-cache-set) (python-nav-with-cache): New functions. (python-nav-beginning-of-block, python-nav-end-of-block): New wrapper functions. (python-nav--beginning-of-block): Renamed from 'python-nav-beginning-of-block'. (python-nav--end-of-block): Renamed from 'python-nav-end-of-block'. (Bug#77620)
2025-04-26Performance optimization of 'python-info-statement-ends-block-p'kobarity1-8/+19
* lisp/progmodes/python.el (python-info-statement-ends-block-p): Add a comparison of the indentation of the next statement with the indentation of the current statement. (Bug#77620)
2025-04-26Fix Python block end predicates (bug#77941)kobarity1-2/+7
* lisp/progmodes/python.el (python-info-statement-ends-block-p) (python-info-end-of-block-p): Add consideration of comments. * test/lisp/progmodes/python-tests.el (python-info-statement-ends-block-p-3) (python-info-end-of-block-p-3): New tests.
2025-04-18Disable echo back instead of setting tty to raw in Inferior Pythonkobarity1-2/+4
* lisp/progmodes/python.el (python-shell-setup-code): Change the Python setup code. (Bug#76943) (cherry picked from commit 4c5c20ddc2cdde570ccf54c4aa60644828ee213d)
2025-04-17Disable echo back instead of setting tty to raw in Inferior Pythonkobarity1-2/+4
* lisp/progmodes/python.el (python-shell-setup-code): Change the Python setup code. (Bug#76943)
2025-04-04Add repeat-map for Python indentation commandsPaul Nelson1-0/+7
* lisp/progmodes/python.el (python-indent-repeat-map): New keymap for repeating Python indentation commands when using 'repeat-mode' (bug#77417).
2025-03-29Replace uses of `replace-buffer-contents`Stefan Monnier1-1/+1
* lisp/vc/vc.el (vc-diff-restore-buffer): * lisp/progmodes/python.el (python--do-isort): * lisp/progmodes/eglot.el (eglot--apply-text-edits): * lisp/files.el (revert-buffer-insert-file-contents-delicately): * lisp/json.el (json-pretty-print): Use `replace-region-contents`.
2025-03-22ElDoc: Add more commands using 'eldoc-add-command-completions'James Cherti1-0/+1
Add more commands to 'eldoc-add-command-completions' to fix disappearing ElDoc help in the minibuffer for the following cases: - All modes: Added "comment-indent-new-line". - All modes: Added "delete-char" for handling when the user presses delete. - Python mode: Added "python-indent-dedent-line-backspace" for handling when the user presses backspace. * lisp/emacs-lisp/eldoc.el (eldoc-remove-command-completions): * lisp/progmodes/python.el (python-base-mode): Add more commands to 'eldoc-add-command-completions'. Copyright-paperwork-exempt: yes
2025-03-11Bump python.el package version to 0.30Stefan Kangas1-1/+1
* lisp/progmodes/python.el: Bump package version to 0.30.
2025-03-11Make python.el compatible with Emacs 29.1Stefan Kangas1-5/+8
* lisp/progmodes/python.el (python--treesit-fontify-string): Don't call treesit--compute-font-lock-level unless it is fboundp. (Bug#76873)
2025-03-07Improve docstrings of python.el import managementkobarity1-1/+17
Added notes that when adding import statements for a file that does not belong to a project, it may take some time to find candidate import statements in the default directory. * lisp/progmodes/python.el (python-add-import) (python-fix-imports): Improve docstring. (Bug#74894)
2025-03-06(python-base-mode-map): Use it!Stefan Monnier1-4/+7
Rather than use `copy-keymap` between `python-mode-map` and `python-ts-mode-map`, move the shared bindings to `python-base-mode-map`. * lisp/progmodes/python.el (python-base-mode-map): Define it explicitly. Move all the bindings of `python-mode-map` to it. (python-mode-map, python-ts-mode-map): Inherit from it.
2025-03-02; Move python.el Maintainer header further upStefan Kangas1-1/+1
This is more consistent with our common practices.
2025-03-02Bump python.el package version to 0.29Stefan Kangas1-1/+1
* lisp/progmodes/python.el: Bump package version to 0.29.
2025-03-02Bump python.el requirement to Emacs 29.1Stefan Kangas1-1/+1
* lisp/progmodes/python.el: Require Emacs 26.3, flymake 1.0 and project 0.1. (Bug#75526)
2025-03-02Bump python.el requirement to Emacs 26.3Stefan Kangas1-2/+3
* lisp/progmodes/python.el: Require Emacs 26.3, flymake 1.0 and project 0.1. (Bug#75526)
2025-02-22; Fix typosStefan Kangas1-1/+1
2025-02-19Add python-ts-mode to ffap-alistkobarity1-3/+2
* lisp/progmodes/python.el (ffap-alist): Add python-ts-mode. (Bug#76364)
2025-02-18Disable PyREPL in Python shellLiu Hui1-0/+1
The new default REPL (PyREPL) in Python 3.13 is incompatible with Python shell and displays a warning message when reverting to the old basic REPL. * lisp/progmodes/python.el (python-shell--calculate-process-environment): Use the basic REPL. (Bug#76205)
2025-02-18Improve completion in IPython/Python 3.13kobarity1-0/+7
IPython/Python 3.13 indirectly imports rlcompleter, and the completer is set up to reference rlcompleter.__main__. However, this rlcompleter.__main__ is different from the __main__ in the REPL execution. Therefore, this completer cannot correctly complete the REPL globals. To address this issue, we override rlcompleter.__main__ with __main__ only in the case of IPython. * lisp/progmodes/python.el (python-shell-completion-native-setup): Modify __PYTHON_EL_native_completion_setup(). (Bug#76205)
2025-02-15Fix string end search in python-nav-end-of-statementkobarity1-2/+5
* lisp/progmodes/python.el (python-nav-end-of-statement): Change to look for string delimiter characters and check syntax, instead of looking for string-delimiter syntax. * test/lisp/progmodes/python-tests.el (python-nav-end-of-statement-5): New test. (Bug#75387)
2025-02-04Make it configurable to highlight Python 2 builtinskobarity1-106/+91
By default, Python 2-only builtins are not highlighted. * lisp/progmodes/python.el (python-2-support): New defcustom. (python-font-lock-builtin-types) (python-font-lock-builtins-python3) (python-font-lock-builtins-python2) (python-font-lock-builtins) (python-font-lock-special-attributes) (python-font-lock-builtin-exceptions-python3) (python-font-lock-builtin-exceptions-python2) (python-font-lock-builtin-exceptions): New variables. (python-font-lock-keywords-level-2) (python-font-lock-keywords-maximum-decoration) (python--treesit-builtin-types) (python--treesit-builtins) (python--treesit-special-attributes) (python--treesit-exceptions): Use new variables. Co-authored-by: Konstantin Kharlamov <Hi-Angel@yandex.ru> Co-authored-by: Stefan Kangas <stefankangas@gmail.com>
2025-01-30; * lisp/progmodes/python.el (treesit-node-prev-sibling): Declare.Eli Zaretskii1-0/+1
2025-01-29Add back tree-sitter declare-function for python.el (bug#75526)Yuan Fu1-1/+8
treesit-declare-unavailable-functions is not available for old emacs versions, but python.el is a core package available on ELPA. Remove the treesit-declare-unavailable-functions until compat.el releases a new version that contains it. * lisp/progmodes/python.el: Remove treesit-declare-unavailable-functions and add back declare-function forms.
2025-01-25python-mode: add 'exit' and 'quit' to the list of block-endersKonstantin Kharlamov1-4/+11
'exit()' and 'quit()' end the current codeflow, there can't be any code past it, similarly to 'return', 'continue', etc. So when calculating indentation for the line next to 'exit()', 'os.exit()', 'os._exit()', 'sys.exit()' and 'quit()', decrease the indentation level. * /lisp/progmodes/python.el (python-rx): Add 'exit()', 'os.exit()', 'os._exit()', 'sys.exit()', 'quit' to the list of block-enders. (Bug#75729)
2025-01-02Update copyright year to 2025Stefan Kangas1-1/+1
Run "TZ=UTC0 admin/update-copyright".
2025-01-01Update copyright year to 2025Paul Eggert1-1/+1
Run "TZ=UTC0 admin/update-copyright".
2024-12-18Make font-lock face variables obsoleteStefan Kangas1-3/+3
Using these variables as "another mechanism for changing face appearance" never really worked, since mode authors were free to use the face instead of the variable (i.e. quoting the symbol). This means that when users customized the variables, it would change its appearance only in some cases, which is a rather surprising interface. Indeed, it turns out that some modes have not always been consistent, and mixed using the variable and the face, increasing the confusion even further. Thus, the only thing users could rely on to always work was to leave the variables at their default value, and to customize the face. We now recommend customizing the face, and are obsoleting these variables. This will lead to some minor code-churn, but it is believed that it will be ultimately worth it. To fix existing Lisp code, you should typically only need to quote the symbol, as this commit shows. It might be the case that we will have to keep the obsolete variables, that have been with us since Emacs 19, around for a longer time-period than normal, to allow package authors to adapt. * lisp/font-lock.el (font-lock-comment-face) (font-lock-comment-delimiter-face, font-lock-string-face) (font-lock-doc-face, font-lock-doc-markup-face, font-lock-keyword-face) (font-lock-builtin-face, font-lock-function-name-face) (font-lock-variable-name-face, font-lock-type-face) (font-lock-constant-face, font-lock-warning-face) (font-lock-negation-char-face, font-lock-preprocessor-face): Make face variables obsolete in favor of customizing the faces directly instead. (Bug#71469) * doc/lispref/modes.texi (Faces for Font Lock): Don't document above obsolete variables. * lisp/cedet/data-debug.el (data-debug-insert-hash-table) (data-debug-insert-widget-properties, data-debug-insert-string) (data-debug-insert-number): * lisp/emacs-lisp/lisp-mode.el (elisp--font-lock-backslash) (lisp-font-lock-syntactic-face-function): * lisp/emacs-lisp/package.el (describe-package-1): * lisp/generic-x.el (rc-generic-mode, rul-generic-mode): * lisp/org/org-table.el (org-table-edit-formulas): * lisp/progmodes/cc-fonts.el (c-font-lock-invalid-single-quotes) (c-maybe-font-lock-wrong-style-comments, c-font-lock-declarators) (c-font-lock-c++-lambda-captures, c-font-lock-c++-modules): * lisp/progmodes/cperl-mode.el (cperl-find-sub-attrs) (cperl-look-at-leading-count, cperl-process-here-doc) (cperl-find-pods-heres): * lisp/progmodes/gdb-mi.el (gdb-init-1, gdb-update, gdb-running) (gdb-starting, gdb-stopped, gdb-internals) (gdb-breakpoints--add-breakpoint-row, gdb-locals-handler-custom) (gdb-registers-handler-custom, gdb-get-source-file): * lisp/progmodes/js.el (js--font-lock-keywords-1) (js--font-lock-keywords-2, js-font-lock-syntactic-face-function): * lisp/progmodes/lua-ts-mode.el (lua-ts--comment-font-lock): * lisp/progmodes/meta-mode.el (meta-indent-in-string-p): * lisp/progmodes/prolog.el (prolog-font-lock-keywords): * lisp/progmodes/python.el (python-font-lock-syntactic-face-function): * lisp/progmodes/ruby-ts-mode.el (ruby-ts--comment-font-lock): * lisp/progmodes/sh-script.el (sh-font-lock-syntactic-face-function): * lisp/textmodes/tex-mode.el (doctex-font-lock-syntactic-face-function): * test/lisp/faces-tests.el (faces--test-color-at-point): * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-extra-delimiters) (cperl-test-bug-47112, cperl-test-bug-65834, cperl-test-bug-66145) (cperl-test-bug-66161, cperl-test-bug-69604): * test/lisp/progmodes/python-tests.el (python-ts-mode-compound-keywords-face) (python-ts-mode-named-assignment-face-1) (python-ts-mode-assignment-face-2, python-ts-mode-nested-types-face-1) (python-ts-mode-union-types-face-1, python-ts-mode-union-types-face-2) (python-ts-mode-types-face-1, python-ts-mode-types-face-2) (python-ts-mode-types-face-3, python-ts-mode-isinstance-type-face-1) (python-ts-mode-isinstance-type-face-2) (python-ts-mode-isinstance-type-face-3) (python-ts-mode-superclass-type-face, python-ts-mode-class-patterns-face) (python-ts-mode-dotted-decorator-face-1) (python-ts-mode-dotted-decorator-face-2) (python-ts-mode-builtin-call-face) (python-ts-mode-interpolation-nested-string) (python-ts-mode-level-fontification-wo-interpolation) (python-ts-mode-disabled-string-interpolation) (python-ts-mode-interpolation-doc-string): * test/lisp/progmodes/ruby-mode-tests.el (ruby-heredoc-font-lock, ruby-heredoc-highlights-interpolations) (ruby-exit!-font-lock, ruby-regexp-interpolation-is-highlighted) (ruby-recognize-symbols-starting-with-at-character) (ruby-hash-character-not-interpolation) (ruby-interpolation-suppresses-quotes-inside) (ruby-interpolation-suppresses-one-double-quote) (ruby-interpolation-inside-percent-literal) (ruby-interpolation-inside-percent-literal-with-paren) (ruby-interpolation-inside-another-interpolation) (ruby-interpolation-inside-double-quoted-percent-literals) (ruby-no-interpolation-in-single-quoted-literals): Don't use above obsolete variables. * lisp/progmodes/cc-fonts.el (font-lock-constant-face): Don't declare now-unused variable.
2024-12-17Fix treesit-font-lock-level in python-ts-modeVincenzo Pupillo1-1/+2
Now that 'treesit-font-lock-level' can be a number or a list, it should be handled using 'treesit--compute-font-lock-level'. * lisp/progmodes/python.el (python--treesit-fontify-string): Apply 'treesit--compute-font-lock-level' to 'treesit-font-lock-level'.
2024-12-16Ignore some more Python tooling directories when greppingStefan Kangas1-1/+2
* lisp/progmodes/python.el (python-base-mode): Add Pytest and Rope cache directories to 'grep-find-ignored-directories'.
2024-12-16Improve heuristic for Python walrus operatorStefan Kangas1-3/+2
* lisp/progmodes/python.el (python-base-mode): Improve heuristic for Python walrus operator in 'electric-layout-mode'.