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.

Joe Corneli
  • 1,786
  • 1
  • 14
  • 27
Mike McFarland
  • 439
  • 3
  • 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 Feb 07 '15 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. – Mike McFarland Feb 07 '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 07 '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 07 '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](https://github.com/mhayashi1120/Emacs-wgrep) instead. – Mike McFarland Feb 08 '15 at 00:58
  • At this point, I am unsure what you still want or need. – PythonNut Feb 09 '15 at 03:02
  • well, I'm still interested in an answer to the original question. Your suggestion works, but Helm swoop is a real nice interface, and I use it for other parts of my workflow. I'm still playing with my own implementation, but haven't gotten around to finishing it. – Mike McFarland Feb 09 '15 at 03:50
  • Ah. I see. Do you just want it to open a ton of file buffers and you can manually delete them later? – PythonNut Feb 09 '15 at 16:03
  • yeah, I've been messing with `find-file-noselect`. I can open the list of buffers fairly easily with `(mapcar 'find-file-noselect (projectile-current-project-files))`. But, as you said, it's pretty painful (they trigger all their hooks/modes). I was playing with using something like `(lambda(file) (find-file-noselect file nil t))` instead but... Helm swoop isn't reading those. Was going to read up on this stuff to see whats the minimum needed, then try it. I figure, if it runs fast enough on my medium sized projects, I can kill the buffers when I'm done fairly easily (just use the list I made) – Mike McFarland Feb 10 '15 at 01:47
  • `Helm Moccur` is your friend. It solves your issue. – ReneFroger Jun 24 '15 at 10:09
  • @ReneFrogerjuh I haven't heard of helm moccur (I'm fairly new to emacs), [Is it this script?](https://github.com/myuhe/helm-c-moccur.el) Just reading the wiki, it looks like moccur works with opened buffers. I'm looking to search in all project files (even if they aren't currently in my buffers). Helm swoop already accommodates all buffer searching. Did I miss something? – Mike McFarland Jun 29 '15 at 16:21

1 Answers1

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

Joe Corneli
  • 1,786
  • 1
  • 14
  • 27