From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: global-replace to include linked files?
Date: Sat, 24 May 2014 22:47:13 +0200 [thread overview]
Message-ID: <87mwe69a5q.fsf@debian.uxu> (raw)
In-Reply-To: mailman.2025.1400961387.1147.help-gnu-emacs@gnu.org
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
next parent reply other threads:[~2014-05-24 20:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.2025.1400961387.1147.help-gnu-emacs@gnu.org>
2014-05-24 20:47 ` Emanuel Berg [this message]
2014-05-25 5:23 ` global-replace to include linked files? Dale Snell
2014-05-25 19:28 ` Robert Thorpe
[not found] ` <mailman.2051.1400995439.1147.help-gnu-emacs@gnu.org>
2014-05-25 20:26 ` Emanuel Berg
2014-05-25 5:30 Tak Kunihiro
-- strict thread matches above, loose matches on Subject: below --
2014-05-24 19:56 Sharon Kimble
2014-05-24 23:23 ` lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mwe69a5q.fsf@debian.uxu \
--to=embe8573@student.uu.se \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).