lucc / nvimpager

Use nvim as a pager to view manpages, diffs, etc with nvim's syntax highlighting
Other
372 stars 20 forks source link

Feature: support dman #45

Closed JingMatrix closed 3 years ago

JingMatrix commented 3 years ago

Is it possible to automatically use dman command on linux to search for man page online?

We need it, for example, when there is no manpage avaible locally.

lucc commented 3 years ago

@JingMatrix hello I don't fully understand your question just yet. Maybe you can explain a bit more.

What is dman? I can not find any info about it. Do you have a link?

If you execute man something then the man program will look for a manual page for "something". If it does find one it will call your pager (so nvimpager :) but if man does not find a man page, it does not call nvimpager. So there might be little we can do about your problem. But maybe I do not understand your problem correctly?

JingMatrix commented 3 years ago

Sorry for that my issue is too short.

Infomation of dman is here:

http://manpages.ubuntu.com/manpages/impish/man1/dman.1.html

I understand that nvimpager is just a pager. My situation is that, when I use nvimpager for some manual page and try to jump to a possible keyword (pressing k, equivalent to ctrl + click), nvim give an error such as "no manual found for xxx" if there is no manual for that command installed.

What I hope is that nvimpager could handld this error by using dman to search on line manual and print it.

lucc commented 3 years ago

It looks like dman is specific for ubuntu and only exists there (tell me if I'm wrong!). I am not using ubuntu so it might be difficult for me to develop something that only exists on ubuntu. And I am not sure if I want to add and maintain a feature in nvimpager that is specific to ubuntu only.

But I have two ideas for you:

1. hack the K keybinding in nvimpager

When you press K in nvimpager you are most probably calling the man plugin that is shipped with nvim. Check

:verbose map K
n  K           *@:Man<CR>
        Last set from /nix/store/70ndw4jcrjkbqk89dlyhr730i4pl9fmk-neovim-unwrapped-0.4.4/share/nvim/runtime/ftplugin/man.vim line 28
:verbose command Man
    Name        Args       Address   Complete  Definition
!   Man         *    0               customlist    if <bang>0 | set ft=man | else | call man#open_page(v:count, v:count1, <q-mods>, <f-args>) | endif
        Last set from /nix/store/70ndw4jcrjkbqk89dlyhr730i4pl9fmk-neovim-unwrapped-0.4.4/share/nvim/runtime/plugin/man.vim line 10

(the long path in the beginning is from my OS (NixOS) but the important part is that K is mapped by a default neovim plugin.

So the first thing you can try is to check for the error that :Man gives you and then call dman somehow.

2. wrap man on your system globally

You could write a short shell script that calls /usr/bin/man (or whatever the correct path is) and if that fails tries to call dman instead. Call it man and place it in your $PATH before the original man. That should "fix" K in nvimpager but also in plain nvim and also man on the command line.

JingMatrix commented 3 years ago

Thank you, now I understand it is more related to the man.vim provided by nvim.

I tried your second solution, not working. Nvim seems hard-code something related to exit on any command fail. My following code could not use dman automatically in nvim.

#! /bin/zsh

[[ $1 == "-w" ]] && shift
if [[ $# -eq 1 ]]; then
    if /bin/man -w $1 2&>1 >/dev/null; then
        /bin/man $1
    else
        /bin/dman $1
    fi
else
    /bin/man $@
fi
lucc commented 3 years ago

You have to accept more options because the man.vim file passes many options to man. Check the autoload/man.vim file, the s:get_page function and the s:localfile_arg variable.

lucc commented 3 years ago

PS: does it at least work from the command line?

JingMatrix commented 3 years ago

Yes, it works in terminal.

From man.vim, I got to know their logic is read local file. This is not compatiable with dman, which I believe is put manual into stdout.

Thanks for you kind help