Module: VER

Defined in:
lib/ver.rb,
lib/ver/font.rb,
lib/ver/help.rb,
lib/ver/mode.rb,
lib/ver/text.rb,
lib/ver/undo.rb,
lib/ver/view.rb,
lib/ver/entry.rb,
lib/ver/plist.rb,
lib/ver/theme.rb,
lib/ver/keymap.rb,
lib/ver/layout.rb,
lib/ver/status.rb,
lib/ver/syntax.rb,
lib/ver/methods.rb,
lib/ver/options.rb,
lib/ver/version.rb,
lib/ver/view/list.rb,
lib/ver/text/index.rb,
lib/ver/view/entry.rb,
lib/ver/methods/help.rb,
lib/ver/methods/move.rb,
lib/ver/methods/open.rb,
lib/ver/methods/save.rb,
lib/ver/methods/undo.rb,
lib/ver/view/console.rb,
lib/ver/view/list/ex.rb,
lib/ver/methods/ctags.rb,
lib/ver/methods/views.rb,
lib/ver/exception_view.rb,
lib/ver/methods/delete.rb,
lib/ver/methods/insert.rb,
lib/ver/methods/search.rb,
lib/ver/status/context.rb,
lib/ver/view/list/grep.rb,
lib/ver/methods/control.rb,
lib/ver/methods/preview.rb,
lib/ver/syntax/detector.rb,
lib/ver/view/list/theme.rb,
lib/ver/hover_completion.rb,
lib/ver/methods/bookmark.rb,
lib/ver/syntax/processor.rb,
lib/ver/view/list/buffer.rb,
lib/ver/view/list/syntax.rb,
lib/ver/help/describe_key.rb,
lib/ver/methods/clipboard.rb,
lib/ver/methods/shortcuts.rb,
lib/ver/view/list/methods.rb,
lib/ver/help/help_for_help.rb,
lib/ver/methods/completion.rb,
lib/ver/vendor/levenshtein.rb,
lib/ver/vendor/binary_search.rb,
lib/ver/view/list/fuzzy_file_finder.rb

Defined Under Namespace

Modules: Font, Help, Levenshtein, Methods, Optioned, Plist, Undo Classes: BinarySearch, Bookmarks, Entry, ExceptionView, HoverCompletion, Keymap, Layout, Mode, Options, Status, Syntax, Text, Theme, View

Constant Summary collapse

KEYSYMS =

Tk keysyms

{
  " "  => "space",
  "!"  => "exclam",
  '"'  => "quotedbl",
  "#"  => "numbersign",
  "$"  => "dollar",
  "%"  => "percent",
  "&"  => "ampersand",
  "'"  => "quoteright",
  "("  => "parenleft",
  ")"  => "parenright",
  "*"  => "asterisk",
  "+"  => "plus",
  ","  => "comma",
  "-"  => "minus",
  "."  => "period",
  "/"  => "slash",
  "0"  => "KeyPress-0",
  "1"  => "KeyPress-1",
  "2"  => "KeyPress-2",
  "3"  => "KeyPress-3",
  "4"  => "KeyPress-4",
  "5"  => "KeyPress-5",
  "6"  => "KeyPress-6",
  "7"  => "KeyPress-7",
  "8"  => "KeyPress-8",
  "9"  => "KeyPress-9",
  ":"  => "colon",
  ";"  => "semicolon",
  "<"  => "less",
  "="  => "equal",
  ">"  => "greater",
  "?"  => "question",
  "@"  => "at",
  "["  => "bracketleft",
  "\\" => "backslash",
  "]"  => "bracketright",
  "^"  => "asciicircum",
  "_"  => "underscore",
  "`"  => "quoteleft",
  "{"  => "braceleft",
  "|"  => "bar",
  "}"  => "braceright",
  "~"  => "asciitilde",
}
VERSION =
"2009.12.14"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.bookmarksObject (readonly)

Returns the value of attribute bookmarks.



