aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Improve Python setup codes to avoid leaving global nameskobarity3 days1-13/+21
| | | | | * lisp/progmodes/python.el (python-shell-setup-code) (python-shell-readline-detect): Improve Python code. (Bug#80551)
* Use a custom Pdb class in the Python shellLiu Hui2026-02-211-127/+155
| | | | | | | | | | | | | | | | | | | | | | | | The custom Pdb class enables native completion in pdb by wrapping the pdb's native completer. It also makes necessary function definitions like __PYTHON_EL_* available between pdb frames, and enables non-native completion/ffap/eldoc functionalities when debugging inside python modules. * lisp/progmodes/python.el (python-shell-send-setup-code): Fix the separator between python-shell-setup-codes. (python-shell-completion-native-setup): Move common completion setup code ... (python-shell-completion-setup-code): ... here. (python-shell-completion-at-point): Enable native completion for pdb and respect the delimiter of pdb completer. (python-shell-pdb-setup-code): New variable. (python-shell-comint-watch-for-first-prompt-output-filter): Send setup codes only once. (python-ffap-module-path, python-eldoc--get-doc-at-point): Stop sending setup code in every function call. * test/lisp/progmodes/python-tests.el (python-tests--pdb-1) (python-shell-pdb-1): New test. * etc/NEWS: Mention the change. (bug#80182)
* Remove (featurep 'project) guards in python.elkobarity2026-02-191-10/+5
| | | | | | | | | | * lisp/progmodes/python.el: Since they are included in emacs 29.1, remove the Package-Requires for seq, project, and flymake. (require 'project): Remove 'noerror argument. (python-shell-get-process-name): Remove (featurep 'project). Use 'project-name'. (run-python) (python--import-sources): Remove (featurep 'project). (Bug#80405)
* Revert "Use 'project-name-cached' in 'python-shell-get-process-name'"kobarity2026-02-131-12/+5
| | | | | | | This reverts commit 482748592f61abed6f675e7b62b2d56e4e18a146. Commit 583a112169f0c964552b94f84ea0c942377a14e6 removed 'project-name-cached' and also resolved bug#80045.
* Change the type of 'python-eldoc-function-timeout' to numberkobarity2026-02-071-1/+1
| | | | | | * etc/NEWS: Announce the change. * lisp/progmodes/python.el (python-eldoc-function-timeout): Change the type. (Bug#80045)
* Use 'project-name-cached' in 'python-shell-get-process-name'kobarity2026-02-071-5/+12
| | | | | | | | * lisp/progmodes/python.el (python-shell-get-project-name): New function. (python-shell-get-process-name): Use it. (Bug#80045) Co-authored-by: Liu Hui <liuhui1610@gmail.com>
* Revert "Performance improvement of 'python-shell-get-process'"kobarity2026-02-071-20/+1
| | | | | | This reverts commit 83b4f1ba26844c178e57ecb93ea8db36e8e6fa89. We concluded that it is better to use 'project-name-cached'. (Bug#80045)
* Fix down-list navigation in python-ts-modeJuri Linkov2026-01-211-1/+2
| | | | | | | | * lisp/progmodes/python.el (python-ts-mode): Set 'treesit-sexp-thing-down-list' to 'list' to override sexp navigation with list navigation (bug#72478). * lisp/emacs-lisp/lisp.el (up-list): Mention 'up-list-function' in docstring.
* Performance improvement of 'python-shell-get-process'kobarity2026-01-171-1/+20
| | | | | | | | | | | | | | | | 'python-shell-get-process' is frequently called from 'python-eldoc--get-doc-at-point' and etc., invoking 'project-current' unless there is a buffer-specific Inferior Python process. When the buffer is a remote buffer not belonging to any project and has significant latency, 'project-current' may take a long time. To avoid this, implement a process cache in 'python-shell-get-process'. * lisp/progmodes/python.el (python-shell--process-cache) (python-shell--process-cache-valid): New variables. (python-shell--invalidate-process-cache): New function. (python-shell-make-comint): Add a call to the above function. (python-shell-get-process): Add process cache. (Bug#80045)
* Improve non-native completion in Python modekobarity2026-01-171-2/+8
| | | | | | | | | | | | | | | | | Previously, both the definition of __PYTHON_EL_get_completions and the call to __PYTHON_EL_get_completions were sent to the inferior Python each time 'python-shell-completion-get-completions' was executed. However, there is no need to send the definition every time as long as the definition remains unchanged. We improved this so that the definition of __PYTHON_EL_get_completions is only sent during the inferior Python initialization; it is no longer sent during 'python-shell-completion-get-completions' execution. * lisp/progmodes/python.el (python-shell-completion-send-setup-code): New function. (python-shell-first-prompt-hook): Add the above new function. (python-shell-completion-get-completions): Omit sending 'python-shell-completion-setup-code'. (Bug#80182)
* Do not use codecs.open for Python 3kobarity2026-01-031-3/+8
| | | | | | * lisp/progmodes/python.el (python-shell-eval-file-setup-code): For Python 3, use built-in open instead of codecs.open to address the deprecation of codecs.open in Python 3.14. (Bug#79723)
* Improve python-shell-completion-get-completionskobarity2026-01-031-6/+11
| | | | | | | | | | | | In 'python-shell-completion-get-completions', since output from the inferior Python is expected to be in JSON format, commands being echoed back or warning messages being output caused parsing errors. We improved this by re-parsing only the last line when a parsing error occurs, preventing echo-back or warning messages from affecting parsing. * lisp/progmodes/python.el (python-shell-completion-get-completions): Improved to re-parse only the last line when a JSON parse error occurs. (Bug#79723)
* ; Add 2026 to copyright years.Sean Whitton2026-01-011-1/+1
|
* Fix specification of 'python-indent-guess-indent-offset-verbose'Morgan Willcock2025-12-281-1/+1
| | | | | * lisp/progmodes/python.el (python-indent-guess-indent-offset-verbose): Fix typo in configuration of safe value function. (Bug#80085)
* hideshow: Rework previous changesElías Gabriel Pérez2025-11-091-11/+27
| | | | | | * lisp/progmodes/hideshow.el (hs-grok-mode-type): Improve 'hs--set-variable'. * lisp/progmodes/python.el (python-base-mode, python-ts-mode): Provide backward-compatibility for older versions.
* hideshow: Rework previous changesElías Gabriel Pérez2025-11-081-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | * lisp/progmodes/hideshow.el: Set default values of buffer-local variables. (hs-inside-comment-p): Restore. (hs--set-variable): Rename from 'hs--get-mode-value'. (hs-grok-mode-type): Rework. * lisp/nxml/nxml-mode.el: * lisp/progmodes/f90.el: * lisp/progmodes/fortran.el: * lisp/progmodes/icon.el: * lisp/progmodes/lua-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/verilog-mode.el: * lisp/progmodes/vhdl-mode.el: * lisp/textmodes/mhtml-mode.el: * lisp/textmodes/sgml-mode.el: * lisp/treesit.el (treesit-major-mode-setup): Rename 'hs-forward-sexp-func' to 'hs-forward-sexp-function', 'hs-adjust-block-beginning' to 'hs-adjust-block-beginning-function', 'hs-find-block-beginning-func' to 'hs-find-block-beginning-function', 'hs-find-next-block-func' to 'hs-find-next-block-function', 'hs-looking-at-block-start-p-func' to 'hs-looking-at-block-start-predicate', 'hs-inside-comment-p-func' to 'hs-inside-comment-predicate'.
* hideshow: Rework previous changesElías Gabriel Pérez2025-11-061-18/+12
| | | | | | | | | | | | | | | | | | | | | | | | | * doc/emacs/programs.texi (Hideshow): * etc/NEWS: Fix doc. * lisp/progmodes/hideshow.el: Update Commentary Header. (hs-modes-alist): Remove. (hs--get-mode-value, hs-grok-mode-type): Rework. * lisp/treesit.el (treesit-major-mode-setup): * lisp/emacs-lisp/lisp-mode.el: * lisp/nxml/nxml-mode.el: * lisp/progmodes/cc-mode.el: * lisp/progmodes/f90.el: * lisp/progmodes/fortran.el: * lisp/progmodes/hideshow.el: * lisp/progmodes/icon.el: * lisp/progmodes/js.el: * lisp/progmodes/lua-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/verilog-mode.el: * lisp/progmodes/vhdl-mode.el: * lisp/textmodes/bibtex.el: * lisp/textmodes/mhtml-mode.el: * lisp/textmodes/sgml-mode.el: * lisp/treesit.el: Fix and rework previous changes.
* ; Fix documentation of a recent changeEli Zaretskii2025-11-041-1/+1
| | | | | | | * lisp/progmodes/python.el (python-ts-hs-adjust-block-end-fn): * lisp/progmodes/hideshow.el (hs-modes-alist) (hs-adjust-block-end, hs-inside-comment-p-func): Doc fixes. (bug#79671)
* hideshow: Rewrite 'hs-special-modes-alist'Elías Gabriel Pérez2025-11-041-15/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewrite the format in 'hs-special-modes-alist' to make easier to exclude some values, add support for settings inheritance according to current major mode and parents, and support string hiding for lisp modes. Bug#79671 * lisp/progmodes/hideshow.el (hs-modes-alist): New variable. (hs-special-modes-alist): Mark as obsolete. (hs-forward-sexp-func, hs-adjust-block-beginning) (hs-find-block-beginning-func, hs-find-next-block-func) (hs-looking-at-block-start-p-func): Set default values to nil. (hs-inside-comment-p): Remove function. (hs-adjust-block-end, hs-treesit-things): New buffer-local variables. (hs-block-positions): Minor updates. (hs--get-mode-value): New function. (hs-grok-mode-type): Rewrite. * lisp/progmodes/f90.el (hs-special-modes-alist): * lisp/progmodes/fortran.el (hs-special-modes-alist): * lisp/progmodes/icon.el (icon-mode): * lisp/progmodes/lua-mode.el (lua-mode): * lisp/progmodes/python.el (python-base-mode): * lisp/progmodes/verilog-mode.el (verilog-mode): * lisp/progmodes/vhdl-mode.el (vhdl-hs-minor-mode): Rewrite settings. * lisp/progmodes/python.el (python-ts-hs-adjust-block-end-fn): New function. * lisp/treesit.el (treesit-hs-block-end) (treesit-hs-find-block-beginning, treesit-hs-find-next-block) (treesit-hs-looking-at-block-start-p): Minor updates. * doc/emacs/programs.texi (Hideshow): * etc/NEWS: Document changes.
* Check if treesit-major-mode-remap-alist is bound in ts-modes autoload formsJuri Linkov2025-10-161-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)
* ; Avoid byte-compiler warnings in python.elEli Zaretskii2025-09-251-0/+2
| | | | | * lisp/progmodes/python.el (treesit-node-prev-sibling) (treesit-node-field-name-for-child): Declare.
* Fix infloop in python-ts-mode string fontification (bug#79457)Yuan Fu2025-09-241-6/+7
| | | | | * lisp/progmodes/python.el (python--treesit-fontify-string): Make sure there's no infloop.
* Fix python-ts-mode font-lock breakage by grammar change (bug#79457)Yuan Fu2025-09-221-30/+37
| | | | | * lisp/progmodes/python.el (python--treesit-fontify-string): Use new algorithm.
* Fix command keys in doc string of 'inferior-python-mode'Eli Zaretskii2025-09-061-1/+1
| | | | | * lisp/progmodes/python.el (inferior-python-mode): Mention the correct mode-map in the doc string. (Bug#79386)
* * lisp/progmodes/python.el: Use 'treesit-major-mode-remap-alist'.Juri Linkov2025-08-291-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'.
* Fix Python PDB tracking for remote inferior Pythonkobarity2025-08-071-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)
* Improve region deletion handling in python.elJakub Ječmínek2025-08-021-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.
* Improve treesit settings for python-ts-mode (bug#73404).Juri Linkov2025-06-251-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'.
* ; * lisp/progmodes/python.el (treesit-thing-settings): Defvar.Eli Zaretskii2025-06-211-0/+1
|
* python-ts-mode: Improve fontificationJostein Kjønigsen2025-06-211-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)
* Use keyword :commit with full hashes for treesit-language-source-alist.Juri Linkov2025-06-201-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.
* Use treesit-thing-settings in python-ts-modeYuan Fu2025-06-171-17/+19
| | | | | * lisp/progmodes/python.el (python--thing-settings): New variable. (python-ts-mode): Setup treesit-thing-settings.
* Add 'treesit-sexp-thing' to use instead of 'treesit-sexp-type-regexp'.Juri Linkov2025-06-121-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
* Fix test-regressions in python-ts-modeJostein Kjønigsen2025-05-051-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.
* Improve python-ts-mode fontification (bug#78129)Jostein Kjønigsen2025-05-011-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.
* Add python tree-sitter grammar data to 'treesit-language-source-alist'.Juri Linkov2025-04-301-1/+8
| | | | | * lisp/progmodes/python.el (python-ts-mode): Use 'treesit-ensure-installed' when it's fboundp.
* Fix filename completion in Python shell (bug#77853)Liu Hui2025-04-261-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'.
* Add cache to Python block navigation functionskobarity2025-04-261-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)
* Performance optimization of 'python-info-statement-ends-block-p'kobarity2025-04-261-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)
* Fix Python block end predicates (bug#77941)kobarity2025-04-261-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.
* Disable echo back instead of setting tty to raw in Inferior Pythonkobarity2025-04-171-2/+4
| | | | | * lisp/progmodes/python.el (python-shell-setup-code): Change the Python setup code. (Bug#76943)
* Add repeat-map for Python indentation commandsPaul Nelson2025-04-041-0/+7
| | | | | | * lisp/progmodes/python.el (python-indent-repeat-map): New keymap for repeating Python indentation commands when using 'repeat-mode' (bug#77417).
* Replace uses of `replace-buffer-contents`Stefan Monnier2025-03-291-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`.
* ElDoc: Add more commands using 'eldoc-add-command-completions'James Cherti2025-03-221-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
* Bump python.el package version to 0.30Stefan Kangas2025-03-111-1/+1
| | | | * lisp/progmodes/python.el: Bump package version to 0.30.
* Make python.el compatible with Emacs 29.1Stefan Kangas2025-03-111-5/+8
| | | | | | * lisp/progmodes/python.el (python--treesit-fontify-string): Don't call treesit--compute-font-lock-level unless it is fboundp. (Bug#76873)
* Merge from origin/emacs-30Eli Zaretskii2025-03-091-1/+17
|\ | | | | | | | | | | | | af8017b23f6 Explicitly document read-string return value cf03c2b6093 Improve docstrings of python.el import management 01bcc6961a6 ; Improve doc strings of Speedbar bd9c76ab175 Avoid warnings about 'image-scaling-factor' in builds --w...
| * Improve docstrings of python.el import managementkobarity2025-03-071-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)
| * Update copyright year to 2025Stefan Kangas2025-01-021-1/+1
| | | | | | | | Run "TZ=UTC0 admin/update-copyright".
| * Revert "Set treesit-primary-parser for tree-sitter modes"Yuan Fu2024-10-081-1/+1
| | | | | | | | This reverts commit ed57faafc74e0810b492841deccb3cdc77a258ff.