aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el (unfollow)
Commit message (Collapse)AuthorFilesLines
2024-02-11Add the public API of Compat to the corePhilip Kaludercic1-1/+1
* lisp/emacs-lisp/compat.el: Add stub file with minimal definitions, so that core packages, that haven't been installed from ELPA, can make use of the public API and use more recent function signatures. * lisp/progmodes/python.el (compat): Remove 'noerror flag, because Compat can now be required without the real package being available. * doc/lispref/package.texi (Forwards-Compatibility): Mention Compat and link to the manual. * etc/NEWS: Document change. (Bug#66554)
2024-02-08Respect the delimiter of completer in Python shell completionLiu Hui1-48/+172
* lisp/progmodes/python.el: (python-shell-completion-setup-code): Fix the completion code of IPython. Change the return value to JSON string and ... (python-shell-completion-get-completions): ... simplify parsing. (inferior-python-mode): Update docstring. (python-shell-readline-completer-delims): New variable indicating the word delimiters of readline completer. (python-shell-completion-native-setup): Set the completer delimiter. (python-shell-completion-native-get-completions): Convert output string to completions properly. (python-shell--get-multiline-input) (python-shell--extra-completion-context) (python-shell-completion-extra-context): New functions. (python-shell-completion-at-point): Send text beginning from the line start if the completion backend does not need word splitting. Remove the detection of import statement because it is not needed anymore. Create proper completion table based on completions returned from different backends. * test/lisp/progmodes/python-tests.el (python-tests--completion-module) (python-tests--completion-parameters) (python-tests--completion-extra-context): New helper functions. (python-shell-completion-at-point-jedi-completer) (python-shell-completion-at-point-ipython): New tests. (bug#68559)
2024-01-27Fix syntax highlighting after string literal concat in python-modeJakub Ječmínek1-0/+3
* lisp/progmodes/python.el (python-syntax-stringify): Fix incorrect font-lock after string literal concatenation. (Bug#45897) * test/lisp/progmodes/python-tests.el (python-font-lock-string-literal-concatenation): New test. Co-authored-by: kobarity <kobarity@gmail.com> Copyright-paperwork-exempt: yes
2024-01-26python--treesit-syntax-propertize: Fix edits in the middleDmitry Gutov1-9/+9
* lisp/progmodes/python.el (python--treesit-syntax-propertize): Process the beginning and the end of the triple-quoted string's delimiters separately. Among other things, that still works when the beginning is outside of the propertized region (bug#68445).
2024-01-13Fix 'python-info-docstring-p' bug in the 2nd line of a bufferkobarity1-1/+3
* lisp/progmodes/python.el (python-info-docstring-p): Add 'looking-at-p' check when bobp. * test/lisp/progmodes/python-tests.el (python-font-lock-operator-1) (python-font-lock-operator-2): Restoration of ERTs deleted by mistake. (python-font-lock-escape-sequence-bytes-newline) (python-font-lock-escape-sequence-hex-octal) (python-font-lock-escape-sequence-unicode) (python-font-lock-raw-escape-sequence): Change 'font-lock-doc-face' to 'font-lock-string-face' and remove :expected-result :failed. (python-info-docstring-p-8): New test. (Bug#68284)
2024-01-11; Fix typosStefan Kangas1-2/+2
2024-01-02; Add 2024 to copyright yearsPo Lu1-1/+1
2023-12-30Improve syntax highlighting for python-ts-modeDenis Zubarev1-62/+178
Fix fontification of strings inside of f-strings interpolation, e.g. for f"beg {'nested'}" - 'nested' was not fontified as string. Do not override the face of builtin functions (all, bytes etc.) with the function call face. Add missing assignment expressions (:= *=). Fontify built-ins (dict,list,etc.) as types when they are used in type hints. Highlight union types (type1|type2). Highlight base class names in the class definition. Fontify class patterns in case statements. Highlight the second argument as a type in isinstance/issubclass call. Highlight dotted decorator names. * lisp/progmodes/python.el (python--treesit-keywords): Add compound keyword "is not". (python--treesit-builtin-types): New variable that stores all python built-in types. (python--treesit-type-regex): New variable. Regex matches if text is either built-in type or text starts with capital letter. (python--treesit-builtins): Extract built-in types to other variable. (python--treesit-fontify-string): fix f-string interpolation. Enable interpolation highlighting only if string-interpolation is presented on the enabled levels of treesit-font-lock-feature-list. (python--treesit-fontify-string-interpolation): Remove function. (python--treesit-fontify-union-types): Fontify nested union types. (python--treesit-fontify-union-types-strict): Fontify nested union types, only if type identifier matches against python--treesit-type-regex. (python--treesit-fontify-dotted-decorator): Fontify all parts of dotted decorator name. (python--treesit-settings): Change/add rules. (Bug#67061) * test/lisp/progmodes/python-tests.el (python-ts-tests-with-temp-buffer): Function for setting up test buffer. (python-ts-mode-compound-keywords-face) (python-ts-mode-named-assignement-face-1) (python-ts-mode-assignement-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-disabled-string-interpolation) (python-ts-mode-interpolation-doc-string): Add tests.
2023-12-23Fix python-ts-mode triple quote syntax (bug#67262)Yuan Fu1-0/+17
* lisp/progmodes/python.el (python--treesit-syntax-propertize): New function. (python-ts-mode): Activate python--treesit-syntax-propertize.
2023-12-11python-ts-mode: Highlight default parametersMaciej Kalandyk1-1/+2
* lisp/progmodes/python.el (python--treesit-settings): Highlight default parameters (bug#67703).
2023-11-24Make python-ts-mode's syntax-highlighting more standardizedDmitry Gutov1-3/+3
This was brought up in a Reddit discussion. * lisp/progmodes/python.el (python--treesit-fontify-variable): Use font-lock-variable-use-face (since it applies to references). (python-ts-mode): Move 'property' from 3rd to 4th treesit-font-lock-level.
2023-11-18Add missing python-ts-mode keyword (bug#67015)Yuan Fu1-1/+1
* lisp/progmodes/python.el (python--treesit-keywords): Add "not in".
2023-10-01; Add missing GNU ELPA :core package statementsStefan Kangas1-0/+3
* lisp/bind-key.el: * lisp/emacs-lisp/map.el: * lisp/erc/erc.el: * lisp/external-completion.el: * lisp/net/ntlm.el: * lisp/net/soap-client.el: * lisp/progmodes/python.el: * lisp/svg.el: * lisp/use-package/use-package.el: Add GNU ELPA :core package statements.
2023-08-08; Fix typoStefan Kangas1-1/+1
2023-08-08Open Pipfile and flake8 config files in conf-modeStefan Kangas1-0/+4
* lisp/progmodes/python.el (auto-mode-alist): Open Pipfile and flake8 configuration files in conf-mode.
2023-08-04Add ruff and flake8 to python-check-commandStefan Kangas1-1/+3
* lisp/progmodes/python.el (python-check-command): Add ruff and flake8.
2023-07-20Custom var python-interpreter-args (bug#64397)Matthias Meulien1-18/+41
* lisp/progmodes/python.el (python-interpreter): Mention new variable in documentation. (python-interpreter-args): New custom variable. (python-shell-interpreter, python-shell-interpreter-args) (python-shell-interpreter-interactive-arg): Improve documentation. (python--list-imports, python--do-isort) (python-fix-imports): Make process use customisable arguments.
2023-07-15Fix "Improve Python imports management commands"Matthias Meulien1-14/+15
* lisp/progmodes/python.el (python--list-imports): Prefer to use an exit status >1. (python--list-imports-check-status): New function to check status of Python script. (python--do-isort): Fix wrong status check introduced with 6295d7abdd4. (Bug#64406)
2023-07-06Improve Python imports management commandsMatthias Meulien1-4/+18
* lisp/progmodes/python.el (python--list-imports): Handle import errors. (python--do-isort): Specialize error message. (Bug#64406)
2023-06-24Fix Python indentation of continuation lines within parenskobarity1-2/+24
* lisp/progmodes/python.el (python-indent-context): Add a new indent context `:inside-paren-continuation-line'. (python-indent--calculate-indentation): Use the new indent context. * test/lisp/progmodes/python-tests.el (python-indent-pep8-2) (python-indent-pep8-3) (python-indent-inside-paren-1) (python-indent-inside-paren-2) (python-indent-inside-paren-3) (python-indent-inside-paren-6) (python-indent-after-backslash-2): Change to use the new indent context. (python-indent-inside-paren-8) (python-indent-inside-paren-9): New tests. (Bug#63959)
2023-06-13Fix bol/bos anchors in tree-sitter :match regexpsBasil L. Contovounesios1-1/+1
Further regexp fixes to follow separately (bug#64019#29). * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode--font-lock-settings): * lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings): * lisp/progmodes/js.el (js--treesit-font-lock-settings): * lisp/progmodes/python.el (python--treesit-settings): * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--font-lock-settings): * lisp/progmodes/sh-script.el (sh-mode--treesit-settings): * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--font-lock-settings): * test/src/treesit-tests.el (treesit-query-api): Anchor :match regexps at beginning/end of string, not line.
2023-06-03Fix 'python-util-clone-local-variables'Eli Zaretskii1-1/+2
* lisp/progmodes/python.el (python-util-clone-local-variables): Avoid signaling an error when a local variable is unbound. Patch by Ernesto Alfonso <erjoalgo@gmail.com>. (Bug#63818)
2023-06-03Revert "Enhance Python font-lock to support multilines"kobarity1-34/+15
This reverts commit 4915ca5dd4245a909c046e6691e8d4a1919890c8. We have found that there are performance issues when editing a large file. The issue can be reproduced as follows: 1. emacs -Q 2. Open large Python file (e.g. turtle.py in Python) 3. Near the top of the buffer, enter open paren and some characters. The above commit extends the region to be font-locked using `python-nav-end-of-statement'. However, if there are unbalanced parens, it may move point to the end of the buffer. This causes almost the entire buffer to be font-locked, which is not acceptable for large files.
2023-05-26Use 'font-lock-extend-region-functions' in python-modekobarity1-15/+19
* lisp/progmodes/python.el (python-font-lock-extend-region): Change arguments and return value for 'font-lock-extend-region-functions'. (python-mode): Change from 'font-lock-extend-after-change-region-function' to 'font-lock-extend-region-functions'. (Bug#63622)
2023-05-26Fix python-info-docstring-pkobarity1-5/+2
* lisp/progmodes/python.el (python-info-docstring-p): Stop using python-rx string-delimiter. * test/lisp/progmodes/python-tests.el (python-font-lock-escape-sequence-bytes-newline) (python-font-lock-escape-sequence-hex-octal) (python-font-lock-escape-sequence-unicode) (python-font-lock-raw-escape-sequence): Mark as expected failures until another bug in 'python-info-docstring-p' is corrected. (python-info-docstring-p-7): New test. (Bug#63622)
2023-05-20Fix Skeletons menu-bar menu in Python modesEli Zaretskii1-2/+4
* lisp/progmodes/python.el (python-mode, python-ts-mode): Call 'python-skeleton-add-menu-items' here, not in 'python-base-mode', since the "Python" menu is not yet set up in the latter. (Bug#63598)
2023-05-18Simplify python.el completion-predicateBasil L. Contovounesios1-16/+6
* lisp/progmodes/python.el: (python-skeleton-define): Use command-modes as a shorthand for completion-predicate (bug#63552). (python--completion-predicate, python-shell--completion-predicate): Remove accordingly; no longer used. (python-define-auxiliary-skeleton): Prefer function-put over put.
2023-05-17Fix M-x completion-predicate under python-ts-modeBasil L. Contovounesios1-2/+2
* lisp/progmodes/python.el (python--completion-predicate) (python-shell--completion-predicate): Filter M-x completion based on python-base-mode instead of python-mode. This allows for python-ts-mode as well (bug#63552).
2023-05-01Declare `cl-delete` to have important-return-value (bug#61730)Mattias Engdegård1-2/+1
* lisp/emacs-lisp/cl-macs.el: Set property on `cl-delete`. * lisp/progmodes/python.el (python-shell--add-to-path-with-priority): Prevent warning by cleaner code.
2023-04-22Improve docstring of python-indent-def-block-scalekobarity1-1/+24
* lisp/progmodes/python.el (python-indent-def-block-scale): Improve docstring. (Bug#62696)
2023-04-22Add a new user option in Python mode to improve the indentationkobarity1-7/+50
* lisp/progmodes/python.el (python-indent-block-paren-deeper): New user option. (python-indent-context): Add a new context :inside-paren-from-block. (python-indent--calculate-indentation): Modify according to `python-indent-block-paren-deeper' and :inside-paren-from-block. * test/lisp/progmodes/python-tests.el (python-indent-inside-paren-block-1) (python-indent-inside-paren-block-2) (python-indent-inside-paren-block-3) (python-indent-inside-paren-block-4): New tests. (python-indent-inside-paren-5, python-indent-dedenters-8): Modify according to the new context. * etc/NEWS: Document the new user option. (Bug#62696)
2023-03-26Improve indenting "case" in Pythonkobarity1-1/+8
* lisp/progmodes/python.el (python-info-dedenter-statement-p): Do not consider the first "case" in the block as dedenter. * test/lisp/progmodes/python-tests.el (python-info-dedenter-opening-block-positions-7) (python-info-dedenter-statement-p-6): New tests. (Bug#62092)
2023-03-16Fix python-fill-paragraph problems on filling strings (bug#62142)kobarity1-8/+27
* lisp/progmodes/python.el (python-syntax--context-compiler-macro) (python-syntax-context): Add single-quoted-string and triple-quoted-string as TYPE argument. (python-info-triple-quoted-string-p): New helper function. (python-fill-paragraph) (python-fill-string): Use it. * test/lisp/progmodes/python-tests.el (python-syntax-context-1) (python-fill-paragraph-single-quoted-string-1) (python-fill-paragraph-single-quoted-string-2) (python-fill-paragraph-triple-quoted-string-1) (python-info-triple-quoted-string-p-1) (python-info-triple-quoted-string-p-2) (python-info-triple-quoted-string-p-3): New tests.
2023-03-11Make "case" keyword a dedenter in Pythonkobarity1-2/+3
* lisp/progmodes/python.el (python-rx): Add "case" to dedenter. (python-info-dedenter-opening-block-positions): Add "case" to pairs. * test/lisp/progmodes/python-tests.el (python-indent-dedenters-9): New test.
2023-03-09python-info-dedenter-opening-block-positions: Fix to support "bare" matchDmitry Gutov1-1/+3
* lisp/progmodes/python.el (python-info-dedenter-opening-block-positions): Make the check stricter. Require that block starts only at indentation. * test/lisp/progmodes/python-tests.el (python-indent-after-bare-match): Another test (bug#62031).
2023-03-09Revert workaround introduced in Bug#56271kobarity1-8/+1
* lisp/progmodes/python.el (python-nav-end-of-statement) (python-nav-end-of-block): Revert workaround introduced in Bug#56271 as the bug is fixedin Bug#58780.
2023-03-09Fix searching for end of string in python-nav-end-of-statementkobarity1-4/+10
* lisp/progmodes/python.el (python-nav-end-of-statement): Add searching for corresponding string-quote. * test/lisp/progmodes/python-tests.el (python-nav-end-of-statement-3) (python-nav-end-of-statement-4, python-info-current-defun-4): New tests. (Bug#58780)
2023-03-09Avoid potential infloopDmitry Gutov1-3/+3
* lisp/progmodes/python.el (python-info-dedenter-opening-block-positions): Avoid potential infloop (bug#62031).
2023-03-08Don't misindent 'else:' after 'if re.match:' in PythonDmitry Gutov1-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>
2023-02-28Rename the newly added -ref- faces to -use-Dmitry Gutov1-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).
2023-02-26python-ts-mode: Fix single-quote string fontificationDmitry Gutov1-1/+1
* lisp/progmodes/python.el (python--treesit-fontify-string): Look for ', not just ", as opening delimiter (bug#61796).
2023-02-25Add more/finer faces for tree-sitterDmitry Gutov1-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.
2023-02-22* lisp/progmodes/python.el (python--import-sources): Fix regexp (bug#61648)Augusto Stoffel1-1/+1
2023-02-18Fix point moving when calling python-shell-send-regionkobarity1-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)
2023-01-28python.el: Use correct regexp when enabling python-ts-modeBrian Leung1-2/+2
* lisp/progmodes/python.el: Use "python[0-9.]*" regexp for 'interpreter-mode-alist', and not 'auto-mode-alist'. (Bug#61090)
2023-01-20Make tree-sitter based modes optionalEli Zaretskii1-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)
2023-01-07Fix string fontification on python-ts-mode (bug#60599)Yuan Fu1-2/+5
* lisp/progmodes/python.el: (python--treesit-fontify-string): Generalize and skip anything before the first quote character.
2023-01-07Fix string-interpolation feature of python-ts-mode (bug#60599)Yuan Fu1-2/+18
* lisp/progmodes/python.el: (python--treesit-fontify-string-interpolation): New function. (python--treesit-settings): Use the new function for string-interpolation.
2023-01-07Fix 'python-shell-buffer-substring' when START is in middle of 1st linekobarity1-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.
2023-01-01; Add 2023 to copyright years.Eli Zaretskii1-1/+1