lucc / nvimpager

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

Doesn't work with neovim from snap #82

Open appomsk opened 1 year ago

appomsk commented 1 year ago

Kubuntu 22.04.1:

$ which -a nvim
/snap/bin/nvim

$ echo hi | ~/.local/bin/nvimpager
error: unknown flag `R'

$ (exec -a nvimpager nvim -R)  
error: unknown flag `R' 

$ (exec -a nvimpager nvim)   
The snap command lets you install, configure, refresh and remove snaps.
  ...

$ snap -R
error: unknown flag `R' 
lucc commented 1 year ago

The actual nvim binary has a -R option: https://neovim.io/doc/user/starting.html#-R

I do not have snap (and the ubuntu docker container does not have systemd so I can not try it there) so you will have to figure out what snap does to the binary of neovim and why it does not pass on the switch.

Maybe start with

/snap/bin/nvim --help
/snap/bin/nvim -R some-file
appomsk commented 1 year ago

Yes, of course, nvim has -R switch. But snap somehow intercepts this option when nvim is invoked through exec.

I really don't want to go in snap guts. It is simpler for me to download the appimage or the deb package. So it is just for your information. You may close this issue if you see fit.

lucc commented 1 year ago

I spun up a VM with Ubuntu and found:

I conclude that snap uses symlinks and the "original name" that we can set with "exec -a" to figure out which application to start.

I have to think about it, if I want to drop the -a nvimpager part.

lucc commented 1 year ago

@appomsk can you try the commit 9da7585? If you have several nvim verions installed you can select the snap version with

export NVIMPAGER_NVIM=/snap/bin/nvim 
appomsk commented 1 year ago

Well, there is another problem. I removed all nvim directories with rm -rf:

~/.config/nvim
~/.local/share/nvim
~/.local/state/nvim
~/.cache/nvim

Install nvimpager:

$ make PREFIX=$HOME/.local install
mkdir -p /home/and/.local/bin /home/and/.local/share/nvimpager/runtime/lua \
  /home/and/.local/share/zsh/site-functions
install nvimpager.configured /home/and/.local/bin/nvimpager
install -m 644 lua/nvimpager.lua /home/and/.local/share/nvimpager/runtime/lua
install -m 644 _nvimpager /home/and/.local/share/zsh/site-functions
mkdir -p /home/and/.local/share/man/man1
install -m 644 nvimpager.1 /home/and/.local/share/man/man1

Then changed ~/.local/bin/nvimpager with the new one with your patch (just pasted and copied from gui). And then tried with nvim-8.2 from snap and with nvim-9.0dev appimage but:

$ export NVIMPAGER_NVIM=/snap/bin/nvim; echo hi | nvimpager

Error detected while processing pre-vimrc command line:
E5108: Error executing lua [string ":lua"]:1: module 'nvimpager' not found:
        no field package.preload['nvimpager']
        no file './nvimpager.lua'
        no file '/__w/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/nvimpager.lua'
        no file '/usr/local/share/lua/5.1/nvimpager.lua'
        no file '/usr/local/share/lua/5.1/nvimpager/init.lua'
        no file '/__w/neovim/neovim/.deps/usr/share/lua/5.1/nvimpager.lua'
        no file '/__w/neovim/neovim/.deps/usr/share/lua/5.1/nvimpager/init.lua'
        no file './nvimpager.so'
        no file '/usr/local/lib/lua/5.1/nvimpager.so'
        no file '/__w/neovim/neovim/.deps/usr/lib/lua/5.1/nvimpager.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        [string ":lua"]:1: in main chunk
E5108: Error executing lua [string ":lua"]:1: attempt to index global 'nvimpager' (a nil value)
stack traceback:
        [string ":lua"]:1: in main chunk
Error detected while processing command line:
E5108: Error executing lua [string ":lua"]:1: attempt to index global 'nvimpager' (a nil value)
stack traceback:
        [string ":lua"]:1: in main chunk

I also moved away .vimrc and .vim from $HOME but the result was the same.

Well, then I installed nvimpager into /usr/local/bin with sudo and then it worked. But when I tried export NVINPAGER_NVIM=... it stopped working again (with the same message about no lua package "nvimpager"). And then I felt bad from my stupidity and I deleted everything - and neovim and nvimpager and decided to continue to use old good vim and less)). Sorry.