I use shell-mode in Emacs a lot (and have never been that taken with Eshell or term-mode). I got tired of seeing this sort of thing:
1 2 3
It’s reasonable for commands that generate a lot of output to go through
less works poorly in an Emacs buffer.
However, Emacs itself is quite good at paging. So I wondered if I could make Emacs take over for
less. I wrote this shell script
emacs-pager and placed it on my
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Then I made sure the following was in my
1 2 3 4
Now when I invoke
git log or
man, the output appears in a new paging buffer.
- Note use of “ps” to figure out what to call the buffer.
- Note use of
printf '%q'to double escape the string that is substituted into Lisp code. (Why did I need double escaping? Shell scripting is terrible is why.)
'kill-buffermeans that the paging buffer will be deleted when you press “q”. This is not standard Emacs behavior but I don’t want a whole gaggle of temporary buffers laying around.
- The process filter is there just to keep point at the top of the buffer as you receive input.
- There was a weird interaction with Emacs’ builtin
M-x mancommand. I worked around it with:
1 2 3 4 5 6
- There is a further problem when running
manfrom the shell, in that
manoutputs backspace codes for bold/underline and so on. (TODO)