From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jim Porter Newsgroups: gmane.emacs.devel Subject: Re: How best to set grep command based on current directory? Date: Sat, 9 Apr 2022 15:43:22 -0700 Message-ID: <494ee5b0-3b62-c8f3-dd2d-f3e10ce674c4@gmail.com> References: <87a6cvkqo4.fsf@md5i.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14307"; mail-complaints-to="usenet@ciao.gmane.io" To: Michael Welsh Duggan , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 10 00:45:37 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ndJpp-0003Xi-Df for ged-emacs-devel@m.gmane-mx.org; Sun, 10 Apr 2022 00:45:37 +0200 Original-Received: from localhost ([::1]:47208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndJpo-0001kN-Cj for ged-emacs-devel@m.gmane-mx.org; Sat, 09 Apr 2022 18:45:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndJni-0007el-Sm for emacs-devel@gnu.org; Sat, 09 Apr 2022 18:43:27 -0400 Original-Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:45726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndJnh-0004ZR-8t for emacs-devel@gnu.org; Sat, 09 Apr 2022 18:43:26 -0400 Original-Received: by mail-pl1-x62c.google.com with SMTP id k13so5721144plk.12 for ; Sat, 09 Apr 2022 15:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=/Y9aRXulkZaLSTptiZ4HP4vQ+ZolXEryXUUuJ+YFASY=; b=WbsrYD9GEWu25fQhrmESWPfo/B7F3SgKnmlIGVXSkp3Exlv+sKHaZiWAmXVBm0Fs6W J1ge5cAj9qTC+6TBQj4Kx0+XqroPg5Z7bmzRGigPA6Ug58E09pmIAnqjBVf72YmWfLcd FDeEWGgCpMa6e/fIzx/McCHhPT9GTbb33sNF603dMA5mdv9f0WFyFveyTP6SmVRVJz4f aTGhhpCG9WVNTHRHlWAepZVo9rlz5ix6T3PD0BIhp+S+rY+0OIajzWjMebXlUGD4tb6c dw2ZmAATTPG11mLUdmFFvDwCMRhehTWDpj22varhHChZ+nmhup+nKXEwC+ws6kg7DkQX vM/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/Y9aRXulkZaLSTptiZ4HP4vQ+ZolXEryXUUuJ+YFASY=; b=ZxS0AhNujHYgFxhI8pjgEtZiVQZBzEyk6c3wS6AvtROvs+/IO2d5HLiD7IIDcsaqoL u1bbZLeQYbHBqW+74qipEOxRZCscdpivyHaxggNP6eR0hLr9ZBpofSRC2CX5UpenNK8L 8aqzdTrH6MjeuAEhtvU2SY8dTV8dbPCfCi/+qkv8zH8HG7k2Jh0mDE9fNx99aaafxMUt hh1AycsvQhvmRyEkvSM6o52Ngj14rgt3ud+8jLINCjBIAE5ric4b2AW/dcX9SwPCeXDD vhSZHKAxMaPh+VB0XxQ59JKJD+k6XD63J7IRWY3l5+oaWm32hZFI3filEg+9U1npYj0V 00xQ== X-Gm-Message-State: AOAM531+8eBoGYKoFs6+WDl4BREsxUHvj+BV+434ot8RyBB4Wc7GJ3gp jza/7rEfNgf7Q336a3WBGB680724ULg= X-Google-Smtp-Source: ABdhPJxUTytV6WtV8Xi3+YtSINw4qnfyprt3KcIM7ld9ibH47lO/aSfMel5v8kyPtCEAn8QXmKrWTg== X-Received: by 2002:a17:90b:17cf:b0:1cb:7c80:616d with SMTP id me15-20020a17090b17cf00b001cb7c80616dmr1914097pjb.105.1649544203271; Sat, 09 Apr 2022 15:43:23 -0700 (PDT) Original-Received: from [192.168.1.2] (cpe-76-168-148-233.socal.res.rr.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id 6-20020a621406000000b00505ad87290dsm767463pfu.162.2022.04.09.15.43.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Apr 2022 15:43:22 -0700 (PDT) In-Reply-To: <87a6cvkqo4.fsf@md5i.com> Content-Language: en-US Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=jporterbugs@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:288068 Archived-At: On 4/8/2022 6:10 PM, Michael Welsh Duggan wrote: > I would like to change the program invocation in "M-x grep" (or maybe > "M-x grep-find") to default to "git grep" when in directories that are > in git trees. I could hack away at the grep.el sources to do this, or I > could write some advice around the grep command to do this, but I want > to ask here, first, if anyone believes that there is a more principled > way to make this change. If *recursive* grep is ok (as opposed to `M-x grep'), that's what I wrote urgrep[1] to do. It's aware of Git directories as well as remote Tramp hosts that may have a different set of commands available for use. I've seen using it for a while and I think I've worked out most of the bugs. (I haven't submitted it for inclusion in GNU ELPA yet since I'm still debating on what to do with a few parts, especially the API.) If not, maybe the code will at least give you some ideas. After a fair bit of experimentation, I found that the following command produces the most consistent rgrep-like results for both Git and non-Git directories: git grep --no-index --exclude-standard Even within Git repos, I found the above to work best, since it searches untracked files (excluding .gitignored files) and recurses into submodules. The fact that it also works well for non-Git directories is a nice bonus too. - Jim [1] https://github.com/jimporter/urgrep