lucc / nvimpager

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

Manual pages aren't displaying correctly #55

Closed slococo closed 2 years ago

slococo commented 2 years ago

This is the output of man nvimpager: https://i.imgur.com/lhZrjaN.png

Do you know what can I do?

lucc commented 2 years ago

What version of nvim and nvimpager are you running? On which OS?

If you do not have the newest version of nvimpager you can try to update that first. Otherwise we have to investigate (I can not reproduce your problem here (yet)).

slococo commented 2 years ago

nvimpager-git 0.10.2.r6.g49315df-1 (https://aur.archlinux.org/packages/nvimpager-git/) Arch Linux

lucc commented 2 years ago

I can reproduce this in a podman container like so:

podman run --rm --tty --interactive archlinux

pacman -Syu
pacman -Syu neovim git scdoc make man
git clone https://github.com/lucc/nvimpager
cd nvimpager/
make nvimpager.1
PAGER=./nvimpager man ./nvimpager.1

It might be that I am still using neovim 0.5 and arch linux already has 0.5.1. There was a note about something like that: https://github.com/neovim/neovim/issues/14090#issuecomment-913837694

Can you check if this patch helps:

diff --git a/lua/nvimpager.lua b/lua/nvimpager.lua
index 6737833..55f8685 100644
--- a/lua/nvimpager.lua
+++ b/lua/nvimpager.lua
@@ -392,7 +392,7 @@ end
 local function detect_filetype()
   if not doc then
     if detect_man_page_in_current_buffer() then
-      nvim.nvim_buf_set_option(0, 'filetype', 'man')
+      nvim.nvim_command('Man!')
     end
   else
     if doc == 'git' then
slococo commented 2 years ago

Sorry, but the patch didn't fix the problem.

lucc commented 2 years ago

Ok, maybe this works better:

diff --git a/lua/nvimpager.lua b/lua/nvimpager.lua
index 6737833..deebccf 100644
--- a/lua/nvimpager.lua
+++ b/lua/nvimpager.lua
@@ -390,18 +390,18 @@ end
 -- Detect possible filetypes for the current buffer by looking at the pstree
 -- or ansi escape sequences or manpage sequences in the current buffer.
 local function detect_filetype()
-  if not doc then
-    if detect_man_page_in_current_buffer() then
-      nvim.nvim_buf_set_option(0, 'filetype', 'man')
-    end
+  if not doc and detect_man_page_in_current_buffer() then doc = 'man' end
+  if doc == 'git' then
+    -- Use nvim's syntax highlighting for git buffers instead of git's
+    -- internal highlighting.
+    strip_ansi_escape_sequences_from_current_buffer()
+  end
+  if doc == 'man' then
+    nvim.nvim_buf_set_option(0, 'readonly', false)
+    nvim.nvim_command("Man!")
+    nvim.nvim_buf_set_option(0, 'readonly', true)
   else
-    if doc == 'git' then
-      -- Use nvim's syntax highlighting for git buffers instead of git's
-      -- internal highlighting.
-      strip_ansi_escape_sequences_from_current_buffer()
-    elseif doc == 'pydoc' or doc == 'perldoc' or doc == 'ri' then
-      doc = 'man'
-    end
+    if doc == 'pydoc' or doc == 'perldoc' or doc == 'ri' then doc = 'man' end
     nvim.nvim_buf_set_option(0, 'filetype', doc)
   end
 end
slococo commented 2 years ago

Yep, that definitely works! TY!!!

slococo commented 2 years ago

Hi, I have a problem with this patch. If I run nmcli -a it will show: "Error detected while processing command line: E5108: Error executing lua ...user/.local/share/nvimpager/runtime/lua/nvimpager.lua:405: Cannot unset option 'filety pe' because it doesn't have a global value". Line 405 is nvim.nvim_buf_set_option(0, 'filetype', doc). I can live with this bug but I thought it was worth mentioning

lucc commented 2 years ago

sorry @slococo for the late reply: is your new problem with the patch as posted in this thread or with 63709c4 ?

I think the commit has a fix for your problem.

slococo commented 2 years ago

I installed the latest version and now it works perfectly. TY.