From e9fc6f0b5b0e475898eec604e787505546e666af Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 29 Jun 2024 21:30:19 +0200 Subject: [PATCH] Support grep.el better in `python-base-mode` * lisp/progmodes/python.el (python-base-mode): When mode is first enabled, add *.py alias to 'grep-files-aliases', and add common Python tooling directories to 'grep-find-ignored-directories'. (cherry picked from commit bc2e9210bf9f09e69a119ad998e05b2123113b5c) --- lisp/progmodes/python.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 89eefd1f08a..73d6bdd2d2d 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -7042,6 +7042,7 @@ Add import for undefined name `%s' (empty to skip): " (defvar electric-indent-inhibit) (defvar prettify-symbols-alist) +(defvar python--installed-grep-hook nil) ;;;###autoload (define-derived-mode python-base-mode prog-mode "Python" @@ -7126,6 +7127,15 @@ implementations: `python-mode' and `python-ts-mode'." "`outline-level' function for Python mode." (1+ (/ (current-indentation) python-indent-offset)))) + (unless python--installed-grep-hook + (setq python--installed-grep-hook t) + (with-eval-after-load 'grep + (defvar grep-files-aliases) + (defvar grep-find-ignored-directories) + (cl-pushnew '("py" . "*.py") grep-files-aliases :test #'equal) + (dolist (dir '(".tox" ".venv" ".mypy_cache" ".ruff_cache")) + (cl-pushnew dir grep-find-ignored-directories)))) + (setq-local prettify-symbols-alist python-prettify-symbols-alist) (make-local-variable 'python-shell-internal-buffer) -- 2.39.2