From 7384288e079c7c7dfc24f94c2189e2e075f7dcdf Mon Sep 17 00:00:00 2001 From: Martin Chaine Date: Tue, 6 Dec 2016 14:40:14 +0100 Subject: [PATCH 1/4] 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 %{(? Date: Tue, 6 Dec 2016 14:46:25 +0100 Subject: [PATCH 2/4] better filetype detection http://asciidoctor.org/docs/asciidoc-recommended-practices/#document-extension --- rc/core/asciidoc.kak | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rc/core/asciidoc.kak b/rc/core/asciidoc.kak index a7bb1539..308d211f 100644 --- a/rc/core/asciidoc.kak +++ b/rc/core/asciidoc.kak @@ -4,7 +4,9 @@ # Detection # ‾‾‾‾‾‾‾‾‾ -hook global BufCreate .*\.asciidoc %{ set buffer filetype asciidoc } +hook global BufCreate .+\.(a(scii)?doc|asc) %{ + set buffer filetype asciidoc +} # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ From 74432ac8f2336d557a60485c29b95adbe3a5345e Mon Sep 17 00:00:00 2001 From: Martin Chaine Date: Tue, 6 Dec 2016 17:53:12 +0100 Subject: [PATCH 3/4] match filetype for eml extension stolen from #878 --- rc/base/mail.kak | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rc/base/mail.kak b/rc/base/mail.kak index b5d99f8c..9eb3894d 100644 --- a/rc/base/mail.kak +++ b/rc/base/mail.kak @@ -1,4 +1,10 @@ -hook global BufSetOption mimetype=message/rfc822 %{ set buffer filetype mail } +hook global BufCreate .+\.eml %{ + set buffer filetype mail +} + +hook global BufSetOption mimetype=message/rfc822 %{ + set buffer filetype mail +} addhl -group / group mail addhl -group /mail regex ^(From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To):([^\n]*(?:\n\h+[^\n]+)*)$ 1:keyword 2:attribute From 5fcb99a1545d5f5bcf230d40ee8afc0d69ab4bb4 Mon Sep 17 00:00:00 2001 From: Martin Chaine Date: Wed, 7 Dec 2016 14:00:06 +0100 Subject: [PATCH 4/4] smarter mimetype matching --- rc/base/file.kak | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rc/base/file.kak b/rc/base/file.kak index 0aef21ec..89442fa9 100644 --- a/rc/base/file.kak +++ b/rc/base/file.kak @@ -3,9 +3,12 @@ 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}" + case "${mime}" in + text/x-*) filetype="${mime#text/x-}" ;; + text/*) filetype="${mime#text/}" ;; + esac + if [ -n "${filetype}" ]; then + printf "set buffer filetype '%s'\n" "${filetype}" else printf "set buffer mimetype '%s'\n" "${mime}" fi