From 36631fc4734dfff2bcd6582b61b9ca083964d57e Mon Sep 17 00:00:00 2001 From: Reed Wade Date: Tue, 17 Nov 2020 22:32:09 +0100 Subject: [PATCH] Detect filetype on buffer save too This allow kaking a new file, add a shebang in the first line, and get the right filetype detected automatically on save. --- rc/detection/file.kak | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rc/detection/file.kak b/rc/detection/file.kak index c9b2a4042..cdc076e22 100644 --- a/rc/detection/file.kak +++ b/rc/detection/file.kak @@ -1,4 +1,4 @@ -hook global BufOpenFile .* %{ evaluate-commands %sh{ +define-command -hidden file-detection %{ evaluate-commands %sh{ if [ -z "${kak_opt_filetype}" ]; then mime=$(file -b --mime-type -L "${kak_buffile}") mime=${mime%;*} @@ -9,6 +9,7 @@ hook global BufOpenFile .* %{ evaluate-commands %sh{ text/x-shellscript) filetype="sh" ;; text/x-script.*) filetype="${mime#text/x-script.}" ;; text/x-*) filetype="${mime#text/x-}" ;; + text/plain) exit ;; text/*) filetype="${mime#text/}" ;; application/x-*) filetype="${mime#application/x-}" ;; application/*) filetype="${mime#application/}" ;; @@ -19,3 +20,6 @@ hook global BufOpenFile .* %{ evaluate-commands %sh{ fi fi } } + +hook global BufOpenFile .* file-detection +hook global BufWritePost .* file-detection