[PATCH] fix man page viewing with man-db

79 views
Skip to first unread message

Pádraig Brady

unread,
Nov 29, 2010, 12:29:06 PM11/29/10
to vim...@vim.org
Fedora 14 switched to man-db for handling man pages.
Ubuntu has been using it for ages.
On older versions of Fedora I was able to just
add this to my .bashrc to have full man page
functionality, (with drill down) using vim

export MANPAGER='bash -c "vim -MRn -c \"set ft=man nomod nolist nospell nonu\" \
-c \"nm q :qa!<CR>\" -c \"nm <end> G\" -c \"nm <home> gg\"</dev/tty <(col -b)"'

(if pasting that in a terminal make sure to \ the ! in the second line)

The above works fine for man-db too, except when using Ctrl-[
to drill down into sub man pages. In that case man-db will
run the output through $MANPAGER again, even though the
output is not a tty. That would cause various vim errors
and hangups. I was able to work around this in my ~/.vimrc with:

augroup man
au!
"Ensure vim is not recursively invoked (man-db does this)
"when doing ctrl-[ on a man page reference
au FileType man let $MANPAGER=""
augroup END

So rather than doing that, the patch below
just does the same in man.vim

cheers,
Pádraig.

--- /usr/share/vim/vim73/ftplugin/man.vim 2010-11-29 10:00:14.392636934 +0000
+++ man.vim 2010-11-29 10:00:07.233636869 +0000
@@ -15,6 +15,10 @@
endif
let b:did_ftplugin = 1

+ "Ensure vim is not recursively invoked (man-db does this)
+ "when doing ctrl-[ on a man page reference
+ let $MANPAGER=""
+
" allow dot and dash in manual page name.
setlocal iskeyword+=\.,-

Bram Moolenaar

unread,
Nov 29, 2010, 4:27:24 PM11/29/10
to Pádraig Brady, vim...@vim.org

Pádraig wrote:

> Fedora 14 switched to man-db for handling man pages.
> Ubuntu has been using it for ages.
> On older versions of Fedora I was able to just
> add this to my .bashrc to have full man page
> functionality, (with drill down) using vim
>
> export MANPAGER='bash -c "vim -MRn -c \"set ft=man nomod nolist nospell nonu\" \
> -c \"nm q :qa!<CR>\" -c \"nm <end> G\" -c \"nm <home> gg\"</dev/tty <(col -b)"'
>
> (if pasting that in a terminal make sure to \ the ! in the second line)
>
> The above works fine for man-db too, except when using Ctrl-[
> to drill down into sub man pages. In that case man-db will
> run the output through $MANPAGER again, even though the
> output is not a tty. That would cause various vim errors
> and hangups. I was able to work around this in my ~/.vimrc with:
>
> augroup man
> au!
> "Ensure vim is not recursively invoked (man-db does this)
> "when doing ctrl-[ on a man page reference
> au FileType man let $MANPAGER=""
> augroup END
>
> So rather than doing that, the patch below
> just does the same in man.vim

Thanks, I'll include it.

--
It is too bad that the speed of light hasn't kept pace with the
changes in CPU speed and network bandwidth. -- <wie...@porcupine.org>

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Matt Wozniski

unread,
Dec 2, 2010, 5:23:19 PM12/2/10
to vim...@googlegroups.com
2010/11/29 Bram Moolenaar <Br...@moolenaar.net>:

>
> Pádraig wrote:
>>     "Ensure vim is not recursively invoked (man-db does this)
>>     "when doing ctrl-[ on a man page reference

Shouldn't that be ctrl-] ?

MikeM

unread,
Feb 2, 2011, 4:34:59 PM2/2/11
to vim...@googlegroups.com, P�draig Brady, vim...@vim.org
This patch causes /usr/bin/man to fail on Mac OS X:

sh: -c: line 0: syntax error near unexpected token `||'
sh: -c: line 0: `(cd '/usr/share/man' && (echo ".ll 13.0i"; echo ".nr LL 13.0i"; /usr/bin/gunzip -c '/usr/share/man/man1/man.1.gz') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | ( || true))'
Error executing formatting or display command.
System command (cd '/usr/share/man' && (echo ".ll 13.0i"; echo ".nr LL 13.0i"; /usr/bin/gunzip -c '/usr/share/man/man1/man.1.gz') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | ( || true)) exited with status 512.
No manual entry for man

It would appear that because MANPAGER has been set to null, null is substituted in the actual command that /usr/bin/man runs (just before the '||'). Please can a more comprehensive solution be found. Unfortunately vim does not appear to allow the removal of a variable from the environment altogether, only adding or setting one.


MikeM

unread,
Jul 24, 2011, 1:31:17 PM7/24/11
to vim...@googlegroups.com, P�draig Brady, vim...@vim.org
It's been a while since I reported a problem with the patch here and no further comment has been made. I guess the majority of users out there are probably using one of the pre-packaged versions of vim 7.3 and so this problem hasn't come down the pipeline to hit them yet. I have seen one other reference to the problem whilst browsing the web: http://crumbtrail.chesmart.in/

I still don't think the original patch was the right solution here, but until someone comes up with a better solution, I wonder if the the following patch could be applied?

--- a/ftplugin/man.vim 2011-07-22 19:55:14.000000000 +0100
+++ b/ftplugin/man.vim 2011-07-24 17:55:49.000000000 +0100
@@ -17,7 +17,9 @@
 
   " Ensure Vim is not recursively invoked (man-db does this)
   " when doing ctrl-[ on a man page reference.
-  let $MANPAGER = ""
+  if exists("$MANPAGER")
+    let $MANPAGER = ""
+  endif
 
   " allow dot and dash in manual page name.
   setlocal iskeyword+=\.,-

This patch maintains the fix for the original problem, but limits the potential side effects to those that have a MANPAGER environment variable actually defined.  

SungHyun Nam

unread,
Jul 24, 2011, 8:35:17 PM7/24/11
to vim...@googlegroups.com, MikeM, P�draig Brady, vim...@vim.org
MikeM wrote:
> It's been a while since I reported a problem with the patch here and no
> further comment has been made. I guess the majority of users out there
> are probably using one of the pre-packaged versions of vim 7.3 and so
> this problem hasn't come down the pipeline to hit them yet. I have seen
> one other reference to the problem whilst browsing the web:
> http://crumbtrail.chesmart.in/
>
> I still don't think the original patch was the right solution here, but
> until someone comes up with a better solution, I wonder if the the
> following patch could be applied?
>
> --- a/ftplugin/man.vim2011-07-22 19:55:14.000000000 +0100
> +++ b/ftplugin/man.vim2011-07-24 17:55:49.000000000 +0100

> @@ -17,7 +17,9 @@
> " Ensure Vim is not recursively invoked (man-db does this)
> " when doing ctrl-[ on a man page reference.
> - let $MANPAGER = ""
> + if exists("$MANPAGER")
> + let $MANPAGER = ""
> + endif
> " allow dot and dash in manual page name.
> setlocal iskeyword+=\.,-
>
> This patch maintains the fix for the original problem, but limits the
> potential side effects to those that have a MANPAGER environment
> variable actually defined.

I have no objection to this patch. so, Ack.

BTW, I'm not sure man.vim should include such lines at all. Original
reporter already found a workaround for his problem. And his patch
caused side-effect for others.

Regards,
namsh

Bram Moolenaar

unread,
Jul 25, 2011, 2:54:13 PM7/25/11
to MikeM, vim...@googlegroups.com, P�draig Brady, vim...@vim.org

Mike Mcewan wrote:

Thanks. Since SungHyun Nam agreed I'll include this.

--
MORTICIAN: What?
CUSTOMER: Nothing -- here's your nine pence.
DEAD PERSON: I'm not dead!
MORTICIAN: Here -- he says he's not dead!
CUSTOMER: Yes, he is.
DEAD PERSON: I'm not!
The Quest for the Holy Grail (Monty Python)

Elias Toivanen

unread,
Jul 25, 2011, 4:50:39 PM7/25/11
to vim...@googlegroups.com
Hello,

I've also experienced man.vim crashing when $MANPAGER had been already
defined to `col -b | vim -R -' in .bashrc. I took a look at the man.vim
file and came up with the following idea.

Instead of asking if $MANPAGER was defined, why not define it
temporarily for the call. It's possible to do this via

let tmp = tempname()
let $MANWIDTH = &tw ? &tw : 80
let manpager = shellescape('less -s') " Fixes problems when user has defined $MANPAGER
silent execute "!MANPAGER=".manpager." /usr/bin/man ".args."| col -b > ".tmp
silent execute "pedit ".tmp

See the attachment for the complete reimplementation of GetPage(). I
also wanted to fix a couple of subtle shortcomings of the original script.

In my opinion, viewing man pages should mimic reading help pages which
is already reflected nicely in the mappings <C-]> and <C-t>. However, it
would also be nice to be able to double click the topics as one can do
in help files.

Man pages should also be closed when the last writable buffer is closed
in the current tab page, as is the case with help files. Now the user is
potentially left with two windows to the same shell script. The first
was used to spawn a man page via <Leader>K for example and the second
appeared unintentionally when the user rewinded man pages one time too
many.

Finally, all man pages shouldn't be only 'readonly' but also
'nomodifiable'.

All of these aspects are taken care of in the script you'll find in the
attachment. I post it to your consideration.


On Mon, 25 Jul 2011, Bram Moolenaar wrote:

>
> Mike Mcewan wrote:
>
>> It's been a while since I reported a problem with the patch here and no
>> further comment has been made. I guess the majority of users out there are
>> probably using one of the pre-packaged versions of vim 7.3 and so this
>> problem hasn't come down the pipeline to hit them yet. I have seen one other
>> reference to the problem whilst browsing the web:
>> http://crumbtrail.chesmart.in/
>>
>> I still don't think the original patch was the right solution here, but
>> until someone comes up with a better solution, I wonder if the the following
>> patch could be applied?
>>
>> --- a/ftplugin/man.vim 2011-07-22 19:55:14.000000000 +0100
>> +++ b/ftplugin/man.vim 2011-07-24 17:55:49.000000000 +0100
>> @@ -17,7 +17,9 @@
>>
>> " Ensure Vim is not recursively invoked (man-db does this)
>> " when doing ctrl-[ on a man page reference.
>> - let $MANPAGER = ""
>> + if exists("$MANPAGER")
>> + let $MANPAGER = ""
>> + endif
>>
>> " allow dot and dash in manual page name.
>> setlocal iskeyword+=\.,-

--
Elias Toivanen <elias.t...@helsinki.fi>

man_addon.vim

James Vega

unread,
Jul 25, 2011, 7:53:45 PM7/25/11
to vim...@googlegroups.com
On Mon, Jul 25, 2011 at 11:50:39PM +0300, Elias Toivanen wrote:
> Hello,
>
> I've also experienced man.vim crashing when $MANPAGER had been already
> defined to `col -b | vim -R -' in .bashrc. I took a look at the man.vim
> file and came up with the following idea.
>
> Instead of asking if $MANPAGER was defined, why not define it
> temporarily for the call. It's possible to do this via
>
> let tmp = tempname()
> let $MANWIDTH = &tw ? &tw : 80
> let manpager = shellescape('less -s') " Fixes problems when user has defined $MANPAGER
> silent execute "!MANPAGER=".manpager." /usr/bin/man ".args."| col -b > ".tmp

Using "!env MANPAGER=...." is better as not all shells support declaring
environment variables to use for a command invocation like that.

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <jame...@jamessan.com>

signature.asc
Reply all
Reply to author
Forward
0 new messages