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