Commit graph

956 commits

Author SHA1 Message Date
Lars Ingebrigtsen
85db21b94b Avoid hangs in python-mode with debug-on-error set
* lisp/progmodes/python.el (python-nav-end-of-statement): Avoid
using cl-assert here, because this is called from the font-lock
machinery, and if debug-on-error is set here, we'll hang Emacs
(bug#54996).
2022-04-18 13:17:32 +02:00
kobarity
078e1f289c Fix fontifying type hints in python-mode
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration): Avoid fontifying
type hints as variable names (bug#54992).

Copyright-paperwork-exempt: yes
2022-04-17 19:28:15 +02:00
Colin Woodbury
139042eb86 * lisp/progmodes/python.el: Account for new keywords.
* lisp/progmodes/python.el (python-font-lock-keywords-level-2): As
of Python 3.10, Python has structured pattern matching. This adds
two new keywords which need to be highlighted (bug#54345).
2022-03-12 18:46:55 +01:00
Stefan Monnier
b4f1ceaf24 python.el: Silence left over warning in last commit
* lisp/progmodes/python.el
(python-shell-calculate-process-environment): Declare
tramp-remote-process-environment before using it.
2022-02-04 13:39:19 -05:00
Stefan Monnier
d340dc0a25 python.el: Try and better split the Tramp code
Massage the Python-Tramp code so that the Tramp part and the Python
part are a bit less intertwined.  It's still not quite right, but it's
a bit closer to the point where the Tramp part can be moved to `tramp.el`.

* lisp/progmodes/python.el: Don't require `tramp-sh`.
Do require `subr-x` OTOH.  Remove redundant `:group`s.
(python-shell--calculate-process-environment): New function, that only
return the entries to be added.
(python-shell-calculate-process-environment): Rewrite and declare obsolete.
(python-shell-tramp-refresh-remote-path)
(python-shell-tramp-refresh-process-environment): Silence
compiler warnings.
(python-shell-with-environment): Move the bulk of its code to
a new function `python-shell--with-environment` for easier debugging
and to avoid code duplication.
(python-shell--with-environment): New function.  Split the Tramp case
into its own function.
(python-shell--tramp-with-environment): New function.
(python-eldoc-function-timeout-permanent): Fix doc's first line.

* test/lisp/progmodes/python-tests.el: Adjust accordingly.
(python-shell-calculate-process-environment-1)
(python-shell-calculate-process-environment-2)
(python-shell-calculate-process-environment-3)
(python-shell-calculate-process-environment-4)
(python-shell-calculate-process-environment-5)
(python-shell-calculate-process-environment-6)
(python-shell-calculate-process-environment-7)
(python-shell-calculate-process-environment-8):
Use `python-shell--calculate-process-environment`.
(python--tests-process-env-canonical, python--tests-process-env-eql):
New functions.
(python-shell-with-environment-2, python-shell-with-environment-3):
Use them.
2022-02-04 13:35:38 -05:00
Miha Rihtaršič
07335abeb4 Fix python-eldoc affecting unrelated comint processes
* lisp/progmodes/python.el (python-shell-send-string-no-output): Don't
let-bind comint-preoutput-filter-functions globally for all comint
processes.  Modify the behaviour of only the current python
process (bug#53219).
2022-01-14 08:34:27 +01:00
Eli Zaretskii
dcd76bd48d Merge from origin/emacs-28
836be7a112 ; * etc/refcards/ru-refcard.tex: Update Copyright year.
86cbc6ee4a * lisp/net/tramp-sh.el: Adapt copyright year
ebe8772f65 ; Minor fixes related to copyright years
23c1ee6989 ; * test/manual/etags/ETAGS.good_N: Adjust to copyright ye...
8d3fc7ec89 * src/xfaces.c (face_for_font): Make 'hash' be uintptr_t.
19dcb237b5 ; Add 2022 to copyright years.

# Conflicts:
#	etc/NEWS
#	etc/refcards/ru-refcard.tex
#	lib/cdefs.h
#	lisp/erc/erc-dcc.el
#	lisp/erc/erc-imenu.el
#	lisp/erc/erc-replace.el
#	lisp/image-dired.el
#	lisp/progmodes/xref.el
#	m4/alloca.m4
#	m4/byteswap.m4
#	m4/errno_h.m4
#	m4/getopt.m4
#	m4/gnulib-common.m4
#	m4/inttypes.m4
#	m4/stddef_h.m4
#	m4/stdint.m4
#	m4/sys_socket_h.m4
2022-01-01 07:03:03 -05:00
Eli Zaretskii
19dcb237b5 ; Add 2022 to copyright years. 2022-01-01 02:45:51 -05:00
Stefan Kangas
5640b055d6 Merge from origin/emacs-28
9bd3f78645 Make `M-x run-python' select the window again
62139aeb42 * lisp/tab-bar.el (tab-bar-switch-to-last-tab): Add 'abs' ...
ea8422204f * make-dist (manifest): Filter out msdos/autogen/* files.
b5354e989d Rewrite the "Quitting Windows" section of Emacs Lisp Refer...
64ea1a178c Fix eshell for systems that do not have subprocesses
2021-12-13 06:30:58 +01:00
Kévin Le Gouguec
9bd3f78645 Make `M-x run-python' select the window again
Interactively, we want M-x run-python to focus the interpreter buffer.
The previous code failed in two ways:

- the call to 'display-buffer' was not reached if an interpreter
  was already running,

- set-buffer is ineffectual if the interpreter's window is not
  selected: once Emacs returns to the command loop, the current buffer
  will revert back to what the selected window contains.

* lisp/progmodes/python.el (python-shell-make-comint): Handle the SHOW
argument regardless of whether an interpreter buffer exists, and use
pop-to-buffer to select the window.
(run-python): Delegate buffer management to
'python-shell-make-comint'.

* test/lisp/progmodes/python-tests.el
(python-tests--run-python-selects-window): Rename from
'python-tests--bug31398', and adjust assertions (bug#52380).
2021-12-13 05:17:00 +01:00
Lars Ingebrigtsen
5708da48d1 Revert "Make `M-x run-python' select the window again"
This reverts commit aa2872a127.

This led to a test failure.
2021-12-10 13:07:24 +01:00
Kévin Le Gouguec
aa2872a127 Make `M-x run-python' select the window again
* lisp/progmodes/python.el (python-shell-make-comint): Make `M-x
run-python' select the window again like in 27.2 (bug#52380).
2021-12-10 13:05:49 +01:00
Eli Zaretskii
d75ba220e0 ; Revert "* lisp/progmodes/python.el (python-forward-sexp-function): :version fix."
This reverts commit e6e29b4352.
The commit was a mistake.
2021-11-14 19:42:37 +02:00
Eli Zaretskii
e6e29b4352 ; * lisp/progmodes/python.el (python-forward-sexp-function): :version fix. 2021-11-14 18:58:57 +02:00
Kévin Le Gouguec
48ffbcf7eb Fix customization group of python-forward-sexp-function
* lisp/progmodes/python.el (python-forward-sexp-function): Move from
the "Flymake integration" subsection to the "Navigation" subsection,
so that the option is sorted into the 'python' group rather than the
'python-flymake' group (bug#51807).
2021-11-14 02:30:06 +01:00
Benj
754810add1 Make the python missing-readline warning more helpful
* lisp/progmodes/python.el
(python-shell-completion-native-turn-on-maybe): Mention the "readline"
package (bug#48998).

Copyright-paperwork-exempt: yes
2021-11-10 10:07:42 +01:00
Carlos Pita
a0973fa7a6 Match dummy output even with non-default rl config
* lisp/progmodes/python.el
(python-shell-completion-native-get-completions): Match dummy output
even when readline is configured in non-default ways.  (Bug#51010)
2021-11-05 08:02:31 +01:00
Lars Ingebrigtsen
1def47fd98 Fix return value of python-nav-end-of-defun
* lisp/progmodes/python.el (python-nav-end-of-defun): Return
non-nil if in a def/class, as the doc string implies (bug#51601).
2021-11-04 18:47:04 +01:00
Eli Zaretskii
d9b309cda8 Merge from origin/emacs-28
335a660b4b Fix display glitches with side-by-side windows on TTY frames
4a96f32def Avoid replacing common prefix with ellipsis
2021-10-31 03:58:55 -04:00
Carlos Pita
4a96f32def Avoid replacing common prefix with ellipsis
* lisp/progmodes/python.el
(python-shell-completion-native-setup): Configure readline not to
suppress common prefixes.  (Bug#51218)
2021-10-30 17:51:27 +02:00
Lars Ingebrigtsen
9e3b3ae9d9 Update Emacs requirement after removing compat code 2021-10-13 19:01:48 +02:00
Lars Ingebrigtsen
ab34293d84 Fix problem with multiline fontification in interactive Python
* lisp/progmodes/python.el
(python-shell-font-lock-post-command-hook): When doing multi-line
(`C-c SPC') inputs, remove all the preceding lines when doing
fontification (bug#47657).
2021-10-13 19:00:31 +02:00
Lars Ingebrigtsen
93b40da8e1 Remove some compat code from python.el
* lisp/progmodes/python.el
(python-shell-font-lock-post-command-hook): Remove Emacs 24.3 and
earlier compat code.
2021-10-13 18:34:58 +02:00
Glenn Morris
d4a033696d Merge from origin/emacs-28
66b8dfd060 (origin/emacs-28) ; Fix last change related to shorthands
3832b983cf In Fdelete_other_windows_internal fix new total window siz...
5deb0ec14f * lisp/mh-e/mh-show.el (mh-junk-whitelist): Custom obsoles...
cf1409db71 Don't apply shorthands to punctuation-only symbols (bug#51...
b3d0f53b29 * lisp/progmodes/python.el: Bump package version to 0.28.
2021-10-12 07:50:19 -07:00
Stefan Kangas
b3d0f53b29 * lisp/progmodes/python.el: Bump package version to 0.28. 2021-10-11 21:24:38 +02:00
Stefan Kangas
392d6708a5 Fontify "print" and "exec" as functions in python-mode
This change was first made on master, but on closer consideration it
is better to fix this bug already in Emacs 28.1.

* lisp/progmodes/python.el (python-font-lock-keywords-level-2):
Fontify "print" and "exec" as functions, which is the case in
Python 3.  (Bug#43298)  Do not merge to master.
2021-10-11 21:24:38 +02:00
Stefan Kangas
9f9c9f934a Fontify "print" and "exec" as functions in python-mode
* lisp/progmodes/python.el (python-font-lock-keywords-level-2):
Fontify "print" and "exec" as functions, which is the case in
Python 3.  (Bug#43298)
2021-10-11 15:18:54 +02:00
Stefan Kangas
6640942221 Use format-prompt for many more prompts
* lisp/bookmark.el (bookmark-completing-read):
* lisp/calc/calc-prog.el (calc-user-define-formula):
* lisp/calc/calc-store.el (calc-permanent-variable):
* lisp/calc/calc-units.el (calc-convert-units)
(calc-convert-exact-units, calc-convert-temperature):
* lisp/cedet/semantic/complete.el
(semantic-complete-read-tag-engine):
* lisp/cus-edit.el (customize-read-group):
* lisp/dired-aux.el (dired-do-chxxx):
* lisp/dired-x.el (dired-mark-unmarked-files):
* lisp/emacs-lisp/debug.el (cancel-debug-on-entry)
(cancel-debug-on-variable-change):
* lisp/emacs-lisp/edebug.el (edebug-cancel-on-entry)
(edebug-remove-instrumentation):
* lisp/epa.el (epa-read-file-name, epa-export-keys):
* lisp/faces.el (read-face-name):
* lisp/format.el (format-decode-buffer, format-decode-region):
* lisp/gnus/gnus-art.el (gnus-read-save-file-name):
* lisp/gnus/gnus-util.el (gnus-completing-read):
* lisp/gnus/message.el (message-check-news-header-syntax):
* lisp/info.el (Info-follow-reference):
* lisp/international/mule-diag.el (describe-font)
(describe-fontset):
* lisp/international/quail.el (quail-show-keyboard-layout):
* lisp/language/cyril-util.el
(standard-display-cyrillic-translit):
* lisp/mail/rmailkwd.el (rmail-read-label):
* lisp/mail/rmailmm.el (rmail-mime-save):
* lisp/mail/rmailout.el (rmail-output-read-file-name):
* lisp/man.el (Man-goto-section, Man-follow-manual-reference):
* lisp/menu-bar.el (emacs-index--prompt):
* lisp/net/ange-ftp.el (ange-ftp-get-passwd):
* lisp/proced.el (proced-send-signal):
* lisp/progmodes/cpp.el (cpp-choose-face):
* lisp/progmodes/ebrowse.el (ebrowse-set-tree-indentation):
* lisp/progmodes/etags.el (visit-tags-table)
(visit-tags-table-buffer):
* lisp/progmodes/grep.el (grep-read-files):
* lisp/progmodes/hideif.el (hide-ifdef-define):
* lisp/progmodes/pascal.el (pascal-goto-defun):
* lisp/progmodes/prolog.el (prolog-read-predicate):
* lisp/progmodes/sql.el (sql-get-login-ext):
* lisp/ses.el (ses-define-local-printer):
* lisp/textmodes/artist.el (artist-figlet-choose-font):
* lisp/textmodes/tex-mode.el (tex-compile):
* lisp/vc/diff.el (diff):
* lisp/vc/ediff-ptch.el (ediff-prompt-for-patch-file):
* lisp/vc/ediff-util.el (ediff-read-file-name):
* lisp/vc/pcvs.el (cvs-mode-mark-on-state):
* lisp/vc/vc.el (vc-diff-build-argument-list-internal)
(vc-revision-other-window, vc-retrieve-tag):
* lisp/wid-edit.el: Prefer format-prompt unconditionally.

* lisp/org/org-capture.el (org-capture-fill-template):
* lisp/org/org-refile.el (org-refile-get-location):
* lisp/progmodes/python.el (python-eldoc-at-point):
* lisp/progmodes/verilog-mode.el (verilog-surelint-off)
(verilog-goto-defun):
* lisp/progmodes/xref.el (xref--read-identifier): Prefer format-prompt
when it is fboundp.
2021-10-05 03:44:56 +02:00
Carlos Pita
60e817e78d Avoid a warning in python-eldoc-setup-code
* lisp/progmodes/python.el (python-eldoc-setup-code): Avoid a
deprecation warning about formatargspec (bug#50996).
2021-10-04 11:43:17 +02:00
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