On 10 October 2017, LCD 47 <[email protected]> wrote:
> On 10 October 2017, Bram Moolenaar <[email protected]> wrote:
> >
> > lcd wrote:
> >
> > > Per title: if MANPAGER is set to "env MAN_PN=1 vim -M +MANPAGER -",
> > > running "man Xorg" results in a message "Cannot find a 'xorg'.".
> > >
> > > The culprit is a "tolower()" in plugin/manpager.vim. Man page names
> > > are case-sensitive on most UNIX systems. The patch below seems to fix
> > > the problem.
> > >
> > > /lcd
> > >
> > >
> > > diff --git a/runtime/plugin/manpager.vim b/runtime/plugin/manpager.vim
> > > index be6e30b70..9d30fab2f 100644
> > > --- a/runtime/plugin/manpager.vim
> > > +++ b/runtime/plugin/manpager.vim
> > > @@ -20,7 +20,7 @@ function! s:MANPAGER()
> > > let manpage = expand('$MAN_PN')
> > > endif
> > >
> > > - let page_sec = matchlist(tolower(manpage), '^' . pagesec_pattern .
> > > '$')
> > > + let page_sec = matchlist(manpage, '^' . pagesec_pattern . '$')
> > >
> > > bwipe!
> >
> > Can you try this instead:
> > let page_sec = matchlist(tolower(manpage), '^' . tolower(pagesec_pattern)
> > . '$')
>
> It doesn't help, "Xorg" still gets converted to "xorg".
>
> As I understand it, what's going on is something like this: Vim
> receives the formatted man page via MANPAGER, but this is not directly
> usable, so Vim needs to run "man" again. However at that point the
> original "man" options are not available, so Vim tries to infer them
> from the first line in the formatted man page.
>
> Now, some man pages preserve the case of the name of the utility
> they document (such as "Xorg(1)"), others uppercase it (f.i. "LS(1)").
> That's why Vim calls tolower(). This works for most man pages,
> because the names are all lower-case, but fails for things like "Xorg"
> and "Net::DNS". Please note that the ":Man" command is not affected,
> it's only the MANPAGER mechanism that has this problem.
[...]
I'm attaching a better partial fix.
The patch to plugin/manpager.vim fixes two issues:
(1) man pages with ":" in names (such as Net::DNS) are not recognized;
(2) man pages with upper case letters in names (f.i. "Xorg") are not
recognized.
The fix is partial because it only addresses (2) when MAN_PN is
set. Sadly BSD "man" and "man" on most commercial UNIX systems don't do
that, only "man-db" on Linux does. On systems where "man" doesn't set
MAN_PN the patch falls back to reading the first line in the formatted
man page. On these systems it's possible to write a wrapper script for
"man" that sets MAN_PN before actually running "man", but the details
are necessarily OS-dependent.
The other patch, to ftplugin/man.vim, is unrelated, and is a minor
optimisation. There is no need for "col -b", a simple %s/.\b//g does
the exact same thing inside Vim.
/lcd
diff --git a/runtime/ftplugin/man.vim b/runtime/ftplugin/man.vim
index c7fc3bbdf..49f2025a5 100644
--- a/runtime/ftplugin/man.vim
+++ b/runtime/ftplugin/man.vim
@@ -176,7 +176,8 @@ func <SID>GetPage(...)
let $MANWIDTH = winwidth(0)
let unsetwidth = 1
endif
- silent exec "r !man ".s:GetCmdArg(sect, page)." | col -b"
+ silent exec "r !man ".s:GetCmdArg(sect, page)
+ silent keepj %s/.\b//ge
if unsetwidth
let $MANWIDTH = ''
endif
diff --git a/runtime/plugin/manpager.vim b/runtime/plugin/manpager.vim
index be6e30b70..939f33ec5 100644
--- a/runtime/plugin/manpager.vim
+++ b/runtime/plugin/manpager.vim
@@ -10,17 +10,17 @@ endif
command! -nargs=0 MANPAGER call s:MANPAGER() | delcommand MANPAGER
function! s:MANPAGER()
- let page_pattern = '\v\w+%([-_.]\w+)*'
+ let page_pattern = '\v\w[-_.:0-9A-Za-z]*'
let sec_pattern = '\v\w+%(\+\w+)*'
let pagesec_pattern = '\v(' . page_pattern . ')\((' . sec_pattern . ')\)'
if $MAN_PN is '1'
- let manpage = matchstr( getline(1), '^' . pagesec_pattern )
+ let manpage = tolower(matchstr( getline(1), '^' . pagesec_pattern ))
else
- let manpage = expand('$MAN_PN')
+ let manpage = $MAN_PN
endif
- let page_sec = matchlist(tolower(manpage), '^' . pagesec_pattern . '$')
+ let page_sec = matchlist(manpage, '^' . pagesec_pattern . '$')
bwipe!
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.