Class: RipperTags::EmacsFormatter
Overview
Generates etags format as described in en.wikipedia.org/wiki/Ctags#Etags_2
The format is non-trivial since it requires section header for each source file to contain the size of tag data in bytes. This is accomplished by buffering tag definitions per-file and flushing them to target IO when a new source file is encountered or when ‘with_output` block finishes. This assumes that incoming tags are ordered by source file.
Instance Attribute Summary
#options
Instance Method Summary
collapse
#check_supported_flags, #constant?, #display_inheritance, #display_kind, #extra_flag?, #field?, #initialize, #relative_path, #stdout?, #supported_fields, #tag_file_dir
Instance Method Details
#flush_file_section(out) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 57
def flush_file_section(out)
if @section_io
write_section(@current_file, @section_io.string, out)
@section_io = nil
end
end
|
69
70
71
72
73
74
75
76
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 69
def format(tag, name_field = :name)
"%s\x7F%s\x01%d,%d" % [
tag.fetch(:pattern),
tag.fetch(name_field),
tag.fetch(:line),
0,
]
end
|
64
65
66
67
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 64
def (filename, data)
data_size = data.respond_to?(:bytesize) ? data.bytesize : data.size
"\x0C\n%s,%d\n" % [ filename, data_size ]
end
|
#include_qualified_names? ⇒ Boolean
16
17
18
19
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 16
def include_qualified_names?
return @include_qualified_names if defined? @include_qualified_names
@include_qualified_names = ('q')
end
|
#start_file_section(filename, io) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 48
def start_file_section(filename, io)
if filename != @current_file
flush_file_section(io)
@current_file = filename
@section_io = StringIO.new
end
@section_io
end
|
#supported_flags ⇒ Object
14
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 14
def supported_flags() ['q'] end
|
#with_output ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 21
def with_output
@current_file = nil
@section_io = nil
super do |io|
begin
yield io
ensure
flush_file_section(io)
end
end
end
|
#write(tag, io) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 34
def write(tag, io)
filename = relative_path(tag)
section_io = start_file_section(filename, io)
section_io.puts format(tag)
if include_qualified_names? && tag[:full_name] != tag[:name] && constant?(tag)
section_io.puts format(tag, :full_name)
end
end
|
#write_section(filename, data, io) ⇒ Object
43
44
45
46
|
# File 'lib/ripper-tags/emacs_formatter.rb', line 43
def write_section(filename, data, io)
io.write (filename, data)
io.write data
end
|