summary refs log tree commit diff
path: root/home
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-20 12:25:30 -0500
committerJune McEnroe <june@causal.agency>2019-02-20 12:25:30 -0500
commitf2e9a9bea332367708dc409939fe3c88296fa787 (patch)
tree7a6e8cc477f2678128e435c66b473811945c5850 /home
parentUse hi -o anchor in up (diff)
downloadsrc-f2e9a9bea332367708dc409939fe3c88296fa787.tar.gz
src-f2e9a9bea332367708dc409939fe3c88296fa787.zip
Set man_hard_wrap in nvim
Vendoring man.vim until <https://github.com/neovim/neovim/pull/9633> is
merged and appears in a release.
Diffstat (limited to '')
-rw-r--r--home/.config/nvim/autoload/man.vim22
-rw-r--r--home/.config/nvim/init.vim1
2 files changed, 18 insertions, 5 deletions
diff --git a/home/.config/nvim/autoload/man.vim b/home/.config/nvim/autoload/man.vim
index 7385862c..c6f49339 100644
--- a/home/.config/nvim/autoload/man.vim
+++ b/home/.config/nvim/autoload/man.vim
@@ -149,8 +149,13 @@ function! s:system(cmd, ...) abort
 endfunction
 
 function! s:get_page(path) abort
-  " Respect $MANWIDTH or default to window width.
-  let manwidth = empty($MANWIDTH) ? winwidth(0) : $MANWIDTH
+  " Disable hard-wrap by using a big $MANWIDTH (max 1000 on some systems #9065).
+  " We use soft wrap: ftplugin/man.vim sets wrap/breakindent/….
+  let manwidth = 999
+  if exists('g:man_hard_wrap')
+    " Respect $MANWIDTH or default to window width.
+    let manwidth = empty($MANWIDTH) ? winwidth(0) : $MANWIDTH
+  endif
   " Force MANPAGER=cat to ensure Vim is not recursively invoked (by man-db).
   " http://comments.gmane.org/gmane.editors.vim.devel/29085
   " Set MAN_KEEP_FORMATTING so Debian man doesn't discard backspaces.
@@ -166,6 +171,11 @@ function! s:put_page(page) abort
   while getline(1) =~# '^\s*$'
     silent keepjumps 1delete _
   endwhile
+  " XXX: nroff justifies text by filling it with whitespace.  That interacts
+  " badly with our use of $MANWIDTH=999.  Hack around this by using a fixed
+  " size for those whitespace regions.
+  silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g
+  1
   lua require("man").highlight_man_page()
   setlocal filetype=man
 endfunction
@@ -386,15 +396,17 @@ function! man#init_pager() abort
     keepjumps 1
   endif
   lua require("man").highlight_man_page()
-  " This is not perfect. See `man glDrawArraysInstanced`. Since the title is
-  " all caps it is impossible to tell what the original capitilization was.
+  " Guess the ref from the heading (which is usually uppercase, so we cannot
+  " know the correct casing, cf. `man glDrawArraysInstanced`).
   let ref = substitute(matchstr(getline(1), '^[^)]\+)'), ' ', '_', 'g')
   try
     let b:man_sect = man#extract_sect_and_name_ref(ref)[0]
   catch
     let b:man_sect = ''
   endtry
-  execute 'silent file man://'.fnameescape(ref)
+  if -1 == match(bufname('%'), 'man:\/\/')  " Avoid duplicate buffers, E95.
+    execute 'silent file man://'.tolower(fnameescape(ref))
+  endif
 endfunction
 
 call s:init()
diff --git a/home/.config/nvim/init.vim b/home/.config/nvim/init.vim
index 0f0e7cb3..0eeae165 100644
--- a/home/.config/nvim/init.vim
+++ b/home/.config/nvim/init.vim
@@ -14,6 +14,7 @@ set foldmethod=syntax foldlevel=99 foldopen-=block
 let asmsyntax = "nasm"
 let c_syntax_for_h = 1
 let is_posix = 1
+let man_hard_wrap = 1
 
 set title laststatus=1
 set scrolloff=1