diff options
-rw-r--r-- | runtime/lua/vim/filetype.lua | 1161 | ||||
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 411 |
2 files changed, 783 insertions, 789 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 536580c604..320d6a2a5b 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -24,13 +24,6 @@ local function starsetf(ft, opts) end ---@private -local function getline(bufnr, start_lnum, end_lnum) - end_lnum = end_lnum or start_lnum - local lines = api.nvim_buf_get_lines(bufnr, start_lnum - 1, end_lnum, false) - return table.concat(lines) or '' -end - ----@private --- Get a single line or line-range from the buffer. --- ---@param bufnr number|nil The buffer to get the lines from @@ -127,6 +120,15 @@ local extension = { end return 'aspvbs' end, + asm = function(path, bufnr) + return require('vim.filetype.detect').asm(bufnr) + end, + lst = function(path, bufnr) + return require('vim.filetype.detect').asm(bufnr) + end, + mac = function(path, bufnr) + return require('vim.filetype.detect').asm(bufnr) + end, ['asn1'] = 'asn', asn = 'asn', asp = function(path, bufnr) @@ -142,14 +144,32 @@ local extension = { ref = 'b', imp = 'b', mch = 'b', + bas = function(path, bufnr) + return require('vim.filetype.detect').bas(bufnr) + end, + bi = function(path, bufnr) + return require('vim.filetype.detect').bas(bufnr) + end, + bm = function(path, bufnr) + return require('vim.filetype.detect').bas(bufnr) + end, bc = 'bc', bdf = 'bdf', beancount = 'beancount', bib = 'bib', + com = function(path, bufnr) + return require('vim.filetype.detect').bindzone(bufnr, 'dcl') + end, + db = function(path, bufnr) + return require('vim.filetype.detect').bindzone(bufnr, '') + end, bicep = 'bicep', bl = 'blank', bsdl = 'bsdl', bst = 'bst', + btm = function(path, bufnr) + return (vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0) and 'dosbatch' or 'btm' + end, bzl = 'bzl', bazel = 'bzl', BUILD = 'bzl', @@ -163,6 +183,9 @@ local extension = { hgrc = 'cfg', chf = 'ch', chai = 'chaiscript', + ch = function(path, bufnr) + return require('vim.filetype.detect').change(bufnr) + end, chs = 'chaskell', chopro = 'chordpro', crd = 'chordpro', @@ -184,15 +207,22 @@ local extension = { atg = 'coco', recipe = 'conaryrecipe', hook = function(path, bufnr) - if getline(bufnr, 1) == '[Trigger]' then - return 'conf' - end + return M.getlines(bufnr, 1) == '[Trigger]' and 'conf' end, mklx = 'context', mkiv = 'context', mkii = 'context', mkxl = 'context', mkvi = 'context', + control = function(path, bufnr) + return require('vim.filetype.detect').control(bufnr) + end, + copyright = function(path, bufnr) + return require('vim.filetype.detect').copyright(bufnr) + end, + csh = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, moc = 'cpp', hh = 'cpp', tlh = 'cpp', @@ -206,16 +236,10 @@ local extension = { hxx = 'cpp', hpp = 'cpp', cpp = function(path, bufnr) - if vim.g.cynlib_syntax_for_cpp then - return 'cynlib' - end - return 'cpp' + return vim.g.cynlib_syntax_for_cpp and 'cynlib' or 'cpp' end, cc = function(path, bufnr) - if vim.g.cynlib_syntax_for_cc then - return 'cynlib' - end - return 'cpp' + return vim.g.cynlib_syntax_for_cc and 'cynlib' or 'cpp' end, crm = 'crm', csx = 'cs', @@ -237,6 +261,15 @@ local extension = { drt = 'dart', ds = 'datascript', dcd = 'dcd', + decl = function(path, bufnr) + return require('vim.filetype.detect').decl(bufnr) + end, + dec = function(path, bufnr) + return require('vim.filetype.detect').decl(bufnr) + end, + dcl = function(path, bufnr) + return require('vim.filetype.detect').decl(bufnr) or 'clean' + end, def = 'def', desc = 'desc', directory = 'desktop', @@ -253,17 +286,40 @@ local extension = { drac = 'dracula', drc = 'dracula', dtd = 'dtd', + d = function(path, bufnr) + return require('vim.filetype.detect').dtrace(bufnr) + end, dts = 'dts', dtsi = 'dts', dylan = 'dylan', intr = 'dylanintr', lid = 'dylanlid', + e = function(path, bufnr) + return require('vim.filetype.detect').e(bufnr) + end, + E = function(path, bufnr) + return require('vim.filetype.detect').e(bufnr) + end, ecd = 'ecd', + edf = 'edif', + edfi = 'edif', + edo = 'edif', + edn = function(path, bufnr) + return require('vim.filetype.detect').edn(bufnr) + end, eex = 'eelixir', leex = 'eelixir', + am = function(path, bufnr) + if not path:lower():find('makefile%.am$') then + return 'elf' + end + end, exs = 'elixir', elm = 'elm', elv = 'elvish', + ent = function(path, bufnr) + return require('vim.filetype.detect').ent(bufnr) + end, epp = 'epuppet', erl = 'erlang', hrl = 'erlang', @@ -273,6 +329,36 @@ local extension = { ec = 'esqlc', EC = 'esqlc', strl = 'esterel', + eu = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + EU = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + ew = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + EW = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + EX = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + exu = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + EXU = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + exw = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + EXW = function(path, bufnr) + return vim.g.filetype_euphoria or 'euphoria3' + end, + ex = function(path, bufnr) + return require('vim.filetype.detect').ex(bufnr) + end, exp = 'expect', factor = 'factor', fal = 'falcon', @@ -308,7 +394,13 @@ local extension = { ['f08'] = 'fortran', fpc = 'fpcmake', fsl = 'framescript', + frm = function(path, bufnr) + return require('vim.filetype.detect').frm(bufnr) + end, fb = 'freebasic', + fs = function(path, bufnr) + return require('vim.filetype.detect').fs(bufnr) + end, fsi = 'fsharp', fsx = 'fsharp', fusion = 'fusion', @@ -350,6 +442,9 @@ local extension = { ht = 'haste', htpp = 'hastepreproc', hb = 'hb', + h = function(path, bufnr) + return require('vim.filetype.detect').header(bufnr) + end, sum = 'hercules', errsum = 'hercules', ev = 'hercules', @@ -362,14 +457,56 @@ local extension = { hog = 'hog', hws = 'hollywood', hoon = 'hoon', + cpt = function(path, bufnr) + return require('vim.filetype.detect').html(bufnr) + end, + dtml = function(path, bufnr) + return require('vim.filetype.detect').html(bufnr) + end, + htm = function(path, bufnr) + return require('vim.filetype.detect').html(bufnr) + end, + html = function(path, bufnr) + return require('vim.filetype.detect').html(bufnr) + end, + pt = function(path, bufnr) + return require('vim.filetype.detect').html(bufnr) + end, + shtml = function(path, bufnr) + return require('vim.filetype.detect').html(bufnr) + end, + stm = function(path, bufnr) + return require('vim.filetype.detect').html(bufnr) + end, htt = 'httest', htb = 'httest', + hw = function(path, bufnr) + return require('vim.filetype.detect').hw(bufnr) + end, + module = function(path, bufnr) + return require('vim.filetype.detect').hw(bufnr) + end, + pkg = function(path, bufnr) + return require('vim.filetype.detect').hw(bufnr) + end, iba = 'ibasic', ibi = 'ibasic', icn = 'icon', + idl = function(path, bufnr) + return require('vim.filetype.detect').idl(bufnr) + end, + inc = function(path, bufnr) + return require('vim.filetype.detect').inc(bufnr) + end, inf = 'inform', INF = 'inform', ii = 'initng', + inp = function(path, bufnr) + return require('vim.filetype.detect').inp(bufnr) + end, + ms = function(path, bufnr) + return require('vim.filetype.detect').nroff(bufnr) or 'xmath' + end, iss = 'iss', mst = 'ist', ist = 'ist', @@ -445,14 +582,26 @@ local extension = { lou = 'lout', ulpc = 'lpc', lpc = 'lpc', + c = function(path, bufnr) + return require('vim.filetype.detect').lpc(bufnr) + end, sig = 'lprolog', lsl = 'lsl', lss = 'lss', nse = 'lua', rockspec = 'lua', lua = 'lua', - quake = 'm3quake', + m = function(path, bufnr) + return require('vim.filetype.detect').m(bufnr) + end, at = 'm4', + mc = function(path, bufnr) + return require('vim.filetype.detect').mc(bufnr) + end, + quake = 'm3quake', + ['m4'] = function(path, bufnr) + return require('vim.filetype.detect').m4(path) + end, eml = 'mail', mk = 'make', mak = 'make', @@ -487,8 +636,14 @@ local extension = { mib = 'mib', mix = 'mix', mixal = 'mix', + mm = function(path, bufnr) + return require('vim.filetype.detect').mm(bufnr) + end, nb = 'mma', mmp = 'mmp', + mms = function(path, bufnr) + return require('vim.filetype.detect').mms(bufnr) + end, DEF = 'modula2', ['m2'] = 'modula2', mi = 'modula2', @@ -559,6 +714,9 @@ local extension = { pike = 'pike', pmod = 'pike', rcp = 'pilrc', + PL = function(path, bufnr) + return require('vim.filetype.detect').pl(bufnr) + end, pli = 'pli', ['pl1'] = 'pli', ['p36'] = 'plm', @@ -604,6 +762,9 @@ local extension = { ptl = 'python', ql = 'ql', qll = 'ql', + R = function(path, bufnr) + return require('vim.filetype.detect').r(bufnr) + end, rad = 'radiance', mat = 'radiance', ['pod6'] = 'raku', @@ -685,6 +846,24 @@ local extension = { sdl = 'sdl', sed = 'sed', sexp = 'sexplib', + bash = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ebuild = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + eclass = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + env = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr) + end, + ksh = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'ksh') + end, + sh = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr) + end, sieve = 'sieve', siv = 'sieve', sil = 'sil', @@ -767,14 +946,7 @@ local extension = { latex = 'tex', sty = 'tex', cls = function(path, bufnr) - local line = getline(bufnr, 1) - if line:find('^%%') then - return 'tex' - elseif line:find('^#') and line:lower():find('rexx') then - return 'rexx' - else - return 'st' - end + return require('vim.filetype.detect').cls(bufnr) end, texi = 'texinfo', txi = 'texinfo', @@ -793,11 +965,7 @@ local extension = { tutor = 'tutor', twig = 'twig', ts = function(path, bufnr) - if getline(bufnr, 1):find('<%?xml') then - return 'xml' - else - return 'typescript' - end + return M.getlines(bufnr, 1):find('<%?xml') and 'xml' or 'typescript' end, tsx = 'typescriptreact', uc = 'uc', @@ -855,10 +1023,7 @@ local extension = { wpl = 'xml', xmi = 'xml', xpm = function(path, bufnr) - if getline(bufnr, 1):find('XPM2') then - return 'xpm2' - end - return 'xpm' + return M.getlines(bufnr, 1):find('XPM2') and 'xpm2' or 'xpm' end, ['xpm2'] = 'xpm2', xqy = 'xquery', @@ -882,172 +1047,29 @@ local extension = { zut = 'zimbutempl', zsh = 'zsh', vala = 'vala', - E = function(path, bufnr) - return require('vim.filetype.detect').e(bufnr) - end, - EU = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - EW = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - EX = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - EXU = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - EXW = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) + web = function(path, bufnr) + return require('vim.filetype.detect').web(bufnr) end, - PL = function(path, bufnr) + pl = function(path, bufnr) return require('vim.filetype.detect').pl(bufnr) end, - R = function(path, bufnr) - return require('vim.filetype.detect').r(bufnr) - end, - asm = function(path, bufnr) - return require('vim.filetype.detect').asm(bufnr) - end, - bas = function(path, bufnr) - return require('vim.filetype.detect').bas(bufnr) - end, - bi = function(path, bufnr) - return require('vim.filetype.detect').bas(bufnr) - end, - bm = function(path, bufnr) - return require('vim.filetype.detect').bas(bufnr) - end, - bash = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - btm = function(path, bufnr) - return require('vim.filetype.detect').btm(bufnr) - end, - c = function(path, bufnr) - return require('vim.filetype.detect').lpc(bufnr) - end, - ch = function(path, bufnr) - return require('vim.filetype.detect').change(bufnr) - end, - com = function(path, bufnr) - return require('vim.filetype.detect').bindzone(bufnr, 'dcl') - end, - cpt = function(path, bufnr) - return require('vim.filetype.detect').html(bufnr) - end, - csh = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - d = function(path, bufnr) - return require('vim.filetype.detect').dtrace(bufnr) - end, - db = function(path, bufnr) - return require('vim.filetype.detect').bindzone(bufnr, '') - end, - dtml = function(path, bufnr) - return require('vim.filetype.detect').html(bufnr) - end, - e = function(path, bufnr) - return require('vim.filetype.detect').e(bufnr) - end, - ebuild = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - eclass = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - ent = function(path, bufnr) - return require('vim.filetype.detect').ent(bufnr) - end, - env = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1)) - end, - eu = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - ew = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - ex = function(path, bufnr) - return require('vim.filetype.detect').ex(bufnr) - end, - exu = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - exw = function(path, bufnr) - return require('vim.filetype.detect').euphoria(bufnr) - end, - frm = function(path, bufnr) - return require('vim.filetype.detect').frm(bufnr) - end, - fs = function(path, bufnr) - return require('vim.filetype.detect').fs(bufnr) - end, - h = function(path, bufnr) - return require('vim.filetype.detect').header(bufnr) - end, - htm = function(path, bufnr) - return require('vim.filetype.detect').html(bufnr) - end, - html = function(path, bufnr) - return require('vim.filetype.detect').html(bufnr) + pp = function(path, bufnr) + return require('vim.filetype.detect').pp(bufnr) end, i = function(path, bufnr) return require('vim.filetype.detect').progress_asm(bufnr) end, - idl = function(path, bufnr) - return require('vim.filetype.detect').idl(bufnr) - end, - inc = function(path, bufnr) - return require('vim.filetype.detect').inc(bufnr) - end, - inp = function(path, bufnr) - return require('vim.filetype.detect').inp(bufnr) - end, - ksh = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'ksh') - end, - lst = function(path, bufnr) - return require('vim.filetype.detect').asm(bufnr) - end, - m = function(path, bufnr) - return require('vim.filetype.detect').m(bufnr) - end, - mac = function(path, bufnr) - return require('vim.filetype.detect').asm(bufnr) - end, - mc = function(path, bufnr) - return require('vim.filetype.detect').mc(bufnr) - end, - mm = function(path, bufnr) - return require('vim.filetype.detect').mm(bufnr) - end, - mms = function(path, bufnr) - return require('vim.filetype.detect').mms(bufnr) + w = function(path, bufnr) + return require('vim.filetype.detect').progress_cweb(bufnr) end, p = function(path, bufnr) return require('vim.filetype.detect').progress_pascal(bufnr) end, - patch = function(path, bufnr) - local firstline = getline(bufnr, 1) - if string.find(firstline, '^From ' .. string.rep('%x', 40) .. '+ Mon Sep 17 00:00:00 2001$') then - return 'gitsendemail' - else - return 'diff' - end - end, - pl = function(path, bufnr) - return require('vim.filetype.detect').pl(bufnr) - end, - pp = function(path, bufnr) - return require('vim.filetype.detect').pp(bufnr) - end, pro = function(path, bufnr) return require('vim.filetype.detect').proto(bufnr, 'idlang') end, - pt = function(path, bufnr) - return require('vim.filetype.detect').html('idlang') + patch = function(path, bufnr) + return require('vim.filetype.detect').patch(bufnr) end, r = function(path, bufnr) return require('vim.filetype.detect').r(bufnr) @@ -1056,7 +1078,7 @@ local extension = { return require('vim.filetype.detect').redif(bufnr) end, rules = function(path, bufnr) - return require('vim.filetype.detect').rules(path, bufnr) + return require('vim.filetype.detect').rules(path) end, sc = function(path, bufnr) return require('vim.filetype.detect').sc(bufnr) @@ -1064,20 +1086,14 @@ local extension = { scd = function(path, bufnr) return require('vim.filetype.detect').scd(bufnr) end, - sh = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1)) - end, - shtml = function(path, bufnr) - return require('vim.filetype.detect').html(bufnr) + tcsh = function(path, bufnr) + return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') end, sql = function(path, bufnr) - return require('vim.filetype.detect').sql(bufnr) - end, - stm = function(path, bufnr) - return require('vim.filetype.detect').html(bufnr) + return vim.g.filetype_sql and vim.g.filetype_sql or 'sql' end, - tcsh = function(path, bufnr) - return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') + zsql = function(path, bufnr) + return vim.g.filetype_sql and vim.g.filetype_sql or 'sql' end, tex = function(path, bufnr) return require('vim.filetype.detect').tex(path, bufnr) @@ -1085,8 +1101,8 @@ local extension = { tf = function(path, bufnr) return require('vim.filetype.detect').tf(bufnr) end, - w = function(path, bufnr) - return require('vim.filetype.detect').progress_cweb(bufnr) + txt = function(path, bufnr) + return require('vim.filetype.detect').txt(bufnr) end, xml = function(path, bufnr) return require('vim.filetype.detect').xml(bufnr) @@ -1094,137 +1110,51 @@ local extension = { y = function(path, bufnr) return require('vim.filetype.detect').y(bufnr) end, - zsql = function(path, bufnr) - return require('vim.filetype.detect').sql(bufnr) - end, - txt = function(path, bufnr) - --helpfiles match *.txt, but should have a modeline as last line - if not getline(bufnr, -1):find('vim:.*ft=help') then - return 'text' - end - end, cmd = function(path, bufnr) - if getline(bufnr, 1):find('^/%*') then - return 'rexx' - end - return 'dosbatch' + return M.getlines(bufnr, 1):find('^/%*') and 'rexx' or 'dosbatch' end, rul = function(path, bufnr) return require('vim.filetype.detect').rul(bufnr) end, cpy = function(path, bufnr) - if getline(bufnr, 1):find('^##') then - return 'python' - end - return 'cobol' + return M.getlines(bufnr, 1):find('^##') and 'python' or 'cobol' end, dsl = function(path, bufnr) - if getline(bufnr, 1):find('^%s*<!') then - return 'dsl' - end - return 'structurizr' - end, - edf = 'edif', - edfi = 'edif', - edo = 'edif', - edn = function(path, bufnr) - return require('vim.filetype.detect').edn(bufnr) + return M.getlines(bufnr, 1):find('^%s*<!') and 'dsl' or 'structurizr' end, smil = function(path, bufnr) - if getline(bufnr, 1):find('<%?%s*xml.*%?>') then - return 'xml' - end - return 'smil' + return M.getlines(bufnr, 1):find('<%?%s*xml.*%?>') and 'xml' or 'smil' end, smi = function(path, bufnr) return require('vim.filetype.detect').smi(bufnr) end, install = function(path, bufnr) - if getline(bufnr, 1):lower():find('<%?php') then - return 'php' - end - return require('vim.filetype.detect').sh(path, bufnr, 'bash') + return require('vim.filetype.detect').install(path, bufnr) end, pm = function(path, bufnr) - local line = getline(bufnr, 1) - if line:find('XPM2') then - return 'xpm2' - elseif line:find('XPM') then - return 'xpm' - else - return 'perl' - end + return require('vim.filetype.detect').pm(bufnr) end, me = function(path, bufnr) - local filename = vim.fn.fnamemodify(path, ':t'):lower() - if filename ~= 'read.me' and filename ~= 'click.me' then - return 'nroff' - end + return require('vim.filetype.detect').me(path) end, reg = function(path, bufnr) - local line = getline(bufnr, 1):lower() - if line:find('^regedit[0-9]*%s*$') or line:find('^windows registry editor version %d*%.%d*%s*$') then - return 'registry' - end - end, - decl = function(path, bufnr) - return require('vim.filetype.detect').decl(bufnr) - end, - dec = function(path, bufnr) - return require('vim.filetype.detect').decl(bufnr) - end, - dcl = function(path, bufnr) - local decl = require('vim.filetype.detect').decl(bufnr) - if decl then - return decl - end - return 'clean' - end, - web = function(path, bufnr) - return require('vim.filetype.detect').web(bufnr) + return require('vim.filetype.detect').reg(bufnr) end, ttl = function(path, bufnr) - local line = getline(bufnr, 1):lower() - if line:find('^@?prefix') or line:find('^@?base') then - return 'turtle' - end - return 'teraterm' - end, - am = function(path, bufnr) - if not path:lower():find('makefile%.am$') then - return 'elf' - end + return require('vim.filetype.detect').ttl(bufnr) end, - ['m4'] = function(path, bufnr) - local path_lower = path:lower() - if not path_lower:find('html%.m4$') and not path_lower:find('fvwm2rc') then - return 'm4' - end - end, - hw = function(path, bufnr) - return require('vim.filetype.detect').hw(bufnr) - end, - module = function(path, bufnr) - return require('vim.filetype.detect').hw(bufnr) - end, - pkg = function(path, bufnr) - return require('vim.filetype.detect').hw(bufnr) - end, - ms = function(path, bufnr) - if not require('vim.filetype.detect').nroff(bufnr) then - return 'xmath' + rc = function(path, bufnr) + if not path:find('/etc/Muttrc%.d/') then + return 'rc' end end, - t = function(path, bufnr) - if not require('vim.filetype.detect').nroff(bufnr) and not require('vim.filetype.detect').perl(path, bufnr) then - return 'tads' + rch = function(path, bufnr) + if not path:find('/etc/Muttrc%.d/') then + return 'rc' end end, class = function(path, bufnr) - -- Check if not a Java class (starts with '\xca\xfe\xba\xbe') - if not getline(bufnr, 1):find('^\202\254\186\190') then - return 'stata' - end + require('vim.filetype.detect').class(bufnr) end, sgml = function(path, bufnr) return require('vim.filetype.detect').sgml(bufnr) @@ -1232,27 +1162,20 @@ local extension = { sgm = function(path, bufnr) return require('vim.filetype.detect').sgml(bufnr) end, - rc = function(path, bufnr) - if not path:find('/etc/Muttrc%.d/') then - return 'rc' - end - end, - rch = function(path, bufnr) - if not path:find('/etc/Muttrc%.d/') then - return 'rc' + t = function(path, bufnr) + if not require('vim.filetype.detect').nroff(bufnr) and not require('vim.filetype.detect').perl(path, bufnr) then + return 'tads' end end, - control = function(path, bufnr) - return require('vim.filetype.detect').control(bufnr) - end, - copyright = function(path, bufnr) - return require('vim.filetype.detect').copyright(bufnr) - end, -- Ignored extensions bak = function(path, bufnr) local root = vim.fn.fnamemodify(path, ':r') return M.match(root, bufnr) end, + ['dpkg-bak'] = function(path, bufnr) + local root = vim.fn.fnamemodify(path, ':r') + return M.match(root, bufnr) + end, ['dpkg-dist'] = function(path, bufnr) local root = vim.fn.fnamemodify(path, ':r') return M.match(root, bufnr) @@ -1265,9 +1188,11 @@ local extension = { local root = vim.fn.fnamemodify(path, ':r') return M.match(root, bufnr) end, - ['dpkg-bak'] = function(path, bufnr) - local root = vim.fn.fnamemodify(path, ':r') - return M.match(root, bufnr) + ['in'] = function(path, bufnr) + if vim.fs.basename(path) ~= 'configure.in' then + local root = vim.fn.fnamemodify(path, ':r') + return M.match(root, bufnr) + end end, new = function(path, bufnr) local root = vim.fn.fnamemodify(path, ':r') @@ -1297,12 +1222,6 @@ local extension = { local root = vim.fn.fnamemodify(path, ':r') return M.match(root, bufnr) end, - ['in'] = function(path, bufnr) - if vim.fs.basename(path) ~= 'configure.in' then - local root = vim.fn.fnamemodify(path, ':r') - return M.match(root, bufnr) - end - end, -- END EXTENSION } @@ -1322,6 +1241,13 @@ local filename = { ['.arch-inventory'] = 'arch', ['GNUmakefile.am'] = 'automake', ['named.root'] = 'bindzone', + ['.*/bind/db%..*'] = starsetf('bindzone'), + ['.*/named/db%..*'] = starsetf('bindzone'), + ['cabal%.project%..*'] = starsetf('cabalproject'), + ['sgml%.catalog.*'] = starsetf('catalog'), + ['/etc/hostname%..*'] = starsetf('config'), + ['.*/etc/cron%.d/.*'] = starsetf('crontab'), + ['crontab%..*'] = starsetf('crontab'), WORKSPACE = 'bzl', BUILD = 'bzl', ['cabal.project'] = 'cabalproject', @@ -1335,9 +1261,28 @@ local filename = { ['/etc/defaults/cdrdao'] = 'cdrdaoconf', ['cfengine.conf'] = 'cfengine', ['CMakeLists.txt'] = 'cmake', + ['.alias'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, + ['.cshrc'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, + ['.login'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, + ['csh.cshrc'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, + ['csh.login'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, + ['csh.logout'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, ['auto.master'] = 'conf', ['configure.in'] = 'config', ['configure.ac'] = 'config', + crontab = 'crontab', ['.cvsrc'] = 'cvsrc', ['/debian/changelog'] = 'debchangelog', ['changelog.dch'] = 'debchangelog', @@ -1348,6 +1293,9 @@ local filename = { ['/debian/copyright'] = 'debcopyright', ['/etc/apt/sources.list'] = 'debsources', ['denyhosts.conf'] = 'denyhosts', + ['.*/debian/patches/.*'] = function(path, bufnr) + return require('vim.filetype.detect').dep3patch(path, bufnr) + end, ['dict.conf'] = 'dictconf', ['.dictrc'] = 'dictconf', ['/etc/DIR_COLORS'] = 'dircolors', @@ -1524,6 +1472,9 @@ local filename = { end, ['.procmailrc'] = 'procmail', ['.procmail'] = 'procmail', + ['indent.pro'] = function(path, bufnr) + return require('vim.filetype.detect').proto(bufnr, 'indent') + end, ['/etc/protocols'] = 'protocols', ['INDEX'] = function(path, bufnr) return require('vim.filetype.detect').psf(bufnr) @@ -1551,9 +1502,46 @@ local filename = { ['.screenrc'] = 'screen', ['/etc/sensors3.conf'] = 'sensors', ['/etc/sensors.conf'] = 'sensors', + ['.*/etc/sensors%.d/[^.].*'] = starsetf('sensors'), ['/etc/services'] = 'services', ['/etc/serial.conf'] = 'setserial', ['/etc/udev/cdsymlinks.conf'] = 'sh', + ['bash.bashrc'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + bashrc = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ['.bashrc'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ['.env'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr) + end, + ['.kshrc'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'ksh') + end, + ['.profile'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr) + end, + ['/etc/profile'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr) + end, + APKBUILD = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + PKGBUILD = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ['.tcshrc'] = function(path, bufnr) + return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') + end, + ['tcsh.login'] = function(path, bufnr) + return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') + end, + ['tcsh.tcshrc'] = function(path, bufnr) + return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') + end, ['/etc/slp.conf'] = 'slpconf', ['/etc/slp.reg'] = 'slpreg', ['/etc/slp.spi'] = 'slpspi', @@ -1615,6 +1603,9 @@ local filename = { vim.b[b].xf86conf_xfree86_version = 4 end end, + ['XF86Config'] = function(path, bufnr) + return require('vim.filetype.detect').xfree86() + end, ['/etc/xinetd.conf'] = 'xinetd', fglrxrc = 'xml', ['/etc/blkid.tab'] = 'xml', @@ -1627,67 +1618,6 @@ local filename = { ['.zcompdump'] = 'zsh', ['.zshenv'] = 'zsh', ['.zfbfmarks'] = 'zsh', - ['.alias'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['.bashrc'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - ['.cshrc'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['.env'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1)) - end, - ['.kshrc'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'ksh') - end, - ['.login'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['.profile'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1)) - end, - ['.tcshrc'] = function(path, bufnr) - return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') - end, - ['/etc/profile'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1)) - end, - APKBUILD = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - PKGBUILD = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - ['bash.bashrc'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - bashrc = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - crontab = 'crontab', - ['csh.cshrc'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['csh.login'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['csh.logout'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['indent.pro'] = function(path, bufnr) - return require('vim.filetype.detect').proto(bufnr, 'indent') - end, - ['tcsh.login'] = function(path, bufnr) - return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') - end, - ['tcsh.tcshrc'] = function(path, bufnr) - return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') - end, - ['XF86Config'] = function(path, bufnr) - return require('vim.filetype.detect').xfree86(bufnr) - end, -- END FILENAME } @@ -1699,7 +1629,31 @@ local pattern = { ['.*/etc/asound%.conf'] = 'alsaconf', ['.*/etc/apache2/sites%-.*/.*%.com'] = 'apache', ['.*/etc/httpd/.*%.conf'] = 'apache', + ['.*/etc/apache2/.*%.conf.*'] = starsetf('apache'), + ['.*/etc/apache2/conf%..*/.*'] = starsetf('apache'), + ['.*/etc/apache2/mods%-.*/.*'] = starsetf('apache'), + ['.*/etc/apache2/sites%-.*/.*'] = starsetf('apache'), + ['access%.conf.*'] = starsetf('apache'), + ['apache%.conf.*'] = starsetf('apache'), + ['apache2%.conf.*'] = starsetf('apache'), + ['httpd%.conf.*'] = starsetf('apache'), + ['srm%.conf.*'] = starsetf('apache'), + ['.*/etc/httpd/conf%..*/.*'] = starsetf('apache'), + ['.*/etc/httpd/conf%.d/.*%.conf.*'] = starsetf('apache'), + ['.*/etc/httpd/mods%-.*/.*'] = starsetf('apache'), + ['.*/etc/httpd/sites%-.*/.*'] = starsetf('apache'), + ['.*/etc/proftpd/.*%.conf.*'] = starsetf('apachestyle'), + ['.*/etc/proftpd/conf%..*/.*'] = starsetf('apachestyle'), + ['proftpd%.conf.*'] = starsetf('apachestyle'), + ['.*asterisk/.*%.conf.*'] = starsetf('asterisk'), + ['.*asterisk.*/.*voicemail%.conf.*'] = starsetf('asteriskvm'), ['.*/%.aptitude/config'] = 'aptconf', + ['.*%.[aA]'] = function(path, bufnr) + return require('vim.filetype.detect').asm(bufnr) + end, + ['.*%.[sS]'] = function(path, bufnr) + return require('vim.filetype.detect').asm(bufnr) + end, ['[mM]akefile%.am'] = 'automake', ['.*bsd'] = 'bsdl', ['bzr_log%..*'] = 'bzr', @@ -1711,6 +1665,14 @@ local pattern = { ['.*/etc/cdrdao%.conf'] = 'cdrdaoconf', ['.*/etc/default/cdrdao'] = 'cdrdaoconf', ['.*hgrc'] = 'cfg', + ['.*%.[Cc][Ff][Gg]'] = { + function(path, bufnr) + return require('vim.filetype.detect').cfg(bufnr) + end, + -- Decrease the priority to avoid conflicts with more specific patterns + -- such as '.*/etc/a2ps/.*%.cfg', '.*enlightenment/.*%.cfg', etc. + { priority = -1 }, + }, ['.*%.%.ch'] = 'chill', ['.*%.cmake%.in'] = 'cmake', -- */cmus/rc and */.cmus/rc @@ -1719,7 +1681,24 @@ local pattern = { ['.*/%.?cmus/.*%.theme'] = 'cmusrc', ['.*/%.cmus/autosave'] = 'cmusrc', ['.*/%.cmus/command%-history'] = 'cmusrc', + ['%.cshrc.*'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, + ['%.login.*'] = function(path, bufnr) + return require('vim.filetype.detect').csh(path, bufnr) + end, ['cvs%d+'] = 'cvs', + ['.*%.[Dd][Aa][Tt]'] = function(path, bufnr) + return require('vim.filetype.detect').dat(path, bufnr) + end, + ['[cC]hange[lL]og.*'] = starsetf(function(path, bufnr) + require('vim.filetype.detect').changelog(bufnr) + end), + ['.*/etc/dnsmasq%.d/.*'] = starsetf('dnsmasq'), + ['Containerfile%..*'] = starsetf('dockerfile'), + ['Dockerfile%..*'] = starsetf('dockerfile'), + ['.*/etc/yum%.repos%.d/.*'] = starsetf('dosini'), + ['drac%..*'] = starsetf('dracula'), ['.*/debian/changelog'] = 'debchangelog', ['.*/debian/control'] = 'debcontrol', ['.*/debian/copyright'] = 'debcopyright', @@ -1736,6 +1715,52 @@ local pattern = { ['.*/dtrace/.*%.d'] = 'dtrace', ['.*esmtprc'] = 'esmtprc', ['.*Eterm/.*%.cfg'] = 'eterm', + ['[a-zA-Z0-9].*Dict'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['[a-zA-Z0-9].*Dict%..*'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['[a-zA-Z].*Properties'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['[a-zA-Z].*Properties%..*'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['.*Transport%..*'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['.*/constant/g'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['.*/0/.*'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['.*/0%.orig/.*'] = function(path, bufnr) + return require('vim.filetype.detect').foam(bufnr) + end, + ['.*/%.fvwm/.*'] = starsetf('fvwm'), + ['.*fvwmrc.*'] = starsetf(function(path, bufnr) + return 'fvwm', function(b) + vim.b[b].fvwm_version = 1 + end + end), + ['.*fvwm95.*%.hook'] = starsetf(function(path, bufnr) + return 'fvwm', function(b) + vim.b[b].fvwm_version = 1 + end + end), + ['.*fvwm2rc.*'] = starsetf(function(path, bufnr) + return require('vim.filetype.detect').fvwm(path) + end), + ['.*/tmp/lltmp.*'] = starsetf('gedcom'), + ['/etc/gitconfig%.d/.*'] = starsetf('gitconfig'), + ['.*/gitolite%-admin/conf/.*'] = starsetf('gitolite'), + ['tmac%..*'] = starsetf('nroff'), + ['.*/%.gitconfig%.d/.*'] = starsetf('gitconfig'), + ['.*%.git/.*'] = function(path, bufnr) + require('vim.filetype.detect').git(bufnr) + end, ['.*%.git/modules/.*/config'] = 'gitconfig', ['.*%.git/config'] = 'gitconfig', ['.*/etc/gitconfig'] = 'gitconfig', @@ -1766,13 +1791,15 @@ local pattern = { ['.*/etc/gshadow'] = 'group', ['.*/etc/group%.edit'] = 'group', ['.*/var/backups/gshadow%.bak'] = 'group', - ['.*/etc/group-'] = 'group', - ['.*/etc/gshadow-'] = 'group', + ['.*/etc/group%-'] = 'group', + ['.*/etc/gshadow%-'] = 'group', ['.*/var/backups/group%.bak'] = 'group', ['.*/etc/gshadow%.edit'] = 'group', ['.*/boot/grub/grub%.conf'] = 'grub', ['.*/boot/grub/menu%.lst'] = 'grub', ['.*/etc/grub%.conf'] = 'grub', + -- gtkrc* and .gtkrc* + ['%.?gtkrc.*'] = starsetf('gtkrc'), [vim.env.VIMRUNTIME .. '/doc/.*%.txt'] = 'help', ['hg%-editor%-.*%.txt'] = 'hgcommit', ['.*/etc/host%.conf'] = 'hostconf', @@ -1785,8 +1812,15 @@ local pattern = { ['.*/%.sway/config'] = 'i3config', ['.*/%.icewm/menu'] = 'icemenu', ['.*/etc/initng/.*/.*%.i'] = 'initng', + ['JAM.*%..*'] = starsetf('jam'), + ['Prl.*%..*'] = starsetf('jam'), ['.*%.properties_..'] = 'jproperties', ['.*%.properties_.._..'] = 'jproperties', + ['.*%.properties_.._.._.*'] = starsetf('jproperties'), + ['Kconfig%..*'] = starsetf('kconfig'), + ['.*%.[Ss][Uu][Bb]'] = 'krl', + ['lilo%.conf.*'] = starsetf('lilo'), + ['.*/etc/logcheck/.*%.d.*/.*'] = starsetf('logcheck'), ['.*lftp/rc'] = 'lftp', ['.*/%.libao'] = 'libao', ['.*/etc/libao%.conf'] = 'libao', @@ -1796,52 +1830,99 @@ local pattern = { ['.*/LiteStep/.*/.*%.rc'] = 'litestep', ['.*/etc/login%.access'] = 'loginaccess', ['.*/etc/login%.defs'] = 'logindefs', + ['%.letter%.%d+'] = 'mail', + ['%.article%.%d+'] = 'mail', + ['/tmp/SLRN[0-9A-Z.]+'] = 'mail', + ['ae%d+%.txt'] = 'mail', + ['pico%.%d+'] = 'mail', + ['mutt%-.*%-%w+'] = 'mail', + ['muttng%-.*%-%w+'] = 'mail', + ['neomutt%-.*%-%w+'] = 'mail', + ['mutt' .. string.rep('[%w_-]', 6)] = 'mail', + ['neomutt' .. string.rep('[%w_-]', 6)] = 'mail', + ['snd%.%d+'] = 'mail', + ['reportbug%-.*'] = starsetf('mail'), ['.*/etc/mail/aliases'] = 'mailaliases', ['.*/etc/aliases'] = 'mailaliases', ['.*[mM]akefile'] = 'make', + ['[mM]akefile.*'] = starsetf('make'), ['.*/etc/man%.conf'] = 'manconf', + ['.*%.[Mm][Oo][Dd]'] = function(path, bufnr) + return require('vim.filetype.detect').mod(path, bufnr) + end, ['.*/etc/modules%.conf'] = 'modconf', ['.*/etc/conf%.modules'] = 'modconf', ['.*/etc/modules'] = 'modconf', + ['.*/etc/modprobe%..*'] = starsetf('modconf'), + ['.*/etc/modutils/.*'] = starsetf(function(path, bufnr) + if vim.fn.executable(vim.fn.expand(path)) ~= 1 then + return 'modconf' + end + end), ['.*%.[mi][3g]'] = 'modula3', + ['Muttrc'] = 'muttrc', + ['Muttngrc'] = 'muttrc', + ['.*/etc/Muttrc%.d/.*'] = starsetf('muttrc'), ['.*/%.mplayer/config'] = 'mplayerconf', + ['Muttrc.*'] = starsetf('muttrc'), + ['Muttngrc.*'] = starsetf('muttrc'), + -- muttrc* and .muttrc* + ['%.?muttrc.*'] = starsetf('muttrc'), + -- muttngrc* and .muttngrc* + ['%.?muttngrc.*'] = starsetf('muttrc'), + ['.*/%.mutt/muttrc.*'] = starsetf('muttrc'), + ['.*/%.muttng/muttrc.*'] = starsetf('muttrc'), + ['.*/%.muttng/muttngrc.*'] = starsetf('muttrc'), ['rndc.*%.conf'] = 'named', ['rndc.*%.key'] = 'named', ['named.*%.conf'] = 'named', ['.*/etc/nanorc'] = 'nanorc', ['.*%.NS[ACGLMNPS]'] = 'natural', + ['Neomuttrc.*'] = starsetf('neomuttrc'), + -- neomuttrc* and .neomuttrc* + ['%.?neomuttrc.*'] = starsetf('neomuttrc'), + ['.*/%.neomutt/neomuttrc.*'] = starsetf('neomuttrc'), ['nginx.*%.conf'] = 'nginx', ['.*/etc/nginx/.*'] = 'nginx', ['.*nginx%.conf'] = 'nginx', ['.*/nginx/.*%.conf'] = 'nginx', ['.*/usr/local/nginx/conf/.*'] = 'nginx', + ['.*%.[1-9]'] = function(path, bufnr) + return require('vim.filetype.detect').nroff(bufnr) + end, ['.*%.ml%.cppo'] = 'ocaml', ['.*%.mli%.cppo'] = 'ocaml', ['.*%.opam%.template'] = 'opam', ['.*%.[Oo][Pp][Ll]'] = 'opl', ['.*/etc/pam%.conf'] = 'pamconf', - ['.*/etc/passwd-'] = 'passwd', + ['.*/etc/pam%.d/.*'] = starsetf('pamconf'), + ['.*/etc/passwd%-'] = 'passwd', ['.*/etc/shadow'] = 'passwd', ['.*/etc/shadow%.edit'] = 'passwd', ['.*/var/backups/shadow%.bak'] = 'passwd', ['.*/var/backups/passwd%.bak'] = 'passwd', ['.*/etc/passwd'] = 'passwd', ['.*/etc/passwd%.edit'] = 'passwd', - ['.*/etc/shadow-'] = 'passwd', + ['.*/etc/shadow%-'] = 'passwd', + ['%.?gitolite%.rc'] = 'perl', + ['example%.gitolite%.rc'] = 'perl', ['.*%.php%d'] = 'php', ['.*/%.pinforc'] = 'pinfo', ['.*/etc/pinforc'] = 'pinfo', + ['.*%.[Pp][Rr][Gg]'] = function(path, bufnr) + return require('vim.filetype.detect').prg(bufnr) + end, ['.*/etc/protocols'] = 'protocols', ['.*printcap.*'] = starsetf(function(path, bufnr) - if vim.fn.did_filetype() == 0 then - return 'ptcap', function(b) - vim.b[b].ptcap_type = 'print' - end - end + return require('vim.filetype.detect').printcap('print') end), ['.*baseq[2-3]/.*%.cfg'] = 'quake', ['.*quake[1-3]/.*%.cfg'] = 'quake', ['.*id1/.*%.cfg'] = 'quake', + ['.*/queries/.*%.scm'] = 'query', -- tree-sitter queries (Neovim only) + ['.*,v'] = 'rcs', + ['%.reminders.*'] = starsetf('remind'), + ['[rR]akefile.*'] = starsetf('ruby'), ['[rR]antfile'] = 'ruby', ['[rR]akefile'] = 'ruby', ['.*/etc/sensors%.conf'] = 'sensors', @@ -1849,6 +1930,31 @@ local pattern = { ['.*/etc/services'] = 'services', ['.*/etc/serial%.conf'] = 'setserial', ['.*/etc/udev/cdsymlinks%.conf'] = 'sh', + ['%.bash[_%-]aliases'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ['%.bash[_%-]logout'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ['%.bash[_%-]profile'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ['%.kshrc.*'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'ksh') + end, + ['%.profile.*'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr) + end, + ['.*/etc/profile'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr) + end, + ['bash%-fc[%-%.]'] = function(path, bufnr) + return require('vim.filetype.detect').sh(path, bufnr, 'bash') + end, + ['%.tcshrc.*'] = function(path, bufnr) + return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') + end, + ['.*/etc/sudoers%.d/.*'] = starsetf('sudoers'), ['.*%._sst%.meta'] = 'sisu', ['.*%.%-sst%.meta'] = 'sisu', ['.*%.sst%.meta'] = 'sisu', @@ -1858,9 +1964,15 @@ local pattern = { ['.*/etc/ssh/ssh_config%.d/.*%.conf'] = 'sshconfig', ['.*/%.ssh/config'] = 'sshconfig', ['.*/etc/ssh/sshd_config%.d/.*%.conf'] = 'sshdconfig', + ['.*%.[Ss][Rr][Cc]'] = function(path, bufnr) + return require('vim.filetype.detect').src(bufnr) + end, ['.*/etc/sudoers'] = 'sudoers', ['svn%-commit.*%.tmp'] = 'svn', ['.*%.swift%.gyb'] = 'swiftgyb', + ['.*%.[Ss][Yy][Ss]'] = function(path, bufnr) + return require('vim.filetype.detect').sys(bufnr) + end, ['.*/etc/sysctl%.conf'] = 'sysctl', ['.*/etc/sysctl%.d/.*%.conf'] = 'sysctl', ['.*/systemd/.*%.automount'] = 'systemd', @@ -1885,11 +1997,7 @@ local pattern = { ['.*/%.config/systemd/user/.*%.d/%.#.*'] = 'systemd', ['.*/%.config/systemd/user/%.#.*'] = 'systemd', ['.*termcap.*'] = starsetf(function(path, bufnr) - if vim.fn.did_filetype() == 0 then - return 'ptcap', function(b) - vim.b[b].ptcap_type = 'term' - end - end + return require('vim.filetype.detect').printcap('term') end), ['.*%.t%.html'] = 'tilde', ['%.?tmux.*%.conf'] = 'tmux', @@ -1907,7 +2015,13 @@ local pattern = { ['.*/%.config/upstart/.*%.conf'] = 'upstart', ['.*/%.init/.*%.conf'] = 'upstart', ['.*/usr/share/upstart/.*%.override'] = 'upstart', + ['.*%.[Ll][Oo][Gg]'] = function(path, bufnr) + return require('vim.filetype.detect').log(path) + end, + ['.*%.vhdl_[0-9].*'] = starsetf('vhdl'), ['.*%.ws[fc]'] = 'wsh', + ['.*/Xresources/.*'] = starsetf('xdefaults'), + ['.*/app%-defaults/.*'] = starsetf('xdefaults'), ['.*/etc/xinetd%.conf'] = 'xinetd', ['.*/etc/blkid%.tab'] = 'xml', ['.*/etc/blkid%.tab%.old'] = 'xml', @@ -1917,213 +2031,10 @@ local pattern = { ['.*/etc/xdg/menus/.*%.menu'] = 'xml', ['.*Xmodmap'] = 'xmodmap', ['.*/etc/zprofile'] = 'zsh', - ['%.bash[_-]aliases'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - ['%.bash[_-]logout'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - ['%.bash[_-]profile'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - ['%.cshrc.*'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['%.gtkrc.*'] = starsetf('gtkrc'), - ['%.kshrc.*'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'ksh') - end, - ['%.login.*'] = function(path, bufnr) - return require('vim.filetype.detect').csh(path, bufnr) - end, - ['Muttrc.*'] = starsetf('muttrc'), - ['Muttngrc.*'] = starsetf('muttrc'), - -- muttrc* and .muttrc* - ['%.?muttrc.*'] = starsetf('muttrc'), - -- muttngrc* and .muttngrc* - ['%.?muttngrc.*'] = starsetf('muttrc'), - ['.*/%.mutt/muttrc.*'] = starsetf('muttrc'), - ['.*/%.muttng/muttrc.*'] = starsetf('muttrc'), - ['.*/%.muttng/muttngrc.*'] = starsetf('muttrc'), - ['Neomuttrc.*'] = starsetf('neomuttrc'), - -- neomuttrc* and .neomuttrc* - ['%.?neomuttrc.*'] = starsetf('neomuttrc'), - ['.*/%.neomutt/neomuttrc.*'] = starsetf('neomuttrc'), - ['%.profile.*'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1)) - end, - ['%.reminders.*'] = starsetf('remind'), - ['%.tcshrc.*'] = function(path, bufnr) - return require('vim.filetype.detect').shell(path, bufnr, 'tcsh') - end, - ['%.zcompdump.*'] = starsetf('zsh'), - ['%.zlog.*'] = starsetf('zsh'), - ['%.zsh.*'] = starsetf('zsh'), - ['.*%.[1-9]'] = function(path, bufnr) - return require('vim.filetype.detect').nroff(bufnr) - end, - ['.*%.[aA]'] = function(path, bufnr) - return require('vim.filetype.detect').asm(bufnr) - end, - ['.*%.[sS]'] = function(path, bufnr) - return require('vim.filetype.detect').asm(bufnr) - end, - ['.*%.properties_.._.._.*'] = starsetf('jproperties'), - ['.*%.vhdl_[0-9].*'] = starsetf('vhdl'), - ['.*/%.fvwm/.*'] = starsetf('fvwm'), - ['.*fvwmrc.*'] = starsetf(function(path, bufnr) - return 'fvwm', function(b) - vim.b[b].fvwm_version = 1 - end - end), - ['.*fvwm95.*%.hook'] = starsetf(function(path, bufnr) - return 'fvwm', function(b) - vim.b[b].fvwm_version = 1 - end - end), - ['.*/%.gitconfig%.d/.*'] = starsetf('gitconfig'), - ['.*/Xresources/.*'] = starsetf('xdefaults'), - ['.*/app%-defaults/.*'] = starsetf('xdefaults'), - ['.*/bind/db%..*'] = starsetf('bindzone'), - ['.*/debian/patches/.*'] = function(path, bufnr) - return require('vim.filetype.detect').dep3patch(path, bufnr) - end, - ['.*/etc/Muttrc%.d/.*'] = starsetf('muttrc'), - ['.*/etc/apache2/.*%.conf.*'] = starsetf('apache'), - ['.*/etc/apache2/conf%..*/.*'] = starsetf('apache'), - ['.*/etc/apache2/mods%-.*/.*'] = starsetf('apache'), - ['.*/etc/apache2/sites%-.*/.*'] = starsetf('apache'), - ['.*/etc/cron%.d/.*'] = starsetf('crontab'), - ['.*/etc/dnsmasq%.d/.*'] = starsetf('dnsmasq'), - ['.*/etc/httpd/conf%..*/.*'] = starsetf('apache'), - ['.*/etc/httpd/conf%.d/.*%.conf.*'] = starsetf('apache'), - ['.*/etc/httpd/mods%-.*/.*'] = starsetf('apache'), - ['.*/etc/httpd/sites%-.*/.*'] = starsetf('apache'), - ['.*/etc/logcheck/.*%.d.*/.*'] = starsetf('logcheck'), - ['.*/etc/modprobe%..*'] = starsetf('modconf'), - ['.*/etc/modutils/.*'] = starsetf(function(path, bufnr) - if vim.fn.executable(vim.fn.expand(path)) ~= 1 then - return 'modconf' - end - end), - ['.*/etc/pam%.d/.*'] = starsetf('pamconf'), - ['.*/etc/profile'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1)) - end, - ['.*/etc/proftpd/.*%.conf.*'] = starsetf('apachestyle'), - ['.*/etc/proftpd/conf%..*/.*'] = starsetf('apachestyle'), - ['.*/etc/sudoers%.d/.*'] = starsetf('sudoers'), - ['.*/etc/xinetd%.d/.*'] = starsetf('xinetd'), - ['.*/etc/yum%.repos%.d/.*'] = starsetf('dosini'), - ['.*/gitolite%-admin/conf/.*'] = starsetf('gitolite'), - ['.*/named/db%..*'] = starsetf('bindzone'), - ['.*/tmp/lltmp.*'] = starsetf('gedcom'), - ['.*asterisk.*/.*voicemail%.conf.*'] = starsetf('asteriskvm'), - ['.*asterisk/.*%.conf.*'] = starsetf('asterisk'), ['.*vimrc.*'] = starsetf('vim'), - ['.*xmodmap.*'] = starsetf('xmodmap'), - ['/etc/gitconfig%.d/.*'] = starsetf('gitconfig'), - ['/etc/hostname%..*'] = starsetf('config'), - ['Containerfile%..*'] = starsetf('dockerfile'), - ['Dockerfile%..*'] = starsetf('dockerfile'), - ['JAM.*%..*'] = starsetf('jam'), - ['Kconfig%..*'] = starsetf('kconfig'), - ['Prl.*%..*'] = starsetf('jam'), ['Xresources.*'] = starsetf('xdefaults'), - ['[mM]akefile.*'] = starsetf('make'), - ['[rR]akefile.*'] = starsetf('ruby'), - ['access%.conf.*'] = starsetf('apache'), - ['apache%.conf.*'] = starsetf('apache'), - ['apache2%.conf.*'] = starsetf('apache'), - ['bash%-fc[-%.]'] = function(path, bufnr) - return require('vim.filetype.detect').sh(path, bufnr, 'bash') - end, - ['cabal%.project%..*'] = starsetf('cabalproject'), - ['crontab%..*'] = starsetf('crontab'), - ['drac%..*'] = starsetf('dracula'), - ['gtkrc.*'] = starsetf('gtkrc'), - ['httpd%.conf.*'] = starsetf('apache'), - ['lilo%.conf.*'] = starsetf('lilo'), - ['Muttrc'] = 'muttrc', - ['Muttngrc'] = 'muttrc', - ['proftpd%.conf.*'] = starsetf('apachestyle'), - ['reportbug%-.*'] = starsetf('mail'), - ['sgml%.catalog.*'] = starsetf('catalog'), - ['srm%.conf.*'] = starsetf('apache'), - ['tmac%..*'] = starsetf('nroff'), - ['zlog.*'] = starsetf('zsh'), - ['zsh.*'] = starsetf('zsh'), - ['ae%d+%.txt'] = 'mail', - ['snd%.%d+'] = 'mail', - ['%.letter%.%d+'] = 'mail', - ['%.article%.%d+'] = 'mail', - ['pico%.%d+'] = 'mail', - ['mutt%-.*%-%w+'] = 'mail', - ['muttng%-.*%-%w+'] = 'mail', - ['neomutt%-.*%-%w+'] = 'mail', - ['mutt' .. string.rep('[%w_-]', 6)] = 'mail', - ['neomutt' .. string.rep('[%w_-]', 6)] = 'mail', - ['/tmp/SLRN[0-9A-Z.]+'] = 'mail', - ['[a-zA-Z0-9].*Dict'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['[a-zA-Z0-9].*Dict%..*'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['[a-zA-Z].*Properties'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['[a-zA-Z].*Properties%..*'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['.*Transport%..*'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['.*/constant/g'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['.*/0/.*'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['.*/0%.orig/.*'] = function(path, bufnr) - return require('vim.filetype.detect').foam(bufnr) - end, - ['.*/etc/sensors%.d/[^.].*'] = starsetf('sensors'), - ['.*%.git/.*'] = function(path, bufnr) - local firstline = getline(bufnr, 1) - if firstline:find('^' .. string.rep('%x', 40) .. '+ ') or firstline:sub(1, 5) == 'ref: ' then - return 'git' - end - end, - ['.*%.[Cc][Ff][Gg]'] = { - function(path, bufnr) - return require('vim.filetype.detect').cfg(bufnr) - end, - -- Decrease the priority to avoid conflicts with more specific patterns - -- such as '.*/etc/a2ps/.*%.cfg', '.*enlightenment/.*%.cfg', etc. - { priority = -1 }, - }, - ['.*%.[Dd][Aa][Tt]'] = function(path, bufnr) - return require('vim.filetype.detect').dat(path, bufnr) - end, - ['.*%.[Mm][Oo][Dd]'] = function(path, bufnr) - return require('vim.filetype.detect').mod(path, bufnr) - end, - ['.*%.[Ss][Rr][Cc]'] = function(path, bufnr) - return require('vim.filetype.detect').src(bufnr) - end, - ['.*%.[Ss][Uu][Bb]'] = 'krl', - ['.*%.[Pp][Rr][Gg]'] = function(path, bufnr) - return require('vim.filetype.detect').prg(bufnr) - end, - ['.*%.[Ss][Yy][Ss]'] = function(path, bufnr) - return require('vim.filetype.detect').sys(bufnr) - end, - ['%.?gitolite%.rc'] = 'perl', - ['example%.gitolite%.rc'] = 'perl', - -- Neovim only - ['.*/queries/.*%.scm'] = 'query', -- tree-sitter queries - ['.*,v'] = 'rcs', + ['.*/etc/xinetd%.d/.*'] = starsetf('xinetd'), + ['.*xmodmap.*'] = starsetf('xmodmap'), ['.*/xorg%.conf%.d/.*%.conf'] = function(path, bufnr) return 'xf86config', function(b) vim.b[b].xf86conf_xfree86_version = 4 @@ -2138,37 +2049,11 @@ local pattern = { ['XF86Config.*'] = starsetf(function(path, bufnr) return require('vim.filetype.detect').xfree86(bufnr) end), - ['[cC]hange[lL]og.*'] = starsetf(function(path, bufnr) - local line = getline(bufnr, 1):lower() - if line:find('; urgency=') then - return 'debchangelog' - else - return 'changelog' - end - end), - ['.*fvwm2rc.*'] = starsetf(function(path, bufnr) - if vim.fn.fnamemodify(path, ':e') == 'm4' then - return 'fvwm2m4' - else - return 'fvwm', function(b) - vim.b[b].fvwm_version = 2 - end - end - end), - ['.*%.[Ll][Oo][Gg]'] = function(path, bufnr) - -- Innovation Data Processing - -- (refactor of filetype.vim since the patterns are case-insensitive) - path = path:lower() - if M.findany(path, { 'upstream%.log', 'upstream%..*%.log', '.*%.upstream%.log', 'upstream%-.*%.log' }) then - return 'upstreamlog' - elseif M.findany(path, { 'upstreaminstall%.log', 'upstreaminstall%..*%.log', '.*%.upstreaminstall%.log' }) then - return 'upstreaminstalllog' - elseif M.findany(path, { 'usserver%.log', 'usserver%..*%.log', '.*%.usserver%.log' }) then - return 'usserverlog' - elseif M.findany(path, { 'usw2kagt%.log', 'usws2kagt%..*%.log', '.*%.usws2kagt%.log' }) then - return 'usw2kagtlog' - end - end, + ['%.zcompdump.*'] = starsetf('zsh'), + -- .zlog* and zlog* + ['%.?zlog.*'] = starsetf('zsh'), + -- .zsh* and zsh* + ['%.?zsh.*'] = starsetf('zsh'), -- Ignored extension ['.*~'] = function(path, bufnr) local short = path:gsub('~$', '', 1) diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 7e5ed0f4d1..48dd3cb088 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -1,6 +1,9 @@ --- Contains filetype detection functions converted to Lua from Vim's autoload/runtime/dist/ft.vim file. +-- Contains filetype detection functions for use in filetype.lua that are either: +-- * used more than once or +-- * complex (e.g. check more than one line or use conditionals). +-- Simple one-line checks, such as a check for a string in the first line are better inlined in filetype.lua. --- Here are a few guidelines to follow when porting a new function: +-- A few guidelines to follow when porting a new function: -- * Sort the function alphabetically and omit 'ft' or 'check' from the new function name. -- * Use ':find' instead of ':match' / ':sub' if possible. -- * When '=~' is used to match a pattern, there are two possibilities: @@ -45,6 +48,17 @@ function M.asm(bufnr) end end +-- Active Server Pages (with Perl or Visual Basic Script) +function M.asp(bufnr) + if vim.g.filetype_asp then + return vim.g.filetype_asp + elseif table.concat(getlines(bufnr, 1, 3)):lower():find('perlscript') then + return 'aspperl' + else + return 'aspvbs' + end +end + -- Checks the first 5 lines for a asmsyntax=foo override. -- Only whitespace characters can be present immediately before or after this statement. function M.asm_syntax(bufnr) @@ -91,17 +105,8 @@ function M.bindzone(bufnr, default) local lines = table.concat(getlines(bufnr, 1, 4)) if findany(lines, { '^; <<>> DiG [0-9%.]+.* <<>>', '%$ORIGIN', '%$TTL', 'IN%s+SOA' }) then return 'bindzone' - else - return default - end -end - -function M.btm(bufnr) - if vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0 then - return 'dosbatch' - else - return 'btm' end + return default end -- Returns true if file content looks like RAPID @@ -151,6 +156,46 @@ function M.change(bufnr) return 'chill' end +function M.changelog(bufnr) + local line = getlines(bufnr, 1):lower() + if line:find('; urgency=') then + return 'debchangelog' + end + return 'changelog' +end + +function M.class(bufnr) + -- Check if not a Java class (starts with '\xca\xfe\xba\xbe') + if not getlines(bufnr, 1):find('^\202\254\186\190') then + return 'stata' + end +end + +function M.cls(bufnr) + local line = getlines(bufnr, 1) + if line:find('^%%') then + return 'tex' + elseif line:find('^#') and line:lower():find('rexx') then + return 'rexx' + else + return 'st' + end +end + +-- Debian Control +function M.control(bufnr) + if getlines(bufnr, 1):find('^Source:') then + return 'debcontrol' + end +end + +-- Debian Copyright +function M.copyright(bufnr) + if getlines(bufnr, 1):find('^Format:') then + return 'debcopyright' + end +end + function M.csh(path, bufnr) if vim.fn.did_filetype() ~= 0 then -- Filetype was already detected @@ -180,6 +225,14 @@ function M.dat(path, bufnr) end end +function M.decl(bufnr) + for _, line in ipairs(getlines(bufnr, 1, 3)) do + if line:lower():find('^<!sgml') then + return 'sgmldecl' + end + end +end + -- This function is called for all files under */debian/patches/*, make sure not -- to non-dep3patch files, such as README and other text files. function M.dep3patch(path, bufnr) @@ -240,6 +293,15 @@ function M.e(bufnr) return 'eiffel' end +function M.edn(bufnr) + local line = getlines(bufnr, 1) + if matchregex(line, [[\c^\s*(\s*edif\>]]) then + return 'edif' + else + return 'clojure' + end +end + -- This function checks for valid cl syntax in the first five lines. -- Look for either an opening comment, '#', or a block start, '{'. -- If not found, assume SGML. @@ -256,14 +318,6 @@ function M.ent(bufnr) return 'dtd' end -function M.euphoria(bufnr) - if vim.g.filetype_euphoria then - return vim.g.filetype_euphoria - else - return 'euphoria3' - end -end - function M.ex(bufnr) if vim.g.filetype_euphoria then return vim.g.filetype_euphoria @@ -303,6 +357,15 @@ function M.frm(bufnr) end end +function M.fvwm(path) + if vim.fn.fnamemodify(path, ':e') == 'm4' then + return 'fvwm2m4' + end + return 'fvwm', function(bufnr) + vim.b[bufnr].fvwm_version = 2 + end +end + -- Distinguish between Forth and F#. function M.fs(bufnr) if vim.g.filetype_fs then @@ -316,6 +379,13 @@ function M.fs(bufnr) end end +function M.git(bufnr) + local line = getlines(bufnr, 1) + if line:find('^' .. string.rep('%x', 40) .. '+ ') or line:sub(1, 5) == 'ref: ' then + return 'git' + end +end + function M.header(bufnr) for _, line in ipairs(getlines(bufnr, 1, 200)) do if findany(line:lower(), { '^@interface', '^@end', '^@class' }) then @@ -346,6 +416,14 @@ function M.html(bufnr) return 'html' end +-- Virata Config Script File or Drupal module +function M.hw(bufnr) + if getlines(bufnr, 1):lower():find('<%?php') then + return 'php' + end + return 'virata' +end + function M.idl(bufnr) for _, line in ipairs(getlines(bufnr, 1, 50)) do if findany(line:lower(), { '^%s*import%s+"unknwn"%.idl', '^%s*import%s+"objidl"%.idl' }) then @@ -396,6 +474,28 @@ function M.inp(bufnr) end end +function M.install(path, bufnr) + if getlines(bufnr, 1):lower():find('<%?php') then + return 'php' + end + return M.sh(path, bufnr, 'bash') +end + +-- Innovation Data Processing +-- (refactor of filetype.vim since the patterns are case-insensitive) +function M.log(path) + path = path:lower() + if findany(path, { 'upstream%.log', 'upstream%..*%.log', '.*%.upstream%.log', 'upstream%-.*%.log' }) then + return 'upstreamlog' + elseif findany(path, { 'upstreaminstall%.log', 'upstreaminstall%..*%.log', '.*%.upstreaminstall%.log' }) then + return 'upstreaminstalllog' + elseif findany(path, { 'usserver%.log', 'usserver%..*%.log', '.*%.usserver%.log' }) then + return 'usserverlog' + elseif findany(path, { 'usw2kagt%.log', 'usws2kagt%..*%.log', '.*%.usws2kagt%.log' }) then + return 'usw2kagtlog' + end +end + function M.lpc(bufnr) if vim.g.lpc_syntax_for_c then for _, line in ipairs(getlines(bufnr, 1, 12)) do @@ -467,6 +567,13 @@ function M.m(bufnr) end end +function M.m4(path) + path = path:lower() + if not path:find('html%.m4$') and not path:find('fvwm2rc') then + return 'm4' + end +end + -- Rely on the file to start with a comment. -- MS message text files use ';', Sendmail files use '#' or 'dnl' function M.mc(bufnr) @@ -482,6 +589,13 @@ function M.mc(bufnr) return 'm4' end +function M.me(path) + local filename = vim.fn.fnamemodify(path, ':t'):lower() + if filename ~= 'read.me' and filename ~= 'click.me' then + return 'nroff' + end +end + function M.mm(bufnr) for _, line in ipairs(getlines(bufnr, 1, 20)) do if matchregex(line, [[\c^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\)]]) then @@ -533,15 +647,29 @@ function M.mod(path, bufnr) end end +function M.news(bufnr) + if getlines(bufnr, 1):lower():find('; urgency=') then + return 'debchangelog' + end +end + -- This function checks if one of the first five lines start with a dot. In --- that case it is probably an nroff file: 'filetype' is set and true is returned. +-- that case it is probably an nroff file. function M.nroff(bufnr) for _, line in ipairs(getlines(bufnr, 1, 5)) do if line:find('^%.') then - return true + return 'nroff' end end - return false +end + +function M.patch(bufnr) + local firstline = getlines(bufnr, 1) + if string.find(firstline, '^From ' .. string.rep('%x', 40) .. '+ Mon Sep 17 00:00:00 2001$') then + return 'gitsendemail' + else + return 'diff' + end end -- If the file has an extension of 't' and is in a directory 't' or 'xt' then @@ -551,18 +679,17 @@ end function M.perl(path, bufnr) local dirname = vim.fn.expand(path, '%:p:h:t') if vim.fn.expand(dirname, '%:e') == 't' and (dirname == 't' or dirname == 'xt') then - return true + return 'perl' end local first_line = getlines(bufnr, 1) if first_line:find('^#') and first_line:lower():find('perl') then - return true + return 'perl' end for _, line in ipairs(getlines(bufnr, 1, 30)) do if matchregex(line, [[\c^use\s\s*\k]]) then - return true + return 'perl' end end - return false end function M.pl(bufnr) @@ -583,6 +710,17 @@ function M.pl(bufnr) end end +function M.pm(bufnr) + local line = getlines(bufnr, 1) + if line:find('XPM2') then + return 'xpm2' + elseif line:find('XPM') then + return 'xpm' + else + return 'perl' + end +end + function M.pp(bufnr) if vim.g.filetype_pp then return vim.g.filetype_pp @@ -606,6 +744,14 @@ function M.prg(bufnr) end end +function M.printcap(ptcap_type) + if vim.fn.did_filetype() == 0 then + return 'ptcap', function(bufnr) + vim.b[bufnr].ptcap_type = ptcap_type + end + end +end + -- This function checks for an assembly comment in the first ten lines. -- If not found, assume Progress. function M.progress_asm(bufnr) @@ -670,6 +816,19 @@ function M.proto(bufnr, default) end end +-- Software Distributor Product Specification File (POSIX 1387.2-1995) +function M.psf(bufnr) + local line = getlines(bufnr, 1):lower() + if + findany( + line, + { '^%s*distribution%s*$', '^%s*installed_software%s*$', '^%s*root%s*$', '^%s*bundle%s*$', '^%s*product%s*$' } + ) + then + return 'psf' + end +end + function M.r(bufnr) local lines = getlines(bufnr, 1, 50) -- Rebol is easy to recognize, check for that first @@ -705,8 +864,23 @@ function M.redif(bufnr) end end +function M.reg(bufnr) + local line = getlines(bufnr, 1):lower() + if line:find('^regedit[0-9]*%s*$') or line:find('^windows registry editor version %d*%.%d*%s*$') then + return 'registry' + end +end + +-- Diva (with Skill) or InstallShield +function M.rul(bufnr) + if table.concat(getlines(bufnr, 1, 6)):lower():find('installshield') then + return 'ishd' + end + return 'diva' +end + local udev_rules_pattern = '^%s*udev_rules%s*=%s*"([%^"]+)/*".*' -function M.rules(path, bufnr) +function M.rules(path) path = path:lower() if findany(path, { @@ -770,7 +944,20 @@ function M.scd(bufnr) end end --- Also called from filetype.lua +function M.sgml(bufnr) + local lines = table.concat(getlines(bufnr, 1, 5)) + if lines:find('linuxdoc') then + return 'smgllnx' + elseif lines:find('<!DOCTYPE.*DocBook') then + return 'docbk', function(b) + vim.b[b].docbk_type = 'sgml' + vim.b[b].docbk_ver = 4 + end + else + return 'sgml' + end +end + function M.sh(path, bufnr, name) if vim.fn.did_filetype() ~= 0 or path:find(vim.g.ft_ignore_pat) then -- Filetype was already detected or detection should be skipped @@ -779,6 +966,7 @@ function M.sh(path, bufnr, name) local on_detect + name = name or getlines(bufnr, 1) if matchregex(name, [[\<csh\>]]) then -- Some .sh scripts contain #!/bin/csh. return M.shell(path, bufnr, 'csh') @@ -832,11 +1020,13 @@ function M.shell(path, bufnr, name) return name end -function M.sql(bufnr) - if vim.g.filetype_sql then - return vim.g.filetype_sql +-- SMIL or SNMP MIB file +function M.smi(bufnr) + local line = getlines(bufnr, 1) + if matchregex(line, [[\c\<smil\>]]) then + return 'smil' else - return 'sql' + return 'mib' end end @@ -919,6 +1109,43 @@ function M.tf(bufnr) return 'tf' end +function M.ttl(bufnr) + local line = getlines(bufnr, 1):lower() + if line:find('^@?prefix') or line:find('^@?base') then + return 'turtle' + end + return 'teraterm' +end + +function M.txt(bufnr) + -- helpfiles match *.txt, but should have a modeline as last line + if not getlines(bufnr, -1):find('vim:.*ft=help') then + return 'text' + end +end + +-- WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment +-- lines in a WEB file). +function M.web(bufnr) + for _, line in ipairs(getlines(bufnr, 1, 5)) do + if line:find('^%%') then + return 'web' + end + end + return 'winbatch' +end + +-- XFree86 config +function M.xfree86() + return 'xf86conf', + function(bufnr) + local line = getlines(bufnr, 1) + if matchregex(line, [[\<XConfigurator\>]]) then + vim.b[bufnr].xf86conf_xfree86_version = 3 + end + end +end + function M.xml(bufnr) for _, line in ipairs(getlines(bufnr, 1, 100)) do local is_docbook4 = line:find('<!DOCTYPE.*DocBook') @@ -950,124 +1177,6 @@ function M.y(bufnr) return 'yacc' end -function M.decl(bufnr) - for _, line in ipairs(getlines(bufnr, 1, 3)) do - if line:lower():find('^<!sgml') then - return 'sgmldecl' - end - end -end - -function M.sgml(bufnr) - local lines = table.concat(getlines(bufnr, 1, 5)) - if lines:find('linuxdoc') then - return 'smgllnx' - elseif lines:find('<!DOCTYPE.*DocBook') then - return 'docbk', function(b) - vim.b[b].docbk_type = 'sgml' - vim.b[b].docbk_ver = 4 - end - else - return 'sgml' - end -end - -function M.web(bufnr) - for _, line in ipairs(getlines(bufnr, 1, 5)) do - if line:find('^%%') then - return 'web' - end - end - return 'winbatch' -end - -function M.rul(bufnr) - if table.concat(getlines(bufnr, 1, 6)):lower():find('installshield') then - return 'ishd' - end - return 'diva' -end - -function M.asp(bufnr) - if vim.g.filetype_asp then - return vim.g.filetype_asp - elseif table.concat(getlines(bufnr, 1, 3)):lower():find('perlscript') then - return 'aspperl' - else - return 'aspvbs' - end -end - -function M.edn(bufnr) - local line = getlines(bufnr, 1) - if matchregex(line, [[\c^\s*(\s*edif\>]]) then - return 'edif' - else - return 'clojure' - end -end - -function M.smi(bufnr) - local line = getlines(bufnr, 1) - if matchregex(line, [[\c\<smil\>]]) then - return 'smil' - else - return 'mib' - end -end - -function M.hw(bufnr) - if getlines(bufnr, 1):lower():find('<%?php') then - return 'php' - end - return 'virata' -end - -function M.news(bufnr) - if getlines(bufnr, 1):lower():find('; urgency=') then - return 'debchangelog' - end -end - --- Debian Control -function M.control(bufnr) - if getlines(bufnr, 1):find('^Source:') then - return 'debcontrol' - end -end - --- Debian Copyright -function M.copyright(bufnr) - if getlines(bufnr, 1):find('^Format:') then - return 'debcopyright' - end -end - --- Software Distributor Product Specification File (POSIX 1387.2-1995) -function M.psf(bufnr) - local line = getlines(bufnr, 1):lower() - if - findany( - line, - { '^%s*distribution%s*$', '^%s*installed_software%s*$', '^%s*root%s*$', '^%s*bundle%s*$', '^%s*product%s*$' } - ) - then - return 'psf' - end -end - --- XFree86 config -function M.xfree86(bufnr) - local line = getlines(bufnr, 1) - local on_detect - if matchregex(line, [[\<XConfigurator\>]]) then - on_detect = function(b) - vim.b[b].xf86conf_xfree86_version = 3 - end - end - return 'xf86conf', on_detect -end - -- luacheck: pop -- luacheck: pop |