modelist.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var modes = [];
  4. /**
  5. * Suggests a mode based on the file extension present in the given path
  6. * @param {string} path The path to the file
  7. * @returns {object} Returns an object containing information about the
  8. * suggested mode.
  9. */
  10. function getModeForPath(path) {
  11. var mode = modesByName.text;
  12. var fileName = path.split(/[\/\\]/).pop();
  13. for (var i = 0; i < modes.length; i++) {
  14. if (modes[i].supportsFile(fileName)) {
  15. mode = modes[i];
  16. break;
  17. }
  18. }
  19. return mode;
  20. }
  21. var Mode = function(name, caption, extensions) {
  22. this.name = name;
  23. this.caption = caption;
  24. this.mode = "ace/mode/" + name;
  25. this.extensions = extensions;
  26. if (/\^/.test(extensions)) {
  27. var re = extensions.replace(/\|(\^)?/g, function(a, b){
  28. return "$|" + (b ? "^" : "^.*\\.");
  29. }) + "$";
  30. } else {
  31. var re = "^.*\\.(" + extensions + ")$";
  32. }
  33. this.extRe = new RegExp(re, "gi");
  34. };
  35. Mode.prototype.supportsFile = function(filename) {
  36. return filename.match(this.extRe);
  37. };
  38. // todo firstlinematch
  39. var supportedModes = {
  40. ABAP: ["abap"],
  41. ABC: ["abc"],
  42. ActionScript:["as"],
  43. ADA: ["ada|adb"],
  44. Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
  45. AsciiDoc: ["asciidoc|adoc"],
  46. Assembly_x86:["asm"],
  47. AutoHotKey: ["ahk"],
  48. BatchFile: ["bat|cmd"],
  49. C9Search: ["c9search_results"],
  50. C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp"],
  51. Cirru: ["cirru|cr"],
  52. Clojure: ["clj|cljs"],
  53. Cobol: ["CBL|COB"],
  54. coffee: ["coffee|cf|cson|^Cakefile"],
  55. ColdFusion: ["cfm"],
  56. CSharp: ["cs"],
  57. CSS: ["css"],
  58. Curly: ["curly"],
  59. D: ["d|di"],
  60. Dart: ["dart"],
  61. Diff: ["diff|patch"],
  62. Dockerfile: ["^Dockerfile"],
  63. Dot: ["dot"],
  64. Dummy: ["dummy"],
  65. DummySyntax: ["dummy"],
  66. Eiffel: ["e"],
  67. EJS: ["ejs"],
  68. Elixir: ["ex|exs"],
  69. Elm: ["elm"],
  70. Erlang: ["erl|hrl"],
  71. Forth: ["frt|fs|ldr"],
  72. FTL: ["ftl"],
  73. Gcode: ["gcode"],
  74. Gherkin: ["feature"],
  75. Gitignore: ["^.gitignore"],
  76. Glsl: ["glsl|frag|vert"],
  77. golang: ["go"],
  78. Groovy: ["groovy"],
  79. HAML: ["haml"],
  80. Handlebars: ["hbs|handlebars|tpl|mustache"],
  81. Haskell: ["hs"],
  82. haXe: ["hx"],
  83. Hive: ["hql|q|ql"],
  84. HTML: ["html|htm|xhtml"],
  85. HTML_Ruby: ["erb|rhtml|html.erb"],
  86. INI: ["ini|conf|cfg|prefs"],
  87. Io: ["io"],
  88. Jack: ["jack"],
  89. Jade: ["jade"],
  90. Java: ["java"],
  91. JavaScript: ["js|jsm"],
  92. JSON: ["json"],
  93. JSONiq: ["jq"],
  94. JSP: ["jsp"],
  95. JSX: ["jsx"],
  96. Julia: ["jl"],
  97. LaTeX: ["tex|latex|ltx|bib"],
  98. Lean: ["lean|hlean"],
  99. LESS: ["less"],
  100. Liquid: ["liquid"],
  101. Lisp: ["lisp"],
  102. LiveScript: ["ls"],
  103. LogiQL: ["logic|lql"],
  104. LSL: ["lsl"],
  105. Lua: ["lua"],
  106. LuaPage: ["lp"],
  107. Lucene: ["lucene"],
  108. Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
  109. Markdown: ["md|markdown"],
  110. Mask: ["mask"],
  111. MATLAB: ["matlab"],
  112. Maze: ["mz"],
  113. MEL: ["mel"],
  114. MUSHCode: ["mc|mush"],
  115. MySQL: ["mysql"],
  116. Nix: ["nix"],
  117. ObjectiveC: ["m|mm"],
  118. OCaml: ["ml|mli"],
  119. Pascal: ["pas|p"],
  120. Perl: ["pl|pm"],
  121. pgSQL: ["pgsql"],
  122. PHP: ["php|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp"],
  123. PigLatin: ["pig"],
  124. Powershell: ["ps1"],
  125. Praat: ["praat|praatscript|psc|proc"],
  126. Prolog: ["plg|prolog"],
  127. Properties: ["properties"],
  128. Protobuf: ["proto"],
  129. Python: ["py"],
  130. R: ["r"],
  131. RDoc: ["Rd"],
  132. RHTML: ["Rhtml"],
  133. Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
  134. Rust: ["rs"],
  135. SASS: ["sass"],
  136. SCAD: ["scad"],
  137. Scala: ["scala"],
  138. Scheme: ["scm|rkt"],
  139. SCSS: ["scss"],
  140. SH: ["sh|bash|^.bashrc"],
  141. SJS: ["sjs"],
  142. Smarty: ["smarty|tpl"],
  143. snippets: ["snippets"],
  144. Soy_Template:["soy"],
  145. Space: ["space"],
  146. SQL: ["sql"],
  147. SQLServer: ["sqlserver"],
  148. Stylus: ["styl|stylus"],
  149. SVG: ["svg"],
  150. Tcl: ["tcl"],
  151. Tex: ["tex"],
  152. Text: ["txt"],
  153. Textile: ["textile"],
  154. Toml: ["toml"],
  155. Twig: ["twig"],
  156. Typescript: ["ts|typescript|str"],
  157. Vala: ["vala"],
  158. VBScript: ["vbs|vb"],
  159. Velocity: ["vm"],
  160. Verilog: ["v|vh|sv|svh"],
  161. VHDL: ["vhd|vhdl"],
  162. XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"],
  163. XQuery: ["xq"],
  164. YAML: ["yaml|yml"],
  165. // Add the missing mode "Django" to ext-modelist
  166. Django: ["html"]
  167. };
  168. var nameOverrides = {
  169. ObjectiveC: "Objective-C",
  170. CSharp: "C#",
  171. golang: "Go",
  172. C_Cpp: "C and C++",
  173. coffee: "CoffeeScript",
  174. HTML_Ruby: "HTML (Ruby)",
  175. FTL: "FreeMarker"
  176. };
  177. var modesByName = {};
  178. for (var name in supportedModes) {
  179. var data = supportedModes[name];
  180. var displayName = (nameOverrides[name] || name).replace(/_/g, " ");
  181. var filename = name.toLowerCase();
  182. var mode = new Mode(filename, displayName, data[0]);
  183. modesByName[filename] = mode;
  184. modes.push(mode);
  185. }
  186. module.exports = {
  187. getModeForPath: getModeForPath,
  188. modes: modes,
  189. modesByName: modesByName
  190. };
  191. });