8

I am looking for a way to use emacs as my pager command in the shell (for example with man or to scroll the output of an asynchronous command with a large amount of output). I use emacsclient as my $EDITOR, but emacsclient cannot use stdin as its input file. Is there an emacs extension that does this, or failing that, a pager that uses most of the emacs buffer motion and search commands?

I know that I could just be using M-x term or M-x ansi-term and set my $PAGER variable to 'cat', but I am hoping there is something that will integrate with my current habit of using emacs and xterm separately.

Justin Smith
  • 4,166

2 Answers2

3

You can use this shell script as your pager:

#!/bin/sh
t=$(tempfile -s .emacs-pager) || exit 1
cat - >> $t
echo 'reading into emacs...'
emacsclient "$t"
rm -f -- $t

Save it as something like ~/bin/emacs_pager.sh, make it executable (eg: chmod +x ~/bin/emacs_pager.sh), and then set it as the value for the PAGER environment variable (eg: export PAGER=~/bin/emacs_pager.sh).

Note: the above shell script came from this reddit post: https://www.reddit.com/r/emacs/comments/2rr1ha/use_a_buffer_as_pager_from_shellmode/cnik8wb/

1

less supports most of the emacs buffer motion key bindings but not the search bindings out of the box. You may be able to use lesskey to customize the key binding to match emacs.

Craig
  • 1,347