@@ -515,6 +515,22 @@ If called with a prefix, prompts for flags to pass to ag."
515
515
(defalias 'ag-regexp-project-at-point 'ag-project-regexp )
516
516
(make-obsolete 'ag-regexp-project-at-point 'ag-project-regexp " 0.46" )
517
517
518
+ ;;;### autoload
519
+ (defun ag-on-marked-files (string )
520
+ " Same as `ag`, but look only for the files marked on the current dired buffer."
521
+ (interactive (list (ag/read-from-minibuffer " Search string" )))
522
+ (let ((files (if (version< emacs-version " 27.0" )
523
+ (dired-get-marked-files t current-prefix-arg nil nil )
524
+ (dired-get-marked-files t current-prefix-arg nil nil t ))))
525
+ (ag/search string default-directory :files files )))
526
+
527
+ ;;;### autoload
528
+ (defun ag-regexp-on-marked-files (string )
529
+ " Same as `ag-regexp`, but look only for the files marked on the current dired buffer."
530
+ (interactive (list (ag/read-from-minibuffer " Search regexp" )))
531
+ (let ((files (dired-get-marked-files t current-prefix-arg nil nil t )))
532
+ (ag/search string default-directory :regexp t :files files )))
533
+
518
534
;;;### autoload
519
535
(defun ag-dired (dir string )
520
536
" Recursively find files in DIR matching literal search STRING.
@@ -530,13 +546,22 @@ See also `ag-dired-regexp'."
530
546
(ag-dired-regexp dir (ag/escape-pcre string)))
531
547
532
548
;;;### autoload
533
- (defun ag-dired-regexp (dir regexp )
549
+ (defun ag-contents-dired (dir string )
550
+ " Same as `ag-dired`, but look at file contents rather than file paths."
551
+ (interactive " DDirectory: \n sFile contents pattern: " )
552
+ (ag-dired-regexp dir (ag/escape-pcre string) t ))
553
+
554
+ ;;;### autoload
555
+ (defun ag-dired-regexp (dir regexp &optional match-contents-p )
534
556
" Recursively find files in DIR matching REGEXP.
535
557
REGEXP should be in PCRE syntax, not Emacs regexp syntax.
536
558
537
559
The REGEXP is matched against the full path to the file, not
538
560
only against the file name.
539
561
562
+ If `match-contents-p` is non-nil, look at the file contents
563
+ rather than the file full paths.
564
+
540
565
Results are presented as a `dired-mode' buffer with
541
566
`default-directory' being DIR.
542
567
@@ -549,12 +574,16 @@ See also `find-dired'."
549
574
" *ag dired*"
550
575
(format " *ag dired pattern:%s dir:%s * " regexp dir)))
551
576
(cmd (if (string= system-type " windows-nt" )
552
- (concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " " ) " -g \" " regexp " \" "
577
+ (concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " " )
578
+ (if match-contents-p " -l " " -g " )
579
+ " \" " regexp " \" "
553
580
(shell-quote-argument dir)
554
581
" | grep -v \" ^$\" | sed \" s/'/\\\\\\\\ '/g\" | xargs -I '{}' "
555
582
insert-directory-program " "
556
583
dired-listing-switches " '{}' &" )
557
- (concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " " ) " -g '" regexp " ' "
584
+ (concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " " )
585
+ (if match-contents-p " -l " " -g " )
586
+ " '" regexp " ' "
558
587
(shell-quote-argument dir)
559
588
" | grep -v '^$' | sed s/\\ '/\\\\\\\\\\ '/g | xargs -I '{}' "
560
589
insert-directory-program " "
@@ -592,6 +621,13 @@ See also `find-dired'."
592
621
(move-marker (process-mark proc) 1 (current-buffer )))
593
622
(setq mode-line-process '(" :%s" )))))
594
623
624
+ ;;;### autoload
625
+ (defun ag-contents-dired-regexp (dir regexp )
626
+ " Same as `ag-dired-regexp`, but look for regexp in file contents rather
627
+ than in file names."
628
+ (interactive " DDirectory: \n sFile contents regexp: " )
629
+ (ag-dired-regexp dir regexp t ))
630
+
595
631
;;;### autoload
596
632
(defun ag-project-dired (pattern )
597
633
" Recursively find files in current project matching PATTERN.
0 commit comments