@@ -149,6 +149,24 @@ display."
149149(defvar-local deadgrep--file-type 'all )
150150(put 'deadgrep--file-type 'permanent-local t )
151151
152+ (defcustom deadgrep-file-type-alist
153+ nil
154+ " Alist defining predetermined file types.
155+ The key is a symbol which will be used as the name as the value
156+ of `deadgrep--file-type' and as the name of a button in the
157+ *deadgreap* buffer. The value is a list of arguments to pass to rg.
158+
159+ For example, to only search in test files you might add the
160+ following key-value pair.
161+
162+ (tests . (\" --type-add=TEST:*_test.cpp\"
163+ \" --type=TEST\" ))
164+
165+ The types of `all' , `type' , and `glob' will always be available."
166+ :type '(alist :key-type symbol
167+ :value-type (repeat :tag " Arguments for rg" string))
168+ :group 'deadgrep )
169+
152170(defvar-local deadgrep--context nil
153171 " When set, also show context of results.
154172This is stored as a cons cell of integers (lines-before . lines-after)." )
@@ -629,6 +647,8 @@ with a text face property `deadgrep-match-face'."
629647 (cons 'type (deadgrep--read-file-type deadgrep--initial-filename))))
630648 ((eq button-type 'glob )
631649 (setq deadgrep--file-type (cons 'glob (deadgrep--read-file-glob))))
650+ ((alist-get button-type deadgrep-file-type-alist)
651+ (setq deadgrep--file-type button-type))
632652 (t
633653 (error " Unknown button type: %S " button-type))))
634654 (deadgrep-restart))
@@ -722,6 +742,15 @@ to obtain ripgrep results."
722742 (push (format " --type=%s " (cdr deadgrep--file-type)) args))
723743 ((eq (car-safe deadgrep--file-type) 'glob )
724744 (push (format " --glob=%s " (cdr deadgrep--file-type)) args))
745+ ((alist-get deadgrep--file-type deadgrep-file-type-alist)
746+ (let ((a (alist-get deadgrep--file-type deadgrep-file-type-alist)))
747+ (cond ((stringp a)
748+ (push a args))
749+ ((listp a)
750+ (dolist (aa a)
751+ (push aa args)))
752+ (t
753+ (error " unknown argument type in deadgrep-file-type-alist: %s " a)))))
725754 (t
726755 (error " Unknown file-type: %S " deadgrep--file-type)))
727756
@@ -832,6 +861,13 @@ search settings."
832861 (if (eq (car-safe deadgrep--file-type) 'glob )
833862 (format " :%s " (cdr deadgrep--file-type))
834863 " " )
864+ (cl-loop for alist-item in deadgrep-file-type-alist
865+ concat (concat " "
866+ (if (eq deadgrep--file-type (car alist-item))
867+ (symbol-name (car alist-item))
868+ (deadgrep--button (symbol-name (car alist-item))
869+ 'deadgrep-file-type
870+ 'file-type (car alist-item)))))
835871 " \n\n " )
836872 (put-text-property
837873 start-pos (point )
0 commit comments