16

So I'm looking to have helm-swoop look at all files in a project, not just the current set of open buffers.

This is so I can use swoop to find all occurrences in a project, mark relevant ones, then edit them (in helm swoops edit mode).

I feel that there's probably a clean way to do this with Helm/Helm swoop but here's my attempt to think through a solution:

  1. gather filenames from projectile
  2. create a list of buffers from the filename list
  3. do the same routine as helm-multi-swoop-all besides using this new buffer list

(projectile-current-project-files), looks like it gives me the file list I'm looking for.

So helm-multi-swoop-all, looks like it'd be fairly easy to copy and then tweak.

(defun helm-multi-swoop-all (&optional $query)
  (interactive)
  "Apply all buffers to helm-multi-swoop"
  (cond ($query
         (setq helm-multi-swoop-query $query))
        (mark-active
         (let (($st (buffer-substring-no-properties
                     (region-beginning) (region-end))))
           (if (string-match "\n" $st)
               (message "Multi line region is not allowed")
             (setq helm-multi-swoop-query
                   (helm-swoop-pre-input-optimize $st)))))
        ((setq helm-multi-swoop-query
               (helm-swoop-pre-input-optimize
                (funcall helm-swoop-pre-input-function))))
        (t (setq helm-multi-swoop-query "")))
  (helm-multi-swoop--exec nil
                          :$query helm-multi-swoop-query
                          :$buflist (helm-multi-swoop--get-buffer-list)))

Just replace the call to helm-multi-swoop--get-buffer-list, to one that provided a list of buffers using projectiles list.

But now I'm a little stuck. I'm not sure how to create a list of buffers to feed into helm-swoop from a set of file names.

I also can't help but think there's a simpler way to achieve this, maybe without custom functions.

11
  • 1
    This is potentially problematic. Suppose you want to swoop a large project for "abc". Do you want to open a file buffer for every single file you preview? You may well end up with ten or twenty extra buffers that you don't want. I'd suggest using helm-projectile-ack instead.
    – PythonNut
    Commented Feb 7, 2015 at 22:55
  • 3
    yeah, I wasn't imagining using this for a large project. I was also hoping to close the file buffers opened when finished with this routine. Commented Feb 7, 2015 at 22:59
  • Also, helm-projectile-ack (or ag) is nearly what I'm looking for, except I'd like to be able to edit the lines (like helm swoop allows) Commented Feb 7, 2015 at 23:01
  • I don't actually use helm-swoop. Does doing a helm-projectile-grep and then F3 M-x wgrep-mode make it "editable"?
    – PythonNut
    Commented Feb 7, 2015 at 23:27
  • Thanks, I wasn't aware of wgrep-mode. Helm-projectile-grep is picking up ignored files for me, but helm-projectile-ack is working well with wgrep. At least its working after uninstalling the wgrep that came from melpa, and using the one here instead. Commented Feb 8, 2015 at 0:58

1 Answer 1

8

Following the interesting comments from PythonNut, I installed helm-ag, and ran helm-projectile-ag from the projectile package via C-c p s s. I then switched to editing mode with C-c C-e. I changed a few lines and then pressed C-c C-c and these were saved to the relevant files.

This works, but at present one infellicity is that it saves each of the "matched" files multiple times regardless of whether there was a change or not. I raised this as projectile #756.

Apart from that I think it would work well for the need mentioned in the question, and "without custom functions" :-)

3
  • this is actually what I've settled on as well. The only issue I'm having is that sometimes the files ignored by git/projectile aren't ignored in the ag search results. Haven't had the time to dig into it. Commented May 31, 2015 at 17:38
  • 1
    Tip: helm-git-grep should be faster than helm-projectile-ag
    – Debajit
    Commented Aug 9, 2016 at 2:18
  • Why should it be faster?
    – RichieHH
    Commented Jan 28, 2020 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.