]> git.eshelyaron.com Git - emacs.git/commitdiff
Support grep.el better in `python-base-mode`
authorStefan Kangas <stefankangas@gmail.com>
Sat, 29 Jun 2024 19:30:19 +0000 (21:30 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 1 Jul 2024 07:48:48 +0000 (09:48 +0200)
* 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

index 89eefd1f08a0cc486b5f7a38bf89807768f55e35..73d6bdd2d2d25f88703c3b0661465309f0de5a34 100644 (file)
@@ -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)