From 9bfbe1863fd85aa8c8004616daf2a290a08c644a Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Tue, 10 Mar 2015 00:20:54 -0400 Subject: Merged `textadept.file_types.shebangs` into `textadept.file_types.patterns`. --- doc/manual.md | 10 +++++----- modules/textadept/file_types.lua | 23 ++++------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/doc/manual.md b/doc/manual.md index a4547fba..b89c8349 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -1088,17 +1088,17 @@ Learn more about snippet syntax in the [snippets documentation][]. ### File Types Textadept recognizes a wide range of programming language files either by file -extension, by a keyword in the shebang ("#!/path/to/exe") line, or by a -[Lua pattern](#Lua.Patterns) that matches the text of the first line. The editor -does this by consulting a set of tables in [`textadept.file_types`][] that are -modifiable from *~/.textadept/init.lua*. For example: +extension or by a [Lua pattern](#Lua.Patterns) that matches the text of the +first line. The editor does this by consulting a set of tables in +[`textadept.file_types`][] that are modifiable from *~/.textadept/init.lua*. For +example: -- Recognize .luadoc files as Lua code. textadept.file_types.extensions.luadoc = 'lua' -- Change .html files to be recognized as XML files. textadept.file_types.extensions.html = 'xml' -- Recognize a shebang line like "#!/usr/bin/zsh" as shell code. - textadept.file_types.shebangs.zsh = 'bash' + textadept.file_types.patterns['^#!.+/zsh'] = 'bash' [`textadept.file_types`]: api.html#textadept.file_types diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua index 4be182c7..bbaa47ed 100644 --- a/modules/textadept/file_types.lua +++ b/modules/textadept/file_types.lua @@ -19,27 +19,18 @@ events.LEXER_LOADED = 'lexer_loaded' --- -- Map of file extensions to their associated lexer names. --- If the file type is not recognized by shebang words or first-line patterns, --- each file extension is matched against the file's extension. +-- If the file type is not recognized by its first-line, each file extension is +-- matched against the file's extension. -- @class table -- @name extensions M.extensions = {--[[Actionscript]]as='actionscript',asc='actionscript',--[[Ada]]adb='ada',ads='ada',--[[ANTLR]]g='antlr',g4='antlr',--[[APDL]]ans='apdl',inp='apdl',mac='apdl',--[[Applescript]]applescript='applescript',--[[ASM]]asm='asm',ASM='asm',s='asm',S='asm',--[[ASP]]asa='asp',asp='asp',hta='asp',--[[AWK]]awk='awk',--[[Batch]]bat='batch',cmd='batch',--[[BibTeX]]bib='bibtex',--[[Boo]]boo='boo',--[[C#]]cs='csharp',--[[C/C++]]c='ansi_c',cc='ansi_c',C='ansi_c',cpp='cpp',cxx='cpp',['c++']='cpp',h='cpp',hh='cpp',hpp='cpp',hxx='cpp',['h++']='cpp',--[[ChucK]]ck='chuck',--[[CMake]]cmake='cmake',['cmake.in']='cmake',ctest='cmake',['ctest.in']='cmake',--[[CoffeeScript]]coffee='coffeescript',--[[CSS]]css='css',--[[CUDA]]cu='cuda',cuh='cuda',--[[D]]d='dmd',di='dmd',--[[Dart]]dart='dart',--[[Desktop]]desktop='desktop',--[[diff]]diff='diff',patch='diff',--[[dot]]dot='dot',--[[Eiffel]]e='eiffel',eif='eiffel',--[[Erlang]]erl='erlang',hrl='erlang',--[[F#]]fs='fsharp',--[[Fish]]fish='fish',--[[Forth]]forth='forth',frt='forth',fs='forth',--[[Fortran]]f='fortran',['for']='fortran',ftn='fortran',fpp='fortran',f77='fortran',f90='fortran',f95='fortran',f03='fortran',f08='fortran',--[[Gap]]g='gap',gd='gap',gi='gap',gap='gap',--[[Gettext]]po='gettext',pot='gettext',--[[GLSL]]glslf='glsl',glslv='glsl',--[[GNUPlot]]dem='gnuplot',plt='gnuplot',--[[Go]]go='go',--[[Groovy]]groovy='groovy',gvy='groovy',--[[Gtkrc]]gtkrc='gtkrc',--[[Haskell]]hs='haskell',--[[HTML]]htm='html',html='html',shtm='html',shtml='html',xhtml='html',--[[IDL]]idl='idl',odl='idl',--[[Inform]]inf='inform',ni='inform',--[[ini]]cfg='ini',cnf='ini',inf='ini',ini='ini',reg='ini',--[[Io]]io='io_lang',--[[Java]]bsh='java',java='java',--[[Javascript]]js='javascript',jsfl='javascript',--[[JSON]]json='json',--[[JSP]]jsp='jsp',--[[LaTeX]]bbl='latex',dtx='latex',ins='latex',ltx='latex',tex='latex',sty='latex',--[[LESS]]less='less',--[[LilyPond]]lily='lilypond',ly='lilypond',--[[Lisp]]cl='lisp',el='lisp',lisp='lisp',lsp='lisp',--[[Literate Coffeescript]]litcoffee='litcoffee',--[[Lua]]lua='lua',--[[Makefile]]GNUmakefile='makefile',iface='makefile',mak='makefile',makefile='makefile',Makefile='makefile',--[[Markdown]]md='markdown',--[[Nemerle]]n='nemerle',--[[Nimrod]]nim='nimrod',--[[NSIS]]nsh='nsis',nsi='nsis',nsis='nsis',--[[Objective C]]m='objective_c',mm='objective_c',objc='objective_c',--[[OCaml]]caml='caml',ml='caml',mli='caml',mll='caml',mly='caml',--[[Pascal]]dpk='pascal',dpr='pascal',p='pascal',pas='pascal',--[[Perl]]al='perl',perl='perl',pl='perl',pm='perl',pod='perl',--[[PHP]]inc='php',php='php',php3='php',php4='php',phtml='php',--[[Pike]]pike='pike',pmod='pike',--[[PKGBUILD]]PKGBUILD='pkgbuild',--[[Postscript]]eps='ps',ps='ps',--[[Prolog]]prolog='prolog',--[[Properties]]props='props',properties='props',--[[Python]]sc='python',py='python',pyw='python',--[[R]]R='rstats',Rout='rstats',Rhistory='rstats',Rt='rstats',['Rout.save']='rstats',['Rout.fail']='rstats',S='rstats',--[[REBOL]]r='rebol',reb='rebol',--[[reST]]rst='rest',--[[Rexx]]orx='rexx',rex='rexx',--[[RHTML]]erb='rhtml',rhtml='rhtml',--[[Ruby]]Rakefile='ruby',rake='ruby',rb='ruby',rbw='ruby',--[[Sass CSS]]sass='sass',scss='sass',--[[Scala]]scala='scala',--[[Scheme]]sch='scheme',scm='scheme',--[[Shell]]bash='bash',bashrc='bash',bash_profile='bash',configure='bash',csh='bash',sh='bash',zsh='bash',--[[Smalltalk]]changes='smalltalk',st='smalltalk',sources='smalltalk',--[[SQL]]ddl='sql',sql='sql',--[[Tcl]]tcl='tcl',tk='tcl',--[[Texinfo]]texi='texinfo',--[[Vala]]vala='vala',--[[vCard]]vcf='vcard',vcard='vcard',--[[Verilog]]v='verilog',ver='verilog',--[[VHDL]]vh='vhdl',vhd='vhdl',vhdl='vhdl',--[[Visual Basic]]asa='vb',bas='vb',cls='vb',ctl='vb',dob='vb',dsm='vb',dsr='vb',frm='vb',pag='vb',vb='vb',vba='vb',vbs='vb',--[[XML]]dtd='xml',svg='xml',xml='xml',xsd='xml',xsl='xml',xslt='xml',xul='xml',--[[Xtend]]xtend='xtend',--[[YAML]]yaml='yaml'} ---- --- Map of shebang words to their associated lexer names. --- If the file has a shebang line, a line that starts with "#!" and is the first --- line in the file, each shebang word is matched against that line. --- @class table --- @name shebangs -M.shebangs = {awk='awk',lua='lua',octave='matlab',perl='perl',php='php',python='python',ruby='ruby',bash='bash',sh='bash'} - --- -- Map of first-line patterns to their associated lexer names. --- If a file type is not recognized by shebang words, each pattern is matched --- against the first line in the file. +-- Each pattern is matched against the first line in the file. -- @class table -- @name patterns -M.patterns = {['^%s*class%s+%S+%s*<%s*ApplicationController']='rails',['^%s*class%s+%S+%s*<%s*ActionController::Base']='rails',['^%s*class%s+%S+%s*<%s*ActiveRecord::Base']='rails',['^%s*class%s+%S+%s*<%s*ActiveRecord::Migration']='rails',['^%s*<%?xml%s']='xml'} +M.patterns = {['^#!.+/awk']='awk',['^#!.+/lua']='lua',['^#!.+/octave']='matlab',['^#!.+/perl']='perl',['^#!.+/php']='php',['^#!.+/python']='python',['^#!.+/ruby']='ruby',['^#!.+/bash']='bash',['^#!.+/sh']='bash',['^%s*class%s+%S+%s*<%s*ApplicationController']='rails',['^%s*class%s+%S+%s*<%s*ActionController::Base']='rails',['^%s*class%s+%S+%s*<%s*ActiveRecord::Base']='rails',['^%s*class%s+%S+%s*<%s*ActiveRecord::Migration']='rails',['^%s*<%?xml%s']='xml'} --- -- List of available lexer names. @@ -60,12 +51,6 @@ end -- @return lexer language local function detect_language(buffer) local line = buffer:get_line(0) - -- Detect from shebang line. - if line:find('^#!') then - for word in line:gsub('[/\\]', ' '):gmatch('%S+') do - if M.shebangs[word] then return M.shebangs[word] end - end - end -- Detect from first line. for patt, lexer in pairs(M.patterns) do if line:find(patt) then return lexer end -- cgit v1.2.3