diff options
author | mitchell <70453897+667e-11@users.noreply.github.com> | 2013-09-27 21:12:05 -0400 |
---|---|---|
committer | mitchell <70453897+667e-11@users.noreply.github.com> | 2013-09-27 21:12:05 -0400 |
commit | ef23e13ac57cf6a8bcb04ccce10d2e5b34feec06 (patch) | |
tree | 558d22791c4461fc5b765ce9ef57dd2273df73e0 | |
parent | 235a3a04d8cf7f80823d59a8ff6ec77fbf8e61d5 (diff) |
Integrated compile and run commands for most languages.
Compile and run should work out of the box for most languages. Also added a
warning marker, renamed `compile_command` and `run_command` tables to
`compile_commands` and `run_commands`, respectively, and renamed `error_details`
to `error_patterns`, changing its structure to just hold patterns.
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | FAQ.md | 4 | ||||
-rw-r--r-- | core/._M.luadoc | 39 | ||||
-rw-r--r-- | doc/06_AdeptEditing.md | 22 | ||||
-rw-r--r-- | doc/07_Modules.md | 26 | ||||
-rw-r--r-- | doc/08_Preferences.md | 2 | ||||
-rw-r--r-- | doc/14_Appendix.md | 14 | ||||
-rw-r--r-- | doc/images/runerror.png | bin | 42673 -> 39951 bytes | |||
-rw-r--r-- | modules/cpp/init.lua | 12 | ||||
-rw-r--r-- | modules/lua/init.lua | 8 | ||||
-rw-r--r-- | modules/textadept/file_types.lua | 2 | ||||
-rw-r--r-- | modules/textadept/run.lua | 178 | ||||
-rw-r--r-- | properties.lua | 1 | ||||
-rw-r--r-- | themes/dark.lua | 6 | ||||
-rw-r--r-- | themes/light.lua | 12 | ||||
-rw-r--r-- | themes/term.lua | 1 |
16 files changed, 164 insertions, 167 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bd85821..36ca1c21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1941,8 +1941,8 @@ Changes: [list of encodings]: api/io.html#try_encodings [events]: api/events.html [Scintilla]: http://scintilla.org -[compile commands]: api/textadept.run.html#compile_command -[run commands]: api/textadept.run.html#run_command +[compile commands]: api/textadept.run.html#compile_commands +[run commands]: api/textadept.run.html#run_commands [gtdialog]: http://foicica.com/gtdialog [lua_dialog]: http://luaforge.net/projects/lua-dialog [cocoaDialog]: http://cocoadialog.sf.net @@ -41,9 +41,9 @@ either nothing happens or the wrong command is executed. How can I tell Textadept which command to run? **A:** -Take a look at these [commands][]. +Please see the LuaDoc on [compile and run commands][]. -[commands]: http://foicica.com/wiki/run-supplemental +[compile and run commands]: api/_M.html#Compile.and.Run - - - diff --git a/core/._M.luadoc b/core/._M.luadoc index a34223b3..d21b66de 100644 --- a/core/._M.luadoc +++ b/core/._M.luadoc @@ -26,28 +26,27 @@ -- #### Compile and Run -- -- The `Ctrl+Shift+R` and `Ctrl+R` (`⌘⇧R` and `⌘R` on Mac OSX | `M-^R` and `^R` --- in curses) key bindings compile and run code, respectively. In order for --- these to work for your language, the [`textadept.run.compile_command`][] and --- [`textadept.run.run_command`][] tables must have keys with the language's --- lexer name assigned to compile and run shell commands, respectively. Commands --- may contain [macros][]. For Lua, it would look like --- --- textadept.run.compile_command.lua = 'luac %(filename)' --- textadept.run.run_command = 'lua %(filename)' --- --- The module should also define error details in --- [`textadept.run.error_detail`][] so double-clicking on compile or runtime --- errors jumps to the error's location. The format for Lua errors looks like --- --- textadept.run.error_detail.lua = { --- pattern = '^lua: (.-):(%d+): (.+)$', --- filename = 1, line = 2, message = 3 --- } +-- in curses) key bindings compile and run code, respectively. If Textadept does +-- not execute the correct commands for your language, modify them in the +-- [`textadept.run.compile_commands`][] and [`textadept.run.run_commands`][] +-- tables using the appropriate lexer key. Commands may contain [macros][]. For +-- Lua, it would look like +-- +-- textadept.run.compile_commands.lua = 'luac "%(filename)"' +-- textadept.run.run_commands.lua = 'lua "%(filename)"' +-- +-- Double-clicking on compile or runtime errors jumps to the error's location. +-- If Textadept does not recognize your language's errors properly, add an error +-- pattern to [`textadept.run.error_patterns`][]. The Lua error pattern looks +-- like +-- +-- table.insert(textadept.run.error_patterns, 1, +-- '^luac?: (.-):(%d+): (.+)$') -- --- [`textadept.run.compile_command`]: textadept.run.html#compile_command --- [`textadept.run.run_command`]: textadept.run.html#run_command +-- [`textadept.run.compile_commands`]: textadept.run.html#compile_commands +-- [`textadept.run.run_commands`]: textadept.run.html#run_commands -- [macros]: textadept.run.html#execute --- [`textadept.run.error_detail`]: textadept.run.html#error_detail +-- [`textadept.run.error_patterns`]: textadept.run.html#error_patterns -- -- #### Buffer Properties -- diff --git a/doc/06_AdeptEditing.md b/doc/06_AdeptEditing.md index 38f824a9..f27df547 100644 --- a/doc/06_AdeptEditing.md +++ b/doc/06_AdeptEditing.md @@ -212,7 +212,8 @@ search. Being a programmer's editor, Textadept excels at editing source code. It understands the syntax and structure of more than 80 different programming languages and recognizes hundreds of file types. Textadept uses this knowledge -to make viewing and editing code faster and easier. +to make viewing and editing code faster and easier. It can also compile and run +simple source files. ### Lexers @@ -296,3 +297,22 @@ can define some too. Pressing `Ctrl+/` (`⌘/` on Mac OSX | `M-/` in curses) comments or uncomments the code on the selected lines. Selecting any part of a line renders the entire line eligible for commenting or uncommenting. + +### Compile and Run + +Textadept knows most of the commands that compile and/or run code in source +files. Pressing `Ctrl+Shift+R` (`⌘⇧R` on Mac OSX | `M-^R` in curses) executes +the command for compiling code in the current file and `Ctrl+R` (`⌘R` | `^R`) +executes the command for running code. A new buffer shows the output from the +command and marks any recognized warnings and errors. Pressing `Ctrl+Alt+E` +(`^⌘E` | `M-X`) attempts to jump to the source of the next recognized warning or +error and `Ctrl+Alt+Shift+E` (`^⌘⇧E` | `M-S-X`) attempts to jump to the previous +one. Double-clicking on warnings and errors also jumps to their sources. If +Textadept does not know the correct commands for compiling and/or running your +language's source code, or if it does not detect warning or error messages +properly, you can [make changes][] in your [user-init file][]. + +![Runtime Error](images/runerror.png) + +[make changes]: api/_M.html#Compile.and.Run +[user-init file]: 08_Preferences.html#User.Init diff --git a/doc/07_Modules.md b/doc/07_Modules.md index 9af18ab5..3f929ec9 100644 --- a/doc/07_Modules.md +++ b/doc/07_Modules.md @@ -19,29 +19,9 @@ Language modules have a scope limited to a single programming language. The module's name matches the language's lexer in the *lexers/* directory. Textadept automatically loads the module when editing source code in that particular language. In addition to the source code editing features discussed previously, -these kinds of modules typically also define shell commands for running and -compiling code, indentation settings, custom key bindings, and perhaps a custom -context menu. The manual discusses these features below. - -### Compile and Run - -Most language modules specify commands that compile and/or run the code in the -current file. Pressing `Ctrl+Shift+R` (`⌘⇧R` on Mac OSX | `M-^R` in curses) -executes the command for compiling code and `Ctrl+R` (`⌘R` | `^R`) executes the -command for running code. A new buffer shows the output from the command and -marks any recognized errors. Pressing `Ctrl+Alt+E` (`^⌘E` | `M-X`) attempts to -jump to the source of the next recognized error and `Ctrl+Alt+Shift+E` (`^⌘⇧E` | -`M-S-X`) attempts to jump to the previous one. Double-clicking on errors also -jumps to their sources. Note: In order for these features to work, the language -you are working with must have its compile and run commands and error format -defined. If the language module does not exist or does not [define][] commands -or an error format, you can do so [manually][] in your [user-init file][]. - -![Runtime Error](images/runerror.png) - -[define]: api/_M.html#Compile.and.Run -[manually]: http://foicica.com/wiki/run-supplemental -[user-init file]: 08_Preferences.html#User.Init +these kinds of modules typically also define indentation settings, custom key +bindings, and perhaps a custom context menu. The manual discusses these features +below. ### Buffer Properties diff --git a/doc/08_Preferences.md b/doc/08_Preferences.md index 9495a747..a6e0a09f 100644 --- a/doc/08_Preferences.md +++ b/doc/08_Preferences.md @@ -80,7 +80,7 @@ commands, load more [Adeptsense tags][], and add additional [key bindings](#Key.Bindings) and [snippets](#Snippets) (instead of in *~/.textadept/init.lua*). For example: - textadept.run.run_command.lua = 'lua5.2' + textadept.run.run_commands.lua = 'lua5.2' _M.lua.sense:load_ctags('/path/to/my/projects/tags') keys.lua['c\n'] = function() buffer:line_end() buffer:add_text('end') buffer:new_line() diff --git a/doc/14_Appendix.md b/doc/14_Appendix.md index f4834dc7..d5a83c1d 100644 --- a/doc/14_Appendix.md +++ b/doc/14_Appendix.md @@ -175,10 +175,14 @@ grow\_selection() |Replaced|[select\_enclosed()][] menubar |Removed |N/A contextmenu |Removed |N/A **_M.textadept.run** | | +N/A |New |[MARK\_WARNING][] N/A |New |[MARK\_ERROR][] MARK\_ERROR\_BACK |Removed |N/A<sup>c</sup> +compile\_command |Renamed |[compile\_commands][] +run\_command |Renamed |[run\_commands][] +error\_detail |Renamed |[error\_patterns][]<sup>e</sup> **_M.textadept.snapopen** |Removed |N/A -open |Changed |\_G.[io.snapopen()][]<sup>e</sup> +open |Changed |\_G.[io.snapopen()][]<sup>f</sup> **_SCINTILLA.constants** | | SC\_\* |Renamed |Removed "SC\_" prefix. SC(FIND\|MOD\|VS\|WS) |Renamed |Removed "SC" prefix. @@ -211,7 +215,9 @@ close\_all() |Renamed |[close\_all\_buffers()][] <sup>d</sup>Set [`buffer.indic_fore`][] in [`events.VIEW_NEW`][]. -<sup>e</sup>Changed arguments too. +<sup>e</sup>Changed structure too. + +<sup>f</sup>Changed arguments too. [buffer.new()]: api/buffer.html#new [textadept]: api/textadept.html @@ -222,7 +228,11 @@ close\_all() |Renamed |[close\_all\_buffers()][] [INDIC\_HIGHLIGHT]: api/textadept.editing.html#INDIC_HIGHLIGHT [autocomplete\_word]: api/textadept.editing.html#autocomplete_word [select\_enclosed()]: api/textadept.editing.html#select_enclosed +[MARK\_WARNING]: api/textadept.run.html#MARK_WARNING [MARK\_ERROR]: api/textadept.run.html#MARK_ERROR +[compile\_commands]: api/textadept.run.html#compile_commands +[run\_commands]: api/textadept.run.html#run_commands +[error\_patterns]: api/textadept.run.html#error_patterns [io.snapopen()]: api/io.html#snapopen [style\_name]: api/buffer.html#style_name [io.reload\_file()]: api/io.html#reload_file diff --git a/doc/images/runerror.png b/doc/images/runerror.png Binary files differindex 65d272f9..4fe89b53 100644 --- a/doc/images/runerror.png +++ b/doc/images/runerror.png diff --git a/modules/cpp/init.lua b/modules/cpp/init.lua index 95a7452c..f5809608 100644 --- a/modules/cpp/init.lua +++ b/modules/cpp/init.lua @@ -23,18 +23,6 @@ local M = {} -- from *`_USERHOME`/modules/cpp/api*. module('_M.cpp')]] --- Compile and Run command tables use file extensions. -textadept.run.compile_command.c = - 'gcc -pedantic -Os -o "%(filename_noext)" %(filename)' -textadept.run.compile_command.cpp = - 'g++ -pedantic -Os -o "%(filename_noext)" %(filename)' -textadept.run.run_command.c = '%(filedir)%(filename_noext)' -textadept.run.run_command.cpp = '%(filedir)%(filename_noext)' -textadept.run.error_detail.c = { - pattern = '^(.-):(%d+): (.+)$', - filename = 1, line = 2, message = 3 -} - -- Adeptsense. M.sense = textadept.adeptsense.new('cpp') diff --git a/modules/lua/init.lua b/modules/lua/init.lua index 286dbdf6..cb77e9d6 100644 --- a/modules/lua/init.lua +++ b/modules/lua/init.lua @@ -24,14 +24,6 @@ local M = {} -- from *`_USERHOME`/modules/lua/api*. module('_M.lua')]] --- Compile and Run command tables use file extensions. -textadept.run.compile_command.lua = 'luac %(filename)' -textadept.run.run_command.lua = 'lua %(filename)' -textadept.run.error_detail.lua = { - pattern = '^lua: (.-):(%d+): (.+)$', - filename = 1, line = 2, message = 3 -} - -- Adeptsense. M.sense = textadept.adeptsense.new('lua') diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua index e99374a0..1d77c178 100644 --- a/modules/textadept/file_types.lua +++ b/modules/textadept/file_types.lua @@ -24,7 +24,7 @@ events.LEXER_LOADED = 'lexer_loaded' -- each file extension is matched against the file's extension. -- @class table -- @name extensions -M.extensions = {--[[Actionscript]]as='actionscript',asc='actionscript',--[[ADA]]ada='ada',adb='ada',ads='ada',--[[ANTLR]]g='antlr',--[[APDL]]ans='apdl',inp='apdl',mac='apdl',--[[Applescript]]applescript='applescript',--[[ASP]]asa='asp',asp='asp',hta='asp',--[[AWK]]awk='awk',--[[Batch]]bat='batch',cmd='batch',--[[Bibtex]]bib='bibtex',--[[Boo]]boo='boo',--[[C/C++]]c='cpp',cc='cpp',C='cpp',cpp='cpp',cxx='cpp',['c++']='cpp',h='cpp',hh='cpp',hpp='cpp',hxx='cpp',['h++']='cpp',--[[C#]]cs='csharp',--[[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',--[[Desktop]]desktop='desktop',--[[diff]]diff='diff',patch='diff',--[[dot]]dot='dot',--[[Eiffel]]e='eiffel',eif='eiffel',--[[Erlang]]erl='erlang',hrl='erlang',--[[F#]]fs='fsharp',--[[Forth]]f='forth',forth='forth',frt='forth',fs='forth',--[[Fortran]]['for']='fortran',fort='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='hypertext',html='hypertext',shtm='hypertext',shtml='hypertext',xhtml='hypertext',--[[IDL]]idl='idl',odl='odl',--[[Inform]]inf='inform',--[[ini]]cfg='ini',cnf='ini',inf='ini',ini='ini',reg='ini',--[[Io]]io='Io',--[[Java]]bsh='java',java='java',--[[Javascript]]js='javascript',jsfl='javascript',--[[JSP]]jsp='jsp',--[[JSON]]json='json',--[[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',--[[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',--[[Octave]]--[[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',--[[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',--[[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',--[[Vala]]vala='vala',--[[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'} +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',--[[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='cpp',cc='cpp',C='cpp',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',--[[Desktop]]desktop='desktop',--[[diff]]diff='diff',patch='diff',--[[dot]]dot='dot',--[[Eiffel]]e='eiffel',eif='eiffel',--[[Erlang]]erl='erlang',hrl='erlang',--[[F#]]fs='fsharp',--[[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='hypertext',html='hypertext',shtm='hypertext',shtml='hypertext',xhtml='hypertext',--[[IDL]]idl='idl',odl='odl',--[[Inform]]inf='inform',ni='inform',--[[ini]]cfg='ini',cnf='ini',inf='ini',ini='ini',reg='ini',--[[Io]]io='Io',--[[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',--[[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',--[[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',--[[Vala]]vala='vala',--[[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'} --- -- Map of shebang words to their associated lexers. diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index fd3be697..75dca7dd 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -5,11 +5,12 @@ local M = {} --[[ This comment is for LuaDoc. --- -- Compile and run/execute source files with Textadept. --- Typically, [language modules][] populate the `compile_command`, --- `run_command`, and `error_detail` tables for a particular language's file --- extension. +-- [Language modules][] may tweak the `compile_commands`, `run_commands`, and/or +-- `error_patterns` tables for particular languages. -- --- [language modules]: _M.html#Compile.and.Run +-- [Language modules]: _M.html#Compile.and.Run +-- @field MARK_WARNING (number) +-- The run or compile warning marker number. -- @field MARK_ERROR (number) -- The run or compile error marker number. -- @field cwd (string, Read-only) @@ -34,6 +35,7 @@ local M = {} -- * `output`: The string output from the command. module('textadept.run')]] +M.MARK_WARNING = _SCINTILLA.next_marker_number() M.MARK_ERROR = _SCINTILLA.next_marker_number() -- Events. @@ -43,15 +45,16 @@ local preferred_view -- Executes a compile or run command. -- Emits a `COMPILE_OUTPUT` or `RUN_OUTPUT` event based on the `compiling` flag. --- @param cmd_table Either `compile_command` or `run_command`. +-- @param commands Either `compile_commands` or `run_commands`. -- @param compiling Flag indicating whether or not the command is a compiler -- command. The default value is `false`. -- @see _G.events -local function command(cmd_table, compiling) +local function command(commands, compiling) if not buffer.filename then return end buffer:annotation_clear_all() io.save_file() - local command = cmd_table[buffer.filename:match('[^.]+$')] + local command = commands[buffer.filename:match('[^.]+$')] or + commands[buffer:get_lexer()] if not command then return end if type(command) == 'function' then command = command() end @@ -81,125 +84,119 @@ local function command(cmd_table, compiling) lfs.chdir(current_dir) end --- Parses the given message for an error description and returns a table of the --- error's details. --- @param message The message to parse for errors. --- @see error_detail -local function get_error_details(message) - for _, error_detail in pairs(M.error_detail) do - local captures = {message:match(error_detail.pattern)} - if #captures > 0 then - local details = {} - for detail, i in pairs(error_detail) do details[detail] = captures[i] end - details.filename = details.filename:iconv(_CHARSET, 'UTF-8') - return details +-- Parses the given message for a warning or error message and returns a table +-- of the warning/error's details. +-- @param message The message to parse for warnings or errors. +-- @see error_patterns +local function get_error(message) + for i = 1, #M.error_patterns do + local patt = M.error_patterns[i] + if message:find(patt) then + local captures = {message:match(patt)} + for detail in patt:gmatch('[^%%](%b())') do + if detail == '(.-)' then + captures.filename = table.remove(captures, 1):iconv(_CHARSET, 'UTF-8') + elseif detail == '(%d+)' then + captures.line = tonumber(table.remove(captures, 1)) + else + captures.message = table.remove(captures, 1) + end + end + local warn = message:find('[Ww]arning') and not message:find('[Ee]rror') + captures.text, captures.warning = message, warn + return captures end end return nil end -- Prints the output from a run or compile command. --- If the output is a recognized error message, mark it. +-- If the output is a recognized warning or error message, mark it. -- @param lexer The current lexer. -- @param output The output to print. local function print_output(lexer, output) ui.print(output) - if get_error_details(output) then - -- Current position is one line below the error due to ui.print()'s '\n'. - buffer:marker_add(buffer.line_count - 2, M.MARK_ERROR) - end + local error = get_error(output) + if not error then return end + -- Current position is one line below the error due to ui.print()'s '\n'. + buffer:marker_add(buffer.line_count - 2, + error.warning and M.MARK_WARNING or M.MARK_ERROR) end --- --- Map of file extensions (excluding the leading '.') to their associated --- "compile" shell command line strings or functions returning such strings. +-- Map of file extensions (excluding the leading '.') or lexers to their +-- associated "compile" shell command line strings or functions returning such +-- strings. -- Command line strings may have the following macros: -- -- + `%(filepath)`: The full path of the current file. -- + `%(filedir)`: The current file's directory path. -- + `%(filename)`: The name of the file, including its extension. -- + `%(filename_noext)`: The name of the file, excluding its extension. --- --- This table is typically populated by [language modules][]. --- --- [language modules]: _M.html#Compile.and.Run -- @class table --- @name compile_command -M.compile_command = {} +-- @name compile_commands +M.compile_commands = {actionscript='mxmlc "%(filename)"',ada='gnatmake "%(filename)"',antlr='antlr4 "%(filename)"',g='antlr3 "%(filename)"',applescript='osacompile "%(filename)" -o "%(filename_noext).scpt"',boo='booc "%(filename)"',caml='ocamlc -o "%(filename_noext)" "%(filename)"',csharp=WIN32 and 'csc "%(filename)"' or 'mcs "%(filename)"',cpp='g++ -o "%(filename_noext)" "%(filename)"',c='gcc -o "%(filename_noext)" "%(filename)"',coffeescript='coffee -c "%(filename)"',context='context --nonstopmode "%(filename)"',cuda=WIN32 and 'nvcc -o "%(filename_noext).exe" "%(filename)"' or 'nvcc -o "%(filename_noext)" "%(filename)"',dmd='dmd "%(filename)"',dot='dot -Tps "%(filename)" -o "%(filename_noext).ps"',eiffel='se c "%(filename)"',erlang='erl -compile "%(filename_noext)"',fsharp=WIN32 and 'fsc.exe "%(filename)"' or 'mono fsc.exe "%(filename)"',fortran='gfortran -o "%(filename_noext)" "%(filename)"',gap='gac -o "%(filename_noext)" "%(filename)"',go='go build "%(filename)"',groovy='groovyc "%(filename)"',haskell=WIN32 and 'ghc -o "%(filename_noext).exe" "%(filename)"' or 'ghc -o "%(filename_noext)" "%(filename)"',inform=function() return 'inform -c "'..buffer.filename:match('^(.+%.inform[/\\])Source')..'"' end,java='javac "%(filename)"',latex='pdflatex -file-line-error -halt-on-error "%(filename)"',less='lessc "%(filename)" "%(filename_noext).css"',lilypond='lilypond "%(filename)"',lisp='clisp -c "%(filename)"',litcoffee='coffee -c "%(filename)"',lua='luac -o "%(filename_noext).luac" "%(filename)"',markdown='markdown "%(filename)" > "%(filename_noext).html"',nemerle='ncc "%(filename)" -out:"%(filename_noext).exe"',nsis='MakeNSIS "%(filename)"',objective_c='gcc -o "%(filename_noext)" "%(filename)"',pascal='fpc "%(filename)"',perl='perl -c "%(filename)"',php='php -l "%(filename)"',prolog='gplc --no-top-level "%(filename)"',python='python -m py_compile "%(filename)"',ruby='ruby -c "%(filename)"',sass='sass "%(filename)" "%(filename_noext).css"',scala='scalac "%(filename)"',tex='pdftex -file-line-error -halt-on-error "%(filename)"',vala='valac "%(filename)"',vb=WIN32 and 'vbc "%(filename)"' or 'vbnc "%(filename)"',} --- --- Compiles the file based on its extension using the command from the --- `compile_command` table. +-- Compiles the file based on its extension or lexer, using the command from the +-- `compile_commands` table. -- Emits a `COMPILE_OUTPUT` event. --- @see compile_command +-- @see compile_commands -- @see _G.events -- @name compile -function M.compile() command(M.compile_command, true) end +function M.compile() command(M.compile_commands, true) end events.connect(events.COMPILE_OUTPUT, print_output) --- --- Map of file extensions (excluding the leading '.') to their associated --- "run" shell command line strings or functions returning such strings. +-- Map of file extensions (excluding the leading '.') or lexers to their +-- associated "run" shell command line strings or functions returning such +-- strings. -- Command line strings may have the following macros: -- -- + `%(filepath)`: The full path of the current file. -- + `%(filedir)`: The current file's directory path. -- + `%(filename)`: The name of the file, including its extension. -- + `%(filename_noext)`: The name of the file, excluding its extension. --- --- This table is typically populated by [language modules][]. --- --- [language modules]: _M.html#Compile.and.Run -- @class table --- @name run_command -M.run_command = {} +-- @name run_commands +M.run_commands = {actionscript=WIN32 and 'start "" "%(filename_noext).swf"' or OSX and 'open "file://%(filename_noext).swf"' or 'xdg-open "%(filename_noext).swf"',ada=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',applescript='osascript "%(filename)"',awk='awk -f "%(filename)"',batch='"%(filename)"',boo='booi "%(filename)"',caml='ocamlrun "%(filename_noext)"',csharp=WIN32 and '"%(filename_noext)"' or 'mono "%(filename_noext).exe"',cpp=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',chuck='chuck "%(filename)"',cmake='cmake -P "%(filename)"',coffeescript='coffee "%(filename)"',context=WIN32 and 'start "" "%(filename_noext).pdf"' or OSX and 'open "%(filename_noext).pdf"' or 'xdg-open "%(filename_noext).pdf"',cuda=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',dmd=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',eiffel="./a.out",fsharp=WIN32 and '"%(filename_noext)"' or 'mono "%(filename_noext).exe"',forth='gforth "%(filename)" -e bye',fortran=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',gnuplot='gnuplot "%(filename)"',go='go run "%(filename)"',groovy='groovy "%(filename)"',haskell=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',hypertext=WIN32 and 'start "" "%(filename)"' or OSX and 'open "file://%(filename)"' or 'xdg-open "%(filename)"',idl='idl -batch "%(filename)"',Io='io "%(filename)"',java='java "%(filename_noext)"',javascript='node "%(filename)"',latex=WIN32 and 'start "" "%(filename_noext).pdf"' or OSX and 'open "%(filename_noext).pdf"' or 'xdg-open "%(filename_noext).pdf"',less='lessc --no-color "%(filename)"',lilypond=WIN32 and 'start "" "%(filename_noext).pdf"' or OSX and 'open "%(filename_noext).pdf"' or 'xdg-open "%(filename_noext).pdf"',lisp='clisp "%(filename)"',litcoffee='coffee "%(filename)"',lua='lua "%(filename)"',makefile=WIN32 and 'nmake -f "%(filename)"' or 'make -f "%(filename)"',markdown='markdown "%(filename)"',nemerle=WIN32 and '"%(filename_noext)"' or 'mono "%(filename_noext).exe"',objective_c=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',pascal=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',perl='perl "%(filename)"',php='php "%(filename)"',pike='pike "%(filename)"',pkgbuild='makepkg -p "%(filename)"',prolog=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',python='python "%(filename)"',rstats=WIN32 and 'Rterm -f "%(filename)"' or 'R -f "%(filename)"',rebol='REBOL "%(filename)"',rexx=WIN32 and 'rexx "%(filename_noext)"' or 'regina "%(filename_noext)"',ruby='ruby "%(filename)"',sass='sass "%(filename)"',scala='scala "%(filename_noext)"',bash='bash "%(filename)"',csh='tcsh "%(filename)"',sh='sh "%(filename)"',zsh='zsh "%(filename)"',smalltalk='gst "%(filename)"',tcl='tclsh "%(filename)"',tex=WIN32 and 'start "" "%(filename_noext).pdf"' or OSX and 'open "%(filename_noext).pdf"' or 'xdg-open "%(filename_noext).pdf"',vala=WIN32 and '"%(filename_noext)"' or './"%(filename_noext)"',vb=WIN32 and '"%(filename_noext)"' or 'mono "%(filename_noext).exe"',} --- --- Runs/executes the file based on its extension using the command from the --- `run_command` table. +-- Runs/executes the file based on its extension or lexer, using the command +-- from the `run_commands` table. -- Emits a `RUN_OUTPUT` event. --- @see run_command +-- @see run_commands -- @see _G.events -- @name run -function M.run() command(M.run_command) end +function M.run() command(M.run_commands) end events.connect(events.RUN_OUTPUT, print_output) --- --- Map of lexer names to their error string details, tables containing the --- following fields: --- --- + `pattern`: A Lua pattern that matches the language's error string, --- capturing the filename the error occurs in, the line number the error --- occurred on, and optionally the error message. --- + `filename`: The numeric index of the Lua capture containing the filename --- the error occurred in. --- + `line`: The numeric index of the Lua capture containing the line number --- the error occurred on. --- + `message`: (Optional) The numeric index of the Lua capture containing the --- error's message. An annotation will be displayed if a message was --- captured. --- --- When an error message is double-clicked, the user is taken to the point of --- error. --- This table is usually populated by [language modules][]. --- --- [language modules]: _M.html#Compile.and.Run +-- List of warning and error string patterns that match various compile and run +-- warnings and errors. +-- Patterns contain filename, line number, and optional warning or error message +-- captures for single lines. When a warning or error message is double-clicked, +-- the user is taken to the point of warning/error. +-- When adding to this list, use `(.-)` to match filenames and `(%d+)` to match +-- line numbers. Also keep in mind that patterns are matched in sequential +-- order; once a pattern matches, no more are tried. -- @class table --- @name error_detail -M.error_detail = {} +-- @name error_patterns +M.error_patterns = {--[[ANTLR]]'^error%(%d+%): (.-):(%d+):%d+: (.+)$','^warning%(%d+%): (.-):(%d+):%d+: (.+)$',--[[AWK]]'^awk: (.-): line (%d+): (.+)$',--[[ChucK]]'^%[(.-)%]:line%((%d+)%)%.char%(%d+%): (.+)$',--[[CMake]]'^CMake Error at (.-):(%d+)',--[[Dot]]'^Error: (.-):(%d+): (.+)$',--[[Eiffel]]'^Line (%d+) columns? .- in .- %((.-)%):$','^line (%d+) column %d+ file (.-)$',--[[CoffeeScript,LitCoffee]]'^%s+at .-%((.-):(%d+):%d+, .-%)$',--[[Groovy,Java,Javascript]]'^%s+at .-%((.-):(%d+):?%d*%)$',--[[JavaScript]]'^%s+at (.-):(%d+):%d+$',--[[GNUPlot]]'^"(.-)", line (%d+): (.+)$',--[[Lua]]'^luac?: (.-):(%d+): (.+)$',--[[Prolog]]'^warning: (.-):(%d+): (.+)$',--[[OCaml,Python]]'^%s*File "(.-)", line (%d+)',--[[Rexx]]'^Error %d+ running "(.-)", line (%d+): (.+)$',--[[Sass]]'^WARNING on line (%d+) of (.-):$','^%s+on line (%d+) of (.-)$',--[[Tcl]]'^%s*%(file "(.-)" line (%d+)%)$',--[[Actionscript]]'^(.-)%((%d+)%): col %d+ (.+)$',--[[CUDA,D]]'^(.-)%((%d+)%): ([Ee]rror.+)$',--[[Boo,C#,F#,Nemerle,VB]]'^(.-)%((%d+),%d+%): (.+)$',--[[Pascal]]'^(.-)%((%d+),?%d*%) (%w+:.+)$',--[[Ada,C/C++,Haskell,LilyPond,Objective C,Prolog]]'^(.-):(%d+):%d+:%s*(.*)$',--[[Fortran,Vala]]'^(.-):(%d+)[%.%d%-]+:%s*(.*)$',--[[CMake,Javascript]]'^(.-):(%d+):$',--[[Python]]'^.-: %(\'([^\']+)\', %(\'(.-)\', (%d+), %d,','^.-: (.+) %((.-), line (%d+)%)$',--[[Shell (Bash)]]'^(.-): line (%d+): (.+)$',--[[Shell (sh)]]'^(.-): (%d+): %1: (.+)$',--[[Erlang,Forth,Groovy,Go,Java,LilyPond,Makefile,Pike,Ruby,Scala,Smalltalk]]'^%s*(.-):%s*(%d+):%s*(.+)$',--[[Less]]'^(.+) in (.-) on line (%d+), column %d+:$',--[[PHP]]'^(.+) in (.-) on line (%d+)$',--[[Gap]]'^(.+) in (.-) line (%d+)$',--[[Perl]]'^(.+) at (.-) line (%d+)',--[[APDL,IDL,REBOL,Verilog,VHDL:proprietary]]--[[ASP,CSS,Desktop,diff,django,gettext,Gtkrc,HTML,ini,JSON,JSP,Markdown,Postscript,Properties,R,RHTML,XML:none]]--[[Batch,BibTeX,ConTeXt,GLSL,Inform,Io,Lisp,Scheme,SQL,TeX:cannot parse]]} -- Returns whether or not the given buffer is a message buffer. local function is_msg_buf(buf) return buf._type == _L['[Message Buffer]'] end --- --- Goes to the source of the recognized compile/run error on line number *line* --- in the message buffer or the next or previous recognized error depending on --- boolean *next*. --- Displays an annotation with the error message, if available. +-- Goes to the source of the recognized compile/run warning or error on line +-- number *line* in the message buffer or the next or previous recognized +-- warning or error depending on boolean *next*. +-- Displays an annotation with the warning or error message, if available. -- @param line The line number in the message buffer that contains the --- compile/run error to go to. +-- compile/run warning/error to go to. -- @param next Optional flag indicating whether to go to the next recognized --- error or the previous one. Only applicable when *line* is `nil` or `false`. --- @see error_detail +-- warning/error or the previous one. Only applicable when *line* is `nil` or +-- `false`. +-- @see error_patterns -- @see cwd -- @name goto_error function M.goto_error(line, next) @@ -213,28 +210,33 @@ function M.goto_error(line, next) if not msg_view and not msg_buf then return end if msg_view then ui.goto_view(msg_view) else view:goto_buffer(msg_buf) end - -- If no line was given, find the next error marker. + -- If no line was given, find the next warning or error marker. if not line and next ~= nil then local f = buffer['marker_'..(next and 'next' or 'previous')] - line = f(buffer, buffer:line_from_position(buffer.current_pos) + - (next and 1 or -1), 2^M.MARK_ERROR) - if line == -1 then - line = f(buffer, next and 0 or buffer.line_count, 2^M.MARK_ERROR) - if line == -1 then if CURSES then view:goto_buffer(cur_buf) end return end + line = buffer:line_from_position(buffer.current_pos) + local wline = f(buffer, line + (next and 1 or -1), 2^M.MARK_WARNING) + local eline = f(buffer, line + (next and 1 or -1), 2^M.MARK_ERROR) + if wline == -1 and eline == -1 then + wline = f(buffer, next and 0 or buffer.line_count, 2^M.MARK_WARNING) + eline = f(buffer, next and 0 or buffer.line_count, 2^M.MARK_ERROR) + elseif wline == -1 or eline == -1 then + if wline == -1 then wline = eline else eline = wline end end + line = (next and math.min or math.max)(wline, eline) + if line == -1 then if CURSES then view:goto_buffer(cur_buf) end return end end buffer:goto_line(line) - -- Goto the error and show an annotation. - local err = get_error_details(buffer:get_line(line)) - if not err then if CURSES then view:goto_buffer(cur_buf) end return end + -- Goto the warning or error and show an annotation. + local error = get_error(buffer:get_line(line):match('^[^\r\n]+')) + if not error then if CURSES then view:goto_buffer(cur_buf) end return end textadept.editing.select_line() - ui.goto_file(M.cwd..err.filename, true, preferred_view, true) - local line, message = err.line, err.message + ui.goto_file(M.cwd..error.filename, true, preferred_view, true) + local line, message = error.line, error.message buffer:goto_line(line - 1) if message then buffer.annotation_text[line - 1] = message - buffer.annotation_style[line - 1] = 8 -- error + if not error.warning then buffer.annotation_style[line - 1] = 8 end -- error end end events.connect(events.DOUBLE_CLICK, function(pos, line) diff --git a/properties.lua b/properties.lua index 77e60566..bb0c8c42 100644 --- a/properties.lua +++ b/properties.lua @@ -81,6 +81,7 @@ buffer.indentation_guides = buffer.IV_LOOKBOTH local symbol = not CURSES and buffer.MARK_FULLRECT or buffer.MARK_CHARACTER + string.byte(' ') buffer:marker_define(textadept.bookmarks.MARK_BOOKMARK, symbol) +buffer:marker_define(textadept.run.MARK_WARNING, symbol) buffer:marker_define(textadept.run.MARK_ERROR, symbol) if not CURSES then -- Arrow Folding Symbols. diff --git a/themes/dark.lua b/themes/dark.lua index f798b812..71bfd636 100644 --- a/themes/dark.lua +++ b/themes/dark.lua @@ -108,9 +108,11 @@ buffer:set_fold_margin_hi_colour(true, property_int['color.black']) -- Markers. local MARK_BOOKMARK = textadept.bookmarks.MARK_BOOKMARK -buffer.marker_fore[MARK_BOOKMARK] = property_int['color.black'] +--buffer.marker_fore[MARK_BOOKMARK] = property_int['color.black'] buffer.marker_back[MARK_BOOKMARK] = property_int['color.dark_blue'] -buffer.marker_fore[textadept.run.MARK_ERROR] = property_int['color.black'] +--buffer.marker_fore[textadept.run.MARK_WARNING] = property_int['color.black'] +buffer.marker_back[textadept.run.MARK_WARNING] = property_int['color.yellow'] +--buffer.marker_fore[textadept.run.MARK_ERROR] = property_int['color.black'] buffer.marker_back[textadept.run.MARK_ERROR] = property_int['color.red'] for i = 25, 31 do -- fold margin markers buffer.marker_fore[i] = property_int['color.black'] diff --git a/themes/light.lua b/themes/light.lua index f5c54717..b13cb0ed 100644 --- a/themes/light.lua +++ b/themes/light.lua @@ -42,7 +42,7 @@ property['color.lavender'] = 0xE69999 -- Light colors. property['color.light_red'] = 0x8080CC ---property['color.light_yellow'] = 0x80CCCC +property['color.light_yellow'] = 0x80CCCC --property['color.light_green'] = 0x80CC80 --property['color.light_teal'] = 0xCCCC80 --property['color.light_purple'] = 0xCC80CC @@ -107,11 +107,13 @@ buffer:set_fold_margin_colour(true, property_int['color.white']) buffer:set_fold_margin_hi_colour(true, property_int['color.white']) -- Markers. -local MARK_BOOKMARK = textadept.bookmarks.MARK_BOOKMARK -buffer.marker_fore[MARK_BOOKMARK] = property_int['color.white'] +local MARK_BOOKMARK, t_run = textadept.bookmarks.MARK_BOOKMARK, textadept.run +--buffer.marker_fore[MARK_BOOKMARK] = property_int['color.white'] buffer.marker_back[MARK_BOOKMARK] = property_int['color.dark_blue'] -buffer.marker_fore[textadept.run.MARK_ERROR] = property_int['color.white'] -buffer.marker_back[textadept.run.MARK_ERROR] = property_int['color.light_red'] +--buffer.marker_fore[t_run.MARK_WARNING] = property_int['color.white'] +buffer.marker_back[t_run.MARK_WARNING] = property_int['color.light_yellow'] +--buffer.marker_fore[t_run.MARK_ERROR] = property_int['color.white'] +buffer.marker_back[t_run.MARK_ERROR] = property_int['color.light_red'] for i = 25, 31 do -- fold margin markers buffer.marker_fore[i] = property_int['color.white'] buffer.marker_back[i] = property_int['color.grey'] diff --git a/themes/term.lua b/themes/term.lua index fd35e862..bee6b44f 100644 --- a/themes/term.lua +++ b/themes/term.lua @@ -76,6 +76,7 @@ property['style.whitespace'] = '' -- Markers. local MARK_BOOKMARK = textadept.bookmarks.MARK_BOOKMARK buffer.marker_back[MARK_BOOKMARK] = property_int['color.blue'] +buffer.marker_back[textadept.run.MARK_WARNING] = property_int['color.yellow'] buffer.marker_back[textadept.run.MARK_ERROR] = property_int['color.red'] -- Indicators. |