From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#49836: Support ripgrep in semantic-symref-tool-grep Date: Tue, 03 Aug 2021 11:10:05 +0300 Organization: LINKOV.NET Message-ID: <875ywn556i.fsf@mail.linkov.net> References: <87sfzrbke1.fsf_-_@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38491"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 49836@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 03 10:17:26 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1mApc4-0009lw-Am for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 Aug 2021 10:17:24 +0200 Original-Received: from localhost ([::1]:33140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mApc3-0002mj-3b for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 Aug 2021 04:17:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mApal-0008M6-On for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2021 04:16:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mApal-0004Ab-Gp for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2021 04:16:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mApal-00080Y-Dv for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2021 04:16:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 03 Aug 2021 08:16:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49836 X-GNU-PR-Package: emacs Original-Received: via spool by 49836-submit@debbugs.gnu.org id=B49836.162797855130729 (code B ref 49836); Tue, 03 Aug 2021 08:16:03 +0000 Original-Received: (at 49836) by debbugs.gnu.org; 3 Aug 2021 08:15:51 +0000 Original-Received: from localhost ([127.0.0.1]:39809 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mApaY-0007zY-Ns for submit@debbugs.gnu.org; Tue, 03 Aug 2021 04:15:51 -0400 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:50347) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mApaW-0007yw-JX; Tue, 03 Aug 2021 04:15:49 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 36C16FF807; Tue, 3 Aug 2021 08:15:40 +0000 (UTC) In-Reply-To: <87sfzrbke1.fsf_-_@mail.linkov.net> (Juri Linkov's message of "Tue, 03 Aug 2021 00:05:02 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:211090 Archived-At: --=-=-= Content-Type: text/plain tags 49836 + patch quit > This means to turn the existing variable 'grep-program' into the user option > as the following patch does. > > Also later grep.el could use the value "rg" of 'grep-program' > to create the corresponding grep-find-template in grep-compute-defaults. > > But I don't know if it's ok to mention rigrep in grep.el? So here is the complete support for rigrep in grep.el: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=grep-program-ripgrep.patch diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 7453dbed99..c4adee609c 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1544,7 +1544,7 @@ xref-search-program "The program to use for regexp search inside files. This must reference a corresponding entry in `xref-search-program-alist'." - :type `(choice + :type '(choice (const :tag "Use Grep" grep) (const :tag "Use ripgrep" ripgrep) (symbol :tag "User defined")) diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 8f0a5acf70..cc3375a284 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -484,9 +484,14 @@ grep-mode-font-lock-keywords This gets tacked on the end of the generated expressions.") ;;;###autoload -(defvar grep-program (purecopy "grep") +(defcustom grep-program (purecopy "grep") "The default grep program for `grep-command' and `grep-find-command'. -This variable's value takes effect when `grep-compute-defaults' is called.") +This variable's value takes effect when `grep-compute-defaults' is called." + :type '(choice + (const :tag "Use Grep" "grep") + (const :tag "Use ripgrep" "rg") + (string :tag "User defined")) + :version "28.1") ;;;###autoload (defvar find-program (purecopy "find") @@ -709,13 +714,14 @@ grep-compute-defaults (let ((grep-options (concat (if grep-use-null-device "-n" "-nH") (if grep-use-null-filename-separator " --null") + (if (equal grep-program "rg") " --no-heading") (when (grep-probe grep-program `(nil nil nil "-e" "foo" ,(null-device)) nil 1) " -e")))) (unless grep-command (setq grep-command - (format "%s %s %s " grep-program + (format "%s%s %s " grep-program (or (and grep-highlight-matches (grep-probe @@ -723,7 +729,7 @@ grep-compute-defaults `(nil nil nil "--color" "x" ,(null-device)) nil 1) (if (eq grep-highlight-matches 'always) - "--color=always" "--color=auto")) + " --color=always" " --color=auto")) "") grep-options))) (unless grep-template @@ -983,6 +989,8 @@ grep-expand-template (push "--color=always" opts)) ((eq grep-highlight-matches 'auto) (push "--color=auto" opts))) + (when (equal grep-program "rg") + (push "--no-heading" opts)) opts)) (excl . ,excl) (dir . ,dir) @@ -1131,7 +1139,7 @@ lgrep files nil (and grep-find-ignored-files - (concat " --exclude=" + (concat (if (equal grep-program "rg") " -g=!" " --exclude=") (mapconcat (lambda (ignore) (cond ((stringp ignore) @@ -1141,7 +1149,7 @@ lgrep (shell-quote-argument (cdr ignore)))))) grep-find-ignored-files - " --exclude="))) + (if (equal grep-program "rg") " -g=!" " --exclude=")))) (and (eq grep-use-directories-skip t) '("--directories=skip")))) (when command @@ -1339,7 +1347,8 @@ zrgrep nil default-directory t)) (confirm (equal current-prefix-arg '(4)))) (list regexp files dir confirm grep-find-template))))))) - (let ((grep-find-template template) + (let ((grep-program "zgrep") + (grep-find-template template) ;; Set `grep-highlight-matches' to `always' ;; since `zgrep' puts filters in the grep output. (grep-highlight-matches 'always)) diff --git a/lisp/cedet/semantic/symref/grep.el b/lisp/cedet/semantic/symref/grep.el index 180d779a78..034f797076 100644 --- a/lisp/cedet/semantic/symref/grep.el +++ b/lisp/cedet/semantic/symref/grep.el @@ -150,15 +150,14 @@ semantic-symref-perform-search "-l ") ((eq (oref tool searchtype) 'regexp) "-nE ") - (t "-n "))) + (t (if (equal grep-program "rg") "" "-n ")))) (greppat (cond ((eq (oref tool searchtype) 'regexp) (oref tool searchfor)) (t ;; Can't use the word boundaries: Grep ;; doesn't always agree with the language ;; syntax on those. - (format "\\(^\\|\\W\\)%s\\(\\W\\|$\\)" - (oref tool searchfor))))) + (format "\\b%s\\b" (oref tool searchfor))))) ;; Misc (b (get-buffer-create "*Semantic SymRef*")) (ans nil) --=-=-=--