* RE: File System Traversal Map/Collect
2008-06-01 17:20 ` harven
@ 2008-06-01 18:57 ` Drew Adams
2008-06-01 19:41 ` Drew Adams
1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2008-06-01 18:57 UTC (permalink / raw)
To: 'harven', help-gnu-emacs
> On 1 juin, 01:03, Nordlöw <per.nord...@gmail.com> wrote:
> > I am trying to construct a general file system traversal function
> > which operates (map/collect) on each file using a function as
> > argument. Such a function could be query-replace-regexp()
> > specializing it to the functions found in findr.el.
>
> M-x find-name-dired
> then the M and Q command in the resulting Dired buffer allows to make
> a query replacement on a bunch of files. The command find-name-dired
> makes use of the unix find command though, so it is perhaps not so
> useful with respect to what you want to achieve.
>
> There is also an extension called icicles which
> seems to be able to do what you want -- apply
> a function to a bunch of files, without relying on
> some unix find command. Have a look at the wiki.
Hi Per,
Dunno whether you wanted to do this by program or interactively.
The code defining command `icicle-locate-file' shows you how to get all
accessible files under some directory (which could be `/', for all files). You
can then of course map any function over the list.
If you want, you can use `icicle-locate-file' interactively and save the files
as a list (either to a variable or to a file).
If you want to interactively map a function over only some of the files, which
you choose on the fly by matching an input pattern (or by selecting
individually), then you can use command `icicle-map' to do that.
You can do it all interactively, if you want. `icicle-map' expects an alist,
however, whereas when you save the `icicle-locate-file' completion candidates
you get a plain list of file names. So you would do this:
1. `M-x icicle-locate-file' and `C-M-}' to save the completion
candidates in a variable, say `foo'.
2. M-: (setq foo (mapcar 'list foo)), to convert to an alist.
3. `C-u M-x icicle-map', entering `foo' as the variable.
You can specify a pattern for file names to match in either step 1 or step 3, or
both. As you change your input, the set of matching files is updated
incrementally.
In step 3, you can use Icicles action keys (e.g. `C-mouse-2', `C-RET', to act on
specific file names, or `C-!' to act on all matching file names).
If you wanted to act often on the same general set of files (e.g. files of a
certain type in a certain set of directories), then you would use steps 1 & 2 to
define that set only once, and then retrieve the set using step 3 any time you
want.
You can save the set persistently, if you like: just use `C-}' instead of
`C-M-}'. The file names used by `icicle-locate-file' are absolute, so there is
no problem retrieving the set later, whatever the context.
When you act on that set (step 3), you can use an on-the-fly pattern (e.g.
regexp) to specify a subset of the files you are interested in. You can then use
`C-!' to act on all of the files in that subset.
Some doc about this -
`icicle-locate-file':
http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_File-Name_Input
Saving completion candidates:
http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Candidate_Sets
Persistent sets of completion candidates:
http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Persistent_Completions
`icicle-map':
http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Complex_Completions
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: File System Traversal Map/Collect
2008-06-01 17:20 ` harven
2008-06-01 18:57 ` Drew Adams
@ 2008-06-01 19:41 ` Drew Adams
1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2008-06-01 19:41 UTC (permalink / raw)
To: 'harven', help-gnu-emacs
> > I am trying to construct a general file system traversal function
> > which operates (map/collect) on each file using a function as
> > argument. Such a function could be query-replace-regexp()
> > specializing it to the functions found in findr.el.
>
> M-x find-name-dired then the M and Q command in the resulting
> Dired buffer allows to make a query replacement on a
> bunch of files. The command find-name-dired makes use of the
> unix find command though, so it is perhaps not so useful with
> respect to what you want to achieve.
>
> There is also an extension called icicles which
> seems to be able to do what you want -- apply
> a function to a bunch of files, without relying on
> some unix find command. Have a look at the wiki.
In addition to what I mentioned in my previous reply -
If you just want to do what `query-replace-regexp' does, instead of mapping an
arbitrary function over files, then you can use `icicle-search'. You can use it
with a saved set of file names, which you can create using `icicle-locate-file',
as I mentioned previously.
You can replace the current search hit at any time, which gives you behavior
similar to `query-replace' but without requiring you to visit each occurrence
and answer whether or not you want to replace it. You can visit only the hits
you want, and replacement of any given hit is only on demand (`C-S-RET').
You can also change the replacement string at any time, and it can be anything
that is allowed as a replacement by 'query-replace-regexp', which includes Lisp
sexp evaluation via `\,'.
Doc: http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Search-And-Replace
^ permalink raw reply [flat|nested] 4+ messages in thread