Class: FileHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/vimamsa/file_history.rb

Overview

History of previously opened files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileHistory

Returns a new instance of FileHistory.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vimamsa/file_history.rb', line 6

def initialize()
  # puts self.method("update")
  # x = self.method("update")
  # x.call("ASFASF")

  $hook.register(:change_buffer, self.method("update"))
  $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

#historyObject

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_nonexistingObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vimamsa/file_history.rb', line 41

def remove_nonexisting()
  size_orig = @history.size
  for k, v in @history
    if !File.exist?(k)
      @history.delete(k)
      log_message("Delete #{k} from history")
    end
  end
  size_new = @history.size
  message("History size #{size_orig} => #{size_new}")
end

#saveObject



37
38
39
# File 'lib/vimamsa/file_history.rb', line 37

def save()
  vma.marshal_save("file_history", @history)
end

#start_guiObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vimamsa/file_history.rb', line 53

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

def self.init() end



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vimamsa/file_history.rb', line 23

def update(buf)
  puts "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
  puts @history

  # puts "FileHistory.update(buf=#{buf})"
end