Class: FileHistory
- Inherits:
-
Object
- Object
- FileHistory
- Defined in:
- lib/vimamsa/file_history.rb
Overview
History of previously opened files
Instance Attribute Summary collapse
-
#history ⇒ Object
Returns the value of attribute history.
Instance Method Summary collapse
-
#initialize ⇒ FileHistory
constructor
A new instance of FileHistory.
- #remove_nonexisting ⇒ Object
- #save ⇒ Object
- #start_gui ⇒ Object
- #update(buf) ⇒ Object
Constructor Details
#initialize ⇒ FileHistory
Returns a new instance of FileHistory.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vimamsa/file_history.rb', line 6 def initialize() vma.hook.register(:change_buffer, self.method("update")) vma.hook.register(:shutdown, self.method("save")) reg_act(:fhist_remove_nonexisting, proc { remove_nonexisting }, "Cleanup history, remove non-existing files") @history = vma.marshal_load("file_history", {}) $search_list = [] end |
Instance Attribute Details
#history ⇒ Object
Returns the value of attribute history.
4 5 6 |
# File 'lib/vimamsa/file_history.rb', line 4 def history @history end |
Instance Method Details
#remove_nonexisting ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vimamsa/file_history.rb', line 33 def remove_nonexisting() size_orig = @history.size for k, v in @history if !File.exist?(k) @history.delete(k) ("Delete #{k} from history") end end size_new = @history.size ("History size #{size_orig} => #{size_new}") end |
#save ⇒ Object
29 30 31 |
# File 'lib/vimamsa/file_history.rb', line 29 def save() vma.marshal_save("file_history", @history) end |
#start_gui ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vimamsa/file_history.rb', line 45 def start_gui() return if $vma.fh.history.empty? l = [] $select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"] opt = { :title => "File history search", :desc => "Search for previously opened files. Fuzzy search." , :columns => [{:title=>'Filename',:id=>0}] } gui_select_update_window(l, $select_keys.collect { |x| x.upcase }, "gui_file_history_select_callback", "gui_file_history_update_callback", opt) end |
#update(buf) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vimamsa/file_history.rb', line 17 def update(buf) debug "FileHistory.update(buf=#{buf.fname})" return if !buf.fname @history[buf.fname] if !@history[buf.fname] if !@history[buf.fname] @history[buf.fname] = 1 else @history[buf.fname] += 1 end debug @history end |