* global-replace to include linked files?
@ 2014-05-24 19:56 Sharon Kimble
2014-05-24 23:23 ` lee
0 siblings, 1 reply; 7+ messages in thread
From: Sharon Kimble @ 2014-05-24 19:56 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 715 bytes --]
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?
I tried "M-x replace-string" but that wasn't able to follow the
import links to the subsidiary files.
Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, Fluxbox 1.3.5, emacs 24.3.91.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: global-replace to include linked files?
[not found] <mailman.2025.1400961387.1147.help-gnu-emacs@gnu.org>
@ 2014-05-24 20:47 ` Emanuel Berg
2014-05-25 5:23 ` Dale Snell
[not found] ` <mailman.2051.1400995439.1147.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 7+ messages in thread
From: Emanuel Berg @ 2014-05-24 20:47 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: global-replace to include linked files?
2014-05-24 19:56 Sharon Kimble
@ 2014-05-24 23:23 ` lee
0 siblings, 0 replies; 7+ messages in thread
From: lee @ 2014-05-24 23:23 UTC (permalink / raw)
To: help-gnu-emacs
Sharon Kimble <boudiccas@skimble.plus.com> writes:
> I have a master document with 14 files linked into it like this
>
> \include{020-ob2014}
>
> is it possible to do a "global-replace" of
> ╭────
> │\begin{verbatim}
> ╰────
> to
> ╭────
> │\begin{lstlisting}[frame=single]
> ╰────
> please?
>
> I tried "M-x replace-string" but that wasn't able to follow the
> import links to the subsidiary files.
Hm, multisearch[1] is capable of following "include" statements. It`s
designed for "#include", and you can easily change or expand it to go
for "\include{.*}" instead.
Look at multisearch-make-directory-files-list in [2], line 333:
,----
| (multisearch-make-token-list buffer
| "^#include\\s-*[\"<]")))
`----
You can probably get away with changing that to something like
(multisearch-make-token-list buffer
"^\\\include\\s-*{")))
The function multisearch-make-directory-files-list gives you a list of
the relevant files, and you can simply run your own function that does
the replacement you need in each file.
[1]: https://github.com/lee-/emacs
[2]: https://github.com/lee-/emacs/blob/master/multisearch/multisearch.el
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: global-replace to include linked files?
2014-05-24 20:47 ` global-replace to include linked files? Emanuel Berg
@ 2014-05-25 5:23 ` Dale Snell
2014-05-25 19:28 ` Robert Thorpe
[not found] ` <mailman.2051.1400995439.1147.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 7+ messages in thread
From: Dale Snell @ 2014-05-25 5:23 UTC (permalink / raw)
To: help-gnu-emacs
On Sat, 24 May 2014 22:47:13 +0200
Emanuel Berg <embe8573@student.uu.se> wrote:
> 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...
So, Emanuel, is that what Sharon's post looked like to you?
(Excepting the "> > " sequences, of course.) I suspect what is
happening is that your Gnus is set to word wrap at about 52
columns. Since Sharon's "cut here" lines are 65 characters long,
and have only one space to boot, the wrapping gets very confused,
and leaves you with an ugly mess. Assuming (HAH!) that the wrap
size is the problem, rather than something else, simply set the
wrap column to 66 or better. I have Claws-Mail set to wrap at 72
columns, which seems to work well. Certainly Sharon's posts have
always looked fine here. (To compose mail, Claws calls Emacs,
which I have set to wrap at 66 columns, just to be safe.)
Of course, if you're seeing something else, like bizarre strings
of octal characters, then I've no idea what's going on, and I wish
you luck in finding the problem.
--Dale
--
"I recall hearing that highly-classified data must be destroyed by
physically shredding the medium. Yes, throw your disk drive in
the shredder! (Just imagine the class of machinery required to
digest an RA81 HDA.)" -- Mark Wood on linux-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: global-replace to include linked files?
@ 2014-05-25 5:30 Tak Kunihiro
0 siblings, 0 replies; 7+ messages in thread
From: Tak Kunihiro @ 2014-05-25 5:30 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: tak.kunihiro
Use wgrep.
(require 'wgrep)
(setq wgrep-enable-key (kbd "C-x C-q"))
Call grep with recursive option.
grep -Hnir STRING . --include=*.tex
Then call wgrep by wgrep-enable-key and modify *grep* buffer
with `query-replace'. Type C-x C-s to finish.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: global-replace to include linked files?
2014-05-25 5:23 ` Dale Snell
@ 2014-05-25 19:28 ` Robert Thorpe
0 siblings, 0 replies; 7+ messages in thread
From: Robert Thorpe @ 2014-05-25 19:28 UTC (permalink / raw)
To: ddsnell; +Cc: help-gnu-emacs
Dale Snell <ddsnell@frontier.com> writes:
> Certainly Sharon's posts have
> always looked fine here.
Sharon's posts look fine for me too, I use Rmail.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: global-replace to include linked files?
[not found] ` <mailman.2051.1400995439.1147.help-gnu-emacs@gnu.org>
@ 2014-05-25 20:26 ` Emanuel Berg
0 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg @ 2014-05-25 20:26 UTC (permalink / raw)
To: help-gnu-emacs
Dale Snell <ddsnell@frontier.com> writes:
> So, Emanuel, is that what Sharon's post looked like
> to you? (Excepting the "> > " sequences, of course.)
> I suspect what is happening is that your Gnus is set
> to word wrap at about 52 columns. Since Sharon's
> "cut here" lines are 65 characters long, and have
> only one space to boot, the wrapping gets very
> confused, and leaves you with an ugly mess. Assuming
> (HAH!) that the wrap size is the problem, rather than
> something else, simply set the wrap column to 66 or
> better.
Yeah, but this is actually a spot-on illustration to
what I said earlier in the RTF vs. plain text
discussion - if you use plain text, and markup only
when it is necessary, then you don't have to fill to
any specific column or do anything except what you (and
YOU) want with the text. That's the beauty of it!
But while some extra effort is needed, I'm down but
certainly not out.
(article-translate-strings
'(
;; other stuff
("--8<---------------cut etc." "") )
This will remove those lines altogether. Now it is just
a matter of finding the right hook never to hook with a
hooker with.
Actually, perhaps filling should not be done this
crude, but instead a small program could determine if a
paragraph is code or not - difficult but certainly not
impossible... (There should be such routines around.)
Then the paragraphs determined code shouldn't be
filled.
Be sure to catch the next episode of Operation Emacs -
solving problems you never been thought of thinking of
having!
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-05-25 20:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.2025.1400961387.1147.help-gnu-emacs@gnu.org>
2014-05-24 20:47 ` global-replace to include linked files? Emanuel Berg
2014-05-25 5:23 ` 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
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).