From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: global-replace to include linked files? Date: Sat, 24 May 2014 22:47:13 +0200 Organization: Aioe.org NNTP Server Message-ID: <87mwe69a5q.fsf@debian.uxu> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1400964624 21649 80.91.229.3 (24 May 2014 20:50:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 May 2014 20:50:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat May 24 22:50:19 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WoItX-0007iR-9J for geh-help-gnu-emacs@m.gmane.org; Sat, 24 May 2014 22:50:19 +0200 Original-Received: from localhost ([::1]:49284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoItW-0004IT-Vd for geh-help-gnu-emacs@m.gmane.org; Sat, 24 May 2014 16:50:18 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 67 Original-NNTP-Posting-Host: u+UUXbnu1hlDFr5pMibebQ.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:Y/llbxyBObE8edLzPLWeUeyQ51o= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:205560 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97830 Archived-At: Sharon Kimble 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