Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------
- -- GLOBAL / MISC. SETTINGS
- -----------------------------------------------------------------------------
- --_M.ctags = require 'ctags'
- --_M.ctags[#_M.ctags + 1] = '/home/user/.textadept/tags/test.cpp.tags'
- ui.set_theme('delt', {font = 'Monaco2', fontsize = 8})
- ui.size = {940, 1010}
- buffer.sel_eol_filled = true
- buffer.back_space_un_indents = false
- buffer.caret_period = 300
- buffer.caret_line_visible_always = true
- buffer.edge_column = 80
- buffer.edge_mode = buffer.EDGE_LINE
- buffer.extra_ascent = 0
- buffer.extra_descent = 0
- buffer.wrap_mode = buffer.WRAP_NONE
- buffer.wrap_indent_mode = buffer.WRAPINDENT_FIXED
- buffer.wrap_start_indent = 4
- buffer.wrap_visual_flags = buffer.WRAPVISUALFLAG_END | buffer.WRAPVISUALFLAG_START
- buffer.indentation_guides = buffer.IV_LOOKBOTH
- buffer.fold_display_text_style = buffer.FOLDDISPLAYTEXT_BOXED
- autocomplete_table = { } -- this gets filled by whatever lexer we're using
- highlight_text = ""
- updated_lock = false
- --[[
- textadept.editing.typeover_chars [ 44] = false -- '
- textadept.editing.typeover_chars [ 41] = false -- )
- textadept.editing.typeover_chars [ 62] = false -- >
- textadept.editing.typeover_chars [ 93] = false -- ]
- textadept.editing.typeover_chars [125] = false -- }
- ]]
- textadept.editing.typeover_chars = '")]'
- -----------------------------------------------------------------------------
- -- KEYS
- -----------------------------------------------------------------------------
- --keys['cF'] = ui.find.find_incremental
- --keys['cf'] = ui.find.focus
- --keys['cg'] = function () ui.find.find_next (ui.find.find_entry_text, true) end
- keys['ag'] = textadept.editing.goto_line
- --keys['ch'] = textadept.editing.highlight_word
- -- preload the find field when searching
- -- bound to Ctrl+F
- -- thanks ttmrichter - http://slexy.org/view/s21kbqdN1q :D
- keys.cf = function ()
- ui.find.match_case = false
- local text = buffer:get_sel_text()
- -- if #text == 0 then
- -- text = buffer:text_range(buffer:word_start_position(buffer.current_pos),
- -- buffer:word_end_position(buffer.current_pos))
- -- text = text:gsub("^%s*(.-)%s*$", "%1")
- -- end
- ui.find.find_entry_text = text
- ui.find.focus()
- end
- keys['cg'] = function ()
- local old_updated_lock = updated_lock
- updated_lock = true
- ui.find.find_next ()
- updated_lock = old_updated_lock
- end
- keys.cr = function ()
- ui.find.match_case = true
- local text = buffer:get_sel_text()
- ui.find.find_entry_text = text
- ui.find.focus()
- end
- keys.cF = function ()
- local text = buffer:get_sel_text()
- -- if #text == 0 then
- -- text = buffer:text_range(buffer:word_start_position(buffer.current_pos),
- -- buffer:word_end_position(buffer.current_pos))
- -- text = text:gsub("^%s*(.-)%s*$", "%1")
- -- end
- ui.find.find_incremental_text = text
- ui.find.find_incremental ()
- end
- keys.home = buffer.home
- keys.delete = function ()
- print ("delete")
- end
- keys.f10 = function ()
- if buffer.wrap_mode == buffer.WRAP_NONE then
- buffer.wrap_mode = buffer.WRAP_WORD
- else
- buffer.wrap_mode = buffer.WRAP_NONE
- end
- end
- -- our main autocomplete function
- keys['c '] = function ()
- -- filter out auto_complete_table
- local filtered_table = { }
- local text = buffer:get_sel_text()
- if #text == 0 then
- text = buffer:text_range(buffer:word_start_position(buffer.current_pos),
- buffer.current_pos)--buffer:word_end_position(buffer.current_pos))
- text = text:gsub("^%s*(.-)%s*$", "%1")
- --else
- --local k
- --for k = 1, #text, 1
- --do
- -- buffer.delete_back(buffer)
- --end
- --textadept.editing.select_enclosed (text, "")
- textadept.editing.select_word (false)
- end
- local i
- local j = #autocomplete_table
- --print ("entries: " .. j .. ", autocomplete text: " .. text)
- for i = 1, j, 1
- do
- --print (autocomplete_table [i])
- v = string.find (autocomplete_table [i], text)
- if v then
- if v < 15 then
- table.insert (filtered_table, autocomplete_table [i])
- end
- end
- end
- -- because of how the textadept autocomplete works
- if #filtered_table == 1 then
- buffer.anchor = buffer.selection_end
- end
- buffer.auto_c_show (buffer, #text, table.concat (filtered_table, " "))
- end
- -----------------------------------------------------------------------------
- -- EVENT HANDLERS
- -----------------------------------------------------------------------------
- -- autocomplete
- events.connect(events.AUTO_C_SELECTION, function ()
- buffer.clear ()
- --buffer.auto_c_complete ()
- --buffer.auto_c_cancel ()
- return true
- end)
- -- our nice word-highlight
- events.connect (events.UPDATE_UI, function (updated)
- --print (updated_lock)
- if updated_lock then
- --print ("updated_lock")
- return true
- end
- if not updated then
- --print ("not updated")
- return true
- end
- if (updated & buffer.UPDATE_SELECTION) ~= 0 then
- --print ("UPDATE_SELECTION")
- local anch = buffer.anchor
- local sel_start = buffer.selection_start
- local sel_end = buffer.seletion_end
- local text = buffer:get_sel_text()
- if #text > 0
- and not string.find (text, "\n")
- and not string.find (text, ",")
- and not string.find (text, " ")
- and not string.find (text, "\t")
- and not string.find (text, ";")
- and not string.find (text, "{")
- and not string.find (text, "}")
- then
- local pos = buffer.current_pos
- highlight_text = text
- textadept.editing.highlight_word (text)
- buffer.current_pos = pos
- buffer.select_start = sel_start
- buffer.select_end = sel_end
- buffer.anchor = anch
- else
- --textadept.editing.highlight_word ("")
- --buffer.indicator_current = M.INDIC_HIGHLIGHT
- highlight_text = nil
- buffer:indicator_clear_range (0, buffer.length)
- end
- end
- if (updated & (buffer.UPDATE_H_SCROLL | buffer.UPDATE_V_SCROLL)) ~= 0 then
- --print ("UPDATE_H_SCROLL")
- local text = buffer:get_sel_text()
- if #text > 0
- and not string.find (text, "\n")
- and not string.find (text, ",")
- and not string.find (text, " ")
- and not string.find (text, "\t")
- and not string.find (text, ";")
- and not string.find (text, "{")
- and not string.find (text, "}")
- then
- local old_updated_lock = updated_lock
- updated_lock = true
- if highlight_text then
- textadept.editing.highlight_word (highlight_text)
- end
- buffer.selection_start = buffer.anchor
- buffer.selection_end = buffer.anchor
- updated_lock = old_updated_lock
- end
- end
- return true
- end)
- events.connect (events.KEYPRESS, function (str)
- print ("keypress")
- end)
- events.connect (events.MOUSE, function (str)
- print ("mouse")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement