14

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.

  • 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 Feb 7 '15 at 22:55
  • 2
    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. – Mike McFarland Feb 7 '15 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) – Mike McFarland Feb 7 '15 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 Feb 7 '15 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. – Mike McFarland Feb 8 '15 at 0:58
7

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" :-)

  • 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. – Mike McFarland May 31 '15 at 17:38
  • Tip: helm-git-grep should be faster than helm-projectile-ag – PlagueHammer Aug 9 '16 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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