class Object
Constants
- AFTER
- ALTMODIFIER
qt-project.org/doc/qt-5.0/qtcore/qt.html#KeyboardModifier-enum
- BACKWARD
- BACKWARD_CHAR
- BACKWARD_LINE
- BEFORE
- BEGINNING_OF_LINE
- CONTROLMODIFIER
- CURRENT_CHAR_BACKWARD
- CURRENT_CHAR_FORWARD
- DELETE
- END_OF_BUFFER
- END_OF_LINE
- FIRST_NON_WHITESPACE
- FORWARD
- FORWARD_CHAR
- FORWARD_LINE
- GUESS_ENCODING_ORDER
- INSERT
- KEYPADMODIFIER
- KEY_PRESS
- KEY_RELEASE
- METAMODIFIER
- NEXT_MARK
- NOMODIFIER
- PREVIOUS_MARK
- REPLACE
- SELECTION
- SHIFTMODIFIER
- START_OF_BUFFER
- WORD_END
- WORD_START
Public Instance Methods
_quit()
click to toggle source
# File lib/vimamsa/editor.rb, line 266 def _quit() vma.shutdown Gtk.main_quit end
ack_buffer(instr, b = nil)
click to toggle source
# File lib/vimamsa/ack.rb, line 19 def ack_buffer(instr, b = nil) instr = instr.gsub("'", ".") # TODO bufstr = "" for path in $vma.get_content_search_paths bufstr += run_cmd("ack -Q --type-add=gd=.gd -k --nohtml --nojs --nojson '#{instr}' #{path}") end if bufstr.size > 5 create_new_file(nil, bufstr) else message("No results for input:#{instr}") end end
assert_binary_exists(bin)
click to toggle source
# File lib/vimamsa/util.rb, line 17 def assert_binary_exists(bin) if which(bin).nil? raise "Binary #{bin} doesn't exist" end end
backup_all_buffers()
click to toggle source
# File lib/vimamsa/buffer.rb, line 1762 def backup_all_buffers() for buf in $buffers buf.backup end message("Backup all buffers") end
bindkey(key, action)
click to toggle source
# File lib/vimamsa/key_binding_tree.rb, line 588 def bindkey(key, action) $kbd.bindkey(key, action) end
buf()
click to toggle source
Return currently active buffer
# File lib/vimamsa/main.rb, line 39 def buf() return $buffer end
buf_replace(search_str, replace_str)
click to toggle source
# File lib/vimamsa/search_replace.rb, line 139 def buf_replace(search_str, replace_str) if $buffer.visual_mode? r = $buffer.get_visual_mode_range txt = $buffer[r] txt.gsub!(search_str, replace_str) $buffer.replace_range(r, txt) $buffer.end_visual_mode else repbuf = $buffer.to_s.clone repbuf.gsub!(search_str, replace_str) tmppos = $buffer.pos if repbuf == $buffer.to_s.clone message("NO CHANGE. Replacing #{search_str} with #{replace_str}.") else $buffer.set_content(repbuf) $buffer.set_pos(tmppos) message("Replacing #{search_str} with #{replace_str}.") end end end
buf_replace_string(instr)
click to toggle source
Requires instr in form “FROM/TO” Replaces all occurences of FROM with TO
# File lib/vimamsa/search_replace.rb, line 162 def buf_replace_string(instr) # puts "buf_replace_string(instr=#{instr})" a = instr.split("/") if a.size != 2 return end buf_replace(a[0], a[1]) end
buflist()
click to toggle source
# File lib/vimamsa/main.rb, line 47 def buflist() return $buffers end
bufs()
click to toggle source
# File lib/vimamsa/main.rb, line 43 def bufs() return $buffers end
call(id)
click to toggle source
TODO: remove
# File lib/vimamsa/actions.rb, line 35 def call(id) call_action(id) end
call_action(id)
click to toggle source
# File lib/vimamsa/actions.rb, line 39 def call_action(id) a = $actions[id] if a a.method.call() else message("Unknown action: " + id.inspect) end end
can_save_to_directory?(dpath)
click to toggle source
# File lib/vimamsa/editor.rb, line 322 def can_save_to_directory?(dpath) return false if !File.exist?(dpath) return false if !File.directory?(dpath) return false if !File.writable?(dpath) return true end
center_on_current_line()
click to toggle source
# File lib/vimamsa/gui.rb, line 64 def center_on_current_line() b = $view.buffer iter = b.get_iter_at(:offset => b.cursor_position) within_margin = 0.0 #margin as a [0.0,0.5) fraction of screen size use_align = true xalign = 0.0 #0.0=top 1.0=bottom, 0.5=center yalign = 0.5 $view.scroll_to_iter(iter, within_margin, use_align, xalign, yalign) end
conf(id)
click to toggle source
# File lib/vimamsa/key_binding_tree.rb, line 23 def conf(id) return $cnf[id] end
crash(message, e = nil)
click to toggle source
# File lib/vimamsa/debug.rb, line 38 def crash(message, e = nil) puts "FATAL ERROR:#{message}" puts caller().join("\n") # savedebug(message, e) _quit() end
create_new_file(filename = nil, file_contents = "\n")
click to toggle source
# File lib/vimamsa/editor.rb, line 462 def create_new_file(filename = nil, file_contents = "\n") debug "NEW FILE CREATED" buffer = Buffer.new(file_contents) # gui_set_current_buffer(buffer.id) #TODO: remove? $buffers << buffer return buffer end
debug(message)
click to toggle source
# File lib/vimamsa/debug.rb, line 3 def debug(message) if $debug puts "[#{DateTime.now().strftime("%H:%M:%S")}] #{message}" $stdout.flush end end
debug_dump_clipboard()
click to toggle source
# File lib/vimamsa/debug.rb, line 15 def debug_dump_clipboard() puts $clipboard.inspect end
debug_dump_deltas()
click to toggle source
# File lib/vimamsa/debug.rb, line 19 def debug_dump_deltas() puts buf.edit_history.inspect end
debug_print_buffer(c)
click to toggle source
# File lib/vimamsa/debug.rb, line 10 def debug_print_buffer(c) puts buf.inspect puts buf end
decrypt_cur_buffer(password, b = nil)
click to toggle source
# File lib/vimamsa/encrypt.rb, line 35 def decrypt_cur_buffer(password, b = nil) $buffer.decrypt(password) end
diff_buffer()
click to toggle source
# File lib/vimamsa/editor.rb, line 363 def diff_buffer() bufstr = "" orig_path = $buffer.fname infile = Tempfile.new("out") infile = Tempfile.new("in") infile.write($buffer.to_s) infile.flush cmd = "diff -w '#{orig_path}' #{infile.path}" # puts cmd bufstr << run_cmd(cmd) # puts bufstr infile.close; infile.unlink create_new_file(nil, bufstr) end
draw_text(str, x, y)
click to toggle source
# File lib/vimamsa/editor.rb, line 534 def draw_text(str, x, y) vma.paint_stack << [4, x, y, str] end
e_move_backward_char()
click to toggle source
# File lib/vimamsa/key_actions.rb, line 5 def e_move_backward_char buf.move(BACKWARD_CHAR) end
e_move_forward_char()
click to toggle source
# File lib/vimamsa/key_actions.rb, line 1 def e_move_forward_char buf.move(FORWARD_CHAR) end
encrypt_cur_buffer()
click to toggle source
# File lib/vimamsa/encrypt.rb, line 39 def encrypt_cur_buffer() callback = proc{|x|encrypt_cur_buffer_callback(x)} gui_one_input_action("Encrypt", "Password:", "Encrypt", callback) end
encrypt_cur_buffer_callback(password,b=nil)
click to toggle source
# File lib/vimamsa/encrypt.rb, line 44 def encrypt_cur_buffer_callback(password,b=nil) $buffer.set_encrypted(password) end
exec_action(action)
click to toggle source
# File lib/vimamsa/key_binding_tree.rb, line 594 def exec_action(action) $kbd.last_action = $kbd.cur_action $kbd.cur_action = action if action.class == Symbol return call(action) elsif action.class == Proc return action.call else return eval(action) end end
exec_cmd(bin_name, arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil, arg5 = nil)
click to toggle source
# File lib/vimamsa/editor.rb, line 605 def exec_cmd(bin_name, arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil, arg5 = nil) assert_binary_exists(bin_name) if !arg5.nil? p = Open3.popen2(bin_name, arg1, arg2, arg3, arg4, arg5) elsif !arg4.nil? p = Open3.popen2(bin_name, arg1, arg2, arg3, arg4) elsif !arg3.nil? p = Open3.popen2(bin_name, arg1, arg2, arg3) elsif !arg2.nil? p = Open3.popen2(bin_name, arg1, arg2) elsif !arg1.nil? p = Open3.popen2(bin_name, arg1) else p = Open3.popen2(bin_name) end ret_str = p[1].read return ret_str end
exec_in_terminal(cmd)
click to toggle source
# File lib/vimamsa/editor.rb, line 3 def exec_in_terminal(cmd) # puts "CMD:#{cmd}" # global to prevent garbage collect unlink $initf = Tempfile.new("bashinit") # puts $initf.path $initf.write(cmd) $initf.write("rm #{$initf.path}\n") $initf.write("\nexec bash\n") $initf.close # PTY.spawn("gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash") fork { exec "gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash" } end
execute_command(input_str)
click to toggle source
# File lib/vimamsa/editor.rb, line 382 def execute_command(input_str) begin out_str = eval(input_str, TOPLEVEL_BINDING) #TODO: Other binding? $minibuffer.clear $minibuffer << out_str.to_s #TODO: segfaults, why? rescue SyntaxError debug("SYNTAX ERROR with eval cmd #{action}: " + $!.to_s) end end
execute_search(input_str)
click to toggle source
# File lib/vimamsa/search.rb, line 2 def execute_search(input_str) $search = Search.new eval_str="execute_search(#{input_str.dump})" $macro.overwrite_current_action(eval_str) return $search.set(input_str, "simple", $buffer) end
expand_if_existing(fpath)
click to toggle source
# File lib/vimamsa/util.rb, line 58 def expand_if_existing(fpath) return nil if fpath.class != String fpath = File.expand_path(fpath) fpath = nil if !File.exist?(fpath) return fpath end
fatal_error(msg)
click to toggle source
# File lib/vimamsa/editor.rb, line 271 def fatal_error(msg) puts msg exit! end
file_is_text_file(fpath)
click to toggle source
# File lib/vimamsa/editor.rb, line 625 def file_is_text_file(fpath) puts "file_is_text_file(#{fpath})" fpath = File.expand_path(fpath) return false if !File.exist?(fpath) r = exec_cmd("file", fpath) puts "DEBUG:#{r}" return true if r.match(/UTF-8.*text/) return true if r.match(/ASCII.*text/) return false end
file_saveas(filename)
click to toggle source
# File lib/vimamsa/editor.rb, line 276 def file_saveas(filename) buf.save_as_callback(filename) end
filter_buffer(buf)
click to toggle source
# File lib/vimamsa/editor.rb, line 470 def filter_buffer(buf) i = 0 while i < buf.size if buf[i].ord == 160 buf[i] = " " #TODO: hack. fix properly end i += 1 end return buf end
filter_files(search_str)
click to toggle source
# File lib/vimamsa/file_finder.rb, line 54 def filter_files(search_str) dir_hash = {} scores = Parallel.map($dir_list, in_threads: 8) do |file| [file, srn_dst(search_str, file)] end for s in scores dir_hash[s[0]] = s[1] if s[1] > 0 end # puts scores dir_hash = dir_hash.sort_by { |k, v| -v } dir_hash = dir_hash[0..20] dir_hash.map do |file, d| puts "D:#{d} #{file}" end return dir_hash end
filter_items(item_list, item_key, search_str)
click to toggle source
# File lib/vimamsa/actions.rb, line 102 def filter_items(item_list, item_key, search_str) # Ripl.start :binding => binding item_hash = {} scores = Parallel.map(item_list, in_threads: 8) do |item| [item, srn_dst(search_str, item[:str])] end scores.sort_by! { |x| -x[1] } puts scores.inspect scores = scores[0..30] return scores end
find_project_dir_of_cur_buffer()
click to toggle source
# File lib/vimamsa/editor.rb, line 660 def find_project_dir_of_cur_buffer() # Find "project dir" of current file. If currently editing file in path "/foo/bar/baz/fn.txt" and file named "/foo/bar/.vma_project" exists, then dir /foo/bar is treated as project dir and subject to e.g. ack search. pdir = nil if $buffer.fname pdir = find_project_dir_of_fn($buffer.fname) end # puts "Proj dir of current file: #{pdir}" return pdir end
find_project_dir_of_fn(fn)
click to toggle source
# File lib/vimamsa/editor.rb, line 646 def find_project_dir_of_fn(fn) pcomp = Pathname.new(fn).each_filename.to_a parent_dirs = (0..(pcomp.size - 2)).collect { |x| "/" + pcomp[0..x].join("/") }.reverse projdir = nil for pdir in parent_dirs candfn = "#{pdir}/.vma_project" if File.exist?(candfn) projdir = pdir break end end return projdir end
focus_out()
click to toggle source
Try to clear modifiers when program loses focus e.g. after alt-tab
# File lib/vimamsa/key_binding_tree.rb, line 608 def focus_out debug "RB Clear modifiers" $kbd.clear_modifiers() end
fuzzy_filter(search_str, list, maxfinds)
click to toggle source
# File lib/vimamsa/file_history.rb, line 69 def fuzzy_filter(search_str, list, maxfinds) h = {} scores = Parallel.map(list, in_threads: 8) do |l| [l, srn_dst(search_str, l)] end for s in scores h[s[0]] = s[1] if s[1] > 0 end h = h.sort_by { |k, v| -v } h = h[0..maxfinds] # h.map do |i, d| # puts "D:#{d} #{i}" # end return h end
get_dot_path(sfx)
click to toggle source
# File lib/vimamsa/editor.rb, line 567 def get_dot_path(sfx) dot_dir = File.expand_path("~/.vimamsa") Dir.mkdir(dot_dir) unless File.exist?(dot_dir) dpath = "#{dot_dir}/#{sfx}" return dpath end
get_file_line_pointer(s)
click to toggle source
# File lib/vimamsa/editor.rb, line 574 def get_file_line_pointer(s) #"/code/vimamsa/lib/vimamsa/buffer_select.rb:31:def" # m = s.match(/(~[a-z]*)?\/.*\//) m = s.match(/((~[a-z]*)?\/.*\/\S+):(\d+)/) if m != nil if File.exist?(File.expand_path(m[1])) return [m[1], m[3].to_i] end end return nil end
get_visible_area()
click to toggle source
# File lib/vimamsa/gui.rb, line 74 def get_visible_area() view = $view vr = view.visible_rect startpos = view.get_iter_at_position_raw(vr.x, vr.y)[1].offset endpos = view.get_iter_at_position_raw(vr.x + vr.width, vr.y + vr.height)[1].offset return [startpos, endpos] end
grep_cur_buffer(search_str, b = nil)
click to toggle source
# File lib/vimamsa/search_replace.rb, line 72 def grep_cur_buffer(search_str, b = nil) debug "grep_cur_buffer(search_str)" lines = $buffer.split("\n") r = Regexp.new(Regexp.escape(search_str), Regexp::IGNORECASE) fpath = "" fpath = $buffer.pathname.expand_path.to_s + ":" if $buffer.pathname res_str = "" $grep_matches = [] lines.each_with_index { |l, i| if r.match(l) # res_str << "#{fpath}#{i + 1}:#{l}\n" res_str << "#{i + 1}:#{l}\n" $grep_matches << i + 1 # Lines start from index 1 end } $grep_bufid = $buffers.current_buf b = create_new_file(nil, res_str) # set_current_buffer(buffer_i, update_history = true) # @current_buf = buffer_i b.line_action_handler = proc { |lineno| puts "GREP HANDLER:#{lineno}" jumpto = $grep_matches[lineno] if jumpto.class == Integer $buffers.set_current_buffer($grep_bufid, update_history = true) buf.jump_to_line(jumpto) end } end
gui_ack()
click to toggle source
Interface for ack! beyondgrep.com/
# File lib/vimamsa/ack.rb, line 3 def gui_ack() nfo = "<html><h2>Search contents of all files using ack</h2> <div style='width:300px'> <p>Hint: add empty file named .vma_project to dirs you want to search.</p>\n<p>If .vma_project exists in parent dir of current file, searches within that dir</p></div></html>" nfo = "<span size='x-large'>Search contents of all files using ack</span> <span>Hint: add empty file named .vma_project to directories you want to search in. If .vma_project exists in parent directory of current file, searches within that directory. </span>" callback = proc{|x| ack_buffer(x)} gui_one_input_action(nfo, "Search:", "search", callback) end
gui_add_image(imgpath, pos)
click to toggle source
# File lib/vimamsa/gui.rb, line 172 def gui_add_image(imgpath, pos) end
gui_create_buffer(id)
click to toggle source
# File lib/vimamsa/gui.rb, line 134 def gui_create_buffer(id) puts "gui_create_buffer(#{id})" buf1 = GtkSource::Buffer.new() view = VSourceView.new() view.set_highlight_current_line(true) view.set_show_line_numbers(true) view.set_buffer(buf1) ssm = GtkSource::StyleSchemeManager.new ssm.set_search_path(ssm.search_path << ppath("styles/")) # sty = ssm.get_scheme("dark") sty = ssm.get_scheme("molokai_edit") # puts ssm.scheme_ids view.buffer.highlight_matching_brackets = true view.buffer.style_scheme = sty provider = Gtk::CssProvider.new provider.load(data: "textview { font-family: Monospace; font-size: 11pt; }") # provider.load(data: "textview { font-family: Arial; font-size: 12pt; }") view.style_context.add_provider(provider) view.wrap_mode = :char $vmag.buffers[id] = view end
gui_file_finder_handle_char(c)
click to toggle source
# File lib/vimamsa/file_finder.rb, line 90 def gui_file_finder_handle_char(c) puts "BUFFER SELECTOR INPUT CHAR: #{c}" buffer_i = $select_keys.index(c) if buffer_i != nil gui_file_finder_callback(buffer_i) end end
gui_file_finder_init()
click to toggle source
TODO: delete?
# File lib/vimamsa/file_finder.rb, line 99 def gui_file_finder_init() $kbd.add_mode("Z", :filefinder) bindkey "Z enter", "$kbd.set_mode(:command)" bindkey "Z return", "$kbd.set_mode(:command)" end
gui_file_finder_select_callback(search_str, idx)
click to toggle source
# File lib/vimamsa/file_finder.rb, line 83 def gui_file_finder_select_callback(search_str, idx) selected_file = $file_search_list[idx][0] debug "FILE FINDER SELECT CALLBACK: s=#{search_str},i=#{idx}: #{selected_file}" gui_select_window_close(0) open_new_file(selected_file) end
gui_file_finder_update_callback(search_str = "")
click to toggle source
# File lib/vimamsa/file_finder.rb, line 71 def gui_file_finder_update_callback(search_str = "") puts "FILE FINDER UPDATE CALLBACK: #{search_str}" if (search_str.size > 1) files = filter_files(search_str) $file_search_list = files return files #puts files.inspect #return files.values end return [] end
gui_file_history_select_callback(search_str, idx)
click to toggle source
# File lib/vimamsa/file_history.rb, line 100 def gui_file_history_select_callback(search_str, idx) # selected_file = $file_search_list[idx][0] selected_file = $search_list[idx][0] debug "FILE HISTORY SELECT CALLBACK: s=#{search_str},i=#{idx}: #{selected_file}" gui_select_window_close(0) open_new_file(selected_file) end
gui_file_history_update_callback(search_str = "")
click to toggle source
# File lib/vimamsa/file_history.rb, line 85 def gui_file_history_update_callback(search_str = "") puts "gui_file_history_update_callback: #{search_str}" return [] if $vma.fh.history.empty? $search_list = [] files = $vma.fh.history.keys.sort.collect { |x| [x, 0] } if (search_str.size > 1) files = fuzzy_filter(search_str, $vma.fh.history.keys, 40) end $search_list = files ret = files.collect{|x|[x[0]]} return ret end
gui_file_saveas(dirpath)
click to toggle source
# File lib/vimamsa/gui.rb, line 20 def gui_file_saveas(dirpath) dialog = Gtk::FileChooserDialog.new(:title => "Save as", :action => :save, :buttons => [[Gtk::Stock::SAVE, :accept], [Gtk::Stock::CANCEL, :cancel]]) dialog.set_current_folder(dirpath) dialog.signal_connect("response") do |dialog, response_id| if response_id == Gtk::ResponseType::ACCEPT file_saveas(dialog.filename) end dialog.destroy end dialog.run end
gui_find_macro_select_callback(search_str, idx)
click to toggle source
# File lib/vimamsa/macro.rb, line 16 def gui_find_macro_select_callback(search_str, idx) puts "gui_find_macro_select_callback" selected = $macro_search_list[idx] m = $macro.named_macros[selected[0]].clone puts "SELECTED MACRO:#{selected}, #{m}" id = $macro.last_macro $macro.recorded_macros[id] = m $macro.run_macro(id) end
gui_find_macro_update_callback(search_str = "")
click to toggle source
# File lib/vimamsa/macro.rb, line 2 def gui_find_macro_update_callback(search_str = "") puts "gui_find_macro_update_callback: #{search_str}" heystack = $macro.named_macros return [] if heystack.empty? $macro_search_list = [] files = heystack.keys.sort.collect { |x| [x, 0] } if (search_str.size > 1) files = fuzzy_filter(search_str, heystack.keys, 40) end $macro_search_list = files return files end
gui_grep()
click to toggle source
# File lib/vimamsa/search_replace.rb, line 66 def gui_grep() callback = proc { |x| grep_cur_buffer(x) } # gui_one_input_action("Grep", "Search:", "grep", "grep_cur_buffer") gui_one_input_action("Grep", "Search:", "grep", callback) end
gui_one_input_action(title, field_label, button_title, callback)
click to toggle source
# File lib/vimamsa/search_replace.rb, line 107 def gui_one_input_action(title, field_label, button_title, callback) a = OneInputAction.new(nil, title, field_label, button_title, callback) a.run return end
gui_open_file_dialog(dirpath)
click to toggle source
# File lib/vimamsa/gui.rb, line 3 def gui_open_file_dialog(dirpath) dialog = Gtk::FileChooserDialog.new(:title => "Open file", :action => :open, :buttons => [[Gtk::Stock::OPEN, :accept], [Gtk::Stock::CANCEL, :cancel]]) dialog.set_current_folder(dirpath) dialog.signal_connect("response") do |dialog, response_id| if response_id == Gtk::ResponseType::ACCEPT open_new_file(dialog.filename) # puts "uri = #{dialog.uri}" end dialog.destroy end dialog.run end
gui_replace_callback(vals)
click to toggle source
def gui_replace_callback
(search_str, replace_str)
# File lib/vimamsa/search_replace.rb, line 114 def gui_replace_callback(vals) search_str = vals["search"] replace_str = vals["replace"] puts "gui_replace_callback: #{search_str} => #{replace_str}" gui_select_window_close(0) buf_replace(search_str, replace_str) end
gui_search_replace()
click to toggle source
Search
and replace text via GUI interface
# File lib/vimamsa/search_replace.rb, line 123 def gui_search_replace() params = {} params["inputs"] = {} params["inputs"]["search"] = { :label => "Search", :type => :entry } params["inputs"]["replace"] = { :label => "Replace", :type => :entry } params["inputs"]["btn1"] = { :label => "Replace all", :type => :button } callback = proc { |x| gui_replace_callback(x) } params[:callback] = callback PopupFormGenerator.new(params).run end
gui_select_update_window(item_list, jump_keys, select_callback, update_callback, opt={})
click to toggle source
# File lib/vimamsa/gui_select_window.rb, line 1 def gui_select_update_window(item_list, jump_keys, select_callback, update_callback, opt={}) $selup = SelectUpdateWindow.new(nil, item_list, jump_keys, select_callback, update_callback, opt) $selup.run end
gui_select_window_close(arg = nil)
click to toggle source
TODO:?
# File lib/vimamsa/gui.rb, line 176 def gui_select_window_close(arg = nil) end
gui_set_buffer_contents(id, txt)
click to toggle source
def set_window_title(str) unimplemented end
# File lib/vimamsa/gui.rb, line 183 def gui_set_buffer_contents(id, txt) # $vbuf.set_text(txt) puts "gui_set_buffer_contents(#{id}, txt)" $vmag.buffers[id].buffer.set_text(txt) end
gui_set_current_buffer(id)
click to toggle source
# File lib/vimamsa/gui.rb, line 195 def gui_set_current_buffer(id) view = $vmag.buffers[id] puts "gui_set_current_buffer(#{id}), view=#{view}" buf1 = view.buffer $vmag.view = view $vmag.buf1 = buf1 $view = view $vbuf = buf1 $vmag.sw.remove($vmag.sw.child) if !$vmag.sw.child.nil? $vmag.sw.add(view) view.grab_focus #view.set_focus(10) view.set_cursor_visible(true) #view.move_cursor(1, 1, false) view.place_cursor_onscreen #TODO: # itr = view.buffer.get_iter_at(:offset => 0) # view.buffer.place_cursor(itr) # wtitle = "" # wtitle = buf.fname if !buf.fname.nil? $vmag.sw.show_all end
gui_set_cursor_pos(id, pos)
click to toggle source
# File lib/vimamsa/gui.rb, line 190 def gui_set_cursor_pos(id, pos) $view.set_cursor_pos(pos) # Ripl.start :binding => binding end
gui_set_file_lang(id, lname)
click to toggle source
# File lib/vimamsa/gui.rb, line 161 def gui_set_file_lang(id, lname) view = $vmag.buffers[id] lm = GtkSource::LanguageManager.new lang = nil lm.set_search_path(lm.search_path << ppath("lang/")) lang = lm.get_language(lname) view.buffer.language = lang view.buffer.highlight_syntax = true end
gui_set_window_title(wtitle, subtitle = "")
click to toggle source
# File lib/vimamsa/gui.rb, line 222 def gui_set_window_title(wtitle, subtitle = "") $vmag.window.title = wtitle $vmag.window.titlebar.subtitle = subtitle end
gui_sleep(t2)
click to toggle source
TODO: remove?
# File lib/vimamsa/debug.rb, line 99 def gui_sleep(t2) t1 = Time.now() while Time.now < t1 + t2 sleep(0.02) end end
handle_drag_and_drop(fname)
click to toggle source
# File lib/vimamsa/editor.rb, line 17 def handle_drag_and_drop(fname) debug "EDITOR:handle_drag_and_drop" buf.handle_drag_and_drop(fname) end
handle_key_event(event)
click to toggle source
# File lib/vimamsa/key_binding_tree.rb, line 613 def handle_key_event(event) $kbd.handle_key_event(event) end
history_switch_backwards()
click to toggle source
# File lib/vimamsa/key_actions.rb, line 9 def history_switch_backwards bufs.history_switch_backwards end
history_switch_forwards()
click to toggle source
# File lib/vimamsa/key_actions.rb, line 13 def history_switch_forwards bufs.history_switch_forwards end
hook_draw()
click to toggle source
# File lib/vimamsa/editor.rb, line 538 def hook_draw() # TODO: as hook.register # easy_jump_draw() end
hpt_check_cur_word(w)
click to toggle source
# File lib/vimamsa/hyper_plain_text.rb, line 6 def hpt_check_cur_word(w) puts "check_cur_word(w)" m = w.match(/⟦(.*)⟧/) if m fpfx = m[1] if $buffer.fname dn = File.dirname($buffer.fname) fcands = [] fcands << "#{dn}/#{fpfx}" fcands << "#{dn}/#{fpfx}.txt" fcands << File.expand_path("#{fpfx}") fcands << File.expand_path("#{fpfx}.txt") fn = nil for fc in fcands if File.exists?(fc) fn = fc break end end if fn message "HPT opening file #{fn}" return fn # open_existing_file(fn) # return true else message "File not found: #{fpfx}" end end end return nil end
hpt_open_link()
click to toggle source
# File lib/vimamsa/hyper_plain_text.rb, line 3 def hpt_open_link() end
hpt_scan_images()
click to toggle source
# File lib/vimamsa/hyper_plain_text.rb, line 41 def hpt_scan_images() return if !buf.fname return if !buf.fname.match(/.*txt$/) imgpos = scan_indexes(buf, /⟦img:.+?⟧/) imgtags = buf.scan(/(⟦img:(.+?)⟧)/) # i = 0 c = 0 imgpos.each.with_index { |x, i| a = imgpos[i] t = imgtags[i] insert_pos = a + t[0].size + c imgfn = File.expand_path(t[1]) # Ripl.start :binding => binding next if !File.exist?(imgfn) if buf[insert_pos..(insert_pos + 2)] != "\n \n" buf.insert_txt_at("\n \n", insert_pos) c += 3 end buf.add_image(imgfn, insert_pos + 1) } end
idle_func()
click to toggle source
# File lib/vimamsa/gui.rb, line 36 def idle_func # puts "IDLEFUNC" if $idle_scroll_to_mark # Ripl.start :binding => binding # $view.get_visible_rect vr = $view.visible_rect # iter = b.get_iter_at(:offset => i) b = $view.buffer iter = b.get_iter_at(:offset => b.cursor_position) iterxy = $view.get_iter_location(iter) # puts "ITERXY" + iterxy.inspect # Ripl.start :binding => binding intr = iterxy.intersect(vr) if intr.nil? $view.set_cursor_pos($view.buffer.cursor_position) else $idle_scroll_to_mark = false end sleep(0.1) end sleep(0.01) return true end
invoke_command()
click to toggle source
# File lib/vimamsa/editor.rb, line 378 def invoke_command() start_minibuffer_cmd("", "", :execute_command) end
invoke_grep_search()
click to toggle source
# File lib/vimamsa/search_replace.rb, line 103 def invoke_grep_search() start_minibuffer_cmd("", "", :grep_cur_buffer) end
invoke_replace()
click to toggle source
# File lib/vimamsa/search_replace.rb, line 135 def invoke_replace() start_minibuffer_cmd("", "", :buf_replace_string) end
invoke_search()
click to toggle source
# File lib/vimamsa/search.rb, line 9 def invoke_search() nfo = "" callback = proc{|x| execute_search(x)} gui_one_input_action(nfo, "Search:", "search", callback) end
is_command_mode()
click to toggle source
# File lib/vimamsa/key_actions.rb, line 21 def is_command_mode() return true if $kbd.mode_root_state.to_s() == "C" return false end
is_existing_file(s)
click to toggle source
# File lib/vimamsa/util.rb, line 73 def is_existing_file(s) return false if !s if is_path(s) and File.exist?(File.expand_path(s)) return true end return false end
is_image_file(fpath)
click to toggle source
# File lib/vimamsa/util.rb, line 81 def is_image_file(fpath) return false if !File.exist?(fpath) return false if !fpath.match(/.(jpg|jpeg|png)$/i) #TODO: check contents of file return true end
is_path(s)
click to toggle source
# File lib/vimamsa/util.rb, line 95 def is_path(s) m = s.match(/(~[a-z]*)?\/.*\//) if m != nil return true end return false end
is_path_writable(fpath)
click to toggle source
# File lib/vimamsa/buffer.rb, line 1754 def is_path_writable(fpath) r = false if fpath.class == String r = true if File.writable?(Pathname.new(fpath).dirname) end return r end
is_text_file(fpath)
click to toggle source
# File lib/vimamsa/util.rb, line 88 def is_text_file(fpath) return false if !File.exist?(fpath) return false if !fpath.match(/.(txt|cpp|h|rb|c|php|java|py)$/i) #TODO: check contents of file return true end
is_url(s)
click to toggle source
# File lib/vimamsa/util.rb, line 54 def is_url(s) return s.match(/(https?|file):\/\/.*/) != nil end
is_visual_mode()
click to toggle source
# File lib/vimamsa/key_actions.rb, line 26 def is_visual_mode() return 1 if $kbd.mode_root_state.to_s() == "V" return 0 end
jump_to_file(filename, linenum = 0)
click to toggle source
# File lib/vimamsa/editor.rb, line 500 def jump_to_file(filename, linenum = 0) open_new_file(filename) if linenum > 0 $buffer.jump_to_line(linenum) center_on_current_line end end
jump_to_next_edit()
click to toggle source
# File lib/vimamsa/key_actions.rb, line 17 def jump_to_next_edit buf.jump_to_next_edit end
load_buffer(fname)
click to toggle source
# File lib/vimamsa/editor.rb, line 482 def load_buffer(fname) return if !File.exist?(fname) existing_buffer = $buffers.get_buffer_by_filename(fname) if existing_buffer != nil $buffer_history << existing_buffer return end debug("LOAD BUFFER: #{fname}") buffer = Buffer.new(read_file("", fname), fname) # gui_set_current_buffer(buffer.id) buffer.set_active debug("DONE LOAD: #{fname}") #buf = filter_buffer(buffer) # debug("END FILTER: #{fname}") $buffers << buffer #$buffer_history << $buffers.size - 1 end
load_buffer_list()
click to toggle source
# File lib/vimamsa/buffer_list.rb, line 11 def load_buffer_list() message("Load buffer list") buffn = get_dot_path("buffers.txt") return if !File.exist?(buffn) bufstr = IO.read(buffn) bufl = eval(bufstr) debug bufl for b in bufl load_buffer(b) if b != nil and File.file?(b) end end
log_error(message)
click to toggle source
# File lib/vimamsa/debug.rb, line 29 def log_error(message) puts "====== ERROR =====" puts caller[0] puts message puts "==================" $errors << [message, caller] #TODO end
log_message(message)
click to toggle source
# File lib/vimamsa/debug.rb, line 24 def log_message(message) puts message $log_messages << message end
message(s)
click to toggle source
# File lib/vimamsa/editor.rb, line 425 def message(s) s = "[#{DateTime.now().strftime("%H:%M")}] #{s}" puts s $vmag.add_to_minibuf(s) # $minibuffer = Buffer.new(s, "") # $minibuffer[0..-1] = s # TODO #render_minibuffer end
minibuffer_cancel()
click to toggle source
# File lib/vimamsa/editor.rb, line 399 def minibuffer_cancel() debug "minibuffer_cancel" $kbd.set_mode(:command) minibuffer_input = $minibuffer.to_s[0..-2] # $minibuffer.call_func.call('') end
minibuffer_delete()
click to toggle source
def readchar_new_char© $input_char_call_func.call© end
# File lib/vimamsa/editor.rb, line 421 def minibuffer_delete() $minibuffer.delete(BACKWARD_CHAR) end
minibuffer_end()
click to toggle source
# File lib/vimamsa/editor.rb, line 392 def minibuffer_end() debug "minibuffer_end" $kbd.set_mode(:command) minibuffer_input = $minibuffer.to_s[0..-2] return $minibuffer.call_func.call(minibuffer_input) end
minibuffer_new_char(c)
click to toggle source
# File lib/vimamsa/editor.rb, line 406 def minibuffer_new_char(c) if c == "\r" raise "Should not come here" debug "MINIBUFFER END" else $minibuffer.insert_txt(c) debug "MINIBUFFER: #{c}" end #$buffer = $minibuffer end
missing_callfunc()
click to toggle source
# File lib/vimamsa/actions.rb, line 30 def missing_callfunc puts "missing_callfunc" end
mkdir_if_not_exists(_dirpath)
click to toggle source
# File lib/vimamsa/editor.rb, line 22 def mkdir_if_not_exists(_dirpath) dirpath = File.expand_path(_dirpath) Dir.mkdir(dirpath) unless File.exist?(dirpath) end
open_existing_file(filename)
click to toggle source
TODO: needed?
# File lib/vimamsa/editor.rb, line 509 def open_existing_file(filename) open_new_file(filename) end
open_file_dialog()
click to toggle source
# File lib/vimamsa/editor.rb, line 280 def open_file_dialog() path = "" path = $buffer.fname if $buffer.fname gui_open_file_dialog(File.dirname(path)) end
open_new_file(filename, file_contents = "")
click to toggle source
# File lib/vimamsa/editor.rb, line 513 def open_new_file(filename, file_contents = "") #TODO: expand path filename = File.expand_path(filename) b = $buffers.get_buffer_by_filename(filename) # File is already opened to existing buffer if b != nil message "Switching to: #{filename}" $buffers.set_current_buffer(b) else message "New file opened: #{filename}" fname = filename load_buffer(fname) end end
open_url(url)
click to toggle source
# File lib/vimamsa/editor.rb, line 586 def open_url(url) system("xdg-open", url) end
open_with_default_program(url)
click to toggle source
# File lib/vimamsa/editor.rb, line 590 def open_with_default_program(url) system("xdg-open", url) end
page_down()
click to toggle source
# File lib/vimamsa/gui.rb, line 87 def page_down $view.signal_emit("move-cursor", Gtk::MovementStep.new(:PAGES), 1, false) return true end
page_up()
click to toggle source
# File lib/vimamsa/gui.rb, line 82 def page_up $view.signal_emit("move-cursor", Gtk::MovementStep.new(:PAGES), -1, false) return true end
paste_register(char)
click to toggle source
# File lib/vimamsa/editor.rb, line 641 def paste_register(char) $c = $register[char] message("Paste: #{$c}") end
paste_system_clipboard()
click to toggle source
# File lib/vimamsa/gui.rb, line 92 def paste_system_clipboard() # clipboard = $vmag.window.get_clipboard(Gdk::Selection::CLIPBOARD) utf8_string = Gdk::Atom.intern("UTF8_STRING") # x = clipboard.request_contents(utf8_string) widget = Gtk::Invisible.new clipboard = Gtk::Clipboard.get_default($vmag.window.display) received_text = "" target_string = Gdk::Selection::TARGET_STRING ti = clipboard.request_contents(target_string) # clipboard.request_contents(target_string) do |_clipboard, selection_data| # received_text = selection_data.text # puts "received_text=#{received_text}" # end if clipboard.wait_is_text_available? received_text = clipboard.wait_for_text end if received_text != "" and !received_text.nil? max_clipboard_items = 100 if received_text != $clipboard[-1] #TODO: HACK $paste_lines = false end $clipboard << received_text # puts $clipboard[-1] $clipboard = $clipboard[-([$clipboard.size, max_clipboard_items].min)..-1] end return received_text end
ppath(s)
click to toggle source
# File lib/vimamsa/util.rb, line 65 def ppath(s) selfpath = __FILE__ selfpath = File.readlink(selfpath) if File.lstat(selfpath).symlink? scriptdir = File.expand_path(File.dirname(selfpath)) p = "#{scriptdir}/../../#{s}" return File.expand_path(p) end
read_file(text, path)
click to toggle source
# File lib/vimamsa/util.rb, line 23 def read_file(text, path) path = Pathname(path.to_s).expand_path FileUtils.touch(path) unless File.exist?(path) if !File.exist?(path) #TODO: fail gracefully return end encoding = text.encoding content = path.open("r:#{encoding.name}") { |io| io.read } debug("GUESS ENCODING") unless content.valid_encoding? # take a guess GUESS_ENCODING_ORDER.find { |enc| content.force_encoding(enc) content.valid_encoding? } content.encode!(Encoding::UTF_8) end debug("END GUESS ENCODING") #TODO: Should put these as option: content.gsub!(/\r\n/, "\n") # content.gsub!(/\t/, " ") content.gsub!(/\b/, "") # content = filter_buffer(content) debug("END FILTER") return content end
recursively_find_files()
click to toggle source
# File lib/vimamsa/file_finder.rb, line 38 def recursively_find_files() debug("START find files") dlist = [] for d in $search_dirs debug("FIND FILEs IN #{d}") dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and $find_extensions.include?(File.extname(e)) } debug("FIND FILEs IN #{d} END") end #$dir_list = Dir.glob('./**/*').select { |e| File.file? e } debug("END find files2") $dir_list = dlist debug("END find files") return $dir_list end
reg_act(id, callfunc, name = "", opt = {})
click to toggle source
# File lib/vimamsa/actions.rb, line 16 def reg_act(id, callfunc, name = "", opt = {}) if callfunc.class == Proc a = Action.new(id, name, callfunc, opt) else begin m = method(callfunc) rescue NameError m = method("missing_callfunc") end a = Action.new(id, name, m, opt) end return a end
render_buffer(buffer = 0, reset = 0)
click to toggle source
# File lib/vimamsa/editor.rb, line 543 def render_buffer(buffer = 0, reset = 0) tmpbuf = $buffer.to_s debug "pos:#{$buffer.pos} L:#{$buffer.lpos} C:#{$buffer.cpos}" pos = $buffer.pos selection_start = $buffer.selection_start if $buffer.need_redraw? reset = 1 end t1 = Time.now hook_draw() if $buffer.need_redraw? hpt_scan_images() if $debug #experimental end $buffer.highlight if Time.now - t1 > 1 / 100.0 debug "SLOW render" debug "Render time: #{Time.now - t1}" end $buffer.set_redrawed if reset == 1 end
repeat_last_action()
click to toggle source
# File lib/vimamsa/editor.rb, line 329 def repeat_last_action() cmd = $command_history.last cmd[:method].call *cmd[:params] if cmd != nil end
repeat_last_find()
click to toggle source
# File lib/vimamsa/editor.rb, line 334 def repeat_last_find() return if !defined? $last_find_command $buffer.jump_to_next_instance_of_char($last_find_command[:char], $last_find_command[:direction]) end
run_cmd(cmd)
click to toggle source
# File lib/vimamsa/editor.rb, line 594 def run_cmd(cmd) tmpf = Tempfile.new("vmarun", "/tmp").path cmd = "#{cmd} > #{tmpf}" puts "CMD:\n#{cmd}" system("bash", "-c", cmd) res_str = File.read(tmpf) return res_str end
run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
click to toggle source
# File lib/vimamsa/debug.rb, line 106 def run_random_jump_test__tmpl(test_time = 60 * 60 * 10) open_new_file("TODO"); gui_sleep(0.1) ttstart = Time.now Kernel.srand(1231) step = 0 while Time.now < ttstart + test_time debug "step=#{step}" buf.jump_to_random_pos buf.insert_txt("Z") if rand() > 0.25 buf.reset_highlight() if rand() > 0.1 gui_trigger_event # puts "========line:=========" # puts buf.current_line() # puts "======================" render_buffer($buffer) gui_sleep(rand() / 2) if rand() < (1 / 40.0) buf.revert end gui_trigger_event buf.insert_txt("X") if rand() > 0.25 render_buffer($buffer) $buffers.set_current_buffer(rand($buffers.size)) if rand > 0.25 step += 1 end end
run_test(test_id)
click to toggle source
# File lib/vimamsa/debug.rb, line 81 def run_test(test_id) target_results = read_file("", "tests/test_#{test_id}_output.txt") old_buffer = $buffer $buffer = Buffer.new("", "") load "tests/test_#{test_id}.rb" test_ok = $buffer.to_s.strip == target_results.strip puts "##################" puts target_results puts "##################" puts $buffer.to_s puts "##################" puts "TEST OK" if test_ok puts "TEST FAILED" if !test_ok puts "##################" $buffer = old_buffer end
run_tests()
click to toggle source
# File lib/vimamsa/debug.rb, line 76 def run_tests() run_test("01") run_test("02") end
save_buffer_list()
click to toggle source
# File lib/vimamsa/buffer_list.rb, line 2 def save_buffer_list() message("Save buffer list") buffn = get_dot_path("buffers.txt") f = File.open(buffn, "w") bufstr = $buffers.collect { |buf| buf.fname }.inspect f.write(bufstr) f.close() end
savedebug(message, e)
click to toggle source
# File lib/vimamsa/debug.rb, line 45 def savedebug(message, e) FileUtils.mkdir_p("debug") puts "savedebug()" dbginfo = {} dbginfo["message"] = message dbginfo["debuginfo"] = $debuginfo dbginfo["trace"] = caller() dbginfo["trace"] = e.backtrace() if e dbginfo["trace_str"] = dbginfo["trace"].join("\n") dbginfo["edit_history"] = buf.edit_history dbginfo["cnf"] = $cnf dbginfo["register"] = $register dbginfo["clipboard"] = $clipboard # dbginfo["last_event"] = $last_event dbginfo["buffer"] = {} dbginfo["buffer"]["str"] = buf.to_s dbginfo["buffer"]["lpos"] = buf.lpos dbginfo["buffer"]["cpos"] = buf.cpos dbginfo["buffer"]["pos"] = buf.pos pfxs = DateTime.now().strftime("%d%m%Y_%H%M%S") save_fn_dump = sprintf("debug/crash_%s.marshal", pfxs) save_fn_json = sprintf("debug/crash_%s.json", pfxs) mdump = Marshal.dump(dbginfo) IO.binwrite(save_fn_dump, mdump) IO.write(save_fn_json, dbginfo.to_json) puts "SAVED CRASH INFO TO:" puts save_fn_dump puts save_fn_json end
scan_indexes(txt, regex)
click to toggle source
# File lib/vimamsa/rbvma.rb, line 57 def scan_indexes(txt, regex) # indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) + 1 } indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) } return indexes end
scan_word_start_marks(search_str)
click to toggle source
# File lib/vimamsa/editor.rb, line 528 def scan_word_start_marks(search_str) # \Z = end of string, just before last newline. wsmarks = scan_indexes(search_str, /(?<=[^\p{Word}])\p{Word}|\Z/) return wsmarks end
search_actions()
click to toggle source
# File lib/vimamsa/actions.rb, line 48 def search_actions() l = [] $select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"] gui_select_update_window(l, $select_keys.collect { |x| x.upcase }, "search_actions_select_callback", "search_actions_update_callback") end
search_actions_select_callback(search_str, idx)
click to toggle source
# File lib/vimamsa/actions.rb, line 87 def search_actions_select_callback(search_str, idx) item = $item_list[idx][2] acc = item[0][:action] puts "Selected:" + acc.to_s gui_select_window_close(0) if acc.class == String eval(acc) elsif acc.class == Symbol puts "Symbol" call(acc) end end
search_actions_update_callback(search_str = "")
click to toggle source
# File lib/vimamsa/actions.rb, line 58 def search_actions_update_callback(search_str = "") return [] if search_str == "" item_list2 = [] for act_id in $actions.keys act = $actions[act_id] item = {} item[:key] = "" item[:action] = act_id item[:str] = act_id.to_s if $actions[act_id].method_name != "" item[:str] = $actions[act_id].method_name end item_list2 << item end item_list = item_list2 a = filter_items(item_list, 0, search_str) puts a.inspect r = a.collect { |x| [x[0][0], 0, x] } puts r.inspect $item_list = r r = a.collect { |x| ["[#{x[0][:key]}] #{x[0][:str]}", 0, x] } return r end
set_clipboard(s)
click to toggle source
# File lib/vimamsa/editor.rb, line 297 def set_clipboard(s) if !(s.class <= String) or s.size == 0 puts s.inspect puts [s, s.class, s.size] log_error("s.class != String or s.size == 0") Ripl.start :binding => binding return end $clipboard << s set_system_clipboard(s) $register[$cur_register] = s debug "SET CLIPBOARD: [#{s}]" debug "REGISTER: #{$cur_register}:#{$register[$cur_register]}" end
set_conf(id, val)
click to toggle source
# File lib/vimamsa/key_binding_tree.rb, line 27 def set_conf(id, val) $cnf[id] = val end
set_cursor_pos(new_pos)
click to toggle source
# File lib/vimamsa/editor.rb, line 312 def set_cursor_pos(new_pos) buf.set_pos(new_pos) #render_buffer($buffer) debug "New pos: #{new_pos}lpos:#{$buffer.lpos} cpos:#{$buffer.cpos}" end
set_last_command(cmd)
click to toggle source
# File lib/vimamsa/editor.rb, line 318 def set_last_command(cmd) $command_history << cmd end
set_next_command_count(num)
click to toggle source
# File lib/vimamsa/editor.rb, line 340 def set_next_command_count(num) if $next_command_count != nil $next_command_count = $next_command_count * 10 + num.to_i else $next_command_count = num.to_i end debug("NEXT COMMAND COUNT: #{$next_command_count}") end
set_register(char)
click to toggle source
# File lib/vimamsa/editor.rb, line 636 def set_register(char) $cur_register = char message("Set register #{char}") end
set_system_clipboard(arg)
click to toggle source
# File lib/vimamsa/gui.rb, line 125 def set_system_clipboard(arg) # return if arg.class != String # return if s.size < 1 # utf8_string = Gdk::Atom.intern("UTF8_STRING") widget = Gtk::Invisible.new clipboard = Gtk::Clipboard.get_default($vmag.window.display) clipboard.text = arg end
setcnf(id, val)
click to toggle source
# File lib/vimamsa/key_binding_tree.rb, line 31 def setcnf(id, val) set_conf(id, val) end
show_key_bindings()
click to toggle source
# File lib/vimamsa/editor.rb, line 355 def show_key_bindings() kbd_s = "❙Key bindings❙\n" kbd_s << "=======================================\n" kbd_s << $kbd.to_s kbd_s << "\n=======================================\n" create_new_file(nil, kbd_s) end
start_minibuffer_cmd(bufname, bufstr, cmd)
click to toggle source
# File lib/vimamsa/editor.rb, line 349 def start_minibuffer_cmd(bufname, bufstr, cmd) $kbd.set_mode(:minibuffer) $minibuffer = Buffer.new(bufstr, "") $minibuffer.call_func = method(cmd) end
start_ripl()
click to toggle source
# File lib/vimamsa/debug.rb, line 140 def start_ripl Ripl.start :binding => binding end
system_clipboard_changed(clipboard_contents)
click to toggle source
# File lib/vimamsa/editor.rb, line 286 def system_clipboard_changed(clipboard_contents) max_clipboard_items = 100 if clipboard_contents != $clipboard[-1] #TODO: HACK $paste_lines = false end $clipboard << clipboard_contents # puts $clipboard[-1] $clipboard = $clipboard[-([$clipboard.size, max_clipboard_items].min)..-1] end
unimplemented()
click to toggle source
# File lib/vimamsa/rbvma.rb, line 50 def unimplemented puts "unimplemented" end
update_file_index()
click to toggle source
# File lib/vimamsa/file_finder.rb, line 30 def update_file_index() message("Start updating file index") Thread.new { recursively_find_files() message("Finnish updating file index") } end
vma()
click to toggle source
# File lib/vimamsa/main.rb, line 56 def vma() return $vma end
which(cmd)
click to toggle source
From stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby Cross-platform way of finding an executable in the $PATH.
which('ruby') #=> /usr/bin/ruby
# File lib/vimamsa/util.rb, line 6 def which(cmd) exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""] ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end
write_to_file(savepath, s)
click to toggle source
TODO
# File lib/vimamsa/buffer.rb, line 1746 def write_to_file(savepath, s) if is_path_writable(savepath) IO.write(savepath, $buffer.to_s) else message("PATH NOT WRITABLE: #{savepath}") end end