On 2023-10-15, Janis Papanagnou <
[email protected]> wrote:
On 15.10.2023 02:46, Kaz Kylheku wrote:
Hi All,
Prompted by a Unix StackExchange question, I started a mini project
called mnpgr a few days ago. It's in a very usable state now.
This is glue code, written in TXR Lisp which turns Vim into a
page for reading man pages.
Plus, a small Vim syntax filee.
https://www.kylheku.com/cgit/mnpgr/about/
The benefits are
- Remembers your last position in any man page. This is useful for
working with long man pages.
- Leverages your Vim skills and environment.
- Has better rendering of backspace overstrikes than the "less" utility.
For instance, it correctly renders the French accented characters
exemplified in the GNU grep man page.
- bold+italic is recognized and assigned to its own highlight
category.
The program translates man's overstrikes into its own markup notation;
for instance, bold text is {B{bold text}B}. The Vim syntax file hides
the markup and colorizes the payload.
I don't think I'll use 'txr', but your post made me think about the
task...
If 'vim' is your pager you could do
man ... | vim -
:set syntax=man will also do some (predefined) highlighting. While in
The problem is that vim will not remember the position in a buffer that
had been read from a pipe. This whole thing was prompted by someone
trying to solve that problem. They wanted to remember the position in
each individual man page. That resonated with me because there have been
times when I wanted to revisit something I recently read in a man page.
(One such situation is when I'm working *on* a man page, making
adjustments to some section and wanting to see their effect!)
Secondly, the "man" syntax highlighting in Vim is a poor hack. It only highlights some salient features like headings. It has no idea where the keywords are that were supposed to be bolded and italicized.
Vim you can of course not only remember the "last position" (there's
the default mark, a single quote, for that) but you can also define
arbitrary marks and, of course, randomly jump between them. Or split
the screen to see more than one man page context. You can also (e.g.)
extract portions of the man page. Do whatever an editor supports.
A reason against using an editor is probably the size consideration.
I tried it on a 13-year-old Core i5, slow machine, on the txr man page,
which is 65000 lines. There is a bit of a delay, but otherwise it's
fine.
I don't know of a larger man page; it makes a PDF document over 930
pages with the default troff margins.
(That man page also uses text that is both bold and italic, which
provides a test case for the third color.)
What doesn't seem to work nicely is setting the pager to vim
PAGER='vim -' man ...
For that you want:
MANPAGER='vim +MANPAGER' man
(The MANPAGER variable is a red herring here; I'm using it in
this example instead of PAGER because PAGER will have no effect on man
if MANPAGER is already defined.)
The :MANPAGER vim command referenced by +MANPAGER brings in some
packaged support for reading man pages, and does render the overstrikes.
But:
1. I was not able to use +MANPAGER as the basis of a solution that
can remember the last position.
Here is why, I think: vim +MANPAGER doesn't actually read the man page
input; it seems to work by analyzing the MAN_PN environment variable and
itself fetching the man page.
2. For that reason, it also doesn't work with "man -l <file>",
which is a dealbreaker for people who work on man pages or view
man pages inside source trees, not only installed pages.
3. While the overstrike codes are rendered, the underlying data
has the interspersed backspaces. This means you cannot search for
those words. If foo is highlighted, /foo won't find it because it's
actually f^Hfo^Hoo^Ho.
So I gave up on the vim +MANPAGER approach.
--
TXR Programming Language:
http://nongnu.org/txr
Cygnal: Cygwin Native Application Library:
http://kylheku.com/cygnal
Mastodon: @
[email protected]
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)