[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: global-replace to include linked files?
From: |
Emanuel Berg |
Subject: |
Re: global-replace to include linked files? |
Date: |
Sat, 24 May 2014 22:47:13 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Sharon Kimble <boudiccas@skimble.plus.com> writes:
> I have a master document with 14 files linked into it
> like this --8<---------------cut
> here---------------start------------->8---
> \include{020-ob2014} --8<---------------cut
> here---------------end--------------->8--- is it
> possible to do a "global-replace" of ╭────
> │\begin{verbatim} ╰──── to ╭────
> │\begin{lstlisting}[frame=single] ╰──── please?
Another psychedelic post from Sharon...
> I tried "M-x replace-string" but that wasn't able to
> follow the import links to the subsidiary files.
Well, no. replace-string and almost everything you come
across won't work on anything else than the buffer.
But it is still possible to use Emacs to apply "set
functions" to files:
emacs --batch -l cl --eval '
(dolist (filename (list $FILES))
(find-file filename)
; do whatever to the file (i.e., to all files)
(save-buffer)
(kill-buffer) )'
Now, the $FILES is where it gets tricky. In zsh,
(I think) I had it working like this:
FILES=()
for f in $@; do
FILES+=\"$f\"
done
Then just provide the files as arguments (the $@
part). You might do something similar in bash.
I also tried to do something similar in dired -
actually very close to what you want. Idea was, just
mark the files, then invoke (but it might be a problem
for you, as your files are perhaps not in the same
directory even, so the first method might be easier to
get right). Anyway:
(defun replace-regexp-in-marked (regexp to-string)
(interactive "sRegexp: \nsTo: ")
(save-window-excursion
(let ((the-regexp regexp)
(the-to-string to-string)
(case-fold-search t) )
(dolist (f (dired-get-marked-files))
(find-file f)
(replace-regexp the-regexp to-string nil (point-min) (point-max))
(save-buffer) )))
(dired-unmark-all-marks) )
Also, the Unix tools come to mind (sed, awk, Perl)...
Good luck! Be sure to tell us if you find a good way to
do it.
--
underground experts united:
http://user.it.uu.se/~embe8573