logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

filetype.lua (12885B)


  1. vis.ftdetect = {}
  2. vis.ftdetect.ignoresuffixes = {
  3. "~+$", "%.orig$", "%.bak$", "%.old$", "%.new$"
  4. }
  5. vis.ftdetect.filetypes = {
  6. actionscript = {
  7. ext = { "%.as$", "%.asc$" },
  8. },
  9. ada = {
  10. ext = { "%.adb$", "%.ads$" },
  11. },
  12. ansi_c = {
  13. ext = { "%.c$", "%.C$", "%.h$" },
  14. mime = { "text/x-c" },
  15. },
  16. antlr = {
  17. ext = { "%.g$", "%.g4$" },
  18. },
  19. apdl = {
  20. ext = { "%.ans$", "%.inp$", "%.mac$" },
  21. },
  22. apl = {
  23. ext = { "%.apl$" }
  24. },
  25. applescript = {
  26. ext = { "%.applescript$" },
  27. },
  28. asm = {
  29. ext = { "%.asm$", "%.ASM$", "%.s$", "%.S$" },
  30. },
  31. asp = {
  32. ext = { "%.asa$", "%.asp$", "%.hta$" },
  33. },
  34. autoit = {
  35. ext = { "%.au3$", "%.a3x$" },
  36. },
  37. awk = {
  38. hashbang = { "^/usr/bin/[mng]awk%s+%-f" },
  39. utility = { "^[mgn]?awk$", "^goawk$" },
  40. ext = { "%.awk$" },
  41. },
  42. bash = {
  43. utility = { "^[db]ash$", "^sh$","^t?csh$","^zsh$" },
  44. ext = { "%.bash$", "%.csh$", "%.sh$", "%.zsh$" ,"^APKBUILD$", "%.ebuild$", "^.bashrc$", "^.bash_profile$" },
  45. mime = { "text/x-shellscript", "application/x-shellscript" },
  46. },
  47. batch = {
  48. ext = { "%.bat$", "%.cmd$" },
  49. },
  50. bibtex = {
  51. ext = { "%.bib$" },
  52. },
  53. boo = {
  54. ext = { "%.boo$" },
  55. },
  56. caml = {
  57. ext = { "%.caml$", "%.ml$", "%.mli$", "%.mll$", "%.mly$" },
  58. },
  59. chuck = {
  60. ext = { "%.ck$" },
  61. },
  62. clojure = {
  63. ext = { "%.clj$", "%.cljc$", "%.cljs$", "%.edn$" }
  64. },
  65. cmake = {
  66. ext = { "%.cmake$", "%.cmake.in$", "%.ctest$", "%.ctest.in$" },
  67. },
  68. coffeescript = {
  69. ext = { "%.coffee$" },
  70. mime = { "text/x-coffee" },
  71. },
  72. cpp = {
  73. ext = { "%.cpp$", "%.cxx$", "%.c++$", "%.cc$", "%.hh$", "%.hpp$", "%.hxx$", "%.h++$" },
  74. mime = { "text/x-c++" },
  75. },
  76. crontab = {
  77. ext = { "^crontab.*$" },
  78. cmd = { "set savemethod inplace" },
  79. },
  80. crystal = {
  81. ext = { "%.cr$" },
  82. },
  83. csharp = {
  84. ext = { "%.cs$" },
  85. },
  86. css = {
  87. ext = { "%.css$" },
  88. mime = { "text/x-css" },
  89. },
  90. cuda = {
  91. ext = { "%.cu$", "%.cuh$" },
  92. },
  93. dart = {
  94. ext = { "%.dart$" },
  95. },
  96. desktop = {
  97. ext = { "%.desktop$" },
  98. },
  99. diff = {
  100. ext = { "%.diff$", "%.patch$", "%.rej$" },
  101. },
  102. dmd = {
  103. ext = { "%.d$", "%.di$" },
  104. },
  105. dockerfile = {
  106. ext = { "^Dockerfile$", "%.Dockerfile$" },
  107. },
  108. dot = {
  109. ext = { "%.dot$" },
  110. },
  111. dsv = {
  112. ext = { "^group$", "^gshadow$", "^passwd$", "^shadow$" },
  113. },
  114. eiffel = {
  115. ext = { "%.e$", "%.eif$" },
  116. },
  117. elixir = {
  118. ext = { "%.ex$", "%.exs$" },
  119. },
  120. elm = {
  121. ext = { "%.elm$" },
  122. },
  123. mail = {
  124. ext = { "%.eml$" },
  125. },
  126. erlang = {
  127. ext = { "%.erl$", "%.hrl$" },
  128. },
  129. fantom = {
  130. ext = { "%.fan$" },
  131. },
  132. faust = {
  133. ext = { "%.dsp$" },
  134. },
  135. fennel = {
  136. ext = { "%.fnl$" },
  137. },
  138. fish = {
  139. utility = { "^fish$" },
  140. ext = { "%.fish$" },
  141. },
  142. forth = {
  143. ext = { "%.forth$", "%.frt$", "%.fs$", "%.fth$" },
  144. },
  145. fortran = {
  146. ext = { "%.f$", "%.for$", "%.ftn$", "%.fpp$", "%.f77$", "%.f90$", "%.f95$", "%.f03$", "%.f08$" },
  147. },
  148. fsharp = {
  149. ext = { "%.fs$" },
  150. },
  151. fstab = {
  152. ext = { "^fstab$" },
  153. },
  154. gap = {
  155. ext = { "%.g$", "%.gd$", "%.gi$", "%.gap$" },
  156. },
  157. gemini = {
  158. ext = { "%.gmi" },
  159. mime = { "text/gemini" },
  160. },
  161. gettext = {
  162. ext = { "%.po$", "%.pot$" },
  163. },
  164. gherkin = {
  165. ext = { "%.feature$" },
  166. },
  167. ['git-commit'] = {
  168. alt_name = "diff",
  169. ext = { "^COMMIT_EDITMSG$" },
  170. cmd = { "set colorcolumn 72" },
  171. },
  172. ['git-rebase'] = {
  173. ext = { "git%-rebase%-todo" },
  174. },
  175. gleam = {
  176. ext = { "%.gleam$" },
  177. },
  178. glsl = {
  179. ext = { "%.glsl[fv]?$" },
  180. },
  181. gnuplot = {
  182. ext = { "%.dem$", "%.plt$" },
  183. },
  184. go = {
  185. ext = { "%.go$" },
  186. },
  187. groovy = {
  188. ext = { "%.groovy$", "%.gvy$", "^Jenkinsfile$" },
  189. },
  190. gtkrc = {
  191. ext = { "%.gtkrc$" },
  192. },
  193. hare = {
  194. ext = { "%.ha$" }
  195. },
  196. haskell = {
  197. ext = { "%.hs$" },
  198. mime = { "text/x-haskell" },
  199. },
  200. html = {
  201. ext = { "%.[sx]?htm[l]?$" },
  202. mime = { "text/x-html" },
  203. },
  204. icon = {
  205. ext = { "%.icn$" },
  206. },
  207. idl = {
  208. ext = { "%.idl$", "%.odl$" },
  209. },
  210. inform = {
  211. ext = { "%.inf$", "%.ni$" },
  212. },
  213. ini = {
  214. ext = { "%.cfg$", "%.cnf$", "%.conf$", "%.inf$", "%.ini$", "%.reg$" },
  215. },
  216. io_lang = {
  217. ext = { "%.io$" },
  218. },
  219. java = {
  220. ext = { "%.bsh$", "%.java$" },
  221. },
  222. javascript = {
  223. ext = { "%.cjs$", "%.js$", "%.jsfl$", "%.mjs$", "%.jsx$" },
  224. },
  225. jq = {
  226. ext = { "%.jq$" },
  227. },
  228. json = {
  229. ext = { "%.json$" },
  230. mime = { "text/x-json" },
  231. },
  232. jsp = {
  233. ext = { "%.jsp$" },
  234. },
  235. julia = {
  236. ext = { "%.jl$" },
  237. },
  238. latex = {
  239. ext = { "%.bbl$", "%.cls$", "%.dtx$", "%.ins$", "%.ltx$", "%.tex$", "%.sty$" },
  240. mime = { "text/x-tex" },
  241. },
  242. ledger = {
  243. ext = { "%.ledger$", "%.journal$" },
  244. },
  245. less = {
  246. ext = { "%.less$" },
  247. },
  248. lilypond = {
  249. ext = { "%.ily$", "%.ly$" },
  250. },
  251. lisp = {
  252. ext = { "%.cl$", "%.el$", "%.lisp$", "%.lsp$" },
  253. mime = { "text/x-lisp" },
  254. },
  255. litcoffee = {
  256. ext = { "%.litcoffee$" },
  257. },
  258. logtalk = {
  259. ext = { "%.lgt$" },
  260. },
  261. lua = {
  262. utility = {"^lua%-?5?%d?$", "^lua%-?5%.%d$" },
  263. ext = { "%.lua$" },
  264. mime = { "text/x-lua" },
  265. },
  266. makefile = {
  267. hashbang = {"^#!/usr/bin/make"},
  268. utility = {"^make$"},
  269. ext = { "%.iface$", "%.mak$", "%.mk$", "^GNUmakefile$", "^makefile$", "^Makefile$" },
  270. mime = { "text/x-makefile" },
  271. },
  272. man = {
  273. ext = { "%.[1-9][xp]?$", "%.ms$", "%.me$", "%.mom$", "%.mm$", "%.tmac$" },
  274. },
  275. markdown = {
  276. ext = { "%.md$", "%.markdown$" },
  277. mime = { "text/x-markdown" },
  278. },
  279. meson = {
  280. ext = { "^meson%.build$" },
  281. },
  282. modula2 = {
  283. ext = { "%.mod$", "%.def$" },
  284. },
  285. modula3 = {
  286. ext = { "%.mg$", "%.ig$", "%.i3$", "%.m3$" },
  287. },
  288. moonscript = {
  289. ext = { "%.moon$" },
  290. mime = { "text/x-moon" },
  291. },
  292. myrddin = {
  293. ext = { "%.myr$" },
  294. },
  295. nemerle = {
  296. ext = { "%.n$" },
  297. },
  298. networkd = {
  299. ext = { "%.link$", "%.network$", "%.netdev$" },
  300. },
  301. nim = {
  302. ext = { "%.nim$" },
  303. },
  304. nsis = {
  305. ext = { "%.nsh$", "%.nsi$", "%.nsis$" },
  306. },
  307. objective_c = {
  308. ext = { "%.m$", "%.mm$", "%.objc$" },
  309. mime = { "text/x-objc" },
  310. },
  311. pascal = {
  312. ext = { "%.dpk$", "%.dpr$", "%.p$", "%.pas$" },
  313. },
  314. perl = {
  315. ext = { "%.al$", "%.perl$", "%.pl$", "%.pm$", "%.pod$" },
  316. mime = { "text/x-perl" },
  317. },
  318. php = {
  319. ext = { "%.inc$", "%.php$", "%.php3$", "%.php4$", "%.phtml$" },
  320. },
  321. pico8 = {
  322. ext = { "%.p8$" },
  323. },
  324. pike = {
  325. ext = { "%.pike$", "%.pmod$" },
  326. },
  327. pkgbuild = {
  328. ext = { "^PKGBUILD$", "%.PKGBUILD$" },
  329. },
  330. pony = {
  331. ext = { "%.pony$" },
  332. },
  333. powershell = {
  334. ext = { "%.ps1$", "%.psm1$" },
  335. },
  336. prolog = {
  337. ext = { "%.pl$", "%.pro$", "%.prolog$" },
  338. },
  339. props = {
  340. ext = { "%.props$", "%.properties$" },
  341. },
  342. protobuf = {
  343. ext = { "%.proto$" },
  344. },
  345. ps = {
  346. ext = { "%.eps$", "%.ps$" },
  347. },
  348. pure = {
  349. ext = { "%.pure$" },
  350. },
  351. python = {
  352. utility = { "^python%d?" },
  353. ext = { "%.sc$", "%.py[iw]?$" },
  354. mime = { "text/x-python", "text/x-script.python" },
  355. },
  356. reason = {
  357. ext = { "%.re$" },
  358. },
  359. rc = {
  360. utility = {"^rc$"},
  361. ext = { "%.rc$", "%.es$" },
  362. },
  363. rebol = {
  364. ext = { "%.r$", "%.reb$" },
  365. },
  366. rest = {
  367. ext = { "%.rst$" },
  368. },
  369. rexx = {
  370. ext = { "%.orx$", "%.rex$" },
  371. },
  372. rhtml = {
  373. ext = { "%.erb$", "%.rhtml$" },
  374. },
  375. routeros = {
  376. ext = { "%.rsc" },
  377. detect = function(_, data)
  378. return data:match("^#.* by RouterOS")
  379. end
  380. },
  381. rpmspec = {
  382. ext = { "%.spec$" },
  383. },
  384. rstats = {
  385. ext = { "%.R$", "%.Rout$", "%.Rhistory$", "%.Rt$", "Rout.save", "Rout.fail" },
  386. },
  387. ruby = {
  388. ext = { "%.Rakefile$", "%.rake$", "%.rb$", "%.rbw$", "^Vagrantfile$" },
  389. mime = { "text/x-ruby" },
  390. },
  391. rust = {
  392. ext = { "%.rs$" },
  393. mime = { "text/x-rust" },
  394. },
  395. sass = {
  396. ext = { "%.sass$", "%.scss$" },
  397. mime = { "text/x-sass", "text/x-scss" },
  398. },
  399. scala = {
  400. ext = { "%.scala$" },
  401. mime = { "text/x-scala" },
  402. },
  403. scheme = {
  404. ext = { "%.rkt$", "%.sch$", "%.scm$", "%.sld$", "%.sls$", "%.ss$" },
  405. },
  406. smalltalk = {
  407. ext = { "%.changes$", "%.st$", "%.sources$" },
  408. },
  409. sml = {
  410. ext = { "%.sml$", "%.fun$", "%.sig$" },
  411. },
  412. snobol4 = {
  413. ext = { "%.sno$", "%.SNO$" },
  414. },
  415. spin = {
  416. ext = { "%.spin$" }
  417. },
  418. sql= {
  419. ext = { "%.ddl$", "%.sql$" },
  420. },
  421. strace = {
  422. detect = function(_, data)
  423. return data:match("^execve%(")
  424. end
  425. },
  426. systemd = {
  427. ext = {
  428. "%.automount$", "%.device$", "%.mount$", "%.path$",
  429. "%.scope$", "%.service$", "%.slice$", "%.socket$",
  430. "%.swap$", "%.target$", "%.timer$"
  431. },
  432. },
  433. taskpaper = {
  434. ext = { "%.taskpaper$" },
  435. },
  436. tcl = {
  437. utility = {"^tclsh$", "^jimsh$" },
  438. ext = { "%.tcl$", "%.tk$" },
  439. },
  440. texinfo = {
  441. ext = { "%.texi$" },
  442. },
  443. text = {
  444. ext = { "%.txt$" },
  445. -- Do *not* list mime "text/plain" here, it is covered below,
  446. -- see 'try text lexer as a last resort'
  447. },
  448. toml = {
  449. ext = { "%.toml$" },
  450. },
  451. typescript = {
  452. ext = { "%.ts$", "%.tsx$" },
  453. },
  454. typst = {
  455. ext = { "%.typ$", "%.typst$" },
  456. },
  457. vala = {
  458. ext = { "%.vala$" }
  459. },
  460. vb = {
  461. ext = {
  462. "%.asa$", "%.bas$", "%.ctl$", "%.dob$",
  463. "%.dsm$", "%.dsr$", "%.frm$", "%.pag$", "%.vb$",
  464. "%.vba$", "%.vbs$"
  465. },
  466. },
  467. vcard = {
  468. ext = { "%.vcf$", "%.vcard$" },
  469. },
  470. verilog = {
  471. ext = { "%.v$", "%.ver$", "%.sv$" },
  472. },
  473. vhdl = {
  474. ext = { "%.vh$", "%.vhd$", "%.vhdl$" },
  475. },
  476. wsf = {
  477. ext = { "%.wsf$" },
  478. },
  479. xs = {
  480. ext = { "%.xs$", "^%.xsin$", "^%.xsrc$" },
  481. },
  482. xml = {
  483. ext = {
  484. "%.dtd$", "%.glif$", "%.plist$", "%.svg$", "%.xml$",
  485. "%.xsd$", "%.xsl$", "%.xslt$", "%.xul$"
  486. },
  487. mime = { "text/xml" },
  488. },
  489. xtend = {
  490. ext = {"%.xtend$" },
  491. },
  492. yaml = {
  493. ext = { "%.yaml$", "%.yml$" },
  494. mime = { "text/x-yaml" },
  495. },
  496. zig = {
  497. ext = { "%.zig$" },
  498. },
  499. }
  500. vis.events.subscribe(vis.events.WIN_OPEN, function(win)
  501. local set_filetype = function(syntax, filetype)
  502. for _, cmd in pairs(filetype.cmd or {}) do
  503. vis:command(cmd)
  504. end
  505. if not vis.lexers.property then return end
  506. local path = vis.lexers.property['scintillua.lexers']:gsub(';', '/?.lua;')
  507. local lexname = filetype.alt_name or syntax
  508. local lexpath = package.searchpath(lexname, path)
  509. if lexpath ~= nil then
  510. win:set_syntax(lexname)
  511. else
  512. win:set_syntax(nil)
  513. end
  514. end
  515. local path = win.file.name -- filepath
  516. local mime
  517. if path and #path > 0 then
  518. local name = path:match("[^/]+$") -- filename
  519. if name then
  520. local unchanged
  521. while #name > 0 and name ~= unchanged do
  522. unchanged = name
  523. for _, pattern in ipairs(vis.ftdetect.ignoresuffixes) do
  524. name = name:gsub(pattern, "")
  525. end
  526. end
  527. end
  528. if name and #name > 0 then
  529. -- detect filetype by filename ending with a configured extension
  530. for lang, ft in pairs(vis.ftdetect.filetypes) do
  531. for _, pattern in pairs(ft.ext or {}) do
  532. if name:match(pattern) then
  533. set_filetype(lang, ft)
  534. return
  535. end
  536. end
  537. end
  538. end
  539. -- run file(1) to determine mime type
  540. local file = io.popen(string.format("file -bL --mime-type -- '%s'", path:gsub("'", "'\\''")))
  541. if file then
  542. mime = file:read('*all')
  543. file:close()
  544. if mime then
  545. mime = mime:gsub('%s*$', '')
  546. end
  547. if mime and #mime > 0 then
  548. for lang, ft in pairs(vis.ftdetect.filetypes) do
  549. for _, ft_mime in pairs(ft.mime or {}) do
  550. if mime == ft_mime then
  551. set_filetype(lang, ft)
  552. return
  553. end
  554. end
  555. end
  556. end
  557. end
  558. end
  559. -- pass first few bytes of file to custom file type detector functions
  560. local file = win.file
  561. local data = file:content(0, 256)
  562. if data and #data > 0 then
  563. for lang, ft in pairs(vis.ftdetect.filetypes) do
  564. if type(ft.detect) == 'function' and ft.detect(file, data) then
  565. set_filetype(lang, ft)
  566. return
  567. end
  568. end
  569. --[[ hashbang check
  570. hashbangs only have command <SPACE> argument
  571. if /env, find utility in args
  572. discard first arg if /-[^S]*S/; and all subsequent /=/
  573. NOTE: this means you can't have a command with /^-|=/
  574. return first field, which should be the utility.
  575. NOTE: long-options unsupported
  576. --]]
  577. local fullhb, utility = data:match"^#![ \t]*(/+[^/\n]+[^\n]*)"
  578. if fullhb then
  579. local i, field = 1, {}
  580. for m in fullhb:gmatch"%g+" do field[i],i = m,i+1 end
  581. -- NOTE: executables should not have a space (or =, see below)
  582. if field[1]:match"/env$" then
  583. table.remove(field,1)
  584. -- it is assumed that the first argument are short options, with -S inside
  585. if string.match(field[1] or "", "^%-[^S-]*S") then -- -S found
  586. table.remove(field,1)
  587. -- skip all name=value
  588. while string.match(field[1] or "","=") do
  589. table.remove(field,1)
  590. end
  591. -- (hopefully) whatever is left in field[1] should be the utility or nil
  592. end
  593. end
  594. utility = string.match(field[1] or "", "[^/]+$") -- remove filepath
  595. end
  596. local function searcher(tbl, subject)
  597. for _, pattern in ipairs(tbl or {}) do
  598. if string.match(subject, pattern) then
  599. return true
  600. end
  601. end
  602. return false
  603. end
  604. if utility or fullhb then
  605. for lang, ft in pairs(vis.ftdetect.filetypes) do
  606. if
  607. utility and searcher(ft.utility, utility)
  608. or
  609. fullhb and searcher(ft.hashbang, fullhb)
  610. then
  611. set_filetype(lang, ft)
  612. return
  613. end
  614. end
  615. end
  616. end
  617. -- try text lexer as a last resort
  618. if (mime or 'text/plain'):match('^text/.+$') then
  619. set_filetype('text', vis.ftdetect.filetypes.text)
  620. return
  621. end
  622. win:set_syntax(nil)
  623. end)