From 7384288e079c7c7dfc24f94c2189e2e075f7dcdf Mon Sep 17 00:00:00 2001 From: Martin Chaine Date: Tue, 6 Dec 2016 14:40:14 +0100 Subject: [PATCH] transform mimetype to a fallback option The option is now used as a fallback when detection by extension fails. Some scripts like `base/mail.kak` and `base/html.kak` still rely heavily on it. --- rc/base/clojure.kak | 4 ---- rc/base/css.kak | 4 ---- rc/base/d.kak | 1 - rc/base/file.kak | 13 +++++++++++++ rc/base/fish.kak | 4 ---- rc/base/go.kak | 1 - rc/base/haskell.kak | 4 ---- rc/base/java.kak | 4 ---- rc/base/javascript.kak | 4 ---- rc/base/json.kak | 4 ---- rc/base/lisp.kak | 4 ---- rc/base/lua.kak | 4 ---- rc/base/markdown.kak | 4 ---- rc/base/mime.kak | 5 ----- rc/base/perl.kak | 4 ---- rc/base/ruby.kak | 4 ---- rc/base/rust.kak | 5 ----- rc/base/scala.kak | 4 ---- rc/base/yaml.kak | 4 ---- rc/core/c-family.kak | 20 ++++---------------- rc/core/makefile.kak | 4 ---- rc/core/python.kak | 4 ---- rc/core/sh.kak | 4 ---- rc/extra/cabal.kak | 4 ---- rc/extra/coffee.kak | 4 ---- rc/extra/cucumber.kak | 4 ---- rc/extra/haml.kak | 4 ---- rc/extra/latex.kak | 4 ---- rc/extra/modeline.kak | 1 - rc/extra/moon.kak | 6 +----- rc/extra/pug.kak | 4 ---- rc/extra/ragel.kak | 4 ---- rc/extra/sass.kak | 4 ---- rc/extra/scss.kak | 4 ---- rc/extra/taskpaper.kak | 1 - rc/extra/tupfile.kak | 1 - 36 files changed, 18 insertions(+), 140 deletions(-) create mode 100644 rc/base/file.kak delete mode 100644 rc/base/mime.kak diff --git a/rc/base/clojure.kak b/rc/base/clojure.kak index 1336bd41..194a2815 100644 --- a/rc/base/clojure.kak +++ b/rc/base/clojure.kak @@ -6,10 +6,6 @@ # Detection # ‾‾‾‾‾‾‾‾‾ -hook global BufSetOption mimetype=text/x-clojure %{ - set buffer filetype clojure -} - hook global BufCreate .*[.](cljs?) %{ set buffer filetype clojure } diff --git a/rc/base/css.kak b/rc/base/css.kak index 06c483aa..27a58712 100644 --- a/rc/base/css.kak +++ b/rc/base/css.kak @@ -4,10 +4,6 @@ # Detection # ‾‾‾‾‾‾‾‾‾ -hook global BufSetOption mimetype=text/x-css %{ - set buffer filetype css -} - hook global BufCreate .*[.](css) %{ set buffer filetype css } diff --git a/rc/base/d.kak b/rc/base/d.kak index d5ab7df9..3344572b 100644 --- a/rc/base/d.kak +++ b/rc/base/d.kak @@ -5,7 +5,6 @@ # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*\.di? %{ - set buffer mimetype "" set buffer filetype d } diff --git a/rc/base/file.kak b/rc/base/file.kak new file mode 100644 index 00000000..0aef21ec --- /dev/null +++ b/rc/base/file.kak @@ -0,0 +1,13 @@ +decl str mimetype + +hook global BufOpen .* %{ %sh{ + if [ -z "${kak_opt_filetype}" ]; then + mime=$(file -b --mime-type "${kak_buffile}") + printf %s\\n "${mime}" | grep -q '^text/x-' + if [ $? -eq 0 ]; then + printf "set buffer filetype '%s'\n" "${mime:7}" + else + printf "set buffer mimetype '%s'\n" "${mime}" + fi + fi +} } diff --git a/rc/base/fish.kak b/rc/base/fish.kak index 81c1dabc..6bb4a5f5 100644 --- a/rc/base/fish.kak +++ b/rc/base/fish.kak @@ -4,10 +4,6 @@ # Detection # ‾‾‾‾‾‾‾‾‾ -hook global BufSetOption mimetype=text/x-fish %{ - set buffer filetype fish -} - hook global BufCreate .*[.](fish) %{ set buffer filetype fish } diff --git a/rc/base/go.kak b/rc/base/go.kak index b925576a..0b0be61b 100644 --- a/rc/base/go.kak +++ b/rc/base/go.kak @@ -5,7 +5,6 @@ # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*\.go %{ - set buffer mimetype "" set buffer filetype go } diff --git a/rc/base/haskell.kak b/rc/base/haskell.kak index 823c4be0..bb5fb5c1 100644 --- a/rc/base/haskell.kak +++ b/rc/base/haskell.kak @@ -4,10 +4,6 @@ # Detection # ‾‾‾‾‾‾‾‾‾ -hook global BufSetOption mimetype=text/x-haskell %{ - set buffer filetype haskell -} - hook global BufCreate .*[.](hs) %{ set buffer filetype haskell } diff --git a/rc/base/java.kak b/rc/base/java.kak index 606f0318..1ccc82fc 100644 --- a/rc/base/java.kak +++ b/rc/base/java.kak @@ -2,10 +2,6 @@ hook global BufCreate .*\.java %{ set buffer filetype java } -hook global BufSetOption mimetype=text/java %{ - set buffer filetype java -} - addhl -group / regions -default code java \ string %{(?