| Alan D. Salewski on 27 Apr 2011 20:53:03 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [PLUG] fold output of 'tree' with 'vim'? |
On Tue, Apr 26, 2011 at 08:47:36AM +0200, sean finney spake thus:
> Hi,
>
> On Mon, Apr 25, 2011 at 02:28:51PM -0400, Randall A Sindlinger wrote:
> > just work on an input file. It *seems* like vim should be able to do this
> > for me by using it's folding feature, but I've not had any luck.
>
> One idea: use foldmethod=expr, and make a function that counts the number
> of /'s to determine the folding level via foldexpr?
>
> sean
Because emacs vs. vim is always fun, here's a quick and dirty way of
doing it in emacs with emacs's 'outline' mode, from within a bash shell:
$ ( tfile=$(mktemp) && echo '-*-outline-*-' >> "$tfile" && tree -ifF | while read line; do pat='.*/$'; if [[ $line =~ $pat ]]; then for cnt in $(seq 3 $(echo "$line" | sed -n 's,[^/],,pg' | wc -c)); do printf '*'; done; printf ' %s\n' "$line"; else echo $line; fi; done >> "$tfile" && emacsclient "$tfile" && rm -f "$tfile" )
It basically turns the output of directory lines into the header lines
recognized by outline mode, which can be collapsed and expanded using
the normal outline-mode navigation.
The magic number 3 comes from the observation that the first-level child
directories will be displayed with 2 '/' characters in them in the
output of 'tree -ifF', and the full line (post sed) will have 3
characters due to the newline.
It also uses 'emacsclient', which presumes there's a running emacs
server.
I was disappointed to learn that I could not get emacs to just stream
the data from stdin to a new buffer without first going through a tmp
file. Anyone got some mojo for that?
-Al
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug