]> git.eshelyaron.com Git - emacs.git/commitdiff
Regexp-quote literal symbols when grepping
authorMattias Engdegård <mattiase@acm.org>
Sat, 18 Sep 2021 11:39:09 +0000 (13:39 +0200)
committerMattias Engdegård <mattiase@acm.org>
Sat, 18 Sep 2021 11:45:03 +0000 (13:45 +0200)
`xref-find-references` was unable to find symbols like
`backquote-list*-macro`.

* lisp/cedet/semantic/symref/grep.el
(semantic-symref-grep--quote-extended): New function.
(semantic-symref-perform-search): Call it.

lisp/cedet/semantic/symref/grep.el

index 53745b429a239c962a36384bd09c0545fec03352..1e282c3052c106f31a0cb0b7ed25cb35020c9d2e 100644 (file)
@@ -133,6 +133,12 @@ This shell should support pipe redirect syntax."
   :group 'semantic
   :type 'string)
 
+(defun semantic-symref-grep--quote-extended (string)
+  "Quote STRING as an extended-syntax regexp."
+  (replace-regexp-in-string (rx (in ".^$*+?|{}[]()|\\"))
+                            (lambda (s) (concat "\\" s))
+                            string nil t))
+
 (cl-defmethod semantic-symref-perform-search ((tool semantic-symref-tool-grep))
   "Perform a search with Grep."
   ;; Grep doesn't support some types of searches.
@@ -151,7 +157,10 @@ This shell should support pipe redirect syntax."
                           ((eq (oref tool searchtype) 'regexp)
                            "-nE ")
                           (t "-nw ")))
-         (greppat (oref tool searchfor))
+         (searchfor (oref tool searchfor))
+         (greppat (if (eq (oref tool searchtype) 'regexp)
+                      searchfor
+                    (semantic-symref-grep--quote-extended searchfor)))
         ;; Misc
         (b (get-buffer-create "*Semantic SymRef*"))
         (ans nil)