Subject: bug#57184: [PATCH] Assorted improvements to python.el

From: Augusto Stoffel <[email-masked]>
Date: Mon, 22 Aug 2022 18:24:57 +0200

On Fri, 19 Aug 2022 at 06:39, Stefan Kangas <[email-masked]> wrote:

>
> close 57184 29.1
> thanks
>
>> Patch 3 seems to break "make bootstrap" with:
>>
>>     In toplevel form:
>>     cedet/semantic/wisent/python.el:30:2: Error: Symbol’s function
>> definition is void: closure
>>     make[3]: *** [Makefile:321: cedet/semantic/wisent/python.elc] Error 1
>>
>>     In toplevel form:
>>     org/ob-python.el:33:2: Error: Symbol’s function definition is void: closure
>>     make[3]: *** [Makefile:321: org/ob-python.elc] Error 1
>>
>> Could you take a look at it?
>
> I fixed it by changing the completion-predicate lambda into a defun.
> Now pushed to master with that change.  Thanks!

Thanks for looking into this!

So the compilation problem seems to be caused by lambda forms that are
evaluated at the time the file is loaded.  I'd have slight preference
for keeping the lambdas, among other things because they are kind of a
provisional solution and could be deleted in a decade or so when we can
rely on the (interactive ARG . MODES) feature.

So I wonder -- why did we get those compilation errors?  Sounds like a
bug somewhere else to me.

Also, a slight fix is needed, see attached patch.

>From 8ada860fae0a8784500ea03b375f63bf6884b9cd Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Mon, 22 Aug 2022 18:16:50 +0200
Subject: [PATCH] Fix completion-predicate of Python shell commands

* lisp/progmodes/python.el:  Change some completion predicates.
(python-shell--completion-predicate): New completion predicate
function.
---
 lisp/progmodes/python.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index a545240805..e1347754c4 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5897,6 +5897,7 @@ python-mode
   (add-hook 'flymake-diagnostic-functions #'python-flymake nil t))
 
 ;;; Completion predicates for M-x
+;; Commands that only make sense when editing Python code
 (dolist (sym '(python-check
                python-fill-paragraph
                python-indent-dedent-line
@@ -5928,6 +5929,13 @@ python-mode
                python-shell-send-statement))
   (put sym 'completion-predicate #'python--completion-predicate))
 
+(defun python-shell--completion-predicate (_ buffer)
+  (provided-mode-derived-p
+   (buffer-local-value 'major-mode buffer)
+   'python-mode 'inferior-python-mode))
+
+;; Commands that only make sense in the Python shell or when editing
+;; Python code.
 (dolist (sym '(python-describe-at-point
                python-eldoc-at-point
                python-shell-completion-native-toggle
@@ -5940,7 +5948,7 @@ python-mode
                python-shell-font-lock-turn-on
                python-shell-package-enable
                python-shell-completion-complete-or-indent  ))
-  (put sym 'completion-predicate #'python--completion-predicate))
+  (put sym 'completion-predicate #'python-shell--completion-predicate))
 
 (provide 'python)
 
-- 
2.37.2