From: Augusto Stoffel Date: Sat, 13 Aug 2022 16:10:14 +0000 (+0200) Subject: python.el: Add completion-predicate symbol property to commands X-Git-Tag: emacs-29.0.90~1447^2~43 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=705c45041fc37f9372e811dc404a518ad15350d4;p=emacs.git python.el: Add completion-predicate symbol property to commands * lisp/progmodes/python.el: Add a completion-predicate property to most commands defined in this file; some are only useful in python-mode, others in inferior-python mode as well. (Bug#53913) (python-skeleton-define, python-define-auxiliary-skeleton): Add appropriate completion-predicate properties. (python--completion-predicate): New function. --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 62fc45b2adf..a545240805a 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4562,6 +4562,11 @@ the if condition." (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 @@ -4570,6 +4575,7 @@ be added to `python-mode-skeleton-abbrev-table'." (let* ((name (symbol-name name)) (function-name (intern (concat "python-skeleton-" name)))) `(progn + (put ',function-name 'completion-predicate #'python--completion-predicate) (define-abbrev python-mode-skeleton-abbrev-table ,name "" ',function-name :system t) (setq python-skeleton-available @@ -4595,13 +4601,15 @@ The skeleton will be bound to python-skeleton-NAME." (setq skel `(< ,(format "%s:" name) \n \n > _ \n))) - `(define-skeleton ,function-name - ,(or doc - (format "Auxiliary skeleton for %s statement." name)) - nil - (unless (y-or-n-p ,msg) - (signal 'quit t)) - ,@skel))) + `(progn + (put ',function-name 'completion-predicate #'ignore) + (define-skeleton ,function-name + ,(or doc + (format "Auxiliary skeleton for %s statement." name)) + nil + (unless (y-or-n-p ,msg) + (signal 'quit t)) + ,@skel)))) (python-define-auxiliary-skeleton else) @@ -5888,6 +5896,52 @@ REPORT-FN is Flymake's callback function." (add-hook 'flymake-diagnostic-functions #'python-flymake nil t)) +;;; Completion predicates for M-x +(dolist (sym '(python-check + python-fill-paragraph + python-indent-dedent-line + python-indent-dedent-line-backspace + python-indent-guess-indent-offset + python-indent-shift-left + python-indent-shift-right + python-mark-defun + python-nav-backward-block + python-nav-backward-defun + python-nav-backward-sexp + python-nav-backward-sexp-safe + python-nav-backward-statement + python-nav-backward-up-list + python-nav-beginning-of-block + python-nav-beginning-of-statement + python-nav-end-of-block + python-nav-end-of-defun + python-nav-end-of-statement + python-nav-forward-block + python-nav-forward-defun + python-nav-forward-sexp + python-nav-forward-sexp-safe + python-nav-forward-statement + python-nav-if-name-main + python-nav-up-list + python-shell-send-buffer + python-shell-send-defun + python-shell-send-statement)) + (put sym 'completion-predicate #'python--completion-predicate)) + +(dolist (sym '(python-describe-at-point + python-eldoc-at-point + python-shell-completion-native-toggle + python-shell-completion-native-turn-off + python-shell-completion-native-turn-on + python-shell-completion-native-turn-on-maybe + python-shell-font-lock-cleanup-buffer + python-shell-font-lock-toggle + 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--completion-predicate)) + (provide 'python) ;;; python.el ends here