summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-04-18 19:07:31 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-04-18 19:07:31 +0200
commit7af98eae43a7f703d7314adb74fdd5ccbc866c14 (patch)
treed94d86dda36e8b0054fb9b7956c90f144d6fab0e /src
parent03238df9677c8a92386466c4d2bec468b12f9fc0 (diff)
add man.kak which provides a man command for displaying man pages in kakoune
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/rc/man.kak36
2 files changed, 37 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index d252715e..e35dbf8e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -34,6 +34,6 @@ XDG_CONFIG_HOME ?= $(HOME)/.config
userconfig:
mkdir -p $(XDG_CONFIG_HOME)/kak/autoload
- ln -s $(CURDIR)/rc/{asciidoc,client,cpp,diff,git,grep,kakrc,make,sh,mail}.kak $(XDG_CONFIG_HOME)/kak/autoload/
+ ln -s $(CURDIR)/rc/{asciidoc,client,cpp,diff,git,grep,kakrc,make,sh,mail,man}.kak $(XDG_CONFIG_HOME)/kak/autoload/
.PHONY: tags userconfig
diff --git a/src/rc/man.kak b/src/rc/man.kak
new file mode 100644
index 00000000..6d2c27a6
--- /dev/null
+++ b/src/rc/man.kak
@@ -0,0 +1,36 @@
+decl str docsclient
+
+hook global WinSetOption filetype=man %{
+ addhl group man-highlight
+ addhl -group man-highlight regex ^\S.*?$ 0:blue
+ addhl -group man-highlight regex ^\h+-+[-a-zA-Z_]+ 0:yellow
+ addhl -group man-highlight regex [-a-zA-Z_.]+\(\d\) 0:green
+ hook window -id man-hooks NormalKey <c-m> man
+ setb tabstop 8
+}
+
+hook global WinSetOption filetype=(?!man).* %{
+ rmhl man-higlight
+ rmhooks window man-hooks
+}
+
+def -shell-params man %{ %sh{
+ [[ -z "$@" ]] && set -- "$kak_selection"
+ # eval in the docsclient context so that kak_window_width is the good one
+ if [[ -n "$kak_opt_docsclient" && "$kak_client" != "$kak_opt_docsclient" ]]; then
+ echo "eval -client $kak_opt_docsclient %{ man $@ }"
+ exit
+ fi
+
+ tmpfile=$(mktemp /tmp/kak-man-XXXXXX)
+ MANWIDTH=${kak_window_width} man "$@" | col -b > ${tmpfile}
+ if (( ${PIPESTATUS[0]} == 0 )); then
+ echo "edit! -scratch '*man*'
+ exec |cat<space>${tmpfile}<ret>gk
+ nop %sh{rm ${tmpfile}}
+ setb filetype man"
+ else
+ echo "echo %{man '$@' failed: see *debug* buffer for details }"
+ rm ${tmpfile}
+ fi
+}}