Module: Modeselector
- Defined in:
- lib/version.rb,
lib/modeselector.rb
Overview
Modeselector - extract mode line variables from source code files
Constant Summary collapse
- VERSION =
'0.2'
Class Method Summary collapse
-
.modelines(path) ⇒ Object
Retrieve modelines, if any.
-
.multiline_modelines(path) ⇒ Object
Retrieve multiline modelines, if any.
-
.single_line_modelines(path) ⇒ Object
Retrieve single line vim and emacs variables, if any.
Class Method Details
.modelines(path) ⇒ Object
Retrieve modelines, if any
Assumes file exists.
62 63 64 |
# File 'lib/modeselector.rb', line 62 def self.modelines(path) single_line_modelines(path) + multiline_modelines(path) end |
.multiline_modelines(path) ⇒ Object
Retrieve multiline modelines, if any
Assumes file exists.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/modeselector.rb', line 33 def self.multiline_modelines(path) results = [] inside_multiline_modeline = false File.foreach(path).with_index do |line, line_number| if inside_multiline_modeline results << [line_number + 1, line.chomp] if line =~ /End:/ inside_multiline_modeline = false end elsif line =~ /Local Variables:/ results << [line_number + 1, line.chomp] inside_multiline_modeline = true end end results end |
.single_line_modelines(path) ⇒ Object
Retrieve single line vim and emacs variables, if any
Assumes file exists.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/modeselector.rb', line 14 def self.single_line_modelines(path) results = [] File.foreach(path).with_index do |line, line_number| if line =~ /(vim:\s)|(-\*- mode:.+-\*-)/ results << [line_number + 1, line.chomp] end end results end |