@Malabarba mentioned the use of wgrep package for editing grep/ack/ag results.
I would like to write a detailed walk-through of how I use the ag package and wgrep-ag packages to achieve editing of 'ag'ged results using multiple-cursors package.
These packages are available through Melpa. You also need to have ag aka the_silver_searcher installed on your ...
What I would like to do is to either quickly build a dired buffer from existing grep output [...], or transform grep output into a list of buffers for multi-occur [...].
You don't need to convert the grep results buffer into anything, there's already a mode specifically for editing grep output (and reflecting the changes on the files, of course).
Occur has a hook, occur-hook, that contains a list of functions to run after a match is found. So we can add a hook to jump to the *Occur* window there:
I don't see the behavior that you describe, at all. For me, when I choose an occurrence in buffer *Occur* it visits the occurrence in the source buffer, putting that smack in the middle of the source-buffer window (vertically).
But if you see what you describe, then just put some window-recentering code on occur-mode-find-occurrence-hook.
Something like ...
There are a number of Emacs commands for which M-n at the input prompt (next-history-element) will insert a reasonable default if there is no next history element available. For occur that happens to be the symbol at point.
So this might do what you want: M-s o M-n
(You might have to hit M-n twice if you have a recent occur search provided as the first '...
If you only care about a particular order (e.g. Buy comes first) then you can use a regexp: Buy.*0.00000057, as mentioned by @zck. But if you need to check for both orders then a single regexp won't do the job.\
To match multiple things in any order, here are two approaches.
Use occur, refining its output with multiple patterns.
Use M-x occur Buy to get ...
Use helm-swoop to find occurrences of words WORD1 and WORD2 in the buffer.
M-x helm-swoop RET WORD1\|WORD2 RET
Use helm-swoop to find occurrences of pairs of words WORD1 and WORD2 in the buffer, in the same line.
M-x helm-swoop RET WORD1 WORD2 RET
If you know that BUY always comes before 0.00000057, you can give occur the regex BUY.*0.00000057.
That will search for all lines that have BUY, any number of characters, then 0.00000057 in it.
If you use helm swoop, not only can you specify them in either order (swooping for BUY 0.00000057 is the same as 0.00000057 BUY), but you also ...
The easiest might be (occur "kittens[
If you use occur interactively, you can insert the actual newlines with C-q C-j. If you use the above lisp snippet, you can replace the newlines by \n:
(occur "kittens[ \n]and[ \n]puppies" nil)
This functionality exists within projectile (projectile-replace). It will use ag/ack/git grep/grep if available (in that order) to find occurrences, and tags-query-replace to execute the query-replace.
By default occur searches are case-insensitive. To force them to be case sensitive, you need to set the variable case-fold-search to nil. Note that this is a buffer-local variable. If you set it for one buffer, it won't change it's value for other buffers.
In your function, adding the form (case-fold-search nil) to your let statement should work:
You can use write-file (C-x C-w), then specify a filename.
C-x C-w runs the command write-file (found in global-map), which is an
interactive compiled Lisp function in ‘files.el’.
Note however this does not preserve the metadata of the buffer : if you save the buffer to a file, kill the buffer and re-open the file you just saved, you only get the text, ...
You have to use a literal C-j to match the newline, which you can etnter by prefixing it with C-q, i.e.
M-x occur RET
(occur also takes a prefix argument that tells it how many lines of context to show, which can be useful too).
The *Occur* buffer will be in a major mode unsurprisingly called occur-mode.
This mode, or perhaps the code that prepares it, or a combination of the two,
do a number of things, including these:
the buffer is marked read-only
it gets its own keymap, with most keys marked undefined
the first line is given some text properties
The best way to deal with the ...
If you want another way to do this, you can use Icicles. A non-negative prefix arg with command icicle-occur (C-c ') searches multiple buffers line by line (like occur, moccur, and grep). If you hit C-! at the prompt that asks which buffers then all buffers are searched.
C-9 C-c ' C-! RET
Here, C-9 says search multiple buffers. C-c ' is icicle-occur, ...
If the question is not limited to Helm, you can do this in Icicles using command icicle-occur (bound to C-c ') in either of these ways, depending on what you want:
Type the regexp Hello.*Bye, if you want to look for Hello followed by Bye.
Type Hello then S-SPC then Bye, if you want to look for both words in either order.
C-c ' uses lines as search contexts....
Looking at the source of occur-mode, I found this:
(setq next-error-function 'occur-next-error))
This suggests occur-next-error is the function next-error calls in a "occured" buffer. And indeed, it seems that calling occur-next-error (with a negative arg to go backward) does work even after M-x compile. I have not tested this extensively, though.
So it ...
Not sure how helm-swoop worked, but you can do this:
(defun call-helm-occur (query)
"Passes QUERY to helm-occur using `isearch-string'."
(let ((isearch-string query))
helm-occur-from-isearch pulls its input from the variable isearch-string, so use let binding to set this variable.
For replace-regexp in many files, select the files in Dired and press Q to run dired-do-find-regexp-and-replace. See also the FAQ entry.
For the equivalent of occur in many files, you can use A (dired-do-find-regexp) in Dired. Another solution that doesn't use Dired is the grep functions and its variants, where you select files with shell wildcards. ...
One way this can be accomplished is by using dired. Here's an article from Xah Lee on how to use dired to find and replace across files: http://ergoemacs.org/emacs/find_replace_inter.html
In short, open dired and place the cursor on the directory in which you wish to find and replace. Press Q to start up the query replace prompt. Enter your search ...
Use the command next-error that is bound to the key sequence C-x ` (the second char is a backtick).
As Omar pointed out in his comment, there is also a global keymap for motion commands bound to M-g.
M-g ? gives the following listing:
Global Bindings Starting With M-g:
M-g TAB move-to-column
You can scroll the window in occur-mode-find-occurrence-hook such that point is at the top of the window:
(defun my-occur-recenter ()
"Scroll point to the top of the window."
(add-hook 'occur-mode-find-occurrence-hook #'my-occur-recenter)
The functions registered in occur-mode-find-occurrence-hook are called with point at the ...
You might try using rgrep to find the regexp, then in the results buffer enable wgrep-mode (M-x wgrep-change-to-wgrep-mode, or C-c C-p).
This will allow you to edit (replace) the regexp directly from within the results buffer, bypassing the need to open each file individually.
When the replacement is complete, press C-c C-c to apply the changes to the ...