Class: Buffers

Inherits:
Object show all
Defined in:
lib/xiki/buffers.rb

Class Method Summary collapse

Class Method Details

.current(*name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/xiki/buffers.rb', line 19

def self.current *name
  if name.empty?  # If no buffer passed in, show list
    case Keys.prefix :clear=>true

    # Show all by default
    when nil, "all";  return list.map{ |b| $el.buffer_name(b) }.map{ |o| "| #{o}\n" }.join('')

    # Only files (no buffers)
    when :u;  return list.select{ |b| $el.buffer_file_name(b) }.map{ |b| "| #{$el.buffer_name(b)}\n" }.join('')

    # Only buffer without files
    when 0;  return list.select{ |b| ! $el.buffer_file_name(b) }.map{ |b| "| #{$el.buffer_name(b)}\n" }[1..-1].join('')

    when 1;  return list.select{ |b| $el.buffer_file_name(b) }.map{ |b| $el.buffer_name(b) }[1..-1]
    when 3;  return list.select{ |b| ! $el.buffer_file_name(b) && $el.buffer_name(b) =~ /^#/ }.map{ |b| $el.buffer_name(b) }
    when 4;  return list.select{ |b| ! $el.buffer_file_name(b) && $el.buffer_name(b) =~ /^\*console / }.map{ |b| $el.buffer_name(b) }
    when 6;  return list.select{ |b| $el.buffer_file_name(b) =~ /\.rb$/ }.map{ |b| $el.buffer_name(b) }
    when 7;  return list.select{ |b| $el.buffer_file_name(b) =~ /\.notes$/ }.map{ |b| $el.buffer_name(b) }

    end
    return
  end

  # If a buffer name passed, get whole line and escape it

  name = Line.without_indent

  name.sub! /^\| /, ''

  # Switch to buffer
  View.to_after_bar if View.in_bar?
  View.to_buffer(name)
end

.delete(name) ⇒ Object



155
156
157
# File 'lib/xiki/buffers.rb', line 155

def self.delete name
  $el.kill_buffer name
end

.from_string(name) ⇒ Object



129
130
131
# File 'lib/xiki/buffers.rb', line 129

def self.from_string name
  $el.get_buffer name
end

.kill(name) ⇒ Object



151
152
153
# File 'lib/xiki/buffers.rb', line 151

def self.kill name
  self.delete name
end

.listObject



57
58
59
# File 'lib/xiki/buffers.rb', line 57

def self.list
  $el.buffer_list.to_a
end

buffer=nil



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/xiki/buffers.rb', line 3

def self.menu# buffer=nil
  "
  - .current/
  - .tree/
    - 20/
  - .search/

  > Lists
  - .list/
  - .current/

  - docs/
    > Todo
  "
end

.name(buffer) ⇒ Object



147
148
149
# File 'lib/xiki/buffers.rb', line 147

def self.name buffer
  $el.buffer_name(buffer)
end

.names_arrayObject



53
54
55
# File 'lib/xiki/buffers.rb', line 53

def self.names_array
  self.list.map { |b| $el.buffer_name(b) }.to_a
end

.open_viewingObject



133
134
135
136
137
138
139
# File 'lib/xiki/buffers.rb', line 133

def self.open_viewing
  case Keys.prefix
  when nil;  Launcher.open("- Buffers.tree 25/")
  when 0;  Launcher.open("- Buffers.tree/")
  else  Launcher.open("- Buffers.tree #{Keys.prefix}/")
  end
end

.renameObject



141
142
143
144
145
# File 'lib/xiki/buffers.rb', line 141

def self.rename
  options = {:prompt => "Rename buffer to: "}
  options[:initial_input] = $el.buffer_name if Keys.prefix_u?
  $el.rename_buffer Keys.input(options)
end

.search(string, options = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/xiki/buffers.rb', line 70

def self.search string, options={}

  orig = View.buffer

  # Get buffer from name
  list = options[:buffer] ?
    [self.from_string(options[:buffer])] :
    self.list
  found = ""

  list.to_a.each do |b|  # Each buffer open

    file = $el.buffer_file_name(b)
    #       file = $el.buffer_file_name(b) || "*#{View.name}"
    # Show buffers too - wasn't as simple as just removing, because of filename indenting!

    next unless file
    next if file =~ /_ol.notes/

    if options[:buffer].nil?   # If we're not searching in one buffer
      next if ["todo.notes", "files.notes"].
        member? file.sub(/.+\//, '')
    end

    # Skip if a verboten file
    unless options[:buffer]
      next if file =~ /(\/difflog\.notes|\.log|\/\.emacs)$/
    end

    $el.set_buffer b
    started = $el.point
    View.to_top
    found_yet = nil
    while(true)
      break unless $el.search_forward(string, nil, true)
      unless found_yet
        found << "- @#{file.sub(/(.+)\//, "\\1\/\n  - ")}\n"

        found_yet = true
      end
      found << "    | #{Line.value}\n"
      Line.end
    end
    View.to started
  end

  View.to_buffer orig

  # If nothing found, just insert message
  if found.size == 0
    Tree << "- nothing found!\n"
    Search.isearch string, :reverse=>1
    return
  end

  Tree << found
  # $el.highlight_regexp string, :ls_quote_highlight
end

.to(name) ⇒ Object



159
160
161
# File 'lib/xiki/buffers.rb', line 159

def self.to name
  View.to_buffer name
end

.tree(times = 0, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/xiki/buffers.rb', line 61

def self.tree times=0, options={}
  times ||= History.prefix_times
  paths = View.files[0..(times-1)]
  if options[:dir]
    paths = paths.grep(Regexp.new(Regexp.escape(options[:dir])))
  end
  puts CodeTree.tree_search_option + Tree.paths_to_tree(paths)
end

.txt(name) ⇒ Object



163
164
165
166
167
168
# File 'lib/xiki/buffers.rb', line 163

def self.txt name
  $el.with(:save_window_excursion) do
    $el.switch_to_buffer name
    View.txt
  end
end