vimamsa 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 510c17ec3221823fe5e8c800b4146879c11f278b37a0ad807d57729210af6b3a
4
- data.tar.gz: 211596938920f6a785830d9d516cd9c999b4c8f54a67610eaf971ce127c4b8e5
3
+ metadata.gz: ea3e4fa5b65895cba0a20cae08fad4f422008e786f4cd3ab405d39bf630f52db
4
+ data.tar.gz: 65b80bb0e663f64d241e51130aac9e13106c58ff20f698c095e5cf43b416ce41
5
5
  SHA512:
6
- metadata.gz: '08b64e33fe9c031326ac005bf42da69f5e3ed9ce7ffe73d84a387ede95be8e37a44d0c57d6b5b62d3d2842b8de855dc6145e42cf4cd4a4eb8341cab33cb2b86d'
7
- data.tar.gz: 3057288ea2ab7b13939a96282da7540287ebba518714b8aa2db7a285d9aff99e435142ab915d13d92684d229069388a0b52c86a971abad8acb817c5343ba2fff
6
+ metadata.gz: 1c056fa3ed552a410b7a9f06ebfb0f2eb1444feba9a5810a520e8012a245b83bd156115566d2965095e8d7bacc184883e1bb16e724efa26c9abd0180c2640050
7
+ data.tar.gz: 9196b537289ac4a08b09c53dbbdf03ccd5bec1cb50d3de4b40a03352cf64c0fc0776d489803a421d00d72bad72fd96cefc45865f27d1df5f22b67b9906c4edf9
data/custom_example.rb CHANGED
@@ -16,8 +16,15 @@
16
16
  # setcnf :startup_file, "~/Documents/startup.txt"
17
17
 
18
18
  # To enable LSP:
19
- # conf(:custom_lsp)[:ruby] = {name: "solargraph", command:"solargraph stdio", type: "stdio"}
20
- # conf(:custom_lsp)[:cpp] = {name: "clangd", command:"clangd-12 --offset-encoding=utf-8", type: "stdio"}
19
+ # cnf.lsp.enabled = true
20
+ # cnf.lsp.server.solargraph = { name: "solargraph", command: "solargraph stdio", type: "stdio" }
21
+ # cnf.lsp.server.solargraph.languages = ["ruby"]
22
+
23
+ # cnf.lsp.server.clangd = { name: "clangd", command: "clangd-12 --offset-encoding=utf-8", type: "stdio" }
24
+ # cnf.lsp.server.clangd.languages = ["c", "cpp"]
25
+
26
+
27
+
21
28
 
22
29
 
23
30
  def insert_date()
@@ -121,9 +121,8 @@ def search_actions_select_callback(search_str, idx)
121
121
  end
122
122
 
123
123
  def filter_items(item_list, item_key, search_str)
124
- # Ripl.start :binding => binding
125
124
  item_hash = {}
126
- puts item_list.inspect
125
+ # debug item_list.inspect
127
126
  scores = Parallel.map(item_list, in_threads: 8) do |item|
128
127
  if item[:str].class != String
129
128
  puts item.inspect
@@ -12,7 +12,7 @@ $update_highlight = false
12
12
  $ifuncon = false
13
13
 
14
14
  class Buffer < String
15
- attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :dirname, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang, :images, :last_save
15
+ attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :dirname, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang, :images, :last_save, :access_time
16
16
  attr_writer :call_func, :update_highlight
17
17
  attr_accessor :gui_update_highlight, :update_hl_startpos, :update_hl_endpos, :hl_queue, :syntax_parser, :highlights, :gui_reset_highlight, :is_parsing_syntax, :line_ends, :bt, :line_action_handler, :module, :active_kbd_mode, :title, :subtitle, :paste_lines, :mode_stack, :default_mode
18
18
 
@@ -22,14 +22,15 @@ class Buffer < String
22
22
  debug "Buffer.rb: def initialize"
23
23
  super(str)
24
24
 
25
+ update_access_time
25
26
  @images = []
26
27
  @audiofiles = []
27
28
  @lang = nil
28
29
  @id = @@num_buffers
29
30
  @@num_buffers += 1
30
31
  @version = 0
31
- @mode_stack = [:command] # TODO
32
- @default_mode = :command # TODO
32
+ @default_mode = vma.kbd.default_mode
33
+ @mode_stack = [@default_mode]
33
34
  gui_create_buffer(@id, self)
34
35
  debug "NEW BUFFER fn=#{fname} ID:#{@id}"
35
36
 
@@ -76,7 +77,7 @@ class Buffer < String
76
77
  self << "\n" if self[-1] != "\n"
77
78
  @current_word = nil
78
79
  @active_kbd_mode = nil
79
- if conf(:enable_lsp)
80
+ if cnf.lsp.enabled?
80
81
  init_lsp
81
82
  end
82
83
  return self
@@ -91,14 +92,33 @@ class Buffer < String
91
92
  return x
92
93
  end
93
94
 
95
+ #Check if this buffer is attached to any windows
96
+ def is_active
97
+ for k in vma.gui.windows.keys
98
+ return true if vma.gui.windows[k][:sw].child.bufo == self
99
+ end
100
+ return false
101
+ end
102
+
103
+ def update_access_time
104
+ @access_time = Time.now
105
+ end
106
+
107
+ # This function is to be called whenever keyboard events start affecting this buffer
108
+ # e.g. switching between buffers, opening a new (this) file
94
109
  def set_active
95
- if !@active_kbd_mode.nil?
96
- # $kbd.set_mode(@active_kbd_mode) #TODO: remove?
97
- else
98
- $kbd.set_mode_to_default
110
+ debug "def set_active", 2
111
+ if vma.kbd.get_scope != :editor
112
+ # If current keyboard mode is not an editor wide mode spanning multiple buffers(e.g. browsing)
113
+ restore_kbd_mode
99
114
  end
100
115
  end
101
116
 
117
+ # Restore the previous keyboard mode specific to this buffer
118
+ def restore_kbd_mode
119
+ vma.kbd.set_mode_stack(@mode_stack.clone)
120
+ end
121
+
102
122
  def set_executable
103
123
  if File.exist?(@fname)
104
124
  FileUtils.chmod("+x", @fname)
@@ -114,6 +134,7 @@ class Buffer < String
114
134
  end
115
135
 
116
136
  def lsp_jump_to_def()
137
+ message("LSP not activated") if @lsp.nil?
117
138
  if !@lsp.nil?
118
139
  fpuri = URI.join("file:///", @fname).to_s
119
140
  r = @lsp.get_definition(fpuri, @lpos, @cpos)
@@ -124,8 +145,9 @@ class Buffer < String
124
145
  end
125
146
 
126
147
  def init_lsp()
127
- if conf(:enable_lsp) and !@lang.nil?
128
- @lsp = LangSrv.get(@lang.to_sym)
148
+ if cnf.lsp.enabled?
149
+ @lsp = LangSrv.get(@lang)
150
+
129
151
  if @lang == "php"
130
152
  # Ripl.start :binding => binding
131
153
  end
@@ -157,7 +179,7 @@ class Buffer < String
157
179
  debug "Guessed LANG: #{lang.id}"
158
180
  @lang = lang.id
159
181
  end
160
- puts @lang.inspect
182
+ debug @lang.inspect
161
183
 
162
184
  if @lang
163
185
  gui_set_file_lang(@id, @lang)
@@ -224,6 +246,11 @@ class Buffer < String
224
246
  return false
225
247
  end
226
248
 
249
+ def scan_all_words
250
+ words = self.scan(/\b\w+\b/).uniq
251
+ return words
252
+ end
253
+
227
254
  def add_image(imgpath, pos)
228
255
  return if !is_legal_pos(pos)
229
256
 
@@ -350,6 +377,8 @@ class Buffer < String
350
377
 
351
378
  self.replace(str)
352
379
  @line_ends = scan_indexes(self, /\n/)
380
+ words = scan_all_words
381
+ Autocomplete.add_words(words)
353
382
 
354
383
  if cnf.btree.experimental?
355
384
  @bt = BufferTree.new(self)
@@ -515,7 +544,6 @@ class Buffer < String
515
544
  end
516
545
  end
517
546
 
518
-
519
547
  def undo()
520
548
  debug @edit_history.inspect
521
549
  return if !@edit_history.any?
@@ -677,11 +705,6 @@ class Buffer < String
677
705
  end
678
706
  end
679
707
 
680
- def replace_range(range, text)
681
- delete_range(range.first, range.last)
682
- insert_txt_at(text, range.begin)
683
- end
684
-
685
708
  def current_line_range()
686
709
  range = line_range(@lpos, 1)
687
710
  return range
@@ -792,7 +815,7 @@ class Buffer < String
792
815
  @line_ends.sort!
793
816
  end
794
817
  end
795
-
818
+
796
819
  # Ranges to use in delete or copy operations
797
820
  def get_range(range_id, mark: nil)
798
821
  range = nil
@@ -1036,15 +1059,28 @@ class Buffer < String
1036
1059
  end
1037
1060
  end
1038
1061
 
1039
- def get_cur_nonwhitespace_word()
1040
- wem = scan_marks(@pos, @pos + 200, /(?<=\S)\s/, -1)
1041
- wsm = scan_marks(@pos - 200, @pos, /((?<=\s)\S)|^\S/)
1062
+ def get_word_in_pos(p, boundary: :space)
1063
+ maxws = 200 # max word size
1064
+ if boundary == :space
1065
+ wem = scan_marks(p, p + maxws, /(?<=\S)\s/, -1)
1066
+ wsm = scan_marks(p - maxws, p, /((?<=\s)\S)|^\S/)
1067
+ word_start = wsm[-1]
1068
+ word_end = wem[0]
1069
+ elsif boundary == :word
1070
+ wsm = scan_marks(p - maxws, p, /\b\w/)
1071
+ word_start = wsm[-1]
1072
+ word_end = p
1073
+ end
1042
1074
 
