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.

2
  • I've been looking for a solution for you, but I fear there is no way to read STDIN. Seems like quite a limitation.... Commented Feb 3, 2010 at 1:02
  • 2
    this is technically a dupe of the following question - superuser.com/questions/31404/… Commented Feb 22, 2010 at 19:19

2 Answers 2

2

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/

2
  • Currently it seems that at least in Linux tempfile is deprecated. Even though the script still works, it gives a warning. Replacing the first line in the script (the second in the file) with: t=$(mktemp .emacs-pager.XXXXXXX) || exit 1 would have the same effect and use the newer and not-deprecated mktemp.
    – paradoja
    Commented Feb 19, 2021 at 8:37
  • This doesn't work for an infinite stream of data, which less easily supports by opening at the top of the file. Is there a way to emulate this behavior in Emacs? Commented Dec 1, 2022 at 21:16
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.

You must log in to answer this question.

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