Advertisement
delt01

Untitled

Apr 8th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.85 KB | None | 0 0
  1.  
  2. -----------------------------------------------------------------------------
  3. -- GLOBAL / MISC. SETTINGS
  4. -----------------------------------------------------------------------------
  5.  
  6. --_M.ctags = require 'ctags'
  7. --_M.ctags[#_M.ctags + 1] = '/home/user/.textadept/tags/test.cpp.tags'
  8. ui.set_theme('delt', {font = 'Monaco2', fontsize = 8})
  9. ui.size = {940, 1010}
  10. buffer.sel_eol_filled = true
  11. buffer.back_space_un_indents = false
  12. buffer.caret_period = 300
  13. buffer.caret_line_visible_always = true
  14. buffer.edge_column = 80
  15. buffer.edge_mode = buffer.EDGE_LINE
  16. buffer.extra_ascent = 0
  17. buffer.extra_descent = 0
  18. buffer.wrap_mode = buffer.WRAP_NONE
  19. buffer.wrap_indent_mode = buffer.WRAPINDENT_FIXED
  20. buffer.wrap_start_indent = 4
  21. buffer.wrap_visual_flags = buffer.WRAPVISUALFLAG_END | buffer.WRAPVISUALFLAG_START
  22. buffer.indentation_guides = buffer.IV_LOOKBOTH
  23. buffer.fold_display_text_style = buffer.FOLDDISPLAYTEXT_BOXED
  24. autocomplete_table = { } -- this gets filled by whatever lexer we're using
  25. highlight_text = ""
  26. updated_lock = false
  27. --[[
  28. textadept.editing.typeover_chars [ 44] = false -- '
  29. textadept.editing.typeover_chars [ 41] = false -- )
  30. textadept.editing.typeover_chars [ 62] = false -- >
  31. textadept.editing.typeover_chars [ 93] = false -- ]
  32. textadept.editing.typeover_chars [125] = false -- }
  33. ]]
  34. textadept.editing.typeover_chars = '")]'
  35.  
  36. -----------------------------------------------------------------------------
  37. -- KEYS
  38. -----------------------------------------------------------------------------
  39.  
  40. --keys['cF'] = ui.find.find_incremental
  41. --keys['cf'] = ui.find.focus
  42. --keys['cg'] = function () ui.find.find_next (ui.find.find_entry_text, true) end
  43. keys['ag'] = textadept.editing.goto_line
  44. --keys['ch'] = textadept.editing.highlight_word
  45.  
  46. -- preload the find field when searching
  47. -- bound to Ctrl+F
  48. -- thanks ttmrichter - http://slexy.org/view/s21kbqdN1q :D
  49. keys.cf = function ()
  50.   ui.find.match_case = false
  51.   local text = buffer:get_sel_text()
  52.  
  53. --  if #text == 0 then
  54. --    text = buffer:text_range(buffer:word_start_position(buffer.current_pos),
  55. --           buffer:word_end_position(buffer.current_pos))
  56. --    text = text:gsub("^%s*(.-)%s*$", "%1")
  57. --  end
  58.   ui.find.find_entry_text = text
  59.   ui.find.focus()
  60. end
  61.  
  62. keys['cg'] = function ()
  63.   local old_updated_lock = updated_lock
  64.   updated_lock = true
  65.   ui.find.find_next ()
  66.   updated_lock = old_updated_lock
  67. end
  68.  
  69. keys.cr = function ()
  70.   ui.find.match_case = true
  71.   local text = buffer:get_sel_text()
  72.   ui.find.find_entry_text = text
  73.   ui.find.focus()
  74. end
  75.  
  76. keys.cF = function ()
  77.   local text = buffer:get_sel_text()
  78.  
  79. --  if #text == 0 then
  80. --    text = buffer:text_range(buffer:word_start_position(buffer.current_pos),
  81. --           buffer:word_end_position(buffer.current_pos))
  82. --    text = text:gsub("^%s*(.-)%s*$", "%1")
  83. --  end
  84.   ui.find.find_incremental_text = text
  85.   ui.find.find_incremental ()
  86. end
  87.  
  88. keys.home = buffer.home
  89. keys.delete = function ()
  90.   print ("delete")
  91. end
  92.  
  93. keys.f10 = function ()
  94.   if buffer.wrap_mode == buffer.WRAP_NONE then
  95.     buffer.wrap_mode = buffer.WRAP_WORD
  96.   else
  97.     buffer.wrap_mode = buffer.WRAP_NONE
  98.   end
  99. end
  100.  
  101. -- our main autocomplete function
  102. keys['c '] = function ()
  103.   -- filter out auto_complete_table
  104.   local filtered_table = { }
  105.   local text = buffer:get_sel_text()
  106.  
  107.   if #text == 0 then
  108.     text = buffer:text_range(buffer:word_start_position(buffer.current_pos),
  109.            buffer.current_pos)--buffer:word_end_position(buffer.current_pos))
  110.     text = text:gsub("^%s*(.-)%s*$", "%1")
  111.   --else
  112.     --local k
  113.     --for k = 1, #text, 1
  114.     --do
  115.     --  buffer.delete_back(buffer)
  116.     --end
  117.     --textadept.editing.select_enclosed (text, "")
  118.     textadept.editing.select_word (false)
  119.   end
  120.   local i
  121.   local j = #autocomplete_table
  122.  
  123.   --print ("entries: " .. j .. ", autocomplete text: " .. text)
  124.   for i = 1, j, 1
  125.   do
  126.     --print (autocomplete_table [i])
  127.     v = string.find (autocomplete_table [i], text)
  128.     if v then
  129.       if v < 15 then
  130.         table.insert (filtered_table, autocomplete_table [i])
  131.       end
  132.     end
  133.   end
  134.  
  135.   -- because of how the textadept autocomplete works
  136.   if #filtered_table == 1 then
  137.     buffer.anchor = buffer.selection_end
  138.   end
  139.    
  140.   buffer.auto_c_show (buffer, #text, table.concat (filtered_table, " "))
  141. end
  142.  
  143. -----------------------------------------------------------------------------
  144. -- EVENT HANDLERS
  145. -----------------------------------------------------------------------------
  146.  
  147. -- autocomplete
  148. events.connect(events.AUTO_C_SELECTION, function ()
  149.   buffer.clear ()
  150.   --buffer.auto_c_complete ()
  151.   --buffer.auto_c_cancel ()
  152.   return true
  153. end)
  154.  
  155. --  our nice word-highlight
  156. events.connect (events.UPDATE_UI, function (updated)
  157.   --print (updated_lock)
  158.  
  159.   if updated_lock then
  160.     --print ("updated_lock")
  161.     return true
  162.   end
  163.    
  164.   if not updated then
  165.     --print ("not updated")
  166.     return true
  167.   end
  168.  
  169.   if (updated & buffer.UPDATE_SELECTION) ~= 0 then
  170.     --print ("UPDATE_SELECTION")
  171.     local anch = buffer.anchor
  172.     local sel_start = buffer.selection_start
  173.     local sel_end = buffer.seletion_end
  174.     local text = buffer:get_sel_text()
  175.    
  176.     if #text > 0
  177.         and not string.find (text, "\n")
  178.         and not string.find (text, ",")
  179.         and not string.find (text, " ")
  180.         and not string.find (text, "\t")
  181.         and not string.find (text, ";")
  182.         and not string.find (text, "{")
  183.         and not string.find (text, "}")
  184.     then
  185.       local pos = buffer.current_pos
  186.       highlight_text = text
  187.       textadept.editing.highlight_word (text)
  188.       buffer.current_pos = pos
  189.       buffer.select_start = sel_start
  190.       buffer.select_end = sel_end
  191.       buffer.anchor = anch
  192.     else
  193.       --textadept.editing.highlight_word ("")
  194.       --buffer.indicator_current = M.INDIC_HIGHLIGHT
  195.       highlight_text = nil
  196.       buffer:indicator_clear_range (0, buffer.length)
  197.     end
  198.   end
  199.  
  200.   if (updated & (buffer.UPDATE_H_SCROLL | buffer.UPDATE_V_SCROLL)) ~= 0 then
  201.     --print ("UPDATE_H_SCROLL")
  202.     local text = buffer:get_sel_text()
  203.     if #text > 0
  204.         and not string.find (text, "\n")
  205.         and not string.find (text, ",")
  206.         and not string.find (text, " ")
  207.         and not string.find (text, "\t")
  208.         and not string.find (text, ";")
  209.         and not string.find (text, "{")
  210.         and not string.find (text, "}")
  211.     then
  212.       local old_updated_lock = updated_lock
  213.       updated_lock = true
  214.       if highlight_text then
  215.         textadept.editing.highlight_word (highlight_text)
  216.       end
  217.       buffer.selection_start = buffer.anchor
  218.       buffer.selection_end = buffer.anchor
  219.       updated_lock = old_updated_lock
  220.     end
  221.   end
  222.  
  223.   return true
  224. end)
  225.  
  226. events.connect (events.KEYPRESS, function (str)
  227.   print ("keypress")
  228. end)
  229.  
  230. events.connect (events.MOUSE, function (str)
  231.   print ("mouse")
  232. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement