vimamsa 0.1.14 → 0.1.16

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: 4603a715f3fd3b549cc38a9744d93617b3a87ba3d95268f77ed2c98c2c04643d
4
+ data.tar.gz: 26e82f3a6564a78dcd7188a69037f97bae3fb53c43be807560facfab8e70dd51
5
5
  SHA512:
6
- metadata.gz: '08b64e33fe9c031326ac005bf42da69f5e3ed9ce7ffe73d84a387ede95be8e37a44d0c57d6b5b62d3d2842b8de855dc6145e42cf4cd4a4eb8341cab33cb2b86d'
7
- data.tar.gz: 3057288ea2ab7b13939a96282da7540287ebba518714b8aa2db7a285d9aff99e435142ab915d13d92684d229069388a0b52c86a971abad8acb817c5343ba2fff
6
+ metadata.gz: 1f05aad90407dfdd0e9c310f08f5e79274a5901f714d63e353e7291f25c7f4dba3d402163f338cebf01fef4f8fae07522f85a58d62e76086661007f24b14a0bd
7
+ data.tar.gz: f503976439de2a311778b48a427354fc21a1b42434eb6a0bcfa5e3c00144fc3508abe029a058249c2b433e9f41f983679f44927ae095b1ec4a4eb36fafdbfe93
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,34 @@ 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
+ next if vma.gui.windows[k][:sw].child.nil?
99
+ return true if vma.gui.windows[k][:sw].child.bufo == self
100
+ end
101
+ return false
102
+ end
103
+
104
+ def update_access_time
105
+ @access_time = Time.now
106
+ end
107
+
108
+ # This function is to be called whenever keyboard events start affecting this buffer
109
+ # e.g. switching between buffers, opening a new (this) file
94
110
  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
111
+ debug "def set_active", 2
112
+ if vma.kbd.get_scope != :editor
113
+ # If current keyboard mode is not an editor wide mode spanning multiple buffers(e.g. browsing)
114
+ restore_kbd_mode
99
115
  end
100
116
  end
101
117
 
118
+ # Restore the previous keyboard mode specific to this buffer
119
+ def restore_kbd_mode
120
+ vma.kbd.set_mode_stack(@mode_stack.clone)
121
+ end
122
+
102
123
  def set_executable
103
124
  if File.exist?(@fname)
104
125
  FileUtils.chmod("+x", @fname)
@@ -114,6 +135,7 @@ class Buffer < String
114
135
  end
115
136
 
116
137
  def lsp_jump_to_def()
138
+ message("LSP not activated") if @lsp.nil?
117
139
  if !@lsp.nil?
118
140
  fpuri = URI.join("file:///", @fname).to_s
119
141
  r = @lsp.get_definition(fpuri, @lpos, @cpos)
@@ -124,8 +146,9 @@ class Buffer < String
124
146
  end
125
147
 
126
148
  def init_lsp()
127
- if conf(:enable_lsp) and !@lang.nil?
128
- @lsp = LangSrv.get(@lang.to_sym)
149
+ if cnf.lsp.enabled?
150
+ @lsp = LangSrv.get(@lang)
151
+
129
152
  if @lang == "php"
130
153
  # Ripl.start :binding => binding
131
154
  end
@@ -157,7 +180,7 @@ class Buffer < String
157
180
  debug "Guessed LANG: #{lang.id}"
158
181
  @lang = lang.id
159
182
  end
160
- puts @lang.inspect
183
+ debug @lang.inspect
161
184
 
162
185
  if @lang
163
186
  gui_set_file_lang(@id, @lang)
@@ -224,6 +247,11 @@ class Buffer < String
224
247
  return false
225
248
  end
226
249
 
250
+ def scan_all_words
251
+ words = self.scan(/\b\w+\b/).uniq
252
+ return words
253
+ end
254
+
227
255
  def add_image(imgpath, pos)
228
256
  return if !is_legal_pos(pos)
229
257
 
@@ -350,6 +378,8 @@ class Buffer < String
350
378
 
351
379
  self.replace(str)
352
380
  @line_ends = scan_indexes(self, /\n/)
381
+ words = scan_all_words
382
+ Autocomplete.add_words(words)
353
383
 
354
384
  if cnf.btree.experimental?
355
385
  @bt = BufferTree.new(self)
@@ -515,7 +545,6 @@ class Buffer < String
515
545
  end
516
546
  end
517
547
 
518
-
519
548
  def undo()
520
549
  debug @edit_history.inspect
521
550
  return if !@edit_history.any?
@@ -677,11 +706,6 @@ class Buffer < String
677
706
  end
678
707
  end
679
708
 
680
- def replace_range(range, text)
681
- delete_range(range.first, range.last)
682
- insert_txt_at(text, range.begin)
683
- end
684
-
685
709
  def current_line_range()
686
710
  range = line_range(@lpos, 1)
687
711
  return range
@@ -792,7 +816,7 @@ class Buffer < String
792
816
  @line_ends.sort!
793
817
  end
794
818
  end
795
-
819
+
796
820
  # Ranges to use in delete or copy operations
797
821
  def get_range(range_id, mark: nil)
798
822
  range = nil
@@ -1036,15 +1060,28 @@ class Buffer < String
1036
1060
  end
1037
1061
  end
1038
1062
 
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/)
1063
+ def get_word_in_pos(p, boundary: :space)
1064
+ maxws = 200 # max word size
1065
+ if boundary == :space
1066
+ wem = scan_marks(p, p + maxws, /(?<=\S)\s/, -1)
1067
+ wsm = scan_marks(p - maxws, p, /((?<=\s)\S)|^\S/)
1068
+ word_start = wsm[-1]
1069
+ word_end = wem[0]
1070
+ elsif boundary == :word
1071
+ wsm = scan_marks(p - maxws, p, /\b\w/)
1072
+ word_start = wsm[-1]
1073
+ word_end = p
1074
+ end
1042
1075
 
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
1076
+ word_start = p if word_start == nil
1077
+ word_end = p if word_end == nil
1047
1078
  word = self[word_start..word_end]
1079
+
1080
+ return [word, (word_start..word_end)]
1081
+ end
1082
+
1083
+ def get_cur_nonwhitespace_word()
1084
+ (word, range) = get_word_in_pos(@pos, boundary: :space)
1048
1085
  debug "'WORD: #{word}'"
1049
1086
  # message("Open link #{word}")
1050
1087
  linep = get_file_line_pointer(word)
@@ -1097,7 +1134,6 @@ class Buffer < String
1097
1134
  end
1098
1135
  end
1099
1136
 
1100
-
1101
1137
  def replace_with_char(char)
1102
1138
  debug "self_pos:'#{self[@pos]}'"
1103
1139
  return if self[@pos] == "\n"
@@ -1228,6 +1264,13 @@ class Buffer < String
1228
1264
  $kbd.set_mode(:visual)
1229
1265
  end
1230
1266
 
1267
+ def start_selection()
1268
+ @visual_mode = true
1269
+ @selection_start = @pos
1270
+ $kbd.set_mode(:visual)
1271
+ #TODO: implement without setting kbd mode
1272
+ end
1273
+
1231
1274
  def copy_active_selection(x = nil)
1232
1275
  debug "!COPY SELECTION"
1233
1276
  @paste_lines = false
@@ -1330,10 +1373,14 @@ class Buffer < String
1330
1373
  end
1331
1374
 
1332
1375
  def end_visual_mode()
1333
- return if !visual_mode?
1376
+ debug "end_visual_mode, #{vma.kbd.get_mode}, #{visual_mode?}", 2
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)