46
47
48
# File 'lib/ver.rb', line 46

def bookmarks
  @bookmarks
end

.ctag_stackObject (readonly)

Returns the value of attribute ctag_stack.



46
47
48
# File 'lib/ver.rb', line 46

def ctag_stack
  @ctag_stack
end

.layoutObject (readonly)

Returns the value of attribute layout.



46
47
48
# File 'lib/ver.rb', line 46

def layout
  @layout
end

.optionsObject (readonly)

Returns the value of attribute options.



46
47
48
# File 'lib/ver.rb', line 46

def options
  @options
end

.pathsObject (readonly)

Returns the value of attribute paths.



46
47
48
# File 'lib/ver.rb', line 46

def paths
  @paths
end

.rootObject (readonly)

Returns the value of attribute root.



46
47
48
# File 'lib/ver.rb', line 46

def root
  @root
end

.statusObject (readonly)

Returns the value of attribute status.



46
47
48
# File 'lib/ver.rb', line 46

def status
  @status
end

Class Method Details

.dump_optionsObject



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/ver.rb', line 271

def dump_options
  out = []

  options.each_pair do |key, value|
    out << [key,
      case value
      when Tk::Font
        "VER::Font[%p]" % [value.actual_hash]
      when Pathname
        value.to_s
      else
        value
      end
      ]
  end

  out.each do |pair|
    puts("VER.options.%s = %p" % pair)
  end
end

.emergency_bindingsObject



263
264
265
# File 'lib/ver.rb', line 263

def emergency_bindings
  Tk::Bind.bind(:all, options.emergency_exit){ exit }
end

.error(exception) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/ver.rb', line 292

def error(exception)
  @status.value = exception.message if @status
  exception_view(exception) if @root
  $stderr.puts("#{exception.class}: #{exception}", *exception.backtrace)
rescue Errno::EIO
  # The original terminal has disappeared, the $stderr pipe was closed on the
  # other side.
  [$stderr, $stdout, $stdin].each(&:close)
rescue IOError
  # Our pipes are closed, maybe put some output to a file logger here, or display
  # in a nicer way, maybe let it bubble up to Tk handling.
end

.exception_view(exception) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/ver.rb', line 305

def exception_view(exception)
  unless @exception_view
    @exception_view ||= ExceptionView.new(@root)

    @exception_view.bind '<<TreeviewOpen>>' do
      @exception_view.on_treeview_open
    end

    @exception_view.bind '<Escape>' do
      @exception_view.pack_forget
      @layout.views.first.focus
    end
  end

  @exception_view.show(exception)
end

.exitObject



208
209
210
211
212
# File 'lib/ver.rb', line 208

def exit
  Tk.exit rescue nil
  EM.stop rescue nil
  Kernel.exit
end

.find_in_loadpath(basename) ⇒ Object



227
228
229
230
231
232
233
234
# File 'lib/ver.rb', line 227

def find_in_loadpath(basename)
  loadpath.each do |dirname|
    file = dirname/basename
    return file if file.file?
  end

  nil
end

.first_startupObject



198
199
200
201
202
203
204
205
206
# File 'lib/ver.rb', line 198

def first_startup
  home, core = options.home_conf_dir, options.core_conf_dir
  home.mkpath

  (core/'rc.rb').cp(home/'rc.rb')
  (core/'scratch').cp(home/'scratch')
  (core/'tutorial').cp(home/'tutorial')
  (core/'welcome').cp(home/'welcome')
end

.forkingObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/ver.rb', line 113

def forking
  if options.fork
    fork do
      trap(:HUP){ 'terminal disconnected' }
      EM.run{ yield }
    end
  else
    EM.run{ yield }
  end
end

.load(name) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/ver.rb', line 214

def load(name)
  loadpath.each do |path|
    file = File.join(path, name)

    begin
      require(file)
      return
    rescue LoadError, TypeError => ex
      # TypeError happens on JRuby sometimes...
    end
  end
end

.loadpathObject



