From 25d8542e87d1549128134cfb50e1bdc2423d3cec Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Thu, 6 Sep 2007 21:17:24 -0400 Subject: Words can be autocompleted from a specified dictionary. --- modules/textadept/editing.lua | 21 ++++++++++++++++++++- modules/textadept/key_commands.lua | 34 ++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 17 deletions(-) (limited to 'modules') diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index d15ebb9b..ac9037da 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -107,7 +107,26 @@ function autocomplete_word(word_chars) end match_pos = buffer:find(root, 1048580, match_pos + 1) end - if #c_list_str > 0 then buffer:auto_c_show(#root, c_list_str:sub(1, -2)) end + if #c_list_str > 0 then buffer:auto_c_show( #root, c_list_str:sub(1, -2) ) end +end + +--- +-- Pops up an autocompletion list for the current word based on the path to a +-- dictionary of words. +-- @param dict Path to a dictionary of words. +function autocomplete_word_from_dict(dict) + local buffer = buffer + local start = buffer:word_start_position(buffer.current_pos, true) + local root = buffer:text_range(start, buffer.current_pos) + if #root == 0 then return end + local f = io.open(dict) + if not f then return end + local c_list_str = '' + for line in f:lines() do + if line:match('^'..root) then c_list_str = c_list_str..line..' ' end + end + f:close() + if #c_list_str > 0 then buffer:auto_c_show( #root, c_list_str:sub(1, -2) ) end end --- diff --git a/modules/textadept/key_commands.lua b/modules/textadept/key_commands.lua index 8d792f61..c58c9afe 100644 --- a/modules/textadept/key_commands.lua +++ b/modules/textadept/key_commands.lua @@ -115,22 +115,24 @@ keys.ai = { m_snippets.show_style } -- Editing commands. local m_editing = _m.textadept.editing -keys.cm = { m_editing.match_brace } -keys.csm = { m_editing.match_brace, 'select' } -keys['c '] = { m_editing.autocomplete_word, '%w_' } -keys.cl = { m_editing.goto_line } -keys.ck = { m_editing.smart_cutcopy, } -keys.csk = { m_editing.smart_cutcopy, 'copy' } -keys.cu = { m_editing.smart_paste, } -keys.au = { m_editing.smart_paste, 'cycle' } -keys.sau = { m_editing.smart_paste, 'reverse' } -keys.cw = { m_editing.current_word, 'delete' } -keys.at = { m_editing.transpose_chars } -keys.csh = { m_editing.squeeze, } -keys.cj = { m_editing.join_lines } -keys.cau = { m_editing.move_line, 'up' } -keys.cad = { m_editing.move_line, 'down' } -keys.csai = { m_editing.convert_indentation } +keys.cm = { m_editing.match_brace } +keys.csm = { m_editing.match_brace, 'select' } +keys['c '] = { m_editing.autocomplete_word, '%w_' } +keys['a '] = { m_editing.autocomplete_word_from_dict, + '/usr/share/dict/cracklib-small' } +keys.cl = { m_editing.goto_line } +keys.ck = { m_editing.smart_cutcopy, } +keys.csk = { m_editing.smart_cutcopy, 'copy' } +keys.cu = { m_editing.smart_paste, } +keys.au = { m_editing.smart_paste, 'cycle' } +keys.sau = { m_editing.smart_paste, 'reverse' } +keys.cw = { m_editing.current_word, 'delete' } +keys.at = { m_editing.transpose_chars } +keys.csh = { m_editing.squeeze, } +keys.cj = { m_editing.join_lines } +keys.cau = { m_editing.move_line, 'up' } +keys.cad = { m_editing.move_line, 'down' } +keys.csai = { m_editing.convert_indentation } keys.cae = { -- code execution r = { m_editing.ruby_exec }, l = { m_editing.lua_exec } -- cgit v1.2.3