tag:blogger.com,1999:blog-3992530807750384868.post8202379143854590612..comments2022-03-28T08:42:20.497+03:00Comments on emacs-fu: search and replace in filesUnknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-3992530807750384868.post-52658407057143843192012-06-23T02:10:17.494+03:002012-06-23T02:10:17.494+03:00With Icicles you can easily search (and replace on...With Icicles you can easily search (and replace on demand) through multiple files. You can choose the files interactively (using multiple-pattern matching if you want) or take them from a file or fileset.<br /><br />With Dired+ and Icicles you can search (and replace on demand) through the marked files, including those in marked subdirectories, recursively.<br /><br />http://www.emacswiki.org/emacs/Icicles_-_Dired_Enhancements#toc2Drewnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-27027067106043783902009-11-20T17:10:21.063+02:002009-11-20T17:10:21.063+02:00You can also open a dired including all subfolders...You can also open a dired including all subfolders recursively by passing a numerical argument to dired:<br /><br />M-1 M-x dired<br /><br />(thats M-'one', not M-'ell').<br /><br />You then get prompted for the flags you would like to pass to dired (nothing more than the arguments you would pass to 'ls' under Unix). Hence for a recursive list, add -R to the list of options.Michaelhttps://www.blogger.com/profile/16464628187960921271noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-5092125017011502312009-06-20T02:54:23.466+03:002009-06-20T02:54:23.466+03:00One thing I don't like about rgrep and friends...One thing I don't like about rgrep and friends is that emacs modifies your search regexp before passing it to grep. I disable this by changing the appropriate grep-expand-keywords.<br /><br />;; modify grep-expand-keywords so that regexp is passed unmodified<br />(let ((assocR (assoc "<R>" grep-expand-keywords)))<br /> ;; was originally ("<R>" shell-quote-argument (or regexp ""))<br /> (when assocR<br /> (setcdr assocR (list 'concat "'" 'regexp "'"))))<br /><br />Perhaps it's because I use extended-regexp mode in grep instead:<br /><br />(setq grep-find-template<br /> ;; was originally "find . <X> -type f <F> -print0 | xargs -0 -e grep <C> -nH -e <R>"<br /> "find . <X> -type f \\( ! -name '*~' \\) -a -type f <F> -print0 | xargs -0 -e grep <C> --extended-regexp -nH -e <R>")piyohttps://www.blogger.com/profile/16255445653576846162noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-81361041935352486812009-06-19T19:10:59.175+03:002009-06-19T19:10:59.175+03:00ah, sorry, my bad. wdired is for renaming files, y...ah, sorry, my bad. wdired is for renaming files, your nice tip is for replacing expressions in multiple files.<br /><br />Nice tipsFerkhttps://www.blogger.com/profile/01619267143296856124noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-15321257893980633042009-06-19T16:17:19.486+03:002009-06-19T16:17:19.486+03:00In dired you can also do...
M-x wdired-change-to-...In dired you can also do...<br /><br />M-x wdired-change-to-wdired-mode<br /><br />(long to type, but you can bind some key to it)<br /><br />And then it will make the dired buffer editable. You can then search-replace filenames or do any editing the usual way you would edit lines in a text buffer, and then apply changes with C-x C-s.Ferkhttps://www.blogger.com/profile/01619267143296856124noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-28993273817967217692009-06-19T15:20:42.872+03:002009-06-19T15:20:42.872+03:00@Anonymous: thanks! updated.@Anonymous: thanks! updated.djcbhttps://www.blogger.com/profile/15938154009846040711noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-88187856769334871452009-06-19T14:41:26.843+03:002009-06-19T14:41:26.843+03:00"Dired does not work recursively - it's o..."Dired does not work recursively - it's one directory at a time."<br /><br />Hmm, not entirely true in practice. You can type "i" to insert subdirectory to the dired buffer. You can also run "M-x find-name-dired" or "M-x find-dired" to generate a dired buffer with find command. Then you can mark wanted files and perform query replace (Q).<br /><br />Check blog post <a href="http://atomized.org/2009/05/emacs-nerdery-search-replace-across-files/" rel="nofollow">Search & replace across files</a>.Anonymousnoreply@blogger.com