class Editor
Attributes
converters[RW]
fh[RW]
file_content_search_paths[R]
file_name_search_paths[R]
gui[R]
kbd[RW]
paint_stack[RW]
Public Class Methods
new()
click to toggle source
attr_writer :call_func, :update_highlight
# File lib/vimamsa/editor.rb, line 32 def initialize() # Thread.new{10000.times{|x|sleep(3);10000.times{|y|y+2};puts "FOOTHREAD #{x}"}} # Search for content inside files (e.g. using ack/grep) in: @file_content_search_paths = [] # Search for files based on filenames in: @file_name_search_paths = [] #Regexp gsubs or other small modifiers of text @converters = {} @paint_stack = [] @_plugins = {} end
Public Instance Methods
add_content_search_path(pathstr)
click to toggle source
# File lib/vimamsa/editor.rb, line 230 def add_content_search_path(pathstr) p = File.expand_path(pathstr) if !@file_content_search_paths.include?(p) @file_content_search_paths << p end end
apply_conv(converter_id, txt)
click to toggle source
# File lib/vimamsa/editor.rb, line 243 def apply_conv(converter_id, txt) @converters[converter_id].apply(txt) end
buf()
click to toggle source
# File lib/vimamsa/editor.rb, line 182 def buf() return $buffer end
can_open_extension?(filepath)
click to toggle source
# File lib/vimamsa/editor.rb, line 257 def can_open_extension?(filepath) exts = $cnf[:extensions_to_open] extname = Pathname.new(filepath).extname.downcase can_open = exts.include?(extname) puts "CAN OPEN?: #{can_open}" return can_open end
get_content_search_paths()
click to toggle source
# File lib/vimamsa/editor.rb, line 247 def get_content_search_paths() r = @file_content_search_paths.clone p = find_project_dir_of_cur_buffer() if p and !@file_content_search_paths.include?(p) r.insert(0, p) end return r end
load_var_from_file(varname)
click to toggle source
# File lib/vimamsa/editor.rb, line 206 def load_var_from_file(varname) fn = get_dot_path(varname) if File.exist?(fn) vardata = IO.binread(fn) if vardata debug("Successfully red #{varname} from file #{fn}") return vardata end end return nil end
marshal_load(varname, default_data = nil)
click to toggle source
# File lib/vimamsa/editor.rb, line 190 def marshal_load(varname, default_data = nil) mdata = load_var_from_file(varname) if mdata return Marshal.load(mdata) else return default_data end end
marshal_save(varname, vardata)
click to toggle source
# File lib/vimamsa/editor.rb, line 186 def marshal_save(varname, vardata) save_var_to_file(varname, Marshal.dump(vardata)) end
open_file_listener(added)
click to toggle source
# File lib/vimamsa/editor.rb, line 48 def open_file_listener(added) if !added.empty? for fp in added sleep 0.1 x = IO.read(fp) File.delete(fp) for f in x.lines f.gsub!("\n", "") if File.exist?(f) if file_is_text_file(f) jump_to_file(f) end end end end end end
plug()
click to toggle source
# File lib/vimamsa/editor.rb, line 218 def plug() return @_plugins end
reg_conv(converter, converter_id)
click to toggle source
Register converter
# File lib/vimamsa/editor.rb, line 238 def reg_conv(converter, converter_id) @converters[converter_id] = converter reg_act(converter_id, proc { $buffer.convert_selected_text(converter_id) }, "Converter #{converter_id}", { :scope => [:selection] }) end
register_plugin(name, obj)
click to toggle source
# File lib/vimamsa/editor.rb, line 176 def register_plugin(name, obj) @_plugins[name] = obj # To access via e.g. vma.FileFinder self.define_singleton_method(name) { obj } end
save_state()
click to toggle source
# File lib/vimamsa/editor.rb, line 227 def save_state end
save_var_to_file(varname, vardata)
click to toggle source
# File lib/vimamsa/editor.rb, line 199 def save_var_to_file(varname, vardata) fn = get_dot_path(varname) f = File.open(fn, "w") File.binwrite(f, vardata) f.close end
shutdown()
click to toggle source
# File lib/vimamsa/editor.rb, line 222 def shutdown() $hook.call(:shutdown) save_state end
start()
click to toggle source
# File lib/vimamsa/editor.rb, line 66 def start # $highlight = {} # GLib::Idle.add # Ripl.start :binding => binding # GLib::Idle.add(proc{ puts "IDLEFUNC"}) # GLib::Idle.add(proc { idle_func }) @gui = $vmag #TODO $hook = Hook.new register_plugin(:Hook, $hook) $macro = Macro.new register_plugin(:Macro, $macro) $search = Search.new register_plugin(:Search, $search) $buffers = BufferList.new $minibuffer = Buffer.new(">", "") require "vimamsa/text_transforms" debug "ARGV: " + ARGV.inspect # build_key_bindings_tree @kbd = KeyBindingTree.new() $kbd = @kbd $kbd.add_mode("C", :command) $kbd.add_mode("I", :insert) $kbd.add_mode("V", :visual) $kbd.add_mode("M", :minibuffer) $kbd.add_mode("R", :readchar) $kbd.add_mode("B", :browse) $kbd.set_default_mode(:command) require "vimamsa/key_bindings_vimlike" sleep(0.03) FileManager.init mkdir_if_not_exists("~/.vimamsa") mkdir_if_not_exists("~/.vimamsa/backup") mkdir_if_not_exists("~/.vimamsa/listen") listen_dir = File.expand_path "~/.vimamsa/listen" listener = Listen.to(listen_dir) do |modified, added, removed| puts(modified: modified, added: added, removed: removed) open_file_listener(added) end listener.start $cnf[:theme] = "Twilight_edit" $cnf[:syntax_highlight] = true settings_path = get_dot_path("settings.rb") if File.exist?(settings_path) $cnf = eval(IO.read(settings_path)) end # set_gui_style(1) # Limit file search to these extensions: $find_extensions = [".txt", ".h", ".c", ".cpp", ".hpp", ".rb"] dotfile = read_file("", "~/.vimamsarc") eval(dotfile) if dotfile # build_options fname = nil if conf(:startup_file) fname_ = File.expand_path(conf(:startup_file)) if File.exist?(fname_) fname = fname_ end end fname = ARGV[0] if ARGV.size >= 1 and File.file?(File.expand_path(ARGV[0])) # vma.add_content_search_path(Dir.pwd) for fn in ARGV fn = File.expand_path(fn) if File.directory?(fn) vma.add_content_search_path(fn) $search_dirs << fn end end if fname buffer = Buffer.new(read_file("", fname), fname) else buffer = Buffer.new(" \n") end $buffers << buffer # load_theme($cnf[:theme]) # render_buffer($buffer, 1) #TODO # gui_select_buffer_init #TODO # gui_file_finder_init #TODO #Load plugins require "vimamsa/file_history.rb" @fh = FileHistory.new # @_plugins[:FileFinder] = FileFinder.new @_plugins[:FileHistory] = @fh register_plugin(:FileHistory, @fh) register_plugin(:FileFinder, FileFinder.new) # To access via vma.FileFinder # self.define_singleton_method(:FileFinder) { @_plugins[:FileFinder] } $hook.call(:after_init) end