From e71f85ef40e99e8ebc65b7907c5d487d47b0a66f Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Mon, 15 May 2023 16:28:56 +0100 Subject: [PATCH] Fix M-x completion-predicate under python-ts-mode * lisp/progmodes/python.el: (python-skeleton-define): Filter M-x completion based on python-base-mode instead of python-mode. This allows for python-ts-mode as well. Use command-modes as a shorthand for completion-predicate. (python--completion-predicate, python-shell--completion-predicate): Remove accordingly; no longer used. (python-define-auxiliary-skeleton): Prefer function-put over put. --- lisp/progmodes/python.el | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index bbabce80b4d..92ac84ff099 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4964,11 +4964,6 @@ 'python-mode-skeleton-abbrev-table (not (python-syntax-comment-or-string-p)) python-skeleton-autoinsert))) -(defun python--completion-predicate (_ buffer) - (provided-mode-derived-p - (buffer-local-value 'major-mode buffer) - 'python-mode)) - (defmacro python-skeleton-define (name doc &rest skel) "Define a `python-mode' skeleton using NAME DOC and SKEL. The skeleton will be bound to python-skeleton-NAME and will @@ -4977,7 +4972,7 @@ python-skeleton-define (let* ((name (symbol-name name)) (function-name (intern (concat "python-skeleton-" name)))) `(progn - (put ',function-name 'completion-predicate #'python--completion-predicate) + (function-put ',function-name 'command-modes '(python-base-mode)) (define-abbrev python-mode-skeleton-abbrev-table ,name "" ',function-name :system t) (setq python-skeleton-available @@ -5004,7 +4999,7 @@ python-define-auxiliary-skeleton `(< ,(format "%s:" name) \n \n > _ \n))) `(progn - (put ',function-name 'completion-predicate #'ignore) + (function-put ',function-name 'completion-predicate #'ignore) (define-skeleton ,function-name ,(or doc (format "Auxiliary skeleton for %s statement." name)) @@ -6752,7 +6747,7 @@ python-ts-mode (add-to-list 'interpreter-mode-alist '("python[0-9.]*" . python-ts-mode)))) ;;; Completion predicates for M-x -;; Commands that only make sense when editing Python code +;; Commands that only make sense when editing Python code. (dolist (sym '(python-add-import python-check python-fill-paragraph @@ -6786,12 +6781,7 @@ python-ts-mode python-shell-send-defun python-shell-send-statement python-sort-imports)) - (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)) + (function-put sym 'command-modes '(python-base-mode))) ;; Commands that only make sense in the Python shell or when editing ;; Python code. @@ -6806,8 +6796,8 @@ python-shell--completion-predicate python-shell-font-lock-turn-off python-shell-font-lock-turn-on python-shell-package-enable - python-shell-completion-complete-or-indent )) - (put sym 'completion-predicate #'python-shell--completion-predicate)) + python-shell-completion-complete-or-indent)) + (function-put sym 'command-modes '(python-base-mode inferior-python-mode))) (provide 'python) -- 2.34.1