all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* creating a tags file for interactive search and replace regexp
@ 2006-06-20  0:12 Ryan Krauss
  2006-06-20  1:40 ` Eric Hanchrow
  0 siblings, 1 reply; 6+ messages in thread
From: Ryan Krauss @ 2006-06-20  0:12 UTC (permalink / raw)


I want to do an interactive regexp search and replace on a list of
files.  I don't want to search all the files in one directory and the
files are actually in many different directories.  How do I do this
search and replace on a specified list?  I think I need a list of tag
files.  But I cannot find an example of the syntax of such a tag file.

Thanks,

Ryan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: creating a tags file for interactive search and replace regexp
  2006-06-20  0:12 Ryan Krauss
@ 2006-06-20  1:40 ` Eric Hanchrow
  2006-06-20  2:21   ` Ryan Krauss
       [not found]   ` <mailman.3042.1150770081.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Hanchrow @ 2006-06-20  1:40 UTC (permalink / raw)


>>>>> "Ryan" == Ryan Krauss <ryanlists@gmail.com> writes:

    Ryan> I want to do an interactive regexp search and replace on a
    Ryan> list of files.  I don't want to search all the files in one
    Ryan> directory and the files are actually in many different
    Ryan> directories.  How do I do this search and replace on a
    Ryan> specified list?  I think I need a list of tag files.  But I
    Ryan> cannot find an example of the syntax of such a tag file.

Sometimes I make a TAGS file, and then do tags-query-replace.  Read
the man page for etags; it's pretty flexible.  Here's an example of a
shell script that creates a TAGS file for certain files only:

find .                                          \
    \(                                          \
      -type d                                   \
         \(  -iname boring -prune \)      \
      -o \(  -iname also-boring -prune \)               \
    \)                                          \
    -o                                          \
    \(                                          \
    -type f                                     \
    \(                                          \
    -name '*.pas'                               \
    -o -name '*.dfm'                            \
    -o -name '*.p[lm]'                          \
    -o -name '*.js'                             \
    -o -name '*.sql'                            \
    \) -print                                   \
    \) | etags -

You can also do "find-dired", then mark any or all of the resulting
files, then type Q (dired-do-query-replace-regexp).

-- 
One of the fundamental philosophical questions of our time is
why Goofy is a person and Pluto is a dog.
        -- Roger Ebert

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: creating a tags file for interactive search and replace regexp
  2006-06-20  1:40 ` Eric Hanchrow
@ 2006-06-20  2:21   ` Ryan Krauss
  2006-06-20 13:22     ` Drew Adams
       [not found]   ` <mailman.3042.1150770081.9609.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 6+ messages in thread
From: Ryan Krauss @ 2006-06-20  2:21 UTC (permalink / raw)
  Cc: help-gnu-emacs

Thanks Eric, this seems like a good start.

It seems like your shell script is just passing a list of file names
or paths to etags.  Is that true?  If I already have a python script
that finds only the files I want, can I just use python to call etags
file1.tex file2.tex ...    ?

Is there a way to do the dired-do-query-replace-regexp based on marked
files in the standard buffer list?  The reason I ask is that it is
very easy for me to use python to open emacs with only the files I
want (basically doing emacs file1.tex file2.tex ...).  The buffer list
will already have all the files I want and only the files I want.

Basically, I have a directory tree with my thesis in it.  I want to
search and replace the Latex files I actually use in the thesis.  But
the tree is a mess with many files I don't think I use but don't dare
delete yet and many subfolders.  So, there are .tex files everywhere.
I have written a python script that parses the main Latex file looking
for \input lines and based on the \input files (and the files they
input), python gives me a list of the *.tex files actually used.
There are 40 "good" *.tex files and over 1300 total *.tex files in the
tree.  So, I really need to do something with the list of
filenames/paths coming out of Python - i.e I need to pass the list to
something, generate my own etags file, or work on the emacs buffer
list.

I know I have made this mess myself, but can someone show me a good
way out of it?

Thanks,

Ryan

