diff options
author | 2011-12-12 19:15:53 -0500 | |
---|---|---|
committer | 2011-12-12 19:15:53 -0500 | |
commit | 9f804f70df793dd2d50c0b14000ab83a6bc02b83 (patch) | |
tree | 12b826dc06b800d868854231d4db56d489697832 /modules/textadept | |
parent | 51bfd53e48d5310eb786069b758e0430129daf54 (diff) | |
download | textadept-9f804f70df793dd2d50c0b14000ab83a6bc02b83.tar.gz textadept-9f804f70df793dd2d50c0b14000ab83a6bc02b83.zip |
Remove 'module' and update LuaDoc comments appropriately.
Diffstat (limited to 'modules/textadept')
-rw-r--r-- | modules/textadept/adeptsense.lua | 64 | ||||
-rw-r--r-- | modules/textadept/bookmarks.lua | 38 | ||||
-rw-r--r-- | modules/textadept/command_entry.lua | 18 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 111 | ||||
-rw-r--r-- | modules/textadept/filter_through.lua | 10 | ||||
-rw-r--r-- | modules/textadept/find.lua | 86 | ||||
-rw-r--r-- | modules/textadept/init.lua | 30 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 74 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 33 | ||||
-rw-r--r-- | modules/textadept/mime_types.lua | 43 | ||||
-rw-r--r-- | modules/textadept/run.lua | 30 | ||||
-rw-r--r-- | modules/textadept/session.lua | 50 | ||||
-rw-r--r-- | modules/textadept/snapopen.lua | 30 | ||||
-rw-r--r-- | modules/textadept/snippets.lua | 27 |
14 files changed, 431 insertions, 213 deletions
diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua index 5be70959..b115bc58 100644 --- a/modules/textadept/adeptsense.lua +++ b/modules/textadept/adeptsense.lua @@ -1,8 +1,11 @@ -- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE. +local M = {} + +--[[ This comment is for LuaDoc. --- -- Language autocompletion support for the textadept module. -module('_m.textadept.adeptsense', package.seeall) +module('_m.textadept.adeptsense', package.seeall)]] -- Markdown: -- ## Overview @@ -324,8 +327,8 @@ module('_m.textadept.adeptsense', package.seeall) local senses = {} -FUNCTIONS = '/* XPM */\nstatic char *function[] = {\n/* columns rows colors chars-per-pixel */\n"16 16 5 1",\n" c #000000",\n". c #E0BC38",\n"X c #F0DC5C",\n"o c #FCFC80",\n"O c None",\n/* pixels */\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOO OOOO",\n"OOOOOOOOO oo OO",\n"OOOOOOOO ooooo O",\n"OOOOOOO ooooo. O",\n"OOOO O XXoo.. O",\n"OOO oo XXX... O",\n"OO ooooo XX.. OO",\n"O ooooo. X. OOO",\n"O XXoo.. O OOOO",\n"O XXX... OOOOOOO",\n"O XXX.. OOOOOOOO",\n"OO X. OOOOOOOOO",\n"OOOO OOOOOOOOOO"\n};' -FIELDS = '/* XPM */\nstatic char *field[] = {\n/* columns rows colors chars-per-pixel */\n"16 16 5 1",\n" c #000000",\n". c #8C748C",\n"X c #9C94A4",\n"o c #ACB4C0",\n"O c None",\n/* pixels */\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOO OOOOO",\n"OOOOOOOO oo OOO",\n"OOOOOOO ooooo OO",\n"OOOOOO ooooo. OO",\n"OOOOOO XXoo.. OO",\n"OOOOOO XXX... OO",\n"OOOOOO XXX.. OOO",\n"OOOOOOO X. OOOO",\n"OOOOOOOOO OOOOO",\n"OOOOOOOOOOOOOOOO"\n};' +M.FUNCTIONS = '/* XPM */\nstatic char *function[] = {\n/* columns rows colors chars-per-pixel */\n"16 16 5 1",\n" c #000000",\n". c #E0BC38",\n"X c #F0DC5C",\n"o c #FCFC80",\n"O c None",\n/* pixels */\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOO OOOO",\n"OOOOOOOOO oo OO",\n"OOOOOOOO ooooo O",\n"OOOOOOO ooooo. O",\n"OOOO O XXoo.. O",\n"OOO oo XXX... O",\n"OO ooooo XX.. OO",\n"O ooooo. X. OOO",\n"O XXoo.. O OOOO",\n"O XXX... OOOOOOO",\n"O XXX.. OOOOOOOO",\n"OO X. OOOOOOOOO",\n"OOOO OOOOOOOOOO"\n};' +M.FIELDS = '/* XPM */\nstatic char *field[] = {\n/* columns rows colors chars-per-pixel */\n"16 16 5 1",\n" c #000000",\n". c #8C748C",\n"X c #9C94A4",\n"o c #ACB4C0",\n"O c None",\n/* pixels */\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOOOOOOOOO",\n"OOOOOOOOO OOOOO",\n"OOOOOOOO oo OOO",\n"OOOOOOO ooooo OO",\n"OOOOOO ooooo. OO",\n"OOOOOO XXoo.. OO",\n"OOOOOO XXX... OO",\n"OOOOOO XXX.. OOO",\n"OOOOOOO X. OOOO",\n"OOOOOOOOO OOOOO",\n"OOOOOOOOOOOOOOOO"\n};' --- -- Returns a full symbol (if any) and current symbol part (if any) behind the @@ -333,7 +336,8 @@ FIELDS = '/* XPM */\nstatic char *field[] = {\n/* columns rows colors chars-per- -- For example: `buffer.cur` would return `'buffer'` and `'cur'`. -- @param sense The Adeptsense returned by `adeptsense.new()`. -- @return symbol or `''`, part or `''`. -function get_symbol(sense) +-- @name get_symbol +function M.get_symbol(sense) local line, p = buffer:get_cur_line() local sc, wc = sense.syntax.symbol_chars, sense.syntax.word_chars local patt = string.format('(%s-)[^%s%%s]+([%s]*)$', sc, wc, wc) @@ -352,7 +356,8 @@ end -- @param symbol The symbol to get the class of. -- @return class or `nil` -- @see syntax -function get_class(sense, symbol) +-- @name get_class +function M.get_class(sense, symbol) local buffer = buffer local self = sense.syntax.self local class_definition = sense.syntax.class_definition @@ -446,7 +451,8 @@ end -- @param only_functions If `true`, returns list of only functions; defaults to -- `false`. -- @return completion_list or `nil` -function get_completions(sense, symbol, only_fields, only_functions) +-- @name get_completions +function M.get_completions(sense, symbol, only_fields, only_functions) if only_fields and only_functions or not symbol then return nil end local compls = sense.completions local class = compls[symbol] and symbol or sense:get_class(symbol) @@ -502,14 +508,15 @@ end -- @return `true` on success or `false`. -- @see get_symbol -- @see get_completions -function complete(sense, only_fields, only_functions) +-- @name complete +function M.complete(sense, only_fields, only_functions) local buffer = buffer local symbol, part = sense:get_symbol() local completions = sense:get_completions(symbol, only_fields, only_functions) if not completions then return false end buffer:clear_registered_images() - buffer:register_image(1, FIELDS) - buffer:register_image(2, FUNCTIONS) + buffer:register_image(1, M.FIELDS) + buffer:register_image(2, M.FUNCTIONS) if not buffer.auto_c_choose_single or #completions ~= 1 then buffer:auto_c_show(#part, table.concat(completions, ' ')) else @@ -533,7 +540,8 @@ end -- @usage sense:add_trigger('.') -- @usage sense:add_trigger(':', false, true) -- only functions -- @usage sense:add_trigger('->') -function add_trigger(sense, c, only_fields, only_functions) +-- @name add_trigger +function M.add_trigger(sense, c, only_fields, only_functions) if #c > 2 then return end -- TODO: warn local c1, c2 = c:match('.$'):byte(), #c > 1 and c:sub(1, 1):byte() local i = events.connect(events.CHAR_ADDED, function(char) @@ -552,7 +560,8 @@ end -- @param sense The Adeptsense returned by `adeptsense.new()`. -- @param symbol The symbol to get apidocs for. -- @return apidoc_list or `nil` -function get_apidoc(sense, symbol) +-- @name get_apidoc +function M.get_apidoc(sense, symbol) if not symbol then return nil end local apidocs = { pos = 1 } local word_chars = sense.syntax.word_chars @@ -588,7 +597,8 @@ end -- @return `true` on success or `false`. -- @see get_symbol -- @see get_apidoc -function show_apidoc(sense) +-- @name show_apidoc +function M.show_apidoc(sense) local buffer = buffer local symbol local s, e = buffer.selection_start, buffer.selection_end @@ -637,7 +647,8 @@ end -- @param tag_file The path of the ctags file to load. -- @param nolocations If `true`, does not store the locations of the tags for -- use by `goto_ctag()`. Defaults to `false`. -function load_ctags(sense, tag_file, nolocations) +-- @name load_ctags +function M.load_ctags(sense, tag_file, nolocations) local ctags_kinds = sense.ctags_kinds local completions = sense.completions local locations = sense.locations @@ -713,7 +724,8 @@ end -- @param sense The Adeptsense returned by `adeptsense.new()`. -- @param k The ctag character kind (e.g. `'f'` for a Lua function). -- @param title The title for the filteredlist dialog. -function goto_ctag(sense, k, title) +-- @name goto_ctag +function M.goto_ctag(sense, k, title) if not sense.locations[k] then return end -- no ctags loaded local items = {} local kind = sense.ctags_kinds[k] @@ -754,14 +766,16 @@ end -- @param file_name The name of the file the tag belongs to. -- @param ex_cmd The `ex_cmd` returned by ctags. -- @param ext_fields The `ext_fields` returned by ctags. -function handle_ctag(sense, tag_name, file_name, ex_cmd, ext_fields) end +-- @name handle_ctag +function M.handle_ctag(sense, tag_name, file_name, ex_cmd, ext_fields) end --- -- Clears an Adeptsense. -- This is necessary for loading a new ctags file or completions from a -- different project. -- @param sense The Adeptsense returned by `adeptsense.new()`. -function clear(sense) +-- @name clear +function M.clear(sense) sense.inherited_classes = {} sense.completions = {} sense.locations = {} @@ -774,7 +788,8 @@ end -- This function should be replaced with your own if you have any persistant -- objects that need to be deleted. -- @param sense The Adeptsense returned by `adeptsense.new()`. -function handle_clear(sense) end +-- @name handle_clear +function M.handle_clear(sense) end --- -- Creates a new Adeptsense for the given lexer language. @@ -782,7 +797,8 @@ function handle_clear(sense) end -- @param lang The lexer language to create an Adeptsense for. -- @return adeptsense -- @usage local lua_sense = _m.textadept.adeptsense.new('lua') -function new(lang) +-- @name new +function M.new(lang) local sense = senses[lang] if sense then sense.ctags_kinds = nil @@ -894,8 +910,8 @@ syntax = { type_assignments = {} }, - super = setmetatable({}, { __index = _M }) - }, { __index = _M }) + super = setmetatable({}, { __index = M }) + }, { __index = M }) senses[lang] = sense return sense @@ -905,7 +921,8 @@ end -- Completes the symbol at the current position based on the current lexer's -- Adeptsense. -- This should be called by key commands and menus instead of `complete()`. -function complete_symbol() +-- @name complete_symbol +function M.complete_symbol() local m = _m[buffer:get_lexer()] if m and m.sense then m.sense:complete() end end @@ -914,7 +931,10 @@ end -- Shows API documentation for the symbol at the current position based on the -- current lexer's Adeptsense. -- This should be called by key commands and menus instead of `show_apidoc()`. -function show_documentation() +-- @name show_documentation +function M.show_documentation() local m = _m[buffer:get_lexer()] if m and m.sense then m.sense:show_apidoc() end end + +return M diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index 254b38a1..146dc157 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -2,9 +2,12 @@ local L = locale.localize +local M = {} + +--[[ This comment is for LuaDoc. --- -- Bookmarks for the textadept module. -module('_m.textadept.bookmarks', package.seeall) +module('_m.textadept.bookmarks', package.seeall)]] -- Markdown: -- ## Settings @@ -13,14 +16,15 @@ module('_m.textadept.bookmarks', package.seeall) -- `0xBBGGRR` format. -- settings -MARK_BOOKMARK_COLOR = 0xB3661A +M.MARK_BOOKMARK_COLOR = 0xB3661A -- end settings local MARK_BOOKMARK = _SCINTILLA.next_marker_number() --- -- Adds a bookmark to the current line. -function add() +-- @name add +function M.add() local buffer = buffer local line = buffer:line_from_position(buffer.current_pos) buffer:marker_add(line, MARK_BOOKMARK) @@ -28,7 +32,8 @@ end --- -- Clears the bookmark at the current line. -function remove() +-- @name remove +function M.remove() local buffer = buffer local line = buffer:line_from_position(buffer.current_pos) buffer:marker_delete(line, MARK_BOOKMARK) @@ -36,21 +41,26 @@ end --- -- Toggles a bookmark on the current line. -function toggle() +-- @name toggle +function M.toggle() local buffer = buffer local line = buffer:line_from_position(buffer.current_pos) local markers = buffer:marker_get(line) -- bit mask local bit = 2^MARK_BOOKMARK - if markers % (bit + bit) < bit then add() else remove() end + if markers % (bit + bit) < bit then M.add() else M.remove() end end --- -- Clears all bookmarks in the current buffer. -function clear() buffer:marker_delete_all(MARK_BOOKMARK) end +-- @name clear +function M.clear() + buffer:marker_delete_all(MARK_BOOKMARK) +end --- -- Goes to the next bookmark in the current buffer. -function goto_next() +-- @name goto_next +function M.goto_next() local buffer = buffer local current_line = buffer:line_from_position(buffer.current_pos) local line = buffer:marker_next(current_line + 1, 2^MARK_BOOKMARK) @@ -60,7 +70,8 @@ end --- -- Goes to the previous bookmark in the current buffer. -function goto_prev() +-- @name goto_prev +function M.goto_prev() local buffer = buffer local current_line = buffer:line_from_position(buffer.current_pos) local line = buffer:marker_previous(current_line - 1, 2^MARK_BOOKMARK) @@ -72,7 +83,8 @@ end --- -- Goes to selected bookmark from a filtered list. -function goto_bookmark() +-- @name goto_bookmark +function M.goto_bookmark() local buffer = buffer local markers, line = {}, buffer:marker_next(0, 2^MARK_BOOKMARK) if line == -1 then return end @@ -85,7 +97,9 @@ function goto_bookmark() if line then _m.textadept.editing.goto_line(line:match('^%d+')) end end -if buffer then buffer:marker_set_back(MARK_BOOKMARK, MARK_BOOKMARK_COLOR) end +if buffer then buffer:marker_set_back(MARK_BOOKMARK, M.MARK_BOOKMARK_COLOR) end events.connect(events.VIEW_NEW, function() - buffer:marker_set_back(MARK_BOOKMARK, MARK_BOOKMARK_COLOR) + buffer:marker_set_back(MARK_BOOKMARK, M.MARK_BOOKMARK_COLOR) end) + +return M diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 3590c2cb..3eb3c6a5 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -4,6 +4,16 @@ local L = locale.localize local events = events +--[[ This comment is for LuaDoc. +--- +-- Textadept's Command entry. +module('gui.command_entry')]] + +-- Markdown: +-- ## Fields +-- +-- * `entry_text` [string]: The text in the entry. + -- Environment for abbreviated commands. -- @class table -- @name env @@ -81,3 +91,11 @@ events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code) return true end end) + +-- The function below is a Lua C function. + +--- +-- Focuses the command entry. +-- @class function +-- @name focus +local focus diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index b6e8bf70..c62b7116 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -4,9 +4,12 @@ local L = locale.localize local events = events local K = keys.KEYSYMS +local M = {} + +--[[ This comment is for LuaDoc. --- -- Editing commands for the textadept module. -module('_m.textadept.editing', package.seeall) +module('_m.textadept.editing', package.seeall)]] -- Markdown: -- ## Settings @@ -28,13 +31,13 @@ module('_m.textadept.editing', package.seeall) -- word. The default value is `100`. -- settings -AUTOPAIR = true -HIGHLIGHT_BRACES = true -AUTOINDENT = true -STRIP_WHITESPACE_ON_SAVE = true -MARK_HIGHLIGHT_BACK = buffer and buffer.caret_line_back or 0xEEEEEE -INDIC_HIGHLIGHT_BACK = 0x4D99E6 -INDIC_HIGHLIGHT_ALPHA = 100 +M.AUTOPAIR = true +M.HIGHLIGHT_BRACES = true +M.AUTOINDENT = true +M.STRIP_WHITESPACE_ON_SAVE = true +M.MARK_HIGHLIGHT_BACK = buffer and buffer.caret_line_back or 0xEEEEEE +M.INDIC_HIGHLIGHT_BACK = 0x4D99E6 +M.INDIC_HIGHLIGHT_ALPHA = 100 -- end settings --- @@ -45,7 +48,7 @@ INDIC_HIGHLIGHT_ALPHA = 100 -- @class table -- @name comment_string -- @see block_comment -comment_string = {} +M.comment_string = {} --- -- Auto-matched characters. @@ -55,7 +58,7 @@ comment_string = {} -- @class table -- @name char_matches -- @usage _m.textadept.editing.char_matches.hypertext = { ..., [60] = '>' } -char_matches = { +M.char_matches = { [40] = ')', [91] = ']', [123] = '}', [39] = "'", [34] = '"' } @@ -67,7 +70,7 @@ char_matches = { -- @class table -- @name braces -- @usage _m.textadept.editing.braces.hypertext = { ..., [60] = 1, [62] = 1 } -braces = { -- () [] {} +M.braces = { -- () [] {} [40] = 1, [91] = 1, [123] = 1, [41] = 1, [93] = 1, [125] = 1, } @@ -80,33 +83,33 @@ local current_call_tip = {} -- Matches characters specified in char_matches. events.connect(events.CHAR_ADDED, function(c) - if not AUTOPAIR then return end + if not M.AUTOPAIR then return end local buffer = buffer - local match = (char_matches[buffer:get_lexer()] or char_matches)[c] + local match = (M.char_matches[buffer:get_lexer()] or M.char_matches)[c] if match and buffer.selections == 1 then buffer:insert_text(-1, match) end end) -- Removes matched chars on backspace. events.connect(events.KEYPRESS, function(code) - if not AUTOPAIR or K[code] ~= '\b' or buffer.selections ~= 1 then return end + if not M.AUTOPAIR or K[code] ~= '\b' or buffer.selections ~= 1 then return end local buffer = buffer local pos = buffer.current_pos local c = buffer.char_at[pos - 1] - local match = (char_matches[buffer:get_lexer()] or char_matches)[c] + local match = (M.char_matches[buffer:get_lexer()] or M.char_matches)[c] if match and buffer.char_at[pos] == string.byte(match) then buffer:clear() end end) -- Highlights matching braces. events.connect(events.UPDATE_UI, function() - if not HIGHLIGHT_BRACES then return end + if not M.HIGHLIGHT_BRACES then return end local buffer = buffer - local current_pos = buffer.current_pos - if (braces[buffer:get_lexer()] or braces)[buffer.char_at[current_pos]] then - local pos = buffer:brace_match(current_pos) - if pos ~= -1 then - buffer:brace_highlight(current_pos, pos) + local pos = buffer.current_pos + if (M.braces[buffer:get_lexer()] or M.braces)[buffer.char_at[pos]] then + local match = buffer:brace_match(pos) + if match ~= -1 then + buffer:brace_highlight(pos, match) else - buffer:brace_bad_light(current_pos) + buffer:brace_bad_light(pos) end else buffer:brace_bad_light(-1) @@ -115,7 +118,7 @@ end) -- Auto-indent on return. events.connect(events.CHAR_ADDED, function(char) - if not AUTOINDENT or char ~= 10 then return end + if not M.AUTOINDENT or char ~= 10 then return end local buffer = buffer local anchor, caret = buffer.anchor, buffer.current_pos local line = buffer:line_from_position(caret) @@ -157,7 +160,8 @@ end) --- -- Goes to a matching brace position, selecting the text inside if specified to. -- @param select If `true`, selects the text between matching braces. -function match_brace(select) +-- @name match_brace +function M.match_brace(select) local buffer = buffer local caret = buffer.current_pos local match_pos = buffer:brace_match(caret) @@ -175,7 +179,8 @@ end -- the document. -- @param word_chars String of chars considered to be part of words. -- @return `true` if there were completions to show; `false` otherwise. -function autocomplete_word(word_chars) +-- @name autocomplete_word +function M.autocomplete_word(word_chars) local buffer = buffer local caret, length = buffer.current_pos, buffer.length local completions, c_list = {}, {} @@ -220,10 +225,11 @@ end -- Block comments or uncomments code with a given comment string. -- @param comment The comment string inserted or removed from the beginning of -- each line in the selection. -function block_comment(comment) +-- @name block_comment +function M.block_comment(comment) local buffer = buffer if not comment then - comment = comment_string[buffer:get_lexer()] + comment = M.comment_string[buffer:get_lexer()] if not comment then return end end local anchor, caret = buffer.selection_start, buffer.selection_end @@ -251,7 +257,8 @@ end -- Goes to the requested line. -- @param line Optional line number to go to. If `nil`, the user is prompted for -- one. -function goto_line(line) +-- @name goto_line +function M.goto_line(line) if not line then line = tonumber(gui.dialog('standard-inputbox', '--title', L('Go To'), @@ -267,8 +274,9 @@ end -- Prepares the buffer for saving to a file. -- Strips trailing whitespace off of every line, ensures an ending newline, and -- converts non-consistent EOLs. -function prepare_for_save() - if not STRIP_WHITESPACE_ON_SAVE then return end +-- @name prepare_for_save +function M.prepare_for_save() + if not M.STRIP_WHITESPACE_ON_SAVE then return end local buffer = buffer buffer:begin_undo_action() -- Strip trailing whitespace. @@ -297,13 +305,14 @@ function prepare_for_save() buffer:convert_eo_ls(buffer.eol_mode) buffer:end_undo_action() end -events.connect(events.FILE_BEFORE_SAVE, prepare_for_save) +events.connect(events.FILE_BEFORE_SAVE, M.prepare_for_save) --- -- Selects the current word under the caret and if action indicates, deletes it. -- @param action Optional action to perform with selected word. If `delete`, it -- is deleted. -function current_word(action) +-- @name current_word +function M.current_word(action) local buffer = buffer buffer:set_sel(buffer:word_start_position(buffer.current_pos), buffer:word_end_position(buffer.current_pos)) @@ -314,7 +323,8 @@ end -- Transposes characters intelligently. -- If the caret is at the end of a line, the two characters before the caret are -- transposed. Otherwise, the characters to the left and right are. -function transpose_chars() +-- @name transpose_chars +function M.transpose_chars() local buffer = buffer local pos = buffer.current_pos if pos == buffer.length then return end @@ -328,7 +338,8 @@ end --- -- Joins the current line with the line below. -function join_lines() +-- @name join_lines +function M.join_lines() local buffer = buffer buffer:line_end() local line = buffer:line_from_position(buffer.current_pos) @@ -343,7 +354,8 @@ end -- enclosed. -- @param left The left part of the enclosure. -- @param right The right part of the enclosure. -function enclose(left, right) +-- @name enclose +function M.enclose(left, right) local buffer = buffer buffer:begin_undo_action() local txt = buffer:get_sel_text() @@ -359,7 +371,8 @@ end -- Selects text between a given pair of strings. -- @param left The left part of the enclosure. -- @param right The right part of the enclosure. -function select_enclosed(left, right) +-- @name select_enclosed +function M.select_enclosed(left, right) local buffer = buffer buffer:search_anchor() local s = buffer:search_prev(0, left) @@ -370,7 +383,8 @@ end --- -- Grows the selection by a character amount on either end. -- @param amount The amount to grow the selection on either end. -function grow_selection(amount) +-- @name grow_selection +function M.grow_selection(amount) local buffer = buffer local anchor, caret = buffer.anchor, buffer.current_pos if anchor < caret then @@ -382,7 +396,8 @@ end --- -- Selects the current line. -function select_line() +-- @name select_line +function M.select_line() buffer:home() buffer:line_end_extend() end @@ -390,7 +405,8 @@ end --- -- Selects the current paragraph. -- Paragraphs are delimited by two or more consecutive newlines. -function select_paragraph() +-- @name select_paragraph +function M.select_paragraph() buffer:para_up() buffer:para_down_extend() end @@ -402,7 +418,8 @@ end -- top and bottom of it are one indentation level lower, they are added to the -- selection. In all other cases, the behavior is the same as if no text is -- selected. -function select_indented_block() +-- @name select_indented_block +function M.select_indented_block() local buffer = buffer local s = buffer:line_from_position(buffer.selection_start) local e = buffer:line_from_position(buffer.selection_end) @@ -423,7 +440,8 @@ end --- -- Converts indentation between tabs and spaces. -function convert_indentation() +-- @name convert_indentation +function M.convert_indentation() local buffer = buffer local line_indentation = buffer.line_indentation local line_indent_position = buffer.line_indent_position @@ -463,7 +481,8 @@ end) --- -- Highlights all occurances of the word under the caret and adds markers to the -- lines they are on. -function highlight_word() +-- @name highlight_word +function M.highlight_word() clear_highlighted_words() local buffer = buffer local s, e = buffer.selection_start, buffer.selection_end @@ -490,10 +509,12 @@ end -- Sets view properties for highlighted word indicators and markers. local function set_highlight_properties() local buffer = buffer - buffer:marker_set_back(MARK_HIGHLIGHT, MARK_HIGHLIGHT_BACK) - buffer.indic_fore[INDIC_HIGHLIGHT] = INDIC_HIGHLIGHT_BACK + buffer:marker_set_back(MARK_HIGHLIGHT, M.MARK_HIGHLIGHT_BACK) + buffer.indic_fore[INDIC_HIGHLIGHT] = M.INDIC_HIGHLIGHT_BACK buffer.indic_style[INDIC_HIGHLIGHT] = _SCINTILLA.constants.INDIC_ROUNDBOX - buffer.indic_alpha[INDIC_HIGHLIGHT] = INDIC_HIGHLIGHT_ALPHA + buffer.indic_alpha[INDIC_HIGHLIGHT] = M.INDIC_HIGHLIGHT_ALPHA end if buffer then set_highlight_properties() end events.connect(events.VIEW_NEW, set_highlight_properties) + +return M diff --git a/modules/textadept/filter_through.lua b/modules/textadept/filter_through.lua index bb55f444..98c21945 100644 --- a/modules/textadept/filter_through.lua +++ b/modules/textadept/filter_through.lua @@ -3,9 +3,12 @@ local L = locale.localize local events = events +local M = {} + +--[[ This comment is for LuaDoc. --- -- Filter-Through for the textadept module. -module('_m.textadept.filter_through', package.seeall) +module('_m.textadept.filter_through', package.seeall)]] local cat = not WIN32 and 'cat' or 'type' local tmpfile = _USERHOME..'/.ft' @@ -22,7 +25,8 @@ local filter_through_active = false -- text is selected and spans a single line, only the selected text is used. (3) -- If no text is selected, the entire buffer is used. -- The input text is replaced with the standard output (stdout) of the command. -function filter_through() +-- @name filter_through +function M.filter_through() filter_through_active = true gui.command_entry.focus() end @@ -69,3 +73,5 @@ events.connect(events.COMMAND_ENTRY_COMMAND, function(text) return true end end, 1) -- place before command_entry.lua's handler (if necessary) + +return M diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index be54e3ae..c9146e7a 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -5,6 +5,41 @@ local events = events local find = gui.find local c = _SCINTILLA.constants +--[[ This comment is for LuaDoc. +--- +-- Textadept's integrated find/replace dialog. +module('gui.find')]] + +-- Markdown: +-- ## Fields +-- +-- * `find_entry_text` [string]: The text in the find entry. +-- * `replace_entry_text` [string]: The text in the replace entry. +-- * `match_case` [bool]: Searches are case-sensitive. +-- * `whole_word` [bool]: Only whole-word matches are allowed in searches. +-- * `lua` [bool]: The search text is interpreted as a Lua pattern. +-- * `in_files` [bool]: Search for the text in a list of files. +-- * `find_label_text` [string]: The text of the 'Find' label. This is primarily +-- used for localization. (Write-only) +-- * `replace_label_text` [string]: The text of the 'Replace' label. This is +-- primarily used for localization. (Write-only) +-- * `find_next_button_text` [string]: The text of the 'Find Next' button. This +-- is primarily used for localization. (Write-only) +-- * `find_prev_button_text` [string]: The text of the 'Find Prev' button. This +-- is primarily used for localization. (Write-only) +-- * `replace_button_text` [string]: The text of the 'Replace' button. This is +-- primarily used for localization. (Write-only) +-- * `replace_all_button_text` [string]: The text of the 'Replace All' button. +-- This is primarily used for localization. (Write-only) +-- * `match_case_label_text` [string]: The text of the 'Match case' label. This +-- is primarily used for localization. (Write-only) +-- * `whole_word_label_text` [string]: The text of the 'Whole word' label. This +-- is primarily used for localization. (Write-only) +-- * `lua_pattern_label_text` [string]: The text of the 'Lua pattern' label. +-- This is primarily used for localization. (Write-only) +-- * `in_files_label_text` [string]: The text of the 'In files' label. This is +-- primarily used for localization. (Write-only) + find.find_label_text = L('Find:') find.replace_label_text = L('Replace:') find.find_next_button_text = L('Find Next') @@ -28,7 +63,12 @@ local escapes = { ['\\r'] = '\r', ['\\t'] = '\t', ['\\v'] = '\v', ['\\\\'] = '\\' } --- LuaDoc is in core/.find.luadoc. +--- +-- Performs a find in files with the given directory. +-- Use the `gui.find` fields to set the text to find and option flags. +-- @param utf8_dir UTF-8 encoded directory name. If none is provided, the user +-- is prompted for one. +-- @name find_in_files function find.find_in_files(utf8_dir) if not utf8_dir then utf8_dir = gui.dialog('fileselect', @@ -166,7 +206,11 @@ local function find_incremental(text) find_(text, true, flags) end --- LuaDoc is in core/.find.luadoc. +--- +-- Begins an incremental find using the Lua command entry. +-- Lua command functionality will be unavailable until the search is finished +-- (pressing 'Escape' by default). +-- @name find_incremental function find.find_incremental() find.incremental = true find.incremental_start = buffer.current_pos @@ -316,7 +360,11 @@ local function goto_file(pos, line_num) end events.connect(events.DOUBLE_CLICK, goto_file) --- LuaDoc is in core/.find.luadoc. +--- +-- Goes to the next or previous file found relative to the file +-- on the current line. +-- @param next Flag indicating whether or not to go to the next file. +-- @name goto_file_in_list function find.goto_file_in_list(next) local orig_view = _VIEWS[view] for _, buffer in ipairs(_BUFFERS) do @@ -348,3 +396,35 @@ if buffer then buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end events.connect(events.VIEW_NEW, function() buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end) + +-- The functions below are Lua C functions. + +--- +-- Displays and focuses the find/replace dialog. +-- @class function +-- @name focus +local focus + +--- +-- Mimicks a press of the 'Find Next' button in the Find box. +-- @class function +-- @name find_next +local find_next + +--- +-- Mimicks a press of the 'Find Prev' button in the Find box. +-- @class function +-- @name find_prev +local find_prev + +--- +-- Mimicks a press of the 'Replace' button in the Find box. +-- @class function +-- @name replace +local replace + +--- +-- Mimicks a press of the 'Replace All' button in the Find box. +-- @class function +-- @name replace_all +local replace_all diff --git a/modules/textadept/init.lua b/modules/textadept/init.lua index 12b085c4..c5dc1ea9 100644 --- a/modules/textadept/init.lua +++ b/modules/textadept/init.lua @@ -1,22 +1,28 @@ -- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE. +local M = {} +_m.textadept = M + +--[[ This comment is for LuaDoc. --- -- The textadept module. -- It provides utilities for editing text in Textadept. -module('_m.textadept', package.seeall) +module('_m.textadept', package.seeall)]] -require 'textadept.adeptsense' -require 'textadept.bookmarks' +M.adeptsense = require 'textadept.adeptsense' +M.bookmarks = require 'textadept.bookmarks' require 'textadept.command_entry' -require 'textadept.editing' +M.editing = require 'textadept.editing' require 'textadept.find' -require 'textadept.filter_through' -require 'textadept.mime_types' -require 'textadept.run' -require 'textadept.session' -require 'textadept.snapopen' -require 'textadept.snippets' +M.filter_through = require 'textadept.filter_through' +M.mime_types = require 'textadept.mime_types' +M.run = require 'textadept.run' +M.session = require 'textadept.session' +M.snapopen = require 'textadept.snapopen' +M.snippets = require 'textadept.snippets' -- These need to be loaded last. -require 'textadept.keys' -require 'textadept.menu' +M.keys = require 'textadept.keys' +M.menu = require 'textadept.menu' + +return M diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 275a5616..ec9133f3 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -3,18 +3,21 @@ local L = locale.localize local gui = gui +local M = {} + +--[[ --- -- Defines key commands for Textadept. -- This set of key commands is pretty standard among other text editors. -- This module, should be 'require'ed last, but before _m.textadept.menu. -module('_m.textadept.keys', package.seeall) +module('_m.textadept.keys', package.seeall)]] local keys, _buffer, _view = keys, buffer, view local m_textadept, m_editing = _m.textadept, _m.textadept.editing local c, OSX = _SCINTILLA.constants, OSX -- Utility functions. -utils = { +M.utils = { enclose_as_xml_tags = function() m_editing.enclose('<', '>') local buffer = buffer @@ -78,7 +81,8 @@ utils = { if not p then error(L('Error loading webpage:')..url) end else cmd = string.format(OSX and 'open "file://%s"' or 'xdg-open "%s" &', url) - if os.execute(cmd) ~= 0 then error(L('Error loading webpage:')..url) end + local _, _, code = os.execute(cmd) + if code ~= 0 then error(L('Error loading webpage:')..url) end end end } @@ -175,7 +179,7 @@ keys[not OSX and 'cI' or 'mI'] = m_editing.select_indented_block -- Selection. keys[not OSX and 'cau' or 'cu'] = _buffer.upper_case keys[not OSX and 'caU' or 'cU'] = _buffer.lower_case -keys[not OSX and 'a<' or 'c<'] = utils.enclose_as_xml_tags +keys[not OSX and 'a<' or 'c<'] = M.utils.enclose_as_xml_tags keys[not OSX and 'a>' or 'c>'] = { m_editing.enclose, '<', ' />' } keys[not OSX and "a'" or "c'"] = { m_editing.enclose, "'", "'" } keys[not OSX and 'a"' or 'c"'] = { m_editing.enclose, '"', '"' } @@ -200,7 +204,7 @@ keys[not OSX and 'caR' or 'cR'] = gui.find.replace_all -- Replace is ar when find pane is focused. -- Replace All is aa when find pane is focused. keys[not OSX and 'caf' or 'cmf'] = gui.find.find_incremental -keys[not OSX and 'cF' or 'mF'] = utils.find_in_files +keys[not OSX and 'cF' or 'mF'] = M.utils.find_in_files -- Find in Files is ai when find pane is focused. keys[not OSX and 'cag' or 'cmg'] = { gui.find.goto_file_in_list, true } keys[not OSX and 'caG' or 'cmG'] = { gui.find.goto_file_in_list, false } @@ -208,7 +212,7 @@ keys[not OSX and 'cj' or 'mj'] = m_editing.goto_line -- Tools. keys[not OSX and 'ce' or 'me'] = gui.command_entry.focus -keys[not OSX and 'cE' or 'mE'] = utils.select_command +keys[not OSX and 'cE' or 'mE'] = M.utils.select_command keys[not OSX and 'cr' or 'mr'] = m_textadept.run.run keys[not OSX and 'cR' or 'mR'] = m_textadept.run.compile keys[not OSX and 'c|' or 'm|'] = m_textadept.filter_through.filter_through @@ -229,30 +233,30 @@ keys.af2 = m_textadept.bookmarks.goto_bookmark -- Snapopen. keys[not OSX and 'cu' or 'mu'] = { m_textadept.snapopen.open, _USERHOME } -- TODO: { m_textadept.snapopen.open, _HOME } -keys[not OSX and 'caO' or 'cmO'] = utils.snapopen_filedir -keys[not OSX and 'ci' or 'mi'] = utils.show_style +keys[not OSX and 'caO' or 'cmO'] = M.utils.snapopen_filedir +keys[not OSX and 'ci' or 'mi'] = M.utils.show_style -- Buffer. keys['c\t'] = { _view.goto_buffer, _view, 1, true } keys['cs\t'] = { _view.goto_buffer, _view, -1, true } keys[not OSX and 'cb' or 'mb'] = gui.switch_buffer -- Indentation. --- TODO: { utils.set_indentation, 2 } --- TODO: { utils.set_indentation, 3 } --- TODO: { utils.set_indentation, 4 } --- TODO: { utils.set_indentation, 8 } -keys[not OSX and 'caT' or 'cT'] = { utils.toggle_property, 'use_tabs' } +-- TODO: { M.utils.set_indentation, 2 } +-- TODO: { M.utils.set_indentation, 3 } +-- TODO: { M.utils.set_indentation, 4 } +-- TODO: { M.utils.set_indentation, 8 } +keys[not OSX and 'caT' or 'cT'] = { M.utils.toggle_property, 'use_tabs' } keys[not OSX and 'cai' or 'ci'] = m_editing.convert_indentation -- EOL Mode. --- TODO: { utils.set_eol_mode, c.SC_EOL_CRLF } --- TODO: { utils.set_eol_mode, c.SC_EOL_CR } --- TODO: { utils.set_eol_mode, c.SC_EOL_LF } +-- TODO: { M.utils.set_eol_mode, c.SC_EOL_CRLF } +-- TODO: { M.utils.set_eol_mode, c.SC_EOL_CR } +-- TODO: { M.utils.set_eol_mode, c.SC_EOL_LF } -- Encoding. --- TODO: { utils.set_encoding, 'UTF-8' } --- TODO: { utils.set_encoding, 'ASCII' } --- TODO: { utils.set_encoding, 'ISO-8859-1' } --- TODO: { utils.set_encoding, 'MacRoman' } --- TODO: { utils.set_encoding, 'UTF-16LE' } +-- TODO: { M.utils.set_encoding, 'UTF-8' } +-- TODO: { M.utils.set_encoding, 'ASCII' } +-- TODO: { M.utils.set_encoding, 'ISO-8859-1' } +-- TODO: { M.utils.set_encoding, 'MacRoman' } +-- TODO: { M.utils.set_encoding, 'UTF-16LE' } keys[not OSX and 'cL' or 'mL'] = m_textadept.mime_types.select_lexer keys.f5 = { _buffer.colourise, _buffer, 0, -1 } @@ -263,27 +267,27 @@ keys[not OSX and 'cas' or 'cs'] = { _view.split, _view } if not OSX then keys.cah = keys.cas end keys[not OSX and 'cav' or 'cv'] = { _view.split, _view, true } keys[not OSX and 'caw' or 'cw'] = { _view.unsplit, _view } -keys[not OSX and 'caW' or 'cW'] = utils.unsplit_all -keys[not OSX and 'ca+' or 'c+'] = { utils.grow, 10 } -keys[not OSX and 'ca=' or 'c='] = { utils.grow, 10 } -keys[not OSX and 'ca-' or 'c-'] = { utils.shrink, 10 } --- TODO: utils.toggle_current_fold -keys[not OSX and 'ca\n' or 'c\n'] = { utils.toggle_property, 'view_eol' } +keys[not OSX and 'caW' or 'cW'] = M.utils.unsplit_all +keys[not OSX and 'ca+' or 'c+'] = { M.utils.grow, 10 } +keys[not OSX and 'ca=' or 'c='] = { M.utils.grow, 10 } +keys[not OSX and 'ca-' or 'c-'] = { M.utils.shrink, 10 } +-- TODO: M.utils.toggle_current_fold +keys[not OSX and 'ca\n' or 'c\n'] = { M.utils.toggle_property, 'view_eol' } if not OSX then keys['ca\n\r'] = keys['ca\n'] end -keys[not OSX and 'ca\\' or 'c\\'] = { utils.toggle_property, 'wrap_mode' } +keys[not OSX and 'ca\\' or 'c\\'] = { M.utils.toggle_property, 'wrap_mode' } keys[not OSX and 'caI' or 'cI'] = - { utils.toggle_property, 'indentation_guides' } -keys[not OSX and 'caS' or 'cS'] = { utils.toggle_property, 'view_ws' } + { M.utils.toggle_property, 'indentation_guides' } +keys[not OSX and 'caS' or 'cS'] = { M.utils.toggle_property, 'view_ws' } keys[not OSX and 'caV' or 'cV'] = - { utils.toggle_property, 'virtual_space_options', c.SCVS_USERACCESSIBLE } + { M.utils.toggle_property, 'virtual_space_options', c.SCVS_USERACCESSIBLE } keys[not OSX and 'c=' or 'm='] = _buffer.zoom_in keys[not OSX and 'c-' or 'm-'] = _buffer.zoom_out -keys[not OSX and 'c0' or 'm0'] = utils.reset_zoom +keys[not OSX and 'c0' or 'm0'] = M.utils.reset_zoom keys[not OSX and 'cT' or 'mT'] = gui.select_theme -- Help. -keys.f1 = { utils.open_webpage, _HOME..'/doc/manual/1_Introduction.html' } -keys.sf1 = { utils.open_webpage, _HOME..'/doc/index.html' } +keys.f1 = { M.utils.open_webpage, _HOME..'/doc/manual/1_Introduction.html' } +keys.sf1 = { M.utils.open_webpage, _HOME..'/doc/index.html' } -- TODO: { gui.dialog, 'ok-msgbox', '--title', 'Textadept' -- '--informative-text', _RELEASE, '--no-cancel' } @@ -312,3 +316,5 @@ if OSX then keys.cd = _buffer.clear keys.cl = _buffer.vertical_centre_caret end + +return M diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 0ba21390..653437cf 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -4,11 +4,14 @@ local L = locale.localize local gui = gui +local M = {} + +--[[ This comment is for LuaDoc. --- -- Provides dynamic menus for Textadept. -- This module should be `require`ed last, after `_m.textadept.keys` since it -- looks up defined key commands to show them in menus. -module('_m.textadept.menu', package.seeall) +module('_m.textadept.menu', package.seeall)]] local _buffer, _view = buffer, view local m_textadept, m_editing = _m.textadept, _m.textadept.editing @@ -32,7 +35,7 @@ end -- Contains the main menubar. -- @class table -- @name menubar -menubar = { +M.menubar = { { title = L('File'), { L('gtk-new'), new_buffer }, { L('gtk-open'), io.open_file }, @@ -220,7 +223,7 @@ menubar = { -- Contains the default right-click context menu. -- @class table -- @name context_menu -context_menu = { +M.context_menu = { { L('gtk-undo'), _buffer.undo }, { L('gtk-redo'), _buffer.redo }, SEPARATOR, @@ -275,7 +278,8 @@ end -- for setting a menu accelerator. If the menu text is `'separator'`, a menu -- separator is created and no action table is required. -- @see keys.get_gdk_key -function set_menubar(menubar) +-- @name set_menubar +function M.set_menubar(menubar) key_shortcuts = {} for key, f in pairs(keys) do key_shortcuts[get_id(f)] = key end menu_actions = {} @@ -285,18 +289,19 @@ function set_menubar(menubar) end gui.menubar = _menubar end -set_menubar(menubar) +M.set_menubar(M.menubar) --- -- Sets `gui.context_menu` from the given menu table. -- @param menu_table The menu table to create the context menu from. Each table -- entry is either a submenu or menu text and a function or action table. -- @see set_menubar -function set_contextmenu(menu_table) +-- @name set_contextmenu +function M.set_contextmenu(menu_table) contextmenu_actions = {} gui.context_menu = gui.gtkmenu(read_menu_table(menu_table, true)) end -set_contextmenu(context_menu) +M.set_contextmenu(M.context_menu) local items, commands @@ -322,7 +327,8 @@ end local columns = { L('Command'), L('Key Command') } --- -- Prompts the user with a filteredlist to run menu commands. -function select_command() +-- @name select_command +function M.select_command() local i = gui.filteredlist(L('Run Command'), columns, items, true) if i then keys.run_command(commands[i + 1], type(commands[i + 1])) end end @@ -330,11 +336,12 @@ end --- -- Rebuilds the tables used by `select_command()`. -- This should be called every time `set_menubar()` is called. -function rebuild_command_tables() +-- @name rebuild_command_tables +function M.rebuild_command_tables() items, commands = {}, {} - build_command_tables(menubar, nil, items, commands) + build_command_tables(M.menubar, nil, items, commands) end -rebuild_command_tables() +M.rebuild_command_tables() events.connect(events.MENU_CLICKED, function(menu_id) local actions = menu_id < 1000 and menu_actions or contextmenu_actions @@ -348,9 +355,11 @@ end) -- Set a language-specific context menu or the default one. local function set_language_contextmenu() local lang = buffer:get_lexer() - set_contextmenu(_m[lang] and _m[lang].context_menu or context_menu) + M.set_contextmenu(_m[lang] and _m[lang].context_menu or M.context_menu) end events.connect(events.LANGUAGE_MODULE_LOADED, set_language_contextmenu) events.connect(events.BUFFER_AFTER_SWITCH, set_language_contextmenu) events.connect(events.VIEW_AFTER_SWITCH, set_language_contextmenu) events.connect(events.BUFFER_NEW, set_lang_contextmenu) + +return M diff --git a/modules/textadept/mime_types.lua b/modules/textadept/mime_types.lua index 51b60636..8a11be5d 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -3,9 +3,12 @@ local L = locale.localize local events = events +local M = {} + +--[[ This comment is for LuaDoc. --- -- Handles file-specific settings. -module('_m.textadept.mime_types', package.seeall) +module('_m.textadept.mime_types', package.seeall)]] -- Markdown: -- ## Overview @@ -36,19 +39,19 @@ events.LANGUAGE_MODULE_LOADED = 'language_module_loaded' -- File extensions with their associated lexers. -- @class table -- @name extensions -extensions = {} +M.extensions = {} --- -- Shebang words and their associated lexers. -- @class table -- @name shebangs -shebangs = {} +M.shebangs = {} --- -- First-line patterns and their associated lexers. -- @class table -- @name patterns -patterns = {} +M.patterns = {} -- Load mime-types from `modules/textadept/mime_types.conf`. local mime_types @@ -66,11 +69,11 @@ for line in mime_types:gmatch('[^\r\n]+') do if not line:find('^%s*%%') then if line:find('^%s*[^#/]') then -- extension definition local ext, lexer_name = line:match('^%s*(.+)%s+(%S+)$') - if ext and lexer_name then extensions[ext] = lexer_name end + if ext and lexer_name then M.extensions[ext] = lexer_name end else -- shebang or pattern local ch, text, lexer_name = line:match('^%s*([#/])(.+)%s+(%S+)$') if ch and text and lexer_name then - (ch == '#' and shebangs or patterns)[text] = lexer_name + (ch == '#' and M.shebangs or M.patterns)[text] = lexer_name end end end @@ -81,7 +84,7 @@ end -- Lexers are read from `lexers/` and `~/.textadept/lexers/`. -- @class table -- @name lexers -lexers = {} +M.lexers = {} -- Generate lexer list local lexers_found = {} @@ -97,14 +100,15 @@ if lfs.attributes(_USERHOME..'/lexers') then end end end -for lexer in pairs(lexers_found) do lexers[#lexers + 1] = lexer end -table.sort(lexers) +for lexer in pairs(lexers_found) do M.lexers[#M.lexers + 1] = lexer end +table.sort(M.lexers) --- -- Prompts the user to select a lexer from a filtered list for the current -- buffer. -function select_lexer() - local lexer = gui.filteredlist(L('Select Lexer'), 'Name', lexers) +-- @name select_lexer +function M.select_lexer() + local lexer = gui.filteredlist(L('Select Lexer'), 'Name', M.lexers) if lexer then buffer:set_lexer(lexer) end end @@ -129,14 +133,13 @@ local function set_lexer(buffer, lang) buffer._lexer = lang buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer) buffer:private_lexer_call(SETLEXERLANGUAGE, lang) - local ok, err = pcall(require, lang) - if ok then - ok, err = pcall(require, lang..'.post_init') + if package.searchpath(lang, package.path) then + _m[lang] = require(lang) + local post_init = lang..'.post_init' + if package.searchpath(post_init, package.path) then require(post_init) end _m[lang].set_buffer_properties() events.emit(events.LANGUAGE_MODULE_LOADED, lang) end - local module_not_found = "^module '"..lang.."[^\']*' not found:" - if not ok and not err:find(module_not_found) then error(err) end buffer:colourise(0, -1) -- Create the ws_styles[lexer] lookup table for `get_lexer()`. if ws_styles[lang] then return end @@ -175,17 +178,17 @@ local function handle_new() local line = buffer:get_line(0) if line:find('^#!') then for word in line:gsub('[/\\]', ' '):gmatch('%S+') do - lexer = shebangs[word] + lexer = M.shebangs[word] if lexer then break end end end if not lexer then - for patt, lex in pairs(patterns) do + for patt, lex in pairs(M.patterns) do if line:find(patt) then lexer = lex break end end end if not lexer and buffer.filename then - lexer = extensions[buffer.filename:match('[^/\\.]+$')] + lexer = M.extensions[buffer.filename:match('[^/\\.]+$')] end buffer:set_lexer(lexer or 'container') end @@ -203,3 +206,5 @@ events.connect(events.VIEW_NEW, restore_lexer, 1) events.connect(events.RESET_AFTER, function() buffer:set_lexer(buffer._lexer or 'container') end) + +return M diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 8e1561f3..7267b486 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -3,12 +3,15 @@ local L = locale.localize local events = events +local M = {} + +--[[ This comment is for LuaDoc. --- -- Module for running/executing source files. -- Typically, language-specific modules populate the 'compile_command', -- 'run_command', and 'error_detail' tables for a particular language's file -- extension. -module('_m.textadept.run', package.seeall) +module('_m.textadept.run', package.seeall)]] -- Markdown: -- ## Run Events @@ -40,7 +43,8 @@ events.RUN_OUTPUT = 'run_output' -- + `%(filedir)`: The current file's directory path. -- + `%(filename)`: The name of the file including extension. -- + `%(filename_noext)`: The name of the file excluding extension. -function execute(command) +-- @name execute +function M.execute(command) local filepath = buffer.filename:iconv(_CHARSET, 'UTF-8') local filedir, filename = '', filepath if filepath:find('[/\\]') then @@ -69,7 +73,7 @@ local function command(cmd_table) buffer:save() local action = cmd_table[buffer.filename:match('[^.]+$')] if not action then return end - return execute(type(action) == 'function' and action() or action) + return M.execute(type(action) == 'function' and action() or action) end --- @@ -79,15 +83,16 @@ end -- This table is typically populated by language-specific modules. -- @class table -- @name compile_command -compile_command = {} +M.compile_command = {} --- -- Compiles the file as specified by its extension in the `compile_command` -- table. -- @see compile_command -function compile() +-- @name compile +function M.compile() events.emit(events.COMPILE_OUTPUT, buffer:get_lexer(), - command(compile_command)) + command(M.compile_command)) end events.connect(events.COMPILE_OUTPUT, function(lexer, output) gui.print(output) end) @@ -99,14 +104,15 @@ events.connect(events.COMPILE_OUTPUT, -- This table is typically populated by language-specific modules. -- @class table -- @name run_command -run_command = {} +M.run_command = {} --- -- Runs/executes the file as specified by its extension in the `run_command` -- table. -- @see run_command -function run() - events.emit(events.RUN_OUTPUT, buffer:get_lexer(), command(run_command)) +-- @name run +function M.run() + events.emit(events.RUN_OUTPUT, buffer:get_lexer(), command(M.run_command)) end events.connect(events.RUN_OUTPUT, function(lexer, output) gui.print(output) end) @@ -126,7 +132,7 @@ events.connect(events.RUN_OUTPUT, -- This table is usually populated by language-specific modules. -- @class table -- @name error_detail -error_detail = {} +M.error_detail = {} --- -- When the user double-clicks an error message, go to the line in the file @@ -141,7 +147,7 @@ function goto_error(pos, line_num) end local buffer = buffer line = buffer:get_line(line_num) - for _, error_detail in pairs(error_detail) do + 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] @@ -159,3 +165,5 @@ function goto_error(pos, line_num) end end events.connect(events.DOUBLE_CLICK, goto_error) + +return M diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index 00d73b56..0bab1b40 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -2,9 +2,12 @@ local L = locale.localize +local M = {} + +--[[ This comment is for LuaDoc. --- -- Session support for the textadept module. -module('_m.textadept.session', package.seeall) +module('_m.textadept.session', package.seeall)]] -- Markdown: -- ## Settings @@ -17,9 +20,9 @@ module('_m.textadept.session', package.seeall) -- files list to save to the session. The default is `10`. -- settings -DEFAULT_SESSION = _USERHOME..'/session' -SAVE_ON_QUIT = true -MAX_RECENT_FILES = 10 +M.DEFAULT_SESSION = _USERHOME..'/session' +M.SAVE_ON_QUIT = true +M.MAX_RECENT_FILES = 10 -- end settings --- @@ -30,9 +33,10 @@ MAX_RECENT_FILES = 10 -- `DEFAULT_SESSION` if not specified. -- @return `true` if the session file was opened and read; `false` otherwise. -- @usage _m.textadept.session.load(filename) -function load(filename) +-- @name load +function M.load(filename) local not_found = {} - local f = io.open(filename or DEFAULT_SESSION, 'rb') + local f = io.open(filename or M.DEFAULT_SESSION, 'rb') if not f then io.close_all() return false end local current_view, splits = 1, { [0] = {} } local lfs_attributes = lfs.attributes @@ -97,7 +101,7 @@ function load(filename) return true end -- Load session when no args are present. -events.connect('arg_none', function() if SAVE_ON_QUIT then load() end end) +events.connect('arg_none', function() if M.SAVE_ON_QUIT then M.load() end end) --- -- Saves a Textadept session to a file. @@ -106,7 +110,8 @@ events.connect('arg_none', function() if SAVE_ON_QUIT then load() end end) -- @param filename The absolute path to the session file to save. Defaults to -- either the current session file or `DEFAULT_SESSION` if not specified. -- @usage _m.textadept.session.save(filename) -function save(filename) +-- @name save +function M.save(filename) local session = {} local buffer_line = "buffer: %d %d %d %s" -- anchor, cursor, line, filename local split_line = "%ssplit%d: %s %d" -- level, number, type, size @@ -155,11 +160,11 @@ function save(filename) local size = gui.size session[#session + 1] = ("size: %d %d"):format(size[1], size[2]) for i, filename in ipairs(io.recent_files) do - if i > MAX_RECENT_FILES then break end + if i > M.MAX_RECENT_FILES then break end session[#session + 1] = ("recent: %s"):format(filename) end -- Write the session. - local f = io.open(filename or DEFAULT_SESSION, 'wb') + local f = io.open(filename or M.DEFAULT_SESSION, 'wb') if f then f:write(table.concat(session, '\n')) f:close() @@ -168,31 +173,36 @@ end --- -- Prompts the user for a Textadept session to load. -function prompt_load() +-- @name prompt_load +function M.prompt_load() local utf8_filename = gui.dialog('fileselect', '--title', L('Load Session'), '--with-directory', - DEFAULT_SESSION:match('.+[/\\]') or '', + M.DEFAULT_SESSION:match('.+[/\\]') or '', '--with-file', - DEFAULT_SESSION:match('[^/\\]+$') or '', + M.DEFAULT_SESSION:match('[^/\\]+$') or '', '--no-newline') - if #utf8_filename > 0 then load(utf8_filename:iconv(_CHARSET, 'UTF-8')) end + if #utf8_filename > 0 then M.load(utf8_filename:iconv(_CHARSET, 'UTF-8')) end end --- -- Prompts the user to save the current Textadept session to a file. -function prompt_save() +-- @name prompt_save +function M.prompt_save() local utf8_filename = gui.dialog('filesave', '--title', L('Save Session'), '--with-directory', - DEFAULT_SESSION:match('.+[/\\]') or '', + M.DEFAULT_SESSION:match('.+[/\\]') or '', '--with-file', - DEFAULT_SESSION:match('[^/\\]+$') or '', + M.DEFAULT_SESSION:match('[^/\\]+$') or '', '--no-newline') - if #utf8_filename > 0 then save(utf8_filename:iconv(_CHARSET, 'UTF-8')) end + if #utf8_filename > 0 then M.save(utf8_filename:iconv(_CHARSET, 'UTF-8')) end end -events.connect(events.QUIT, function() if SAVE_ON_QUIT then save() end end, 1) +events.connect(events.QUIT, + function() if M.SAVE_ON_QUIT then M.save() end end, 1) -local function no_session() SAVE_ON_QUIT = false end +local function no_session() M.SAVE_ON_QUIT = false end args.register('-n', '--nosession', 0, no_session, 'No session functionality') + +return M diff --git a/modules/textadept/snapopen.lua b/modules/textadept/snapopen.lua index f06d9260..3d295730 100644 --- a/modules/textadept/snapopen.lua +++ b/modules/textadept/snapopen.lua @@ -2,9 +2,12 @@ local L = locale.localize +local M = {} + +--[[ This comment is for LuaDoc. --- -- Snapopen for the textadept module. -module('_m.textadept.snapopen', package.seeall) +module('_m.textadept.snapopen', package.seeall)]] -- Markdown: -- ## Settings @@ -33,13 +36,13 @@ module('_m.textadept.snapopen', package.seeall) -- snapopen(project_dir, { folders = { '%.hg' } }, true) -- settings -PATHS = {} -DEFAULT_DEPTH = 4 -MAX = 1000 +M.PATHS = {} +M.DEFAULT_DEPTH = 4 +M.MAX = 1000 -- end settings local lfs_dir, lfs_attributes = lfs.dir, lfs.attributes -local DEPTH = DEFAULT_DEPTH +local DEPTH = M.DEFAULT_DEPTH -- Determines whether or not the given file matches the given filter. -- @param file The filename. @@ -66,7 +69,7 @@ end -- @param depth The current depth of nested folders. -- @param filter The filter table. local function add_directory(utf8_dir, list, depth, filter) - local string_match, string_gsub, MAX = string.match, string.gsub, MAX + local string_match, string_gsub, MAX = string.match, string.gsub, M.MAX local dir = utf8_dir:iconv(_CHARSET, 'UTF-8') for file in lfs_dir(dir) do if not string_match(file, '^%.%.?$') then @@ -101,26 +104,29 @@ end -- @usage _m.textadept.snapopen.open(buffer.filename:match('^.+/'), nil, true) -- @usage _m.textadept.snapopen.open(nil, '!%.lua$') -- @usage _m.textadept.snapopen.open(nil, { folders = { '%.hg' } }) -function open(utf8_paths, filter, exclusive, depth) +-- @name open +function M.open(utf8_paths, filter, exclusive, depth) if not utf8_paths then utf8_paths = {} end if type(utf8_paths) == 'string' then utf8_paths = { utf8_paths } end if not filter then filter = {} end if type(filter) == 'string' then filter = { filter } end if not exclusive then - for _, path in ipairs(PATHS) do utf8_paths[#utf8_paths + 1] = path end + for _, path in ipairs(M.PATHS) do utf8_paths[#utf8_paths + 1] = path end end - DEPTH = depth or DEFAULT_DEPTH + DEPTH = depth or M.DEFAULT_DEPTH local list = {} for _, path in ipairs(utf8_paths) do add_directory(path, list, 1, filter) end - if #list >= MAX then + if #list >= M.MAX then gui.dialog('ok-msgbox', '--title', L('File Limit Exceeded'), '--informative-text', - string.format('%d %s %d', MAX, + string.format('%d %s %d', M.MAX, L('files or more were found. Showing the first'), - MAX)) + M.MAX)) end local utf8_filenames = gui.filteredlist(L('Open'), L('File'), list, false, '--select-multiple') or '' for filename in utf8_filenames:gmatch('[^\n]+') do io.open_file(filename) end end + +return M diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index 8e849ece..883b0fcf 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -2,9 +2,12 @@ local L = locale.localize +local M = {} + +--[[ This comment is for LuaDoc. --- -- Provides Lua-style snippets for Textadept. -module('_m.textadept.snippets', package.seeall) +module('_m.textadept.snippets', package.seeall)]] -- Markdown: -- ## Overview @@ -137,7 +140,7 @@ local function new_snippet(text, trigger) trigger = trigger, original_sel_text = buffer:get_sel_text(), snapshots = {} - }, { __index = _snippet_mt }) + }, { __index = M._snippet_mt }) snippet_stack[#snippet_stack + 1] = snippet -- Convert and match indentation. @@ -175,7 +178,8 @@ end -- @param text Optional snippet text. If none is specified, the snippet text -- is determined from the trigger and lexer. -- @return `false` if no snippet was expanded; `true` otherwise. -function _insert(text) +-- @name _insert +function M._insert(text) local buffer = buffer local trigger if not text then @@ -197,7 +201,8 @@ end -- Goes back to the previous placeholder, reverting any changes from the current -- one. -- @return `false` if no snippet is active; `nil` otherwise. -function _previous() +-- @name _previous +function M._previous() if #snippet_stack == 0 then return false end snippet_stack[#snippet_stack]:previous() end @@ -205,14 +210,16 @@ end --- -- Cancels the active snippet, reverting to the state before its activation, and -- restores the previously running snippet (if any). -function _cancel_current() +-- @name _cancel_current +function M._cancel_current() if #snippet_stack > 0 then snippet_stack[#snippet_stack]:cancel() end end --- -- Prompts the user to select a snippet to insert from a filtered list dialog. -- Global snippets and snippets in the current lexer are shown. -function _select() +-- @name _select +function M._select() local list = {} local type = type for trigger, text in pairs(snippets) do @@ -235,7 +242,7 @@ function _select() local i = gui.filteredlist(L('Select Snippet'), { L('Trigger'), L('Scope'), L('Snippet Text') }, t, true, '--output-column', '2') - if i then _insert(t[(i + 1) * 3]) end + if i then M._insert(t[(i + 1) * 3]) end end -- Table of escape sequences. @@ -252,7 +259,7 @@ local escapes = { -- Metatable for a snippet object. -- @class table -- @name _snippet_mt -_snippet_mt = { +M._snippet_mt = { -- Gets a snippet's end position in the buffer. -- @param snippet The snippet returned by `new_snippet()`. get_end_position = function(snippet) @@ -427,4 +434,6 @@ events.connect(events.VIEW_NEW, -- Provides access to snippets from `_G`. -- @class table -- @name _G.snippets -_G.snippets = _M +_G.snippets = M + +return M |