Commit graph

977 commits

Author SHA1 Message Date
Stefan Monnier
3bc7234349 * python.el (python-syntax-stringify): Extend comment about last change 2021-09-21 11:39:24 -04:00
João Távora
0646c68171 Make syntax-ppss more accurate for Python triple quotes (bug#49518)
By putting delimiter syntax on the last character of Python
triple-quoted strings, this makes syntax-ppss be more accurate.

Previously:

    emacs -Q something.py
    type two single quotes
    M-: (nth 3 (syntax-ppss))
    notice how the return value says you're outside a string, correctly
    type another quote
    M-: (nth 3 (syntax-ppss))
    notice how the return value says you're inside a string, correctly
    backspace the quote just entered
    M-: (nth 3 (syntax-ppss))
    notice how the return value says you're inside a string, incorrectly

With this patch the last step is corrected.  This helps things like
electric-pair-mode.  Also, the test
python-syntax-after-python-backspace now passes, again.

* lisp/progmodes/python.el (python-syntax-stringify): Put
delimiter syntax in "inner" of the surrouding triple quotes.

* test/lisp/progmodes/python-tests.el
(python-syntax-after-python-backspace): Passes again.
2021-09-21 10:56:27 +01:00
Stefan Kangas
63f419f133 ; Minor stylistic fixes found by checkdoc 2021-09-16 19:37:07 +02:00
Lars Ingebrigtsen
b2e3669d96 Tweak python-hideshow-forward-sexp-function warning avoidance
* lisp/progmodes/python.el
(python-hideshow-forward-sexp-function): Avoid compilation warning
in a more standard way.  Problem reported in
https://thedailywtf.com/articles/the-programmer-s-motto-and-other-comments
2021-09-15 15:53:53 +02:00
Augusto Stoffel
6cfc312d71 Python shell: rearrange printing of newline before output
* progmodes/python.el (python-shell-output-filter-in-progress)
(python-shell-output-filter-buffer): Move defvars to avoid compiler
warnings.
(python-shell-eval-setup-code): Don't print a newline in
__PYTHON_EL_eval.
(python-shell-send-string): Insert newline before output when
applicable (bug#50514).
2021-09-15 10:02:34 +02:00
Augusto Stoffel
84e35ff786 Keep python.el compatible with older Emacsen
* progmodes/python.el (python-shell-send-string): Don't assume
comint-max-line-length is defined (bug#50503).
2021-09-11 15:39:32 +02:00
Augusto Stoffel
6343384348 Allow using 'python-shell-send-file' across machines
* progmodes/python.el (python-shell-eval-file-setup-code): Look for a
file coding cookie on the Python rather than on the Emacs side, to
avoid additional file transfers.
(python-shell--save-temp-file): Allow argument to be a buffer.
(python-shell-send-file): Address the case where the selected file and
the inferior process are on different machines (bug#50516).
2021-09-11 15:02:04 +02:00
Augusto Stoffel
e4300777e8 Implement caching for 'python-shell-completion-at-point'
* lisp/progmodes/python.el (python-shell-completion-at-point): cache
results, since computing them involves talking with the inferior
process and, potentially, network communications
(python-shell--capf-cache): new variable, for cache
(python-shell-completion-get-completions)
(python-shell-completion-native-get-completions): 'import' argument is
not needed anymore.
(python-shell-completion-native-setup)
(python-shell-completion-native-try): pass the setup code
synchronously, to avoid printing a message in the shell (bug#50459).
2021-09-11 14:58:12 +02:00
Lars Ingebrigtsen
192a384408 Revert usage of format-prompt in python.el
* lisp/progmodes/python.el (python-eldoc-at-point): Revert usage
of format-prompt in python.el since this is also an ELPA package
(and older Emacs versions doesn't have format-prompt).
2021-09-10 16:39:13 +02:00
Augusto Stoffel
195da78e2e Properly encode all strings sent to Python shell
* lisp/progmodes/python.el: Now depends on Emacs 28.
(python-shell-package-enable, python-shell-completion-get-completions)
(python-ffap-module-path, python-eldoc--get-doc-at-point): Enconde
Python strings using 'python-shell--encode-string' instead of triple
quotes.
(python-shell-completion-string-code, python-eldoc-string-code)
(python-ffap-string-code): Remove defcustoms. (bug#50503).
2021-09-10 16:39:13 +02:00
Eli Zaretskii
ceb60225ba ; * lisp/progmodes/python.el (python-shell-send-string): Fix last change. 2021-09-09 21:04:13 +03:00
Eli Zaretskii
bac632aaec Fix a recent change wrt 'comint-max-line-length'
* lisp/progmodes/python.el (python-shell-send-string): Only heed
'comint-max-line-length' for subprocesses with which we
communicate via PTYs.  (Bug#49822)

* lisp/comint.el (comint-max-line-length): Doc fix.  Add a value
for MS-Windows.
2021-09-09 20:08:56 +03:00
Augusto Stoffel
e27385ec37 Better treatment of line length limits for the Python inferior
* lisp/comint.el (comint-max-line-length): New constant reflecting a
safe maximum line size that can be sent to an inferior process.
* lisp/progmodes/python.el
(python-shell-comint-watch-for-first-prompt-output-filter): Send setup
code to the inferior process only once and at this stage.
(python-shell-eval-setup-code, python-shell-eval-file-setup-code):
Move, unchanged, to an earlier point to avoid byte-compiler warnings.
(python-shell-send-string-no-output): Revert changes of e32c7d2a8d
(python-shell-send-string): Use 'comint-max-line-length' to decide
when to resort to temp files.
(python-shell-send-string, python-shell-send-file): Don't send setup
code each time (bug#49822).
2021-09-09 15:48:37 +02:00
Lars Ingebrigtsen
afddd5529d Don't disable ipython as a native interpreter
* lisp/progmodes/python.el
(python-shell-completion-native-disabled-interpreters): Remove
ipython from list, because it apparently works fine these days
(bug#50458).
2021-09-08 08:59:29 +02:00
Augusto Stoffel
1fdd898704 Fixes for 'python-shell-send-string' and 'python-shell-send-file'
* lisp/progmodes/python.el (python-shell-send-string): use a temporary
file for sufficiently long strings.
(python-shell-send-file, python-shell-eval-file-setup-code): Avoid
showing "plumbing code" in the traceback (bug#32042).
2021-09-05 09:43:13 +02:00
Augusto Stoffel
e32c7d2a8d Change Python eval to send directly instead of using temporary files
* lisp/progmodes/python.el (python-shell-eval-setup-code): New
const for setting up eval (bug#49822).
(python-shell--encode-string): New function.
(python-shell-send-string): Use it to send commands directly
instead of writing to a temporary file.
(python-shell-send-string-no-output): Adjust sending.
(python-shell-send-file): Ditto.
2021-09-03 14:26:51 +02:00
Lars Ingebrigtsen
9c1bbad907 python-shell-interpreter doc string clarification
* lisp/progmodes/python.el (python-shell-interpreter): Note what
to do when using ipython3 (bug#44732).
2021-08-27 04:49:57 +02:00
Augusto Stoffel
926eeb7dd4 Allow evaluating Python code across machines
* python.el (python-shell-send-string): Ensure that the temporary file
is created in the host running the Python process (bug#50057).
2021-08-15 14:00:49 +02:00
Lars Ingebrigtsen
2dcb0f8f52 Add new user option python-forward-sexp-function
* lisp/progmodes/python.el (python-forward-sexp-function): New
user option (bug#41361).
(python-mode): Use it.
2021-07-31 18:44:02 +02:00
Deneb Meketa
7f11dea662 Fix filling of overlong first lines in Python doc strings
* lisp/progmodes/python.el (python-fill-string): Fill overlong
first lines correctly (bug#20860).

Copyright-paperwork-exempt: yes
2021-05-27 01:21:59 +02:00
Stefan Kangas
289ec2d911 ; Remove some useless comments 2021-04-16 14:54:02 +02:00
Shitikanth Kashyap
f2ab4cec7a Fix python-shell-switch-to-shell redisplay bug
* lisp/progmodes/python.el (python-shell-switch-to-shell):
Redisplay the switched-to window faster (bug#47679).

Copyright-paperwork-exempt: yes
2021-04-12 10:43:42 +02:00
Stefan Kangas
4a538c4861 Remove redundant #' before lambda in progmodes/*.el
* lisp/progmodes/cc-styles.el (c-set-offset):
* lisp/progmodes/ebnf-yac.el (ebnf-yac-token-table):
* lisp/progmodes/ebnf2ps.el (ebnf-format-float, ebnf-map-name):
* lisp/progmodes/grep.el (lgrep, rgrep-default-command):
* lisp/progmodes/inf-lisp.el:
* lisp/progmodes/octave.el (octave-lookfor):
* lisp/progmodes/python.el (python-pdbtrack-tracking-finish): Remove
redundant #' before lambda.
2021-04-01 16:26:44 +02:00
Lars Ingebrigtsen
eb9f80e37b Revert "Do interactive mode tagging for python.el navigation functions."
This reverts commit 546f552e7b.

This is a "core package", so can't use the new syntax.
2021-02-18 12:52:55 +01:00
Doug Davis
546f552e7b Do interactive mode tagging for python.el navigation functions.
* lisp/progmodes/python.el (navigation functions): Add python-mode to
`interactive' declarations for mode-specific commands (bug#46610).
Copyright-paperwork-exempt: yes
2021-02-18 12:40:23 +01:00
Lars Ingebrigtsen
3bf21f52b6 Deactivate region in `C-c C-r' in python-mode
* lisp/progmodes/python.el (python-shell-send-region): Deactivate
mark after executing (bug#28789).  This is how this command worked
in Emacs 24, apparently.
2021-02-04 18:24:34 +01:00
Glenn Morris
fa686f0998 Default python-shell-interpreter to python3
* lisp/progmodes/python.el (python-shell-interpreter): Default to
python3 (bug#45655).
2021-01-10 15:48:57 +01:00
Paul Eggert
ba05d005e5 Update copyright year to 2021
Run "TZ=UTC0 admin/update-copyright".
2021-01-01 01:13:56 -08:00
Dario Gjorgjevski
b2ce94fa5e Make python-mode fontify more assignment statements
* lisp/progmodes/python.el (python-font-lock-assignment-matcher): New
function to match assignment statements.
(python-rx): Add `assignment-target' and `grouped-assignment-target'.
(python-font-lock-keywords-maximum-decoration): Add new matchers
(bug#45341).
2020-12-21 05:41:07 +01:00
Tomas Nordin
8b3de06347 Fix narrow-to-defun in python-mode
* lisp/progmodes/python.el (python-nav--beginning-of-defun): Make
narrow-to-defun work better in classes (bug#40563).

Copyright-paperwork-exempt: yes
2020-12-14 16:58:07 +01:00
Stefan Kangas
f22e4bbf1c Prefer setq-local in python.el
* lisp/progmodes/python.el: Require Emacs 24.2 instead of 24.1.
(python-indent-guess-indent-offset)
(python-shell-font-lock-with-font-lock-buffer)
(python-shell-font-lock-turn-on)
(python-shell-font-lock-turn-off, python-shell-font-lock-toggle)
(python-shell-comint-watch-for-first-prompt-output-filter)
(inferior-python-mode, python-shell-completion-native-turn-off)
(python-shell-completion-native-turn-on)
(python-pdbtrack-comint-output-filter-function, python-mode):
Prefer setq-local.
2020-12-12 13:27:35 +01:00
Stefan Kangas
af2695b045 * lisp/progmodes/python.el: Bump version. 2020-12-11 16:16:36 +01:00
Lars Ingebrigtsen
3e6eccc175 Recompute error positions in python-shell-send-region
* lisp/progmodes/python.el (python-shell-send-region): Recompute
line positions when evaluating (bug#22934).
2020-12-03 10:21:19 +01:00
Stefan Kangas
4e94267042 Remove redundant installation instructions
* lisp/net/newsticker.el:
* lisp/net/sieve-mode.el:
* lisp/play/bubbles.el:
* lisp/play/handwrite.el:
* lisp/progmodes/python.el:
* lisp/progmodes/ruby-mode.el:
* lisp/whitespace.el: Remove redundant installation instructions.
These packages are distributed with Emacs and/or GNU ELPA.
* lisp/calendar/timeclock.el:
* lisp/ehelp.el:
* lisp/emacs-lisp/checkdoc.el:
* lisp/filesets.el:
* lisp/mail/reporter.el:
* lisp/net/rfc2104.el:
* lisp/net/webjump.el:
* lisp/pixel-scroll.el: Remove redundant recommendation to call
require before using autoloaded functions.
* lisp/tar-mode.el: Remove reference to package uncompress, removed in
Emacs 23.
2020-11-12 03:12:35 +01:00
Dario Gjorgjevski
e7b4f465e8 Fix python-font-lock-keywords-maximum-decoration performance regression
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration): `symbol-name'
should not be quantified by a `+' as it is redundant and performs
very badly (bug#44572).
2020-11-11 12:27:59 +01:00
Dario Gjorgjevski
296e4dd15e Fix font lock of assignments with type hints in Python
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration): Fix regular
expressions for font lock of assignments with type hints (bug#44568).

The font lock of assignments with type hints in Python is rather bad.
Consider the following example:

    from typing import Mapping, Tuple, Sequence
    var1: int = 5
    var2: Mapping[int, int] = {10: 1024}
    var3: Mapping[Tuple[int, int], int] = {(2, 5): 32}
    var4: Sequence[Sequence[int]] = [[1], [1, 2], [1, 2, 3]]
    var5: Sequence[Mapping[str, Sequence[str]]] = [
        {
            'red': ['scarlet', 'vermilion', 'ruby'],
            'green': ['emerald green', 'aqua']
        },
        {
            'sword': ['cutlass', 'rapier']
        }
    ]

As things stand right now, only ‘var1’ would be highlighted.  To make
things worse, the ‘Mapping’ type hint of ‘var2’ would also be
highlighted, which is entirely incorrect.

This commit makes all of ‘var1’ through ‘var5’ be highlighted
correctly.
2020-11-11 10:49:04 +01:00
Lars Ingebrigtsen
0d9e2b80d8 Make the SHOW parameter work again in `run-python'
* lisp/progmodes/python.el (run-python): Make the SHOW parameter
work again after the fix for 31398 (bug#44421).
2020-11-09 17:21:56 +01:00
Stefan Monnier
a63d905175 Fix misuses of make-local-variable on hooks
* lisp/vc/smerge-mode.el (smerge-ediff):
* lisp/progmodes/python.el (python-pdbtrack-setup-tracking):
* lisp/net/tramp-smb.el (tramp-smb-call-winexe):
* lisp/net/secrets.el (secrets-mode):
* lisp/mail/rmail.el (rmail-variables):
* lisp/ielm.el (inferior-emacs-lisp-mode):
* lisp/erc/erc-log.el (erc-log-setup-logging): Use `add-hook`.

* lisp/eshell/em-unix.el (eshell/diff):
* lisp/eshell/em-hist.el (eshell-hist-initialize): Don't
`make-local-variable` on hooks.
2020-11-04 00:24:45 -05:00
Lars Ingebrigtsen
0d8c6df6c1 Tweak previous python-mode region fix
* lisp/progmodes/python.el (python-shell-buffer-substring): Tweak
the previous fix for bug#39398 to behave somewhat more like it
used to.
2020-10-30 16:15:42 +01:00
Lars Ingebrigtsen
8c8349e4b5 Tweak how `C-c C-r' computes the region in python-mode
* lisp/progmodes/python.el (python-shell-buffer-substring): Don't
extend the region to the start of the line (bug#39398), but allow
sending the actual region as marked.
2020-10-27 20:29:08 +01:00
Stefan Kangas
dd16e46bb9 ; Prefer https to http in more URLs
These were all tested and confirmed working.
2020-10-24 20:23:27 +02:00
Stefan Monnier
f831fa1744 * lisp/progmodes/python.el: Bump version to release the f-string support 2020-10-19 13:39:42 -04:00
Stefan Monnier
3b3274a85c * lisp/progmodes/python.el: Teach f-strings to font-lock
(python--f-string-p, python--font-lock-f-strings): New functions.
(python-font-lock-keywords-maximum-decoration): Use them.
2020-10-16 14:03:59 -04:00
Glenn Morris
726eb835dd Merge from origin/emacs-27
78eacf31e8 ; Fix many typos in symbols in docs and comments
d5d12707d6 * doc/misc/flymake.texi (Using Flymake): Fix a typo.  (Bug...

# Conflicts:
#	lisp/allout.el
#	lisp/progmodes/ebrowse.el
2020-10-02 09:38:24 -07:00
Stefan Kangas
78eacf31e8 ; Fix many typos in symbols in docs and comments 2020-10-02 13:29:45 +02:00
Lars Ingebrigtsen
3f5f3dd604 Make `C-c C-e' in Python buffers work
* lisp/progmodes/python.el (python-shell-send-statement): Don't
send a cookie, because that leads to the naked expression not
being evaled (bug#43450).
(python-shell-send-region): Allow not sending a cookie.
(python-shell-buffer-substring): Ditto.
2020-10-02 05:30:37 +02:00
Per Starbäck
aac3effb8f python-shell-send-defun doesn't find the (whole) definition
* lisp/progmodes/python.el (python-shell-send-defun): Fix C-M-x
for definitions like @property\ndef bar(): (bug#37828).
2020-10-02 05:11:06 +02:00
Lars Ingebrigtsen
bf1b3714cc Fix the defcustom type fix in python.el
* lisp/progmodes/python.el (python-pdbtrack-exit-command): Fix
defcustom type (bug#30990).
2020-09-25 15:17:36 +02:00
Lars Ingebrigtsen
e1c33e29d5 Fix some defcustom types
* lisp/whitespace.el (whitespace-style):
* lisp/gnus/message.el (message-screenshot-command):
* lisp/progmodes/compile.el (compilation-transform-file-match-alist):
* lisp/progmodes/gdb-mi.el (gdb-default-window-configuration-file):
* lisp/progmodes/python.el (python-pdbtrack-exit-command): Fix the
defcustom types.
* lisp/progmodes/sql.el (sql-password-wallet): Fix the value.
2020-09-25 15:15:21 +02:00
Stefan Kangas
462dbc1cb2 ; Fix typos 2020-09-21 14:26:42 +02:00