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.
This commit is contained in:
Martin Chaine 2016-12-06 14:40:14 +01:00
parent b3ac733f33
commit 7384288e07
36 changed files with 18 additions and 140 deletions

View File

@ -6,10 +6,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-clojure %{
set buffer filetype clojure
}
hook global BufCreate .*[.](cljs?) %{
set buffer filetype clojure
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-css %{
set buffer filetype css
}
hook global BufCreate .*[.](css) %{
set buffer filetype css
}

View File

@ -5,7 +5,6 @@
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.di? %{
set buffer mimetype ""
set buffer filetype d
}

13
rc/base/file.kak Normal file
View File

@ -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
} }

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-fish %{
set buffer filetype fish
}
hook global BufCreate .*[.](fish) %{
set buffer filetype fish
}

View File

@ -5,7 +5,6 @@
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.go %{
set buffer mimetype ""
set buffer filetype go
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-haskell %{
set buffer filetype haskell
}
hook global BufCreate .*[.](hs) %{
set buffer filetype haskell
}

View File

@ -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 %{(?<!')"} %{(?<!\\)(\\\\)*"} '' \
comment /\* \*/ '' \

View File

@ -1,10 +1,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-javascript %{
set buffer filetype javascript
}
hook global BufCreate .*[.](js) %{
set buffer filetype javascript
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-json %{
set buffer filetype json
}
hook global BufCreate .*[.](json) %{
set buffer filetype json
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-lisp %{
set buffer filetype lisp
}
hook global BufCreate .*[.](lisp) %{
set buffer filetype lisp
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-lua %{
set buffer filetype lua
}
hook global BufCreate .*[.](lua) %{
set buffer filetype lua
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-markdown %{
set buffer filetype markdown
}
hook global BufCreate .*[.](markdown|md|mkd) %{
set buffer filetype markdown
}

View File

@ -1,5 +0,0 @@
decl str mimetype "text/plain"
hook global BufOpen .* %{
set buffer mimetype %sh{file -b --mime-type "${kak_buffile}" }
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-perl %{
set buffer filetype perl
}
hook global BufCreate .*\.pl %{
set buffer filetype perl
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-ruby %{
set buffer filetype ruby
}
hook global BufCreate .*(([.](rb))|(irbrc)|(pryrc)|(Capfile|[.]cap)|(Gemfile)|(Guardfile)|(Rakefile|[.]rake)|(Thorfile|[.]thor)|(Vagrantfile)) %{
set buffer filetype ruby
}

View File

@ -4,13 +4,8 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-rust %{
set buffer filetype rust
}
hook global BufCreate .*[.](rust|rs) %{
set buffer filetype rust
set buffer mimetype ''
}
# Highlighters

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-scala %{
set buffer filetype scala
}
hook global BufCreate .*[.](scala) %{
set buffer filetype scala
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-yaml %{
set buffer filetype yaml
}
hook global BufCreate .*[.](yaml) %{
set buffer filetype yaml
}

View File

@ -1,11 +1,13 @@
hook global BufCreate .*\.(cc|cpp|cxx|C|hh|hpp|hxx|H)$ %{
set buffer filetype cpp
set buffer mimetype ''
}
hook global BufSetOption filetype=c\+\+ %{
set buffer filetype cpp
}
hook global BufCreate .*\.c$ %{
set buffer filetype c
set buffer mimetype ''
}
hook global BufCreate .*\.h$ %{
@ -15,24 +17,10 @@ hook global BufCreate .*\.h$ %{
} catch %{
set buffer filetype c
}
set buffer mimetype ''
}
hook global BufSetOption mimetype=text/x-c %{
set buffer filetype c
}
hook global BufSetOption mimetype=text/x-c\+\+ %{
set buffer filetype cpp
}
hook global BufCreate .*\.m %{
set buffer filetype objc
set buffer mimetype ''
}
hook global BufSetOption mimetype=text/x-objc %{
set buffer filetype objc
}
def -hidden _c-family-trim-autoindent %[ eval -draft -itersel %[

View File

@ -1,10 +1,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-makefile %{
set buffer filetype makefile
}
hook global BufCreate .*/?[mM]akefile %{
set buffer filetype makefile
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-python %{
set buffer filetype python
}
hook global BufCreate .*[.](py) %{
set buffer filetype python
}

View File

@ -2,10 +2,6 @@ hook global BufCreate .*\.(z|ba|c|k)?sh(rc|_profile)? %{
set buffer filetype sh
}
hook global BufSetOption mimetype=text/x-shellscript %{
set buffer filetype sh
}
addhl -group / regions -default code sh \
double_string %{(?<!\\)(\\\\)*\K"} %{(?<!\\)(\\\\)*"} '' \
single_string %{(?<!\\)(\\\\)*\K'} %{'} '' \

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-cabal %{
set buffer filetype cabal
}
hook global BufCreate .*[.](cabal) %{
set buffer filetype cabal
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-coffee %{
set buffer filetype coffee
}
hook global BufCreate .*[.](coffee) %{
set buffer filetype coffee
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-cucumber %{
set buffer filetype cucumber
}
hook global BufCreate .*[.](feature|story) %{
set buffer filetype cucumber
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-haml %{
set buffer filetype haml
}
hook global BufCreate .*[.](haml) %{
set buffer filetype haml
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-tex %{
set buffer filetype latex
}
hook global BufCreate .*\.tex %{
set buffer filetype latex
}

View File

@ -52,7 +52,6 @@ def -hidden _modeline-parse %{
autowrap_column
eolformat
filetype
mimetype
BOM
)

View File

@ -4,12 +4,8 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-moon %{
set buffer filetype moon
}
hook global BufCreate .*[.](moon) %{
set buffer mimetype text/x-moon
set buffer filetype moon
}
# Highlighters

View File

@ -8,10 +8,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-pug %{
set buffer filetype pug
}
hook global BufCreate .*[.](pug|jade) %{
set buffer filetype pug
}

View File

@ -6,10 +6,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-ragel %{
set buffer filetype ragel
}
hook global BufCreate .*[.](ragel|rl) %{
set buffer filetype ragel
}

View File

@ -4,10 +4,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-sass %{
set buffer filetype sass
}
hook global BufCreate .*[.](sass) %{
set buffer filetype sass
}

View File

@ -6,10 +6,6 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-scss %{
set buffer filetype scss
}
hook global BufCreate .*[.](scss) %{
set buffer filetype scss
}

View File

@ -5,7 +5,6 @@
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.taskpaper %{
set buffer mimetype ""
set buffer filetype taskpaper
}

View File

@ -5,7 +5,6 @@
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate (.+/)?[Tt]upfile %{
set buffer mimetype ""
set buffer filetype tupfile
}