emacs as a pager?

6

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

Posted 2010-02-02T02:10:48.460

Reputation: 3 746

I've been looking for a solution for you, but I fear there is no way to read STDIN. Seems like quite a limitation.... – Joe Casadonte – 2010-02-03T01:02:35.637

2

this is technically a dupe of the following question - http://superuser.com/questions/31404/how-to-make-emacs-read-buffer-from-stdin-on-start

– Darren Hall – 2010-02-22T19:19:50.727

Answers

1

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/

Bryan Oakley

Posted 2010-02-02T02:10:48.460

Reputation: 131

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

Posted 2010-02-02T02:10:48.460

Reputation: 1 097