79
80
81
# File 'lib/ver.rb', line 79

def loadpath
  options.loadpath
end

.open_argvObject



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/ver.rb', line 236

def open_argv
  argv = ARGV.dup
  any = false

  while arg = argv.shift
    layout.create_view do |view|
      if argv.first =~ /\+\d+/
        line = argv.shift.to_i
        view.open_path(arg, line)
      else
        view.open_path(arg)
      end

      any = true
    end
  end

  any
end

.open_welcomeObject



256
257
258
259
260
261
# File 'lib/ver.rb', line 256

def open_welcome
  layout.create_view do |view|
    welcome = find_in_loadpath('welcome')
    view.open_path(welcome)
  end
end

.opened_file(text) ⇒ Object



267
268
269
# File 'lib/ver.rb', line 267

def opened_file(text)
  @paths << text.filename
end

.run(given_options = {}, &block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ver.rb', line 83

def run(given_options = {}, &block)
  setup_tk
  run_startup(given_options)

  forking do
    if Tk::RUN_EVENTLOOP_ON_MAIN_THREAD
      run_aqua(&block)
    else
      run_x11(&block)
    end
  end
rescue => exception
  VER.error(exception)
  exit
end

.run_aqua(&block) ⇒ Object



99
100
101
102
103
# File 'lib/ver.rb', line 99

def run_aqua(&block)
  run_core
  EM.defer(&block) if block
  Tk.mainloop
end

.run_coreObject



130
131
132
133
134
135
136
# File 'lib/ver.rb', line 130

def run_core
  sanitize_options
  # dump_options
  setup_widgets
  open_argv || open_welcome
  emergency_bindings
end

.run_startup(given_options) ⇒ Object



124
125
126
127
128
# File 'lib/ver.rb', line 124

def run_startup(given_options)
  first_startup unless options.home_conf_dir.directory?
  load 'rc'
  @options.merge!(given_options)
end

.run_x11(&block) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/ver.rb', line 105

def run_x11(&block)
  EM.defer do
    run_core
    EM.defer(&block) if block
    Tk.mainloop
  end
end

.sanitize_optionsObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/ver.rb', line 163

def sanitize_options
  font = options.font

  unless font.respond_to?(:measure)
    font = Tk::Font.new(font)
    actual_hash = font.actual_hash
    options.font = Font.cache[actual_hash] = font
  end

  tabs = font.measure('0') * options.tabstop
  options.tabs = tabs

  encoding = options[:encoding]
  unless encoding.is_a?(Encoding)
    external, internal = encoding.to_s.split(':', 2)

    Encoding.default_external = Encoding.find(external) if external
    Encoding.default_internal = Encoding.find(internal) if internal
  end

  # We supply a reasonable default in case the platform doesn't have the theme
  # wished for.
  unless Tk::Tile::Style.theme_names.include?(options.tk_theme)
    options.tk_theme = 'default'
  end

  letter = /[\w\n.-]/
  space = /[^\w.-]/

  # make sure Tcl already has the vars set
  Tk.interp.eval('catch {tcl_endOfWord}')
  Tk.execute('set', 'tcl_wordchars', letter)
  Tk.execute('set', 'tcl_nonwordchars', space)
end

.setup_tkObject



138
139
140
141
# File 'lib/ver.rb', line 138

def setup_tk
  require 'ffi-tk'
  Thread.abort_on_exception = true
end

.setup_widgetsObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ver.rb', line 143

def setup_widgets
  Tk::Tile.set_theme options.tk_theme

  @paths = Set.new

  @root = Tk.root
  @root.wm_geometry = '160x80'

  @layout = Layout.new(@root)
  @layout.strategy = Layout::VerticalTiling

  @status = Entry.new(@root, font: options.font)
  @status.insert :end, 'For information about VER, type F1'
  @status.pack(fill: :x)

  @exception_view = nil
  @bookmarks = Bookmarks.new
  @ctag_stack = []
end