Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Emacs for $PAGER?

Tags:

emacs

There are lots of places in UNIX where programs call out to the program in $PAGER (usually less or some similar command) to display some output. It's certainly true that many of the most common uses have an Emacs replacement (in the case of man, for example), but I'd still like a general way to use Emacs as my system-wide pager. Ideally this would mean that calls to PAGER end up in an Emacs temporary buffer similar to *Help*, a read-only buffer you can navigate around and dismiss by pressing "q".

I usually run a shell through M-x shell, so my envisioned use case is that typing a command like "man foo" in the *shell* window will bring up the man page in another window, more or less exactly like how the built-in *Help* system works.

like image 847
Derek Thurn Avatar asked Dec 06 '11 20:12

Derek Thurn


1 Answers

For general use of $PAGER, you might be interested in e-sink.

For the specific case of man pages, it's better to use Emacs's built-in man mode as you note. I have this in my .bashrc:

man () 
{ 
    if [ "$TERM" == "eterm-color" ]; then
        emacsclient -e "(man \"$1\")";
    else
        command man "$@";
    fi
}

Since you use shell-mode rather than ansi-term-mode like I do you will either have to make this use emacsclient all the time, or do something like (setenv "WITHIN_EMACS" "1") in your .emacs file so you can switch on $WITHIN_EMACS instead.

like image 95
Michael Hoffman Avatar answered Oct 23 '22 09:10

Michael Hoffman