modeselector 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d93b5d4afdee5bc18d0eee76d31df8f92b8b2f69
4
+ data.tar.gz: 1f3038b04d9db2297721cb04aaeb7336263fde7d
5
+ SHA512:
6
+ metadata.gz: 0ee434144b849231bdf50287c5a7d4f5e7567b70f3ac64526ad5aa7845a03934005ec3b2e97d497bcb090cde1b824dc16f975f2d25589a4f300ac887a2e5eec8
7
+ data.tar.gz: bc2abe4239fc94d2dd824e0c5fa59f97ba8f48fe489ef820252270d4aaf4973b83a3219241c2404b80d5b74a2de17cca3d23a42182a3cd77c35be703b6ce4efb
data/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ # FreeBSD License
2
+
3
+ # Copyright 2014 Andrew Pennebaker. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation and/or
12
+ other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED
15
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
17
+ SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/bin/modeselector ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'modeselector'
6
+
7
+ def main
8
+ option = OptionParser.new do |option|
9
+ option.banner = 'Usage: modeselector [options] <path> <path> <path>...'
10
+
11
+ option.on('-h', '--help', 'Print usage info') do
12
+ puts option
13
+ exit
14
+ end
15
+
16
+ option.on('-v', '--version', 'Print version info') do
17
+ puts "modeselector #{Modeselector::VERSION}"
18
+ exit
19
+ end
20
+ end
21
+
22
+ option.parse!
23
+
24
+ if ARGV.length < 1
25
+ puts option
26
+ exit 1
27
+ end
28
+
29
+ paths = ARGV
30
+
31
+ paths.each do |path|
32
+ modelines = Modeselector.modelines(path)
33
+
34
+ if modelines.length > 0
35
+ modelines.each do |modeline|
36
+ line_number, ml = modeline
37
+ puts "#{path}:#{line_number} #{ml}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ begin
44
+ main
45
+ # User may quit before completion.
46
+ rescue Interrupt
47
+ nil
48
+ # May be piped to another program (e.g. `less`),
49
+ # which is quit before completion.
50
+ rescue Errno::EPIPE, Errno::EMFILE
51
+ nil
52
+ end
@@ -0,0 +1,65 @@
1
+ require 'version'
2
+
3
+ #
4
+ # Modeselector - extract mode line variables from source code files
5
+ #
6
+ module Modeselector
7
+ #
8
+ # Retrieve single line vim and emacs variables, if any
9
+ #
10
+ # Assumes file exists.
11
+ #
12
+ # @path a file path (String)
13
+ #
14
+ def self.single_line_modelines(path)
15
+ results = []
16
+
17
+ File.foreach(path).with_index do |line, line_number|
18
+ if line =~ /(vim:\s)|(-\*- mode:.+-\*-)/
19
+ results << [line_number + 1, line.chomp]
20
+ end
21
+ end
22
+
23
+ results
24
+ end
25
+
26
+ #
27
+ # Retrieve multiline modelines, if any
28
+ #
29
+ # Assumes file exists.
30
+ #
31
+ # @path a file path (String)
32
+ #
33
+ def self.multiline_modelines(path)
34
+ results = []
35
+
36
+ inside_multiline_modeline = false
37
+
38
+ File.foreach(path).with_index do |line, line_number|
39
+ if inside_multiline_modeline
40
+ results << [line_number + 1, line.chomp]
41
+
42
+ if line =~ /End:/
43
+ inside_multiline_modeline = false
44
+ end
45
+ elsif line =~ /Local Variables:/
46
+ results << [line_number + 1, line.chomp]
47
+
48
+ inside_multiline_modeline = true
49
+ end
50
+ end
51
+
52
+ results
53
+ end
54
+
55
+ #
56
+ # Retrieve modelines, if any
57
+ #
58
+ # Assumes file exists.
59
+ #
60
+ # @path a file path (String)
61
+ #
62
+ def self.modelines(path)
63
+ single_line_modelines(path) + multiline_modelines(path)
64
+ end
65
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,6 @@
1
+ #
2
+ # Modeselector
3
+ #
4
+ module Modeselector
5
+ VERSION = '0.1'
6
+ end
metadata ADDED
@@ -0,0 +1,244 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modeselector
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Pennebaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '10.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '10.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: reek
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: flay
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: flog
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: roodi
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: churn
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: cane
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '2.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '2.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: excellent
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '2.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '0.24'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '0.24'
139
+ - !ruby/object:Gem::Dependency
140
+ name: tailor
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '1.4'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '1.4'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: '2.6'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: '2.6'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-shell
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '0.6'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ~>
179
+ - !ruby/object:Gem::Version
180
+ version: '0.6'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rspec
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ~>
186
+ - !ruby/object:Gem::Version
187
+ version: '3.0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ~>
193
+ - !ruby/object:Gem::Version
194
+ version: '3.0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: cucumber
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ~>
200
+ - !ruby/object:Gem::Version
201
+ version: '1.3'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ~>
207
+ - !ruby/object:Gem::Version
208
+ version: '1.3'
209
+ description: See README.md for example usage
210
+ email: andrew.pennebaker@gmail.com
211
+ executables:
212
+ - modeselector
213
+ extensions: []
214
+ extra_rdoc_files: []
215
+ files:
216
+ - LICENSE.md
217
+ - bin/modeselector
218
+ - lib/modeselector.rb
219
+ - lib/version.rb
220
+ homepage: https://github.com/mcandre/modeselector
221
+ licenses:
222
+ - FreeBSD
223
+ metadata: {}
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - '>='
231
+ - !ruby/object:Gem::Version
232
+ version: '1.9'
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ requirements: []
239
+ rubyforge_project:
240
+ rubygems_version: 2.4.6
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: extract mode line variables from source code files
244
+ test_files: []