diff options
author | 2012-03-25 12:26:29 -0400 | |
---|---|---|
committer | 2012-03-25 12:26:29 -0400 | |
commit | 50ee1f80ae539185f1d72ece6660b80997f0b2c2 (patch) | |
tree | 6dac5f0e6da220741b1f1fab3296b058b21374ee | |
parent | 1329e9cd55f2741d1d8924b416b1646c23e7dee0 (diff) | |
download | textadept-50ee1f80ae539185f1d72ece6660b80997f0b2c2.tar.gz textadept-50ee1f80ae539185f1d72ece6660b80997f0b2c2.zip |
Improved message double-clicking behavior for run and compile commands.
-rw-r--r-- | core/gui.lua | 15 | ||||
-rw-r--r-- | modules/textadept/run.lua | 16 |
2 files changed, 19 insertions, 12 deletions
diff --git a/core/gui.lua b/core/gui.lua index f97ace83..5be51813 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -122,18 +122,27 @@ end -- other view. -- @param preferred_view When multiple views exist and the desired buffer is not -- open in any of them, open it in this one. +-- @param sloppy Flag indicating whether or not to not match `filename` to +-- `buffer.filename` exactly. When `true`, matches `filename` to only the last +-- part of `buffer.filename` This is useful for run and compile commands which +-- output relative filenames and paths instead of full ones and it is likely +-- that the file in question is already open. The default value is `false`. -- @name goto_file -function gui.goto_file(filename, split, preferred_view) - if #_VIEWS == 1 and view.buffer.filename ~= filename and split then +function gui.goto_file(filename, split, preferred_view, sloppy) + local patt = not sloppy and '^'..filename..'$' or filename..'$' + if #_VIEWS == 1 and split and not (view.buffer.filename or ''):find(patt) then view:split() else local other_view = _VIEWS[preferred_view] for i, v in ipairs(_VIEWS) do - if v.buffer.filename == filename then gui.goto_view(i) return end + if (v.buffer.filename or ''):find(patt) then gui.goto_view(i) return end if not other_view and v ~= view then other_view = i end end if other_view then gui.goto_view(other_view) end end + for i, buffer in ipairs(_BUFFERS) do + if (buffer.filename or ''):find(patt) then view:goto_buffer(i) return end + end io.open_file(filename) end diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index b8af5f66..da914e24 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -36,6 +36,8 @@ local events, events_connect, events_emit = events, events.connect, events.emit local COMPILE_OUTPUT, RUN_OUTPUT = 'compile_output', 'run_output' events.COMPILE_OUTPUT, events.RUN_OUTPUT = COMPILE_OUTPUT, RUN_OUTPUT +local preferred_view + --- -- Executes the command line parameter and prints the output to Textadept. -- @param command The command line string. @@ -47,6 +49,7 @@ events.COMPILE_OUTPUT, events.RUN_OUTPUT = COMPILE_OUTPUT, RUN_OUTPUT -- @param lexer The current lexer. -- @name execute function M.execute(command, lexer) + preferred_view = view local filepath = buffer.filename:iconv(_CHARSET, 'UTF-8') local filedir, filename = '', filepath if filepath:find('[/\\]') then @@ -144,21 +147,16 @@ function goto_error(pos, line_num) buffer._type ~= _L['[Error Buffer]'] then return end - local buffer = buffer line = buffer:get_line(line_num) for _, error_detail in pairs(M.error_detail) do local captures = { line:match(error_detail.pattern) } if #captures > 0 then local utf8_filename = captures[error_detail.filename] local filename = utf8_filename:iconv(_CHARSET, 'UTF-8') - if lfs.attributes(filename) then - gui.goto_file(utf8_filename, true) - _M.textadept.editing.goto_line(captures[error_detail.line]) - local msg = captures[error_detail.message] - if msg then buffer:call_tip_show(buffer.current_pos, msg) end - else - error(string.format('"%s" %s', utf8_filename, _L['does not exist'])) - end + gui.goto_file(utf8_filename, true, preferred_view, true) + _M.textadept.editing.goto_line(captures[error_detail.line]) + local msg = captures[error_detail.message] + if msg then buffer:call_tip_show(buffer.current_pos, msg) end return end end |