On 6/19/06, Eric Hanchrow <offby1@blarg.net> wrote:
> >>>>> "Ryan" == Ryan Krauss <ryanlists@gmail.com> writes:
>
>     Ryan> I want to do an interactive regexp search and replace on a
>     Ryan> list of files.  I don't want to search all the files in one
>     Ryan> directory and the files are actually in many different
>     Ryan> directories.  How do I do this search and replace on a
>     Ryan> specified list?  I think I need a list of tag files.  But I
>     Ryan> cannot find an example of the syntax of such a tag file.
>
> Sometimes I make a TAGS file, and then do tags-query-replace.  Read
> the man page for etags; it's pretty flexible.  Here's an example of a
> shell script that creates a TAGS file for certain files only:
>
> find .                                          \
>     \(                                          \
>       -type d                                   \
>          \(  -iname boring -prune \)      \
>       -o \(  -iname also-boring -prune \)               \
>     \)                                          \
>     -o                                          \
>     \(                                          \
>     -type f                                     \
>     \(                                          \
>     -name '*.pas'                               \
>     -o -name '*.dfm'                            \
>     -o -name '*.p[lm]'                          \
>     -o -name '*.js'                             \
>     -o -name '*.sql'                            \
>     \) -print                                   \
>     \) | etags -
>
> You can also do "find-dired", then mark any or all of the resulting
> files, then type Q (dired-do-query-replace-regexp).
>
> --
> One of the fundamental philosophical questions of our time is
> why Goofy is a person and Pluto is a dog.
>         -- Roger Ebert
>
>
>
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: creating a tags file for interactive search and replace regexp
       [not found]   ` <mailman.3042.1150770081.9609.help-gnu-emacs@gnu.org>
@ 2006-06-20  9:55     ` Mathias Dahl
  0 siblings, 0 replies; 6+ messages in thread
From: Mathias Dahl @ 2006-06-20  9:55 UTC (permalink / raw)


"Ryan Krauss" <ryanlists@gmail.com> writes:

> Is there a way to do the dired-do-query-replace-regexp based on marked
> files in the standard buffer list?  The reason I ask is that it is
> very easy for me to use python to open emacs with only the files I
> want (basically doing emacs file1.tex file2.tex ...).  The buffer list
> will already have all the files I want and only the files I want.

I ripped apart dired-do-query-replace-regexp and came up with this:

(defun query-replace-regexp-in-files (from to files &optional delimited)
  "Do `query-replace-regexp' of FROM with TO, on all FILES.
Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
with the command \\[tags-loop-continue]."
  (dolist (file files)
    (let ((buffer (get-file-buffer file)))
      (if (and buffer (with-current-buffer buffer
			buffer-read-only))
	  (error "File `%s' is visited read-only" file))))
  (tags-query-replace from to delimited
                      'files))

Example of usage:

(query-replace-regexp-in-files 
 "from" "to"
 '("c:/tmp/test1.txt"
   "c:/tmp/test2.txt"))

/Mathias

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: creating a tags file for interactive search and replace regexp
  2006-06-20  2:21   ` Ryan Krauss
@ 2006-06-20 13:22     ` Drew Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2006-06-20 13:22 UTC (permalink / raw)


    Is there a way to do the dired-do-query-replace-regexp based on marked
    files in the standard buffer list? ... The buffer list
    will already have all the files I want and only the files I want.

Maybe I misunderstand your question, but you seem to have answered it
yourself.

`Q' (`dired-do-query-replace-regexp') in Dired does query replace on the
marked files. If you want to use it on all files displayed in Dired, then
mark all those files: `t' (`dired-do-toggle') will do that if all of the
files are unmarked to start with.

So, interactively, `t' followed by `Q' will do what I think you're asking
for.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: creating a tags file for interactive search and replace regexp
       [not found] <mailman.3061.1150809750.9609.help-gnu-emacs@gnu.org>
@ 2006-06-21  7:57 ` Mathias Dahl
  0 siblings, 0 replies; 6+ messages in thread
From: Mathias Dahl @ 2006-06-21  7:57 UTC (permalink / raw)


"Drew Adams" <drew.adams@oracle.com> writes:

>     Is there a way to do the dired-do-query-replace-regexp based on marked
>     files in the standard buffer list? ... The buffer list
>     will already have all the files I want and only the files I want.
>
> Maybe I misunderstand your question, but you seem to have answered it
> yourself.
>
> `Q' (`dired-do-query-replace-regexp') in Dired does query replace on the
> marked files. If you want to use it on all files displayed in Dired, then
> mark all those files: `t' (`dired-do-toggle') will do that if all of the
> files are unmarked to start with.

His problem was that he did not have those files marked in dired, he
had them in some sort of output from an external program.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-06-21  7:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3061.1150809750.9609.help-gnu-emacs@gnu.org>
2006-06-21  7:57 ` creating a tags file for interactive search and replace regexp Mathias Dahl
2006-06-20  0:12 Ryan Krauss
2006-06-20  1:40 ` Eric Hanchrow
2006-06-20  2:21   ` Ryan Krauss
2006-06-20 13:22     ` Drew Adams
     [not found]   ` <mailman.3042.1150770081.9609.help-gnu-emacs@gnu.org>
2006-06-20  9:55     ` Mathias Dahl

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.