1043
- word_start = wsm[-1]
1044
- word_end = wem[0]
1045
- word_start = pos if word_start == nil
1046
- word_end = pos if word_end == nil
1075
+ word_start = p if word_start == nil
1076
+ word_end = p if word_end == nil
1047
1077
  word = self[word_start..word_end]
1078
+
1079
+ return [word, (word_start..word_end)]
1080
+ end
1081
+
1082
+ def get_cur_nonwhitespace_word()
1083
+ (word, range) = get_word_in_pos(@pos, boundary: :space)
1048
1084
  debug "'WORD: #{word}'"
1049
1085
  # message("Open link #{word}")
1050
1086
  linep = get_file_line_pointer(word)
@@ -1097,7 +1133,6 @@ class Buffer < String
1097
1133
  end
1098
1134
  end
1099
1135
 
1100
-
1101
1136
  def replace_with_char(char)
1102
1137
  debug "self_pos:'#{self[@pos]}'"
1103
1138
  return if self[@pos] == "\n"
@@ -1228,6 +1263,13 @@ class Buffer < String
1228
1263
  $kbd.set_mode(:visual)
1229
1264
  end
1230
1265
 
1266
+ def start_selection()
1267
+ @visual_mode = true
1268
+ @selection_start = @pos
1269
+ $kbd.set_mode(:visual)
1270
+ #TODO: implement without setting kbd mode
1271
+ end
1272
+
1231
1273
  def copy_active_selection(x = nil)
1232
1274
  debug "!COPY SELECTION"
1233
1275
  @paste_lines = false
@@ -1330,10 +1372,15 @@ class Buffer < String
1330
1372
  end
1331
1373
 
1332
1374
  def end_visual_mode()
1333
- return if !visual_mode?
1375
+ debug "end_visual_mode, #{vma.kbd.get_mode}, #{visual_mode?}", 2
1376
+ vma.kbd.dump_state
1377
+ return if vma.kbd.get_mode != :visual
1378
+ if !visual_mode?
1379
+ debug "end_visual_mode, !visual_mode?"
1380
+ # TODO: should not happen
1381
+ end
1334
1382
  debug "End visual mode"
1335
- #TODO:take previous mode (insert|command) from stack?
1336
- $kbd.set_mode(:command)
1383
+ vma.kbd.to_previous_mode
1337
1384
  @visual_mode = false
1338
1385
  return true
1339
1386
  end
@@ -1462,7 +1509,7 @@ class Buffer < String
1462
1509
  #TODO: show message box
1463
1510
  end
1464
1511
  @last_save = Time.now
1465
- puts "file saved on #{@last_save}"
1512
+ debug "file saved on #{@last_save}"
1466
1513
  sleep 3
1467
1514
  }
1468
1515
  end
@@ -1501,13 +1548,14 @@ class Buffer < String
1501
1548
  end
1502
1549
 
1503
1550
  def save()
1504
- check_if_modified_outside
1551
+ check_if_modified_outside #TODO
1505
1552
  if !@fname
1506
1553
  save_as()
1507
1554
  return
1508
1555
  end
1509
1556
  message("Saving file #{@fname}")
1510
1557
  write_contents_to_file(@fname)
1558
+ hook.call(:file_saved, self)
1511
1559
  end
1512
1560
 
1513
1561
  def close()
@@ -135,10 +135,26 @@ class Buffer < String
135
135
  return true
136
136
  end
137
137
 
138
+ def complete_current_word(rep)
139
+ debug "complete_current_word", 2
140
+ p = @pos - 1
141
+ return if !is_legal_pos(p)
142
+ (word, range) = get_word_in_pos(p, boundary: :word)
143
+ debug [word, range].to_s, 2
144
+ endpos = range.begin+rep.size
145
+ replace_range(range, rep)
146
+ set_pos(endpos)
147
+ end
148
+
149
+ def replace_range(range, text)
150
+ delete_range(range.first, range.last)
151
+ insert_txt_at(text, range.begin)
152
+ end
153
+
138
154
  def delete2(range_id, mark = nil)
139
155
  @paste_lines = false
140
156
  range = get_range(range_id, mark: mark)
141
- return if range == nil
157
+ return false if range == nil
142
158
  debug "RANGE"
143
159
  debug range.inspect
144
160
  debug range.inspect
@@ -146,6 +162,7 @@ class Buffer < String
146
162
  delete_range(range.first, range.last)
147
163
  pos = [range.first, @pos].min
148
164
  set_pos(pos)
165
+ return true
149
166
  end
150
167
 
151
168
  def delete(op, x = nil)