aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el (unfollow)
Commit message (Collapse)AuthorFilesLines
5 daysImprove Python setup codes to avoid leaving global nameskobarity1-13/+21
* lisp/progmodes/python.el (python-shell-setup-code) (python-shell-readline-detect): Improve Python code. (Bug#80551)
2026-02-21Use a custom Pdb class in the Python shellLiu Hui1-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)
2026-02-19Remove (featurep 'project) guards in python.elkobarity1-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)
2026-02-13Revert "Use 'project-name-cached' in 'python-shell-get-process-name'"kobarity1-12/+5
This reverts commit 482748592f61abed6f675e7b62b2d56e4e18a146. Commit 583a112169f0c964552b94f84ea0c942377a14e6 removed 'project-name-cached' and also resolved bug#80045.
2026-02-07Change the type of 'python-eldoc-function-timeout' to numberkobarity1-1/+1
* etc/NEWS: Announce the change. * lisp/progmodes/python.el (python-eldoc-function-timeout): Change the type. (Bug#80045)
2026-02-07Use 'project-name-cached' in 'python-shell-get-process-name'kobarity1-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>
2026-02-07Revert "Performance improvement of 'python-shell-get-process'"kobarity1-20/+1
This reverts commit 83b4f1ba26844c178e57ecb93ea8db36e8e6fa89. We concluded that it is better to use 'project-name-cached'. (Bug#80045)
2026-01-21Fix down-list navigation in python-ts-modeJuri Linkov1-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.
2026-01-17Performance improvement of 'python-shell-get-process'kobarity1-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)
2026-01-17Improve non-native completion in Python modekobarity1-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)
2026-01-03Do not use codecs.open for Python 3kobarity1-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)
2026-01-03Improve python-shell-completion-get-completionskobarity1-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)
2026-01-01; Add 2026 to copyright years.Sean Whitton1-1/+1
2025-12-28Fix specification of 'python-indent-guess-indent-offset-verbose'Morgan Willcock1-1/+1
* lisp/progmodes/python.el (python-indent-guess-indent-offset-verbose): Fix typo in configuration of safe value function. (Bug#80085)
2025-11-09hideshow: Rework previous changesElías Gabriel Pérez1-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.
2025-11-08hideshow: Rework previous changesElías Gabriel Pérez1-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'.
2025-11-06hideshow: Rework previous changesElías Gabriel Pérez1-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.
2025-11-04; Fix documentation of a recent changeEli Zaretskii1-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)
2025-11-04hideshow: Rewrite 'hs-special-modes-alist'Elías Gabriel Pérez1-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.
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.