help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

replace text in files from buffer=*grep* ?


From: Tom Roche
Subject: replace text in files from buffer=*grep* ?
Date: Tue, 05 May 2015 11:38:44 -0400
User-agent: GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.8.4)

[If possible, please reply both directly to me as well as to the list.]

What functionality exists to automate replacing text from a GNU Emacs *grep* 
(results) buffer? What I mean, why I ask:

Suppose I want to change an identifier in some code. I `M-x find-grep` from the 
root of the filetree of the sources and their docs, producing results like

buffer=*grep*
> find ../ -type f -print | grep -ve '[#~]$\|\.git/' | sort | xargs -e fgrep 
> -nH -e 'F5NAP_FIREFOX_BUILD_DIR'
> ../scripts/install_Firefox_for_F5NAP.sh:88:elif [[ -z 
> "${F5NAP_FIREFOX_BUILD_DIR}" ]] ; then
> ../scripts/install_Firefox_for_F5NAP.sh:89:  echo -e "${ERROR_PREFIX} 
> F5NAP_FIREFOX_BUILD_DIR not defined, exiting ..."
> ../scripts/install_Firefox_for_F5NAP.sh:119:  "mkdir -p 
> ${F5NAP_FIREFOX_BUILD_DIR}" \
> ../scripts/install_Firefox_for_F5NAP.sh:124:  "find 
> ${F5NAP_FIREFOX_BUILD_DIR} | wc -l" \
> ../scripts/public.properties:106:F5NAP_FIREFOX_BUILD_DIR="/tmp/${F5NAP_FIREFOX_WITH_VERSION}"
> ../scripts/public.properties:107:F5NAP_FIREFOX_UNZIP_DIR="${F5NAP_FIREFOX_BUILD_DIR}/firefox"
> ../scripts/start_Firefox_for_F5NAP.sh:82:elif [[ -z 
> "${F5NAP_FIREFOX_BUILD_DIR}" ]] ; then
> ../scripts/start_Firefox_for_F5NAP.sh:83:  echo -e "${ERROR_PREFIX} 
> F5NAP_FIREFOX_BUILD_DIR not defined, exiting ..."
> ../scripts/start_Firefox_for_F5NAP.sh:113:  "mkdir -p 
> ${F5NAP_FIREFOX_BUILD_DIR}" \
> ../scripts/start_Firefox_for_F5NAP.sh:118:  "find ${F5NAP_FIREFOX_BUILD_DIR} 
> | wc -l" \

Depending on the results, I typically take 1 of 3 options:

0. |results| are large && results look dangerous: abort
1. |results| are large && results look safe: run `sed` from the root of the 
filetree
2. |results| are small && results look safe: make a macro changing the first 
one, then repeat on the rest.

Obviously there's no better solution for case#=0 :-) but my handling of the 
other cases feels kludgey. Is there a {better, easier, more Emacs-y} way to 
handle this?

OTTOMH, what I'd really like would be something that would "raise the level of 
abstraction" (RLA) on a *grep* buffer in the manner that Wdired RLAs a Dired 
buffer, by allowing one to treat file metadata as "mere text." If I'm in a 
Dired buffer and want to make several changes to the names/permissions of a 
bunch of files/subdirs of a single directory/folder, I

1. key 'w' to enter Wdired mode
2. apply any of the many wonderful means we have to do text editing on the 
now-editable data
3. key 'C-c C-c'

Wdired then applies the changes made from the Dired buffer to the objects it 
represents. So what I'd most like for my usecase would be to RLA on a *grep* 
buffer, allowing a Wdired-like workflow.

Is there something like that for *grep* buffers, or something even better? 
Apologies if this is a FAQ, but a (probably too casual) web search failed to 
find.

TIA, Tom Roche <Tom_Roche@pobox.com>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]