diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2022-05-09 11:23:51 +0200 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2022-05-09 16:31:55 +0200 |
| commit | aefdc6783cb77f09786542c90901a9e7120bea42 (patch) | |
| tree | ddce6de8f084ab96270f6111d8e423d0b1533171 /runtime/lua/vim/filetype | |
| parent | 676e9e9334043ce74af74f85f889b0327a443d0b (diff) | |
| download | rneovim-aefdc6783cb77f09786542c90901a9e7120bea42.tar.gz rneovim-aefdc6783cb77f09786542c90901a9e7120bea42.tar.bz2 rneovim-aefdc6783cb77f09786542c90901a9e7120bea42.zip | |
chore: format runtime with stylua
Diffstat (limited to 'runtime/lua/vim/filetype')
| -rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 169 |
1 files changed, 87 insertions, 82 deletions
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 787b335251..4c363e7403 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -9,7 +9,7 @@ local function getlines(bufnr, start_lnum, end_lnum, opts) local lines = vim.api.nvim_buf_get_lines(bufnr, start_lnum - 1, end_lnum, false) opts = opts or {} - return opts.concat and (table.concat(lines) or "") or lines + return opts.concat and (table.concat(lines) or '') or lines end ---@private @@ -35,23 +35,23 @@ function M.bindzone(path, bufnr) end function M.btm(bufnr) if vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0 then - vim.bo[bufnr].filetype = "dosbatch" + vim.bo[bufnr].filetype = 'dosbatch' else - vim.bo[bufnr].filetype = "btm" + vim.bo[bufnr].filetype = 'btm' end end -- Returns true if file content looks like RAPID local function is_rapid(bufnr, extension) - if extension == "cfg" then + if extension == 'cfg' then local line = getlines(bufnr, 1):lower() - return findany(line, { "eio:cfg", "mmc:cfg", "moc:cfg", "proc:cfg", "sio:cfg", "sys:cfg" }) + return findany(line, { 'eio:cfg', 'mmc:cfg', 'moc:cfg', 'proc:cfg', 'sio:cfg', 'sys:cfg' }) end - local first = "^%s*module%s+%S+%s*" + local first = '^%s*module%s+%S+%s*' -- Called from mod, prg or sys functions for _, line in ipairs(getlines(bufnr, 1, -1)) do - if not line:find("^%s*$") then - return findany(line:lower(), { "^%s*%%%%%%", first .. "(", first .. "$" }) + if not line:find('^%s*$') then + return findany(line:lower(), { '^%s*%%%%%%', first .. '(', first .. '$' }) end end -- Only found blank lines @@ -61,10 +61,10 @@ end function M.cfg(bufnr) if vim.g.filetype_cfg then vim.bo[bufnr].filetype = vim.g.filetype_cfg - elseif is_rapid(bufnr, "cfg") then - vim.bo[bufnr].filetype = "rapid" + elseif is_rapid(bufnr, 'cfg') then + vim.bo[bufnr].filetype = 'rapid' else - vim.bo[bufnr].filetype = "cfg" + vim.bo[bufnr].filetype = 'cfg' end end @@ -85,23 +85,23 @@ function M.e(path, bufnr) end -- If not found, assume SGML. function M.ent(bufnr) for _, line in ipairs(getlines(bufnr, 1, 5)) do - if line:find("^%s*[#{]") then - vim.bo[bufnr].filetype = "cl" + if line:find('^%s*[#{]') then + vim.bo[bufnr].filetype = 'cl' return - elseif not line:find("^%s*$") then + elseif not line:find('^%s*$') then -- Not a blank line, not a comment, and not a block start, -- so doesn't look like valid cl code. break end end - vim.bo[bufnr].filetype = "dtd" + vim.bo[bufnr].filetype = 'dtd' end function M.euphoria(bufnr) if vim.g.filetype_euphoria then vim.bo[bufnr].filetype = vim.g.filetype_euphoria else - vim.bo[bufnr].filetype = "euphoria3" + vim.bo[bufnr].filetype = 'euphoria3' end end @@ -111,12 +111,12 @@ function M.ex(bufnr) else for _, line in ipairs(getlines(bufnr, 1, 100)) do -- TODO: in the Vim regex, \> is used to match the end of the word, can this be omitted? - if findany(line, { "^%-%-", "^ifdef", "^include" }) then - vim.bo[bufnr].filetype = "euphoria3" + if findany(line, { '^%-%-', '^ifdef', '^include' }) then + vim.bo[bufnr].filetype = 'euphoria3' return end end - vim.bo[bufnr].filetype = "elixir" + vim.bo[bufnr].filetype = 'elixir' end end @@ -126,10 +126,10 @@ end function M.foam(bufnr) local foam_file = false for _, line in ipairs(getlines(bufnr, 1, 15)) do - if line:find("^FoamFile") then + if line:find('^FoamFile') then foam_file = true - elseif foam_file and line:find("^%s*object") then - vim.bo[bufnr].filetype = "foam" + elseif foam_file and line:find('^%s*object') then + vim.bo[bufnr].filetype = 'foam' return end end @@ -141,10 +141,10 @@ function M.frm(bufnr) else -- Always ignore case local lines = getlines(bufnr, 1, 5, { concat = true }):lower() - if findany(lines, { "vb_name", "begin vb%.form", "begin vb%.mdiform" }) then - vim.bo[bufnr].filetype = "vb" + if findany(lines, { 'vb_name', 'begin vb%.form', 'begin vb%.mdiform' }) then + vim.bo[bufnr].filetype = 'vb' else - vim.bo[bufnr].filetype = "form" + vim.bo[bufnr].filetype = 'form' end end end @@ -153,21 +153,21 @@ function M.fs(path, bufnr) end function M.header(bufnr) for _, line in ipairs(getlines(bufnr, 1, 200)) do - if findany(line, { "^@interface", "^@end", "^@class" }) then + if findany(line, { '^@interface', '^@end', '^@class' }) then if vim.g.c_syntax_for_h then - vim.bo[bufnr].filetype = "objc" + vim.bo[bufnr].filetype = 'objc' else - vim.bo[bufnr].filetype = "objcpp" + vim.bo[bufnr].filetype = 'objcpp' end return end end if vim.g.c_syntax_for_h then - vim.bo[bufnr].filetype = "c" + vim.bo[bufnr].filetype = 'c' elseif vim.g.ch_syntax_for_h then - vim.bo[bufnr].filetype = "ch" + vim.bo[bufnr].filetype = 'ch' else - vim.bo[bufnr].filetype = "cpp" + vim.bo[bufnr].filetype = 'cpp' end end @@ -176,22 +176,22 @@ function M.idl(bufnr) -- Always ignore case line = line:lower() if findany(line, { '^%s*import%s+"unknwn"%.idl', '^%s*import%s+"objidl"%.idl' }) then - vim.bo[bufnr].filetype = "msidl" + vim.bo[bufnr].filetype = 'msidl' return end end - vim.bo[bufnr].filetype = "idl" + vim.bo[bufnr].filetype = 'idl' end function M.inc(path, bufnr) end function M.inp(bufnr) - if getlines(bufnr, 1):find("^%*") then - vim.bo[bufnr].filetype = "abaqus" + if getlines(bufnr, 1):find('^%*') then + vim.bo[bufnr].filetype = 'abaqus' else for _, line in ipairs(getlines(bufnr, 1, 500)) do - if line:lower():find("^header surface data") then - vim.bo[bufnr].filetype = "trasys" + if line:lower():find('^header surface data') then + vim.bo[bufnr].filetype = 'trasys' return end end @@ -208,32 +208,32 @@ function M.m(path, bufnr) end -- MS message text files use ';', Sendmail files use '#' or 'dnl' function M.mc(bufnr) for _, line in ipairs(getlines(bufnr, 1, 20)) do - if findany(line:lower(), { "^%s*#", "^%s*dnl" }) then + if findany(line:lower(), { '^%s*#', '^%s*dnl' }) then -- Sendmail .mc file - vim.bo[bufnr].filetype = "m4" + vim.bo[bufnr].filetype = 'm4' return - elseif line:find("^%s*;") then - vim.bo[bufnr].filetype = "msmessages" + elseif line:find('^%s*;') then + vim.bo[bufnr].filetype = 'msmessages' return end end -- Default: Sendmail .mc file - vim.bo[bufnr].filetype = "m4" + vim.bo[bufnr].filetype = 'm4' end function M.mm(path, bufnr) end function M.mms(bufnr) for _, line in ipairs(getlines(bufnr, 1, 20)) do - if findany(line, { "^%s*%%", "^%s*//", "^%*" }) then - vim.bo[bufnr].filetype = "mmix" + if findany(line, { '^%s*%%', '^%s*//', '^%*' }) then + vim.bo[bufnr].filetype = 'mmix' return - elseif line:find("^%s*#") then - vim.bo[bufnr].filetype = "make" + elseif line:find('^%s*#') then + vim.bo[bufnr].filetype = 'make' return end end - vim.bo[bufnr].filetype = "mmix" + vim.bo[bufnr].filetype = 'mmix' end function M.mod(path, bufnr) end @@ -242,8 +242,8 @@ function M.mod(path, bufnr) end -- that case it is probably an nroff file: 'filetype' is set and 1 is returned. function M.nroff(bufnr) for _, line in ipairs(getlines(bufnr, 1, 5)) do - if line:find("^%.") then - vim.bo[bufnr].filetype = "nroff" + if line:find('^%.') then + vim.bo[bufnr].filetype = 'nroff' return 1 end end @@ -264,10 +264,10 @@ function M.progress_cweb(bufnr) if vim.g.filetype_w then vim.bo[bufnr].filetype = vim.g.filetype_w else - if getlines(bufnr, 1):find("^&ANALYZE") or getlines(bufnr, 3):find("^&GLOBAL%-DEFINE") then - vim.bo[bufnr].filetype = "progress" + if getlines(bufnr, 1):find('^&ANALYZE') or getlines(bufnr, 3):find('^&GLOBAL%-DEFINE') then + vim.bo[bufnr].filetype = 'progress' else - vim.bo[bufnr].filetype = "cweb" + vim.bo[bufnr].filetype = 'cweb' end end end @@ -280,20 +280,20 @@ function M.r(bufnr) local lines = getlines(bufnr, 1, 50) -- TODO: \< / \> which match the beginning / end of a word -- Rebol is easy to recognize, check for that first - if table.concat(lines):lower():find("rebol") then - vim.bo[bufnr].filetype = "rebol" + if table.concat(lines):lower():find('rebol') then + vim.bo[bufnr].filetype = 'rebol' return end for _, line in ipairs(lines) do -- R has # comments - if line:find("^%s*#") then - vim.bo[bufnr].filetype = "r" + if line:find('^%s*#') then + vim.bo[bufnr].filetype = 'r' return end -- Rexx has /* comments */ - if line:find("^%s*/%*") then - vim.bo[bufnr].filetype = "rexx" + if line:find('^%s*/%*') then + vim.bo[bufnr].filetype = 'rexx' return end end @@ -303,14 +303,14 @@ function M.r(bufnr) vim.bo[bufnr].filetype = vim.g.filetype_r else -- Rexx used to be the default, but R appears to be much more popular. - vim.bo[bufnr].filetype = "r" + vim.bo[bufnr].filetype = 'r' end end function M.redif(bufnr) for _, line in ipairs(getlines(bufnr, 1, 5)) do - if line:lower():find("^template%-type:") then - vim.bo[bufnr].filetype = "redif" + if line:lower():find('^template%-type:') then + vim.bo[bufnr].filetype = 'redif' end end end @@ -321,24 +321,29 @@ function M.rules(path, bufnr) end -- detection between scala and SuperCollider function M.sc(bufnr) for _, line in ipairs(getlines(bufnr, 1, 25)) do - if findany(line, { "[A-Za-z0-9]*%s:%s[A-Za-z0-9]", "var%s<", "classvar%s<", "%^this.*", "|%w*|", "%+%s%w*%s{", "%*ar%s" }) then - vim.bo[bufnr].filetype = "supercollider" + if + findany( + line, + { '[A-Za-z0-9]*%s:%s[A-Za-z0-9]', 'var%s<', 'classvar%s<', '%^this.*', '|%w*|', '%+%s%w*%s{', '%*ar%s' } + ) + then + vim.bo[bufnr].filetype = 'supercollider' return end end - vim.bo[bufnr].filetype = "scala" + vim.bo[bufnr].filetype = 'scala' end -- This function checks the first line of file extension "scd" to resolve -- detection between scdoc and SuperCollider function M.scd(bufnr) - local first = "^%S+%(%d[0-9A-Za-z]*%)" + local first = '^%S+%(%d[0-9A-Za-z]*%)' local opt = [[%s+"[^"]*"]] local line = getlines(bufnr, 1) - if findany(line, { first .. "$", first .. opt .. "$", first .. opt .. opt .. "$" }) then - vim.bo[bufnr].filetype = "scdoc" + if findany(line, { first .. '$', first .. opt .. '$', first .. opt .. opt .. '$' }) then + vim.bo[bufnr].filetype = 'scdoc' else - vim.bo[bufnr].filetype = "supercollider" + vim.bo[bufnr].filetype = 'supercollider' end end @@ -350,7 +355,7 @@ function M.sql(bufnr) if vim.g.filetype_sql then vim.bo[bufnr].filetype = vim.g.filetype_sql else - vim.bo[bufnr].filetype = "sql" + vim.bo[bufnr].filetype = 'sql' end end @@ -365,46 +370,46 @@ function M.tf(bufnr) for _, line in ipairs(getlines(bufnr, 1, -1)) do -- Assume terraform file on a non-empty line (not whitespace-only) -- and when the first non-whitespace character is not a ; or / - if not line:find("^%s*$") and not line:find("^%s*[;/]") then - vim.bo[bufnr].filetype = "terraform" + if not line:find('^%s*$') and not line:find('^%s*[;/]') then + vim.bo[bufnr].filetype = 'terraform' return end end - vim.bo[bufnr].filetype = "tf" + vim.bo[bufnr].filetype = 'tf' end function M.xml(bufnr) for _, line in ipairs(getlines(bufnr, 1, 100)) do line = line:lower() - local is_docbook4 = line:find("<!doctype.*docbook") + local is_docbook4 = line:find('<!doctype.*docbook') local is_docbook5 = line:find([[ xmlns="http://docbook.org/ns/docbook"]]) if is_docbook4 or is_docbook5 then - vim.b[bufnr].docbk_type = "xml" + vim.b[bufnr].docbk_type = 'xml' vim.b[bufnr].docbk_ver = is_docbook4 and 4 or 5 - vim.bo[bufnr].filetype = "docbk" + vim.bo[bufnr].filetype = 'docbk' return end if line:find([[xmlns:xbl="http://www.mozilla.org/xbl"]]) then - vim.bo[bufnr].filetype = "xbl" + vim.bo[bufnr].filetype = 'xbl' return end end - vim.bo[bufnr].filetype = "xml" + vim.bo[bufnr].filetype = 'xml' end function M.y(bufnr) for _, line in ipairs(getlines(bufnr, 1, 100)) do - if line:find("^%s*%%") then - vim.bo[bufnr].filetype = "yacc" + if line:find('^%s*%%') then + vim.bo[bufnr].filetype = 'yacc' return end -- TODO: in the Vim regex, \> is used to match the end of the word after "class", -- can this be omitted? - if findany(line, { "^%s*#", "^%class", "^%s*#%s*include" }) then - vim.bo[bufnr].filetype = "racc" + if findany(line, { '^%s*#', '^%class', '^%s*#%s*include' }) then + vim.bo[bufnr].filetype = 'racc' end end - vim.bo[bufnr].filetype = "yacc" + vim.bo[bufnr].filetype = 'yacc' end -- luacheck: pop |