diff options
author | 2020-07-12 22:57:53 -0400 | |
---|---|---|
committer | 2020-07-12 22:57:53 -0400 | |
commit | 0a6193a76de6aca1f17996404cc641b5a365af6f (patch) | |
tree | 91af549127359ff547f1c2f993e80ed5fa0bef5b | |
parent | ebd67cde9828e74339c913a62150eb93ba97fe14 (diff) |
Made `ui.find.goto_file_found()` and `textadept.run.goto_error()` args optional.
-rw-r--r-- | modules/textadept/find.lua | 5 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 12 | ||||
-rw-r--r-- | modules/textadept/run.lua | 6 | ||||
-rw-r--r-- | test/test.lua | 10 |
4 files changed, 15 insertions, 18 deletions
diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 51abda3f..c34ce370 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -389,12 +389,13 @@ local function is_ff_buf(buf) return buf._type == _L['[Files Found Buffer]'] end -- Jumps to the source of the find in files search result on line number -- *line_num* in the buffer titled "Files Found" or, if *line_num* is `nil`, -- jumps to the next or previous search result, depending on boolean *next*. --- @param line_num The line number in the files found buffer that contains the --- search result to go to. +-- @param line_num Optional line number in the files found buffer that contains +-- the search result to go to. This parameter may be omitted completely. -- @param next Optional flag indicating whether to go to the next search result -- or the previous one. Only applicable when *line_num* is `nil`. -- @name goto_file_found function M.goto_file_found(line_num, next) + if type(line_num) == 'boolean' then line_num, next = nil, line_num end local ff_view, ff_buf = nil, nil for i = 1, #_VIEWS do if is_ff_buf(_VIEWS[i].buffer) then ff_view = _VIEWS[i] break end diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index c61c8e81..c84e2bd7 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -153,11 +153,9 @@ local default_menubar = { ui.find.in_files = true ui.find.focus() end}, - {_L['Goto Next File Found'], function() - ui.find.goto_file_found(false, true) - end}, + {_L['Goto Next File Found'], function() ui.find.goto_file_found(true) end}, {_L['Goto Previous File Found'], function() - ui.find.goto_file_found(false, false) + ui.find.goto_file_found(false) end}, SEPARATOR, {_L['Jump to'], textadept.editing.goto_line} @@ -198,10 +196,8 @@ local default_menubar = { end}, {_L['Build'], textadept.run.build}, {_L['Stop'], textadept.run.stop}, - {_L['Next Error'], function() textadept.run.goto_error(false, true) end}, - {_L['Previous Error'], function() - textadept.run.goto_error(false, false) - end}, + {_L['Next Error'], function() textadept.run.goto_error(true) end}, + {_L['Previous Error'], function() textadept.run.goto_error(false) end}, SEPARATOR, { title = _L['Bookmarks'], diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 561d873a..13932d1a 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -355,14 +355,16 @@ local function is_msg_buf(buf) return buf._type == _L['[Message Buffer]'] end -- If *line_num* is `nil`, jumps to the next or previous warning or error, -- depending on boolean *next*. Displays an annotation with the warning or error -- message if possible. --- @param line_num The line number in the message buffer that contains the --- compile/run warning or error to go to. +-- @param line_num Optional line number in the message buffer that contains the +-- compile/run warning or error to go to. This parameter may be omitted +-- completely. -- @param next Optional flag indicating whether to go to the next recognized -- warning/error or the previous one. Only applicable when *line_num* is -- `nil`. -- @see error_patterns -- @name goto_error function M.goto_error(line_num, next) + if type(line_num) == 'boolean' then line_num, next = nil, line_num end local msg_view, msg_buf = nil, nil for i = 1, #_VIEWS do if is_msg_buf(_VIEWS[i].buffer) then msg_view = _VIEWS[i] break end diff --git a/test/test.lua b/test/test.lua index 6555b1a2..8ae24678 100644 --- a/test/test.lua +++ b/test/test.lua @@ -2072,7 +2072,7 @@ function test_ui_find_find_in_files() assert_equal(buffer:text_range(s, e), 'foo') s = buffer:indicator_end(ui.find.INDIC_FIND, e + 1) end - ui.find.goto_file_found(nil, true) -- wraps around + ui.find.goto_file_found(true) -- wraps around assert_equal(#_VIEWS, 2) assert(buffer.filename, 'not in file found result') ui.goto_view(1) @@ -2094,7 +2094,6 @@ function test_ui_find_find_in_files() assert(buffer.filename and buffer.filename ~= filename, 'opened the same file') buffer:close() ui.goto_view(1) -- files found buffer - assert_raises(function() ui.find.goto_file_found(true) end, 'number/nil expected, got boolean') ui.find.find_entry_text = '' view:unsplit() buffer:close() @@ -2350,7 +2349,7 @@ function test_run_compile_run() assert(buffer:get_text():find("'end' expected"), 'no compile error') assert(buffer:get_text():find('> exit status: 256'), 'no compile error') if #_VIEWS > 1 then view:unsplit() end - textadept.run.goto_error(nil, true) -- wraps + textadept.run.goto_error(true) -- wraps assert_equal(#_VIEWS, 2) assert_equal(buffer.filename, compile_file) assert_equal(buffer:line_from_position(buffer.current_pos), LINE(3)) @@ -2380,7 +2379,7 @@ function test_run_compile_run() assert_equal(buffer._type, _L['[Message Buffer]']) ui.update() -- process output assert(buffer:get_text():find('attempt to call a nil value'), 'no run error') - textadept.run.goto_error(nil, false) + textadept.run.goto_error(false) assert_equal(buffer.filename, run_file) assert_equal(buffer:line_from_position(buffer.current_pos), LINE(2)) textadept.run.goto_error(nil, false) @@ -2389,12 +2388,11 @@ function test_run_compile_run() ui.goto_view(1) assert(buffer:marker_get(buffer:line_from_position(buffer.current_pos)) & 1 << textadept.run.MARK_WARNING - 1 > 0) ui.goto_view(-1) - textadept.run.goto_error(nil, false) + textadept.run.goto_error(false) assert_equal(buffer.filename, compile_file) if #_VIEWS > 1 then view:unsplit() end buffer:close() -- compile_file buffer:close() -- run_file - assert_raises(function() textadept.run.goto_error(true) end, 'number/nil expected, got boolean') buffer:close() -- message buffer assert_raises(function() textadept.run.compile({}) end, 'string/nil expected, got table') |