diff --git a/.config/fish/functions/kakman.fish b/.config/fish/functions/kakman.fish new file mode 100644 index 00000000..58692f7d --- /dev/null +++ b/.config/fish/functions/kakman.fish @@ -0,0 +1,23 @@ +function kakman --wraps man --description 'Display manual pages with Kakoune' + set -lx MANPATH (string join : $MANPATH) + if test -z "$MANPATH" + type -q manpath + and set MANPATH (command manpath) + end + + # Check data dir for Fish 2.x compatibility + set -l fish_data_dir + if set -q __fish_data_dir + set fish_data_dir $__fish_data_dir + else + set fish_data_dir $__fish_datadir + end + set -l mancmd kak -e "man '$argv'" + set -l fish_manpath (dirname $fish_data_dir)/fish/man + if test -d "$fish_manpath" -a -n "$MANPATH" + set MANPATH "$fish_manpath":$MANPATH + $mancmd + return + end + $mancmd +end diff --git a/.config/fish/functions/lessman.fish b/.config/fish/functions/lessman.fish new file mode 100644 index 00000000..1a3f3ab4 --- /dev/null +++ b/.config/fish/functions/lessman.fish @@ -0,0 +1,38 @@ +function lessman --wraps man --description 'Format and display manual pages with less' + set -l end (printf "\e[0m") + + set -lx LESS_TERMCAP_mb (set_color -o red) + set -lx LESS_TERMCAP_md (set_color -o B14242) + set -lx LESS_TERMCAP_me $end + set -lx LESS_TERMCAP_so (set_color 4A8B8B) + set -lx LESS_TERMCAP_se $end + set -lx LESS_TERMCAP_us (set_color -o D87C4A) + set -lx LESS_TERMCAP_ue $end + set -lx LESS '-R -s' + + set -lx GROFF_NO_SGR yes # fedora + + set -lx MANPATH (string join : $MANPATH) + if test -z "$MANPATH" + type -q manpath + and set MANPATH (command manpath) + end + + # Check data dir for Fish 2.x compatibility + set -l fish_data_dir + if set -q __fish_data_dir + set fish_data_dir $__fish_data_dir + else + set fish_data_dir $__fish_datadir + end + set -l kakargs 'set buffer filetype man; set buffer readonly true; execute-keys %sh{ }' + set -l mancmd kak -e "man '$argv'" + set -l fish_manpath (dirname $fish_data_dir)/fish/man + if test -d "$fish_manpath" -a -n "$MANPATH" + set MANPATH "$fish_manpath":$MANPATH + command man $argv + return + end + command man $argv + $mancmd +end diff --git a/.config/fish/functions/man.fish b/.config/fish/functions/man.fish index 6a401397..02452394 100644 --- a/.config/fish/functions/man.fish +++ b/.config/fish/functions/man.fish @@ -1,39 +1,3 @@ function man --wraps man --description 'Format and display manual pages' - set -l end (printf "\e[0m") - - set -lx LESS_TERMCAP_mb (set_color -o red) - set -lx LESS_TERMCAP_md (set_color -o B14242) - set -lx LESS_TERMCAP_me $end - set -lx LESS_TERMCAP_so (set_color 4A8B8B) - set -lx LESS_TERMCAP_se $end - set -lx LESS_TERMCAP_us (set_color -o D87C4A) - set -lx LESS_TERMCAP_ue $end - set -lx LESS '-R -s' - - set -lx GROFF_NO_SGR yes # fedora - - set -lx MANPATH (string join : $MANPATH) - if test -z "$MANPATH" - type -q manpath - and set MANPATH (command manpath) - end - - # Check data dir for Fish 2.x compatibility - set -l fish_data_dir - if set -q __fish_data_dir - set fish_data_dir $__fish_data_dir - else - set fish_data_dir $__fish_datadir - end - set -l kakargs 'set buffer filetype man; set buffer readonly true; execute-keys %sh{ }' - set -l mancmd kak -e "man '$argv'" - set -l fish_manpath (dirname $fish_data_dir)/fish/man - if test -d "$fish_manpath" -a -n "$MANPATH" - set MANPATH "$fish_manpath":$MANPATH - # command man $argv | kak -e "$kakargs" - $mancmd - return - end - # command man $argv | kak -e "$kakargs" - $mancmd + kakman $argv end diff --git a/.config/kak/autoload/filetype.kak b/.config/kak/autoload/filetype.kak index 9b6f1d11..36079e0b 100644 --- a/.config/kak/autoload/filetype.kak +++ b/.config/kak/autoload/filetype.kak @@ -31,6 +31,9 @@ hook global WinSetOption filetype=fish %{ set-option window formatcmd "fish_indent" } +# TODO: modify man.kak so that it leaves one char of whitespace +# on the rightmost column of the whole file, so that selecting the whole +# line doesn't cause hortizonal overflow! hook global WinSetOption filetype=man %{ try %{ # remove these highlighters so everything displays properly @@ -42,9 +45,11 @@ hook global WinSetOption filetype=man %{ # This is needed because we can't modify the selection # in WinSetOption's context hook -once global User manpageloaded %{ + # This will move the cursor to the enter of the screen execute-keys %sh{ result=$((kak_window_height / 2 - 1)) printf '%d%s' "$result" 'j' } + set-option window scrolloff "99,0" } } diff --git a/.config/kak/autoload/man.kak b/.config/kak/autoload/man.kak index 48b5cc5e..41ef09bd 100644 --- a/.config/kak/autoload/man.kak +++ b/.config/kak/autoload/man.kak @@ -1,3 +1,8 @@ +# CHANGES BY DANIEL: +# man-impl emits the 'manpageloaded' User hook event after it's done. +# It also unsets readonly before changing the buffer, and re-sets it when +# it's done. + declare-option -docstring "name of the client in which documentation is to be displayed" \ str docsclient @@ -67,8 +72,6 @@ define-command -hidden -params ..3 man-impl %{ } -# MAN COMMAND -# TODO: REMOVE number lines and show whitespace highlighters! define-command -params ..1 \ -shell-script-candidates %{ find /usr/share/man/ $(printf %s "${MANPATH}" |