I use the standard grep command a lot. When I execute it, the minibuffer is populated with the following the text, allowing me to complete the command:

Run grep (like this): grep --color -nH --null -e 

I almost always prefer to use Perl regex and ignore casing, so I'm finding myself replacing the last argument very often like so:

Run grep (like this): grep --color -nH --null -Pi 

I would like to change the behavior of grep so that it loads with the argument -Pi instead of -e by default.

When I use describe-function and inspect grep, I can see the lines (in /usr/share/emacs/26.3/lisp/progmodes/grep.el.gz) that define this behavior. Beginning line 650, there is a codeblock like so:

      (let ((grep-options
         (concat (if grep-use-null-device "-n" "-nH")
                     (if grep-use-null-filename-separator " --null")
             (if (grep-probe grep-program
                     `(nil nil nil "-e" "foo" ,null-device)
                     nil 1)
             " -e"))))

How do I override these grep-options in my Emacs config? I cannot find a variable named grep-probe or grep-options which I could just overwrite, for example, so what's the best practice then?


The needed variable to set is called grep-command, resulting in (setq grep-command "grep --color -nH --null -Pi")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.