Concept: a terminal pager, like less for example, that interactively "folds" and "unfolds" the input file (as in emacs outline mode). Folded, a recursive directory listing might show only the directory names. Unfolded, it would show the full contents.

As another example

git log | pager

might allow the user to toggle interactively between seeing the headlines and details of each commit.

pager xxx.c

might fold/unfold functions, allowing the user to switch between seeing function definitions only and function bodies.

Obviously, the pager would need to be told (or to deduce for itself) the type of the content it was dealing with.

Does such a program exist?


1 Answer 1


Put this in an executable file named "pager":

#! /usr/bin/env bash

trap "rm -f $TEMP" EXIT HUP INT TERM

echo '-*- outline -*-' > $TEMP
cat "$@" >> $TEMP
emacs $TEMP 0<&1

The initial line of the temporary text file arranges for emacs to enter outline mode. Then cat appends the zero-or-more specified file(s). Finally the editor allows viewing the input text via your favorite mode, then trap EXIT cleans the temp file.

Zero files implies reading from stdin.

Ordinarily git log | pager would not be well supported, as the pipe can interfere with stdin connected to keyboard. (Diagnostic in that case is: "emacs: standard input is not a tty".) We expect that stdout will be connected to terminal, that is, pager is at the end of the pipeline. Given that, 0<&1 is able to recover from the situation by connecting stdin to the same terminal pty that stdout is connected to, allowing for a successful edit session.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .