diff options
Diffstat (limited to 'modules/textadept')
-rw-r--r-- | modules/textadept/bookmarks.lua | 21 | ||||
-rw-r--r-- | modules/textadept/command_entry.lua | 4 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 55 | ||||
-rw-r--r-- | modules/textadept/file_types.lua | 4 | ||||
-rw-r--r-- | modules/textadept/find.lua | 45 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 6 | ||||
-rw-r--r-- | modules/textadept/run.lua | 23 | ||||
-rw-r--r-- | modules/textadept/session.lua | 6 | ||||
-rw-r--r-- | modules/textadept/snippets.lua | 11 |
9 files changed, 88 insertions, 87 deletions
diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index adf283c7..a065baff 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -16,7 +16,7 @@ M.MARK_BOOKMARK = _SCINTILLA.next_marker_number() -- @name toggle function M.toggle() local line = buffer:line_from_position(buffer.current_pos) - local has_mark = buffer:marker_get(line) & 1 << M.MARK_BOOKMARK > 0 + local has_mark = buffer:marker_get(line) & 1 << M.MARK_BOOKMARK - 1 > 0 local f = has_mark and buffer.marker_delete or buffer.marker_add f(buffer, line, M.MARK_BOOKMARK) end @@ -36,15 +36,15 @@ function M.clear() buffer:marker_delete_all(M.MARK_BOOKMARK) end -- prompting the user for a bookmarked line to go to. -- @name goto_mark function M.goto_mark(next) + local BOOKMARK_BIT = 1 << M.MARK_BOOKMARK - 1 if next ~= nil then local f = next and buffer.marker_next or buffer.marker_previous local current_line = buffer:line_from_position(buffer.current_pos) - local line = f( - buffer, current_line + (next and 1 or -1), 1 << M.MARK_BOOKMARK) + local line = f(buffer, current_line + (next and 1 or -1), BOOKMARK_BIT) if line == -1 then - line = f(buffer, (next and 0 or buffer.line_count), 1 << M.MARK_BOOKMARK) + line = f(buffer, (next and 1 or buffer.line_count), BOOKMARK_BIT) end - if line >= 0 then textadept.editing.goto_line(line) end + if line >= 1 then textadept.editing.goto_line(line) end return end local scan_this_buffer, utf8_list, buffers = true, {}, {} @@ -55,13 +55,12 @@ function M.goto_mark(next) local filename = buffer.filename or buffer._type or _L['Untitled'] if buffer.filename then filename = filename:iconv('UTF-8', _CHARSET) end local basename = buffer.filename and filename:match('[^/\\]+$') or filename - local line = buffer:marker_next(0, 1 << M.MARK_BOOKMARK) - while line >= 0 do + local line = buffer:marker_next(1, BOOKMARK_BIT) + while line >= 1 do utf8_list[#utf8_list + 1] = string.format( - '%s:%d: %s', basename, line + 1, - buffer:get_line(line):match('^[^\r\n]*')) + '%s:%d: %s', basename, line, buffer:get_line(line):match('^[^\r\n]*')) buffers[#buffers + 1] = buffer - line = buffer:marker_next(line + 1, 1 << M.MARK_BOOKMARK) + line = buffer:marker_next(line + 1, BOOKMARK_BIT) end ::continue:: end @@ -73,7 +72,7 @@ function M.goto_mark(next) } if button ~= 1 or not i then return end view:goto_buffer(buffers[i]) - textadept.editing.goto_line(utf8_list[i]:match('^[^:]+:(%d+):') - 1) + textadept.editing.goto_line(tonumber(utf8_list[i]:match('^[^:]+:(%d+):'))) end return M diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 8665e3fd..540c2510 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -216,7 +216,7 @@ function M.run(f, keys, lexer, height) M:set_text('') M.focus() M:set_lexer(lexer or 'text') - M.height = M:text_height(0) * (height or 1) + M.height = M:text_height(1) * (height or 1) _G.keys._command_entry, _G.keys.mode = keys, '_command_entry' end @@ -232,7 +232,7 @@ end -- it to show Lua documentation in the Lua command entry. events.connect(events.INITIALIZED, function() M.h_scroll_bar, M.v_scroll_bar = false, false - for i = 0, M.margins - 1 do M.margin_width_n[i] = 0 end + for i = 1, M.margins do M.margin_width_n[i] = 0 end M.call_tip_position = true for key, f in pairs(keys) do if f == textadept.editing.show_documentation then diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 3b45cee9..7c2551ac 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -130,7 +130,7 @@ end}) events.connect(events.CHAR_ADDED, function(code) if M.auto_pairs and M.auto_pairs[code] then buffer:begin_undo_action() - for i = 0, buffer.selections - 1 do + for i = 1, buffer.selections do local pos = buffer.selection_n_caret[i] buffer:set_target_range(pos, pos) buffer:replace_target(M.auto_pairs[code]) @@ -143,7 +143,7 @@ end) events.connect(events.KEYPRESS, function(code) if not M.auto_pairs or keys.KEYSYMS[code] ~= '\b' then return end buffer:begin_undo_action() - for i = 0, buffer.selections - 1 do + for i = 1, buffer.selections do local pos = buffer.selection_n_caret[i] local complement = M.auto_pairs[buffer.char_at[pos - 1]] if complement and buffer.char_at[pos] == string.byte(complement) then @@ -172,7 +172,7 @@ end) events.connect(events.KEYPRESS, function(code) if M.typeover_chars and M.typeover_chars[code] then local handled = false - for i = 0, buffer.selections - 1 do + for i = 1, buffer.selections do local s, e = buffer.selection_n_start[i], buffer.selection_n_end[i] if s == e and buffer.char_at[s] == code then buffer.selection_n_start[i], buffer.selection_n_end[i] = s + 1, s + 1 @@ -187,13 +187,13 @@ end) events.connect(events.CHAR_ADDED, function(code) if not M.auto_indent or code ~= string.byte('\n') then return end local line = buffer:line_from_position(buffer.current_pos) - if line > 0 and buffer:get_line(line - 1):find('^[\r\n]+$') and + if line > 1 and buffer:get_line(line - 1):find('^[\r\n]+$') and buffer:get_line(line):find('^[^\r\n]') then return -- do not auto-indent when pressing enter from start of previous line end local i = line - 1 - while i >= 0 and buffer:get_line(i):find('^[\r\n]+$') do i = i - 1 end - if i >= 0 then + while i >= 1 and buffer:get_line(i):find('^[\r\n]+$') do i = i - 1 end + if i >= 1 then buffer.line_indentation[line] = buffer.line_indentation[i] buffer:vc_home() end @@ -227,7 +227,7 @@ events.connect(events.FILE_BEFORE_SAVE, function() if not M.strip_trailing_spaces then return end buffer:begin_undo_action() -- Strip trailing whitespace. - for line = 0, buffer.line_count - 1 do + for line = 1, buffer.line_count do local s, e = buffer:position_from_line(line), buffer.line_end_position[line] local i, byte = e - 1, buffer.char_at[e - 1] while i >= s and (byte == 9 or byte == 32) do -- '\t' or ' ' @@ -236,7 +236,7 @@ events.connect(events.FILE_BEFORE_SAVE, function() if i < e - 1 then buffer:delete_range(i + 1, e - i - 1) end end -- Ensure final newline. - if buffer.char_at[buffer.length - 1] ~= 10 then buffer:append_text('\n') end + if buffer.char_at[buffer.length] ~= 10 then buffer:append_text('\n') end -- Convert non-consistent EOLs buffer:convert_eols(buffer.eol_mode) buffer:end_undo_action() @@ -275,8 +275,8 @@ function M.paste_reindent() -- higher indentation amount. However, if the preceding line is a fold header, -- indent by an extra level. local i = line - 1 - while i >= 0 and buffer:get_line(i):find('^[\r\n]+$') do i = i - 1 end - if i < 0 or buffer.line_indentation[i] < buffer.line_indentation[line] then + while i >= 1 and buffer:get_line(i):find('^[\r\n]+$') do i = i - 1 end + if i < 1 or buffer.line_indentation[i] < buffer.line_indentation[line] then i = line end local indentation = buffer:text_range( @@ -318,7 +318,7 @@ function M.block_comment() local anchor, pos = buffer.selection_start, buffer.selection_end local s, e = buffer:line_from_position(anchor), buffer:line_from_position(pos) local ignore_last_line = s ~= e and pos == buffer:position_from_line(e) - anchor, pos = buffer.line_end_position[s] - anchor, buffer.length - pos + anchor, pos = buffer.line_end_position[s] - anchor, buffer.length + 1 - pos local column = math.huge buffer:begin_undo_action() for line = s, not ignore_last_line and e or e - 1 do @@ -342,7 +342,7 @@ function M.block_comment() if line == e then pos = pos + #suffix * (uncomment and -1 or 1) end end buffer:end_undo_action() - anchor, pos = buffer.line_end_position[s] - anchor, buffer.length - pos + anchor, pos = buffer.line_end_position[s] - anchor, buffer.length + 1 - pos -- Keep the anchor and caret on the first line as necessary. local start_pos = buffer:position_from_line(s) anchor, pos = math.max(anchor, start_pos), math.max(pos, start_pos) @@ -363,13 +363,12 @@ function M.goto_line(line) } line = tonumber(value) if button ~= 1 or not line then return end - line = line - 1 end buffer:ensure_visible_enforce_policy(line) buffer:goto_line(line) end args.register( - '-l', '--line', 1, function(line) M.goto_line(line - 1) end, 'Go to line') + '-l', '--line', 1, function(line) M.goto_line(line) end, 'Go to line') --- -- Transposes characters intelligently. @@ -377,7 +376,7 @@ args.register( -- the caret. Otherwise, the characters to the left and right are. -- @name transpose_chars function M.transpose_chars() - if buffer.current_pos == 0 then return end + if buffer.current_pos == 1 then return end local pos = buffer.current_pos local line_end = buffer.line_end_position[buffer:line_from_position(pos)] if pos == line_end then pos = buffer:position_before(pos) end @@ -414,7 +413,7 @@ function M.enclose(left, right) assert_type(left, 'string', 1) assert_type(right, 'string', 2) buffer:begin_undo_action() - for i = 0, buffer.selections - 1 do + for i = 1, buffer.selections do local s, e = buffer.selection_n_start[i], buffer.selection_n_end[i] if s == e then s = buffer:word_start_position(s, true) @@ -447,7 +446,7 @@ function M.select_enclosed(left, right) s, e = buffer:search_prev(0, left), buffer:search_next(0, right) elseif M.auto_pairs then s = buffer.selection_start - while s >= 0 do + while s >= 1 do local match = M.auto_pairs[buffer.char_at[s]] if not match then goto continue end left, right = string.char(buffer.char_at[s]), match @@ -457,7 +456,7 @@ function M.select_enclosed(left, right) elseif M.brace_matches[buffer.char_at[s]] or buffer.style_at[s] == buffer.style_at[buffer.selection_start] then buffer.search_flags = 0 - buffer:set_target_range(s + 1, buffer.length) + buffer:set_target_range(s + 1, buffer.length + 1) if buffer:search_in_target(match) >= buffer.selection_end - 1 then e = buffer.target_end - 1 break @@ -467,7 +466,7 @@ function M.select_enclosed(left, right) s = s - 1 end end - if s >= 0 and e >= 0 then + if s >= 1 and e >= 1 then if s + #left == anchor and e == pos then s, e = s - #left, e + #right end buffer:set_sel(s + #left, e) end @@ -520,7 +519,7 @@ end -- @name convert_indentation function M.convert_indentation() buffer:begin_undo_action() - for line = 0, buffer.line_count - 1 do + for line = 1, buffer.line_count do local s = buffer:position_from_line(line) local indent = buffer.line_indentation[line] local e = buffer.line_indent_position[line] @@ -543,7 +542,7 @@ end -- Clears highlighted word indicators and markers. local function clear_highlighted_words() buffer.indicator_current = M.INDIC_HIGHLIGHT - buffer:indicator_clear_range(0, buffer.length) + buffer:indicator_clear_range(1, buffer.length) end events.connect(events.KEYPRESS, function(code) if keys.KEYSYMS[code] == 'esc' then clear_highlighted_words() end @@ -566,10 +565,10 @@ function M.highlight_word() local word = buffer:text_range(s, e) buffer.search_flags = buffer.FIND_WHOLEWORD + buffer.FIND_MATCHCASE buffer:target_whole_document() - while buffer:search_in_target(word) > -1 do + while buffer:search_in_target(word) ~= -1 do buffer:indicator_fill_range( buffer.target_start, buffer.target_end - buffer.target_start) - buffer:set_target_range(buffer.target_end, buffer.length) + buffer:set_target_range(buffer.target_end, buffer.length + 1) end end @@ -601,7 +600,7 @@ function M.filter_through(command) local i, j = buffer:line_from_position(s), buffer:line_from_position(e) if i < j then s = buffer:position_from_line(i) - if buffer.column[e] > 0 then e = buffer:position_from_line(j + 1) end + if buffer.column[e] > 1 then e = buffer:position_from_line(j + 1) end end buffer:set_target_range(s, e) end @@ -659,13 +658,13 @@ M.autocompleters.word = function() if buffer == _G.buffer or M.autocomplete_all_words then buffer.search_flags = buffer.FIND_WORDSTART + buffer.FIND_MATCHCASE buffer:target_whole_document() - while buffer:search_in_target(word_part) > -1 do + while buffer:search_in_target(word_part) ~= -1 do local e = buffer:word_end_position(buffer.target_end, true) local match = buffer:text_range(buffer.target_start, e) if #match > #word_part and not matches[match] then list[#list + 1], matches[match] = match, true end - buffer:set_target_range(e, buffer.length) + buffer:set_target_range(e, buffer.length + 1) end end end @@ -717,9 +716,9 @@ function M.show_documentation(pos, case_insensitive) end -- Search backwards for an open function call and show API documentation for -- that function as well. - while s > 0 and buffer.char_at[s] ~= 40 do s = s - 1 end -- '(' + while s > 1 and buffer.char_at[s] ~= 40 do s = s - 1 end -- '(' e = buffer:brace_match(s, 0) - if s > 0 and (e == -1 or e >= pos) then + if s > 1 and (e == -1 or e >= pos) then s, e = buffer:word_start_position(s - 1, true), s - 1 symbol = buffer:text_range(s, e + 1) goto lookup diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua index 21261093..2889734c 100644 --- a/modules/textadept/file_types.lua +++ b/modules/textadept/file_types.lua @@ -44,7 +44,7 @@ end -- @param buffer The buffer to detect the language of. -- @return lexer language or nil local function detect_language(buffer) - local line = buffer:get_line(0) + local line = buffer:get_line(1) -- Detect from first line. for patt, lexer in pairs(M.patterns) do if line:find(patt) then return lexer end @@ -71,7 +71,7 @@ local function set_lexer(buffer, lang) if package.searchpath(lang, package.path) then _M[lang] = require(lang) end if buffer ~= ui.command_entry then events.emit(events.LEXER_LOADED, lang) end local last_line = buffer.first_visible_line + buffer.lines_on_screen - buffer:colourise(0, buffer:position_from_line(last_line + 1)) -- refresh + buffer:colourise(1, buffer:position_from_line(last_line + 1)) -- refresh end -- Gives new buffers lexer-specific functions. diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 113a32bb..d15558fb 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -100,9 +100,9 @@ local find_text, found_text -- The "Find in Files" flag is unused by Scintilla, but used by Textadept. -- @return search flag bit-mask local function get_flags() - return (M.match_case and buffer.FIND_MATCHCASE or 0) + - (M.whole_word and buffer.FIND_WHOLEWORD or 0) + - (M.regex and buffer.FIND_REGEXP or 0) + (M.in_files and 1 << 31 or 0) + return (M.match_case and buffer.FIND_MATCHCASE or 0) | + (M.whole_word and buffer.FIND_WHOLEWORD or 0) | + (M.regex and buffer.FIND_REGEXP or 0) | (M.in_files and 1 << 31 or 0) end -- Finds and selects text in the current buffer. @@ -139,7 +139,7 @@ local function find(text, next, flags, no_wrap, wrapped) -- If nothing was found, wrap the search. if pos == -1 and not no_wrap then local anchor = buffer.anchor - buffer:goto_pos(next and 0 or buffer.length) + buffer:goto_pos(next and 1 or buffer.length + 1) events.emit(events.FIND_WRAPPED) pos = find(text, next, flags, true, true) if pos == -1 then @@ -171,7 +171,7 @@ local function find_incremental(text, next, anchor) if anchor then incremental_start = buffer:position_relative(orig_pos, next and 1 or -1) end - buffer:goto_pos(incremental_start or 0) + buffer:goto_pos(incremental_start or 1) -- Note: even though `events.FIND` does not support a flags parameter, the -- default handler has one, so make use of it. events.emit( @@ -213,8 +213,8 @@ M.find_incremental_keys = setmetatable({ M.find_incremental(ui.command_entry:get_text(), true, true) end, ['\b'] = function() - local e = ui.command_entry:position_before(ui.command_entry.length) - M.find_incremental(ui.command_entry:text_range(0, e), true) + local e = ui.command_entry:position_before(ui.command_entry.length + 1) + M.find_incremental(ui.command_entry:text_range(1, e), true) return false -- propagate end }, {__index = function(_, k) @@ -285,9 +285,9 @@ function M.find_in_files(dir, filter) f:close() local binary = nil -- determine lazily for performance reasons buffer:target_whole_document() - while buffer:search_in_target(text) > -1 do + while buffer:search_in_target(text) ~= -1 do found = true - if binary == nil then binary = buffer:text_range(0, 65536):find('\0') end + if binary == nil then binary = buffer:text_range(1, 65536):find('\0') end if binary then _G.buffer:append_text(string.format( '%s:1:%s\n', utf8_filenames[i], _L['Binary file matches.'])) @@ -296,17 +296,17 @@ function M.find_in_files(dir, filter) local line_num = buffer:line_from_position(buffer.target_start) local line = buffer:get_line(line_num) _G.buffer:append_text( - string.format('%s:%d:%s', utf8_filenames[i], line_num + 1, line)) - local pos = _G.buffer.length - #line + + string.format('%s:%d:%s', utf8_filenames[i], line_num, line)) + local pos = _G.buffer.length + 1 - #line + buffer.target_start - buffer:position_from_line(line_num) _G.buffer:indicator_fill_range( pos, buffer.target_end - buffer.target_start) if not line:find('\n$') then _G.buffer:append_text('\n') end - buffer:set_target_range(buffer.target_end, buffer.length) + buffer:set_target_range(buffer.target_end, buffer.length + 1) end buffer:clear_all() buffer:empty_undo_buffer() - _G.buffer:goto_pos(_G.buffer.length) -- [Files Found Buffer] + _G.buffer:goto_pos(_G.buffer.length + 1) -- [Files Found Buffer] i = i + 1 if i > #filenames then return nil end return i * 100 / #filenames, utf8_filenames[i] @@ -352,28 +352,28 @@ events.connect(events.REPLACE_ALL, function(ftext, rtext) buffer.indicator_current = INDIC_REPLACE buffer:indicator_fill_range(e, 1) end - local EOF = replace_in_sel and e == buffer.length -- no indicator at EOF + local EOF = replace_in_sel and e == buffer.length + 1 -- no indicator at EOF local f = not M.regex and buffer.replace_target or buffer.replace_target_re rtext = unescape(rtext) -- Perform the search and replace. buffer:begin_undo_action() buffer.search_flags = get_flags() - buffer:set_target_range(not replace_in_sel and 0 or s, buffer.length) + buffer:set_target_range(not replace_in_sel and 1 or s, buffer.length + 1) while buffer:search_in_target(ftext) ~= -1 and (not replace_in_sel or buffer.target_end <= buffer:indicator_end(INDIC_REPLACE, s) or EOF) do if buffer.target_start == buffer.target_end then break end -- prevent loops f(buffer, rtext) count = count + 1 - buffer:set_target_range(buffer.target_end, buffer.length) + buffer:set_target_range(buffer.target_end, buffer.length + 1) end buffer:end_undo_action() -- Restore any original selection and report the number of replacements made. if replace_in_sel then e = buffer:indicator_end(INDIC_REPLACE, s) - buffer:set_sel(s, e > 0 and e or buffer.length) - if e > 0 then buffer:indicator_clear_range(e, 1) end + buffer:set_sel(s, e > 1 and e or buffer.length + 1) + if e > 1 then buffer:indicator_clear_range(e, 1) end end ui.statusbar_text = string.format('%d %s', count, _L['replacement(s) made']) end) @@ -408,7 +408,7 @@ function M.goto_file_found(line_num, next) local f = next and buffer.search_next or buffer.search_prev local pos = f(buffer, buffer.FIND_REGEXP, '^.+:\\d+:.+$') if pos == -1 then - buffer:goto_line(next and 0 or buffer.line_count) + buffer:goto_line(next and 1 or buffer.line_count) buffer:search_anchor() pos = f(buffer, buffer.FIND_REGEXP, '^.+:\\d+:.+$') end @@ -422,9 +422,10 @@ function M.goto_file_found(line_num, next) local utf8_filename, pos utf8_filename, line_num, pos = line:match('^(.+):(%d+):()') if not utf8_filename then return end + line_num = tonumber(line_num) textadept.editing.select_line() pos = buffer.selection_start + pos - 1 -- absolute pos of result text on line - local s = buffer:indicator_end(M.INDIC_FIND, pos - 1) + local s = buffer:indicator_end(M.INDIC_FIND, buffer.selection_start) local e = buffer:indicator_end(M.INDIC_FIND, s + 1) if buffer:line_from_position(s) == buffer:line_from_position(pos) then s, e = s - pos, e - pos -- relative to line start @@ -432,8 +433,8 @@ function M.goto_file_found(line_num, next) s, e = 0, 0 -- binary file notice, or highlighting was somehow removed end ui.goto_file(utf8_filename:iconv(_CHARSET, 'UTF-8'), true, preferred_view) - textadept.editing.goto_line(line_num - 1) - if buffer:line_from_position(buffer.current_pos + s) == line_num - 1 then + textadept.editing.goto_line(line_num) + if buffer:line_from_position(buffer.current_pos + s) == line_num then buffer:set_sel(buffer.current_pos + e, buffer.current_pos + s) end end diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 153e25b9..a92c2498 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -306,7 +306,7 @@ local default_menubar = { end}, SEPARATOR, {_L['Select Lexer...'], textadept.file_types.select_lexer}, - {_L['Refresh Syntax Highlighting'], function() buffer:colourise(0, -1) end} + {_L['Refresh Syntax Highlighting'], function() buffer:colourise(1, -1) end} }, { title = _L['View'], @@ -318,10 +318,10 @@ local default_menubar = { {_L['Unsplit View'], function() view:unsplit() end}, {_L['Unsplit All Views'], function() while view:unsplit() do end end}, {_L['Grow View'], function() - if view.size then view.size = view.size + buffer:text_height(0) end + if view.size then view.size = view.size + buffer:text_height(1) end end}, {_L['Shrink View'], function() - if view.size then view.size = view.size - buffer:text_height(0) end + if view.size then view.size = view.size - buffer:text_height(1) end end}, SEPARATOR, {_L['Toggle Current Fold'], function() diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 91a2e672..6c9bef23 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -124,7 +124,7 @@ local function print_line(line, ext_or_lexer) if error then -- 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) + buffer.line_count - 1, error.warning and M.MARK_WARNING or M.MARK_ERROR) end end @@ -377,19 +377,20 @@ function M.goto_error(line_num, next) if not assert_type(line_num, 'number/nil', 1) and next ~= nil then local f = next and buffer.marker_next or buffer.marker_previous line_num = buffer:line_from_position(buffer.current_pos) + local WARN_BIT, ERROR_BIT = 1 << M.MARK_WARNING - 1, 1 << M.MARK_ERROR - 1 local wrapped = false ::retry:: - local wline = f(buffer, line_num + (next and 1 or -1), 1 << M.MARK_WARNING) - local eline = f(buffer, line_num + (next and 1 or -1), 1 << M.MARK_ERROR) + local wline = f(buffer, line_num + (next and 1 or -1), WARN_BIT) + local eline = f(buffer, line_num + (next and 1 or -1), ERROR_BIT) if wline == -1 and eline == -1 then - wline = f(buffer, next and 0 or buffer.line_count, 1 << M.MARK_WARNING) - eline = f(buffer, next and 0 or buffer.line_count, 1 << M.MARK_ERROR) + wline = f(buffer, next and 1 or buffer.line_count, WARN_BIT) + eline = f(buffer, next and 1 or buffer.line_count, ERROR_BIT) elseif wline == -1 or eline == -1 then if wline == -1 then wline = eline else eline = wline end end line_num = (next and math.min or math.max)(wline, eline) if line_num == -1 and not wrapped then - line_num = next and 0 or buffer.line_count + line_num = next and 1 or buffer.line_count wrapped = true goto retry end @@ -406,14 +407,14 @@ function M.goto_error(line_num, next) end local sloppy = not detail.filename:find(not WIN32 and '^/' or '^%a:[/\\]') ui.goto_file(detail.filename, true, preferred_view, sloppy) - textadept.editing.goto_line(detail.line - 1) + textadept.editing.goto_line(detail.line) if detail.column then - buffer:goto_pos(buffer:find_column(detail.line - 1, detail.column - 1)) + buffer:goto_pos(buffer:find_column(detail.line, detail.column)) end if detail.message then - buffer.annotation_text[detail.line - 1] = detail.message - -- Style number 8 is the error style. - if not detail.warning then buffer.annotation_style[detail.line - 1] = 8 end + buffer.annotation_text[detail.line] = detail.message + -- Style number 9 is the error style. + if not detail.warning then buffer.annotation_style[detail.line] = 9 end end end events.connect(events.KEYPRESS, function(code) diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index c0e611e5..b446ca54 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -168,11 +168,11 @@ function M.save(filename) top_line = current and buffer.first_visible_line or buffer._top_line, } local bookmarks = {} - local line = buffer:marker_next(0, 1 << textadept.bookmarks.MARK_BOOKMARK) + local BOOKMARK_BIT = 1 << textadept.bookmarks.MARK_BOOKMARK - 1 + local line = buffer:marker_next(1, BOOKMARK_BIT) while line ~= -1 do bookmarks[#bookmarks + 1] = line - line = buffer:marker_next( - line + 1, 1 << textadept.bookmarks.MARK_BOOKMARK) + line = buffer:marker_next(line + 1, BOOKMARK_BIT) end session.buffers[#session.buffers].bookmarks = bookmarks ::continue:: diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index 90617a2d..707ab7ca 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -233,9 +233,9 @@ local function new_snippet(text, trigger) -- snippet. Also account for the marker being at the beginning of the -- snippet. (If so, pos will point to the correct position.) local pos = buffer:indicator_end(INDIC_CURRENTPLACEHOLDER, self.start_pos) - if pos == 0 then pos = self.start_pos end + if pos == 1 then pos = self.start_pos end return buffer:indicator_all_on_for(pos) & - 1 << INDIC_CURRENTPLACEHOLDER > 0 and pos + 1 or pos + 1 << INDIC_CURRENTPLACEHOLDER - 1 > 0 and pos + 1 or pos else return snippet_mt[k] end @@ -455,7 +455,7 @@ snippet_mt = { buffer:add_selection(pos, pos + #text) goto redo -- indicator positions have changed end - buffer.main_selection = 0 + buffer.main_selection = 1 -- Update transforms. self:update_transforms() @@ -502,10 +502,11 @@ snippet_mt = { local snapshot = self.snapshots[self.index > 0 and self.index - 1 or #self.snapshots] local i = self.start_pos + local PLACEHOLDER_BIT = 1 << M.INDIC_PLACEHOLDER - 1 return function() local s = buffer:indicator_end(M.INDIC_PLACEHOLDER, i) - while s > 0 and s <= self.end_pos do - if buffer:indicator_all_on_for(i) & 1 << M.INDIC_PLACEHOLDER > 0 then + while s > 1 and s <= self.end_pos do + if buffer:indicator_all_on_for(i) & PLACEHOLDER_BIT > 0 then -- This next indicator comes directly after the previous one; adjust -- start and end positions to compensate. s, i = buffer:indicator_start(M.INDIC_PLACEHOLDER, i), s |