open 0.1.30 → 0.2.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +110 -31
  3. data/bin/open +1 -1
  4. data/bin/open_in_browser +1 -1
  5. data/doc/README.gen +72 -8
  6. data/doc/deprecated_code/deprecated_code.md +26 -0
  7. data/img/open_logo.png +0 -0
  8. data/lib/open/base/base.rb +265 -128
  9. data/lib/open/books/README.md +8 -0
  10. data/lib/open/books/books.rb +100 -0
  11. data/lib/open/constants/constants.rb +86 -8
  12. data/lib/open/in_browser/in_browser.rb +501 -319
  13. data/lib/open/in_editor/in_editor.rb +367 -162
  14. data/lib/open/last/last.rb +14 -12
  15. data/lib/open/last_url/last_url.rb +4 -3
  16. data/lib/open/nano_open/nano_open.rb +30 -5
  17. data/lib/open/{open.rb → open/open.rb} +596 -654
  18. data/lib/open/project/project.rb +3 -2
  19. data/lib/open/requires/failsafe_require_of_beautiful_url.rb +9 -0
  20. data/lib/open/requires/require_the_project.rb +2 -2
  21. data/lib/open/requires/require_yaml.rb +13 -0
  22. data/lib/open/these_files/these_files.rb +1 -1
  23. data/lib/open/toplevel_methods/browser.rb +71 -0
  24. data/lib/open/toplevel_methods/delay.rb +23 -0
  25. data/lib/open/toplevel_methods/e.rb +14 -0
  26. data/lib/open/toplevel_methods/editor.rb +41 -0
  27. data/lib/open/toplevel_methods/host_os.rb +25 -0
  28. data/lib/open/toplevel_methods/is_on_roebe.rb +16 -0
  29. data/lib/open/toplevel_methods/is_on_windows.rb +26 -0
  30. data/lib/open/toplevel_methods/misc.rb +50 -0
  31. data/lib/open/version/version.rb +2 -2
  32. data/lib/open/with_delay/with_delay.rb +10 -11
  33. data/open.gemspec +3 -3
  34. data/test/testing_open.rb +1 -1
  35. data/test/testing_open_in_browser.rb +16 -0
  36. data/test/testing_open_via_launchy.rb +3 -0
  37. data/test/testing_shortcuts.rb +3 -0
  38. metadata +25 -9
  39. data/lib/open/toplevel_code/toplevel_code.rb +0 -189
@@ -6,12 +6,16 @@
6
6
  #
7
7
  # This class can specifically be used to open a local file via your
8
8
  # favourite editor. This is admittedly more useful for GUI-based editors
9
- # such as "geany" or "gedit" than, say, "vim" or "nano".
9
+ # such as "geany" or "gedit" than, say, "vim" or "nano". Nonetheless
10
+ # I also use this class as base-class for class Open::NanoOpen - that is,
11
+ # opening a local file via the nano editor.
10
12
  #
11
- # If the file was not found, and BeautifulUrl is available, then it will
12
- # be called, to see whether that leads to a file that can be found, and
13
- # if it still can not be found than "dfind" is used, which is based on
14
- # "locate / updatedb".
13
+ # If the file at hand was not found, and BeautifulUrl is available, then this
14
+ # class will tap into the functionality made available by BeautifulUrl, in
15
+ # order to see whether that leads to a file that can be found. If the file
16
+ # can not be found then "dfind" will be tried, as last attempt, which in
17
+ # turn is based on "locate / updatedb" - so it only works on Linux systems
18
+ # really or some UNIX-variants.
15
19
  #
16
20
  # Usage example:
17
21
  #
@@ -33,20 +37,28 @@ class InEditor < Base # === Open::InEditor
33
37
  # The first argument should be the name of the file that we wish to open.
34
38
  # ========================================================================= #
35
39
  def initialize(
36
- i = nil,
37
- run_already = true
40
+ commandline_arguments = ARGV,
41
+ run_already = true
38
42
  )
39
43
  register_sigint
40
44
  reset
41
- set_input(i)
45
+ commandline_arguments = [commandline_arguments].flatten.compact
46
+ set_commandline_arguments(
47
+ commandline_arguments
48
+ )
49
+ set_work_on_these_files(
50
+ commandline_arguments.reject {|entry|
51
+ entry.start_with?('--')
52
+ }
53
+ )
42
54
  # ======================================================================= #
43
55
  # === Handle blocks next
44
56
  # ======================================================================= #
45
57
  if block_given?
46
58
  yielded = yield
47
- # ===================================================================== #
59
+ # ======================================================================= #
48
60
  # === Handle Hashes next
49
- # ===================================================================== #
61
+ # ======================================================================= #
50
62
  if yielded.is_a? Hash
51
63
  # =================================================================== #
52
64
  # === :use_this_editor
@@ -61,7 +73,7 @@ class InEditor < Base # === Open::InEditor
61
73
  # =================================================================== #
62
74
  if yielded.has_key? :this_file
63
75
  _ = yielded[:this_file]
64
- set_input(_)
76
+ set_work_on_these_files(_)
65
77
  end
66
78
  end
67
79
  end
@@ -73,158 +85,377 @@ class InEditor < Base # === Open::InEditor
73
85
  # ========================================================================= #
74
86
  def reset
75
87
  super()
88
+ infer_the_namespace
89
+ # ======================================================================= #
90
+ # === @internal_hash
76
91
  # ======================================================================= #
77
- # === @use_this_editor
92
+ reset_the_internal_hash
78
93
  # ======================================================================= #
79
- @use_this_editor = use_which_editor?
94
+ # === :use_this_editor
95
+ # ======================================================================= #
96
+ set_use_this_editor(:use_the_default_editor_from_the_yaml_file)
97
+ # ======================================================================= #
98
+ # === :work_on_these_files
99
+ #
100
+ # This variable must be nil initially.
101
+ # ======================================================================= #
102
+ @internal_hash[:work_on_these_files] = nil
80
103
  end
81
104
 
82
105
  # ========================================================================= #
83
- # === use_this_editor?
106
+ # === start_the_editor_in_the_background
84
107
  # ========================================================================= #
85
- def use_this_editor?
86
- @use_this_editor
87
- end; alias editor? use_this_editor? # === editor?
108
+ def start_the_editor_in_the_background
109
+ system "#{use_which_editor?} &"
110
+ end; alias start_editor_in_background start_the_editor_in_the_background # === start_editor_in_background
88
111
 
89
112
  # ========================================================================= #
90
- # === set_input
91
- # ========================================================================= #
92
- def set_input(i = '')
93
- if i.is_a? String
94
- i = [i]
95
- end # At this point, we have an array
96
- i = i.flatten if i.is_a? Array
97
- i.map! {|entry|
98
- dataset = nil
99
- # ===================================================================== #
100
- # Next get rid of components past a '#' token.
101
- # ===================================================================== #
102
- entry = entry[0, entry.index('#')] if entry.include? '#'
103
- # ===================================================================== #
104
- # === Handle fake "Symbols" next:
105
- # ===================================================================== #
106
- if entry.start_with? ':' # If this is a "symbol" we assume to do a special action.
107
- name = entry[1 .. -1]
108
- # =================================================================== #
109
- # Since as of March 2023 we will distinguish two use cases:
110
- #
111
- # (1) first, we will try to use the dataset in the file called
112
- # shortcuts.yml. If the input is part of a key in that file
113
- # then the key will be fetched, and the associated files
114
- # will be opened in the editor
115
- #
116
- # (2) otherwise we will look through RUBY_SRC and simply open
117
- # the project-specific .rb file instead
118
- #
119
- # =================================================================== #
120
- base_dir = RUBY_SRC+name
121
- if File.exist?(FILE_SHORTCUTS)
122
- dataset = YAML.load_file(FILE_SHORTCUTS)
123
- end
124
- if dataset and dataset.has_key?(name) # Invoke via: openineditors :gamebooks
125
- entry = dataset[name]
126
- elsif File.directory? base_dir
127
- target = base_dir+'/lib/'+name+'/*.rb' # This is, sort of, the special action.
128
- entry = Dir[target]
129
- end
130
- end
131
- if entry.include? '#' # Then chop off. It is probably not necessary, though.
132
- entry = entry[0..entry.index('#')]
133
- end
134
- if entry.respond_to?(:start_with?) and entry.start_with?('file://')
135
- entry[0, 'file://'.size] = ''
136
- end
137
- entry
138
- } if i.is_a? Array
139
- i = i.flatten if i.is_a? Array
140
- @input = i # Must be an Array.
141
- end
113
+ # === set_work_on_these_files
114
+ #
115
+ # The variable has to be an Array at all times.
116
+ # ========================================================================= #
117
+ def set_work_on_these_files(i)
118
+ i = [i].flatten.compact.reject {|entry| entry.start_with?('--') }
119
+ @internal_hash[:work_on_these_files] = i
120
+ end; alias set_work_on_this_file set_work_on_these_files # === set_work_on_this_file
121
+
122
+ # ========================================================================= #
123
+ # === work_on_these_files?
124
+ # ========================================================================= #
125
+ def work_on_these_files?
126
+ @internal_hash[:work_on_these_files]
127
+ end; alias work_on_this_file? work_on_these_files? # === work_on_this_file?
128
+ alias input? work_on_these_files? # === input?
142
129
 
143
130
  # ========================================================================= #
144
131
  # === try_to_find_expanded_alias_for
145
132
  #
146
- # We delegate towards FindExpandedAlias
133
+ # We delegate towards FindExpandedAlias here.
147
134
  # ========================================================================= #
148
135
  def try_to_find_expanded_alias_for(i)
149
- result = false # Default.
136
+ result = false # Default return value.
137
+ if i and i.include?('$')
138
+ i = sanitize_global_environment(i)
139
+ end
140
+ if i.include? ' ' # For instance, when it includes a ' &'
141
+ i = i[0, i.index(' ')]
142
+ end if i
150
143
  if Object.const_defined?(:Roebe) and
151
144
  Roebe.const_defined?(:FindExpandedAlias)
152
- _ = ::Roebe::FindExpandedAlias[i]
153
- result = sanitize(_)
145
+ expanded_alias = Roebe::FindExpandedAlias.new(i) { :be_quiet }
146
+ if expanded_alias.does_include?(i)
147
+ result = true
148
+ end
154
149
  end
155
- if result.include? ' ' # For instance, when it includes a ' &'
156
- result = result[0, result.index(' ')]
157
- end if result
158
150
  return result
159
151
  end
152
+
153
+ # ========================================================================= #
154
+ # === use_this_editor?
155
+ # ========================================================================= #
156
+ def use_this_editor?
157
+ @internal_hash[:use_this_editor]
158
+ end; alias editor? use_this_editor? # === editor?
159
+ alias use_which_editor? use_this_editor? # === use_which_editor?
160
+
161
+ # ========================================================================= #
162
+ # === set_editor
163
+ # ========================================================================= #
164
+ def set_editor(
165
+ i = :use_the_default_editor_from_the_yaml_file
166
+ )
167
+ case i
168
+ # ======================================================================= #
169
+ # === :use_the_default_editor_from_the_yaml_file
170
+ # ======================================================================= #
171
+ when :use_the_default_editor_from_the_yaml_file
172
+ i = file_load_default_editor?
173
+ end
174
+ @internal_hash[:use_this_editor] = i
175
+ end; alias editor= set_editor # === editor=
176
+ alias set_use_this_editor set_editor # === set_use_this_editor
177
+
178
+ # ========================================================================= #
179
+ # === do_save_this_file_into_a_local_yaml_file
180
+ #
181
+ # Since as of August 2019, this will also be logged into a local file,
182
+ # if we are on a roebe-system.
183
+ # ========================================================================= #
184
+ def do_save_this_file_into_a_local_yaml_file(i)
185
+ if File.file?(i) and
186
+ Object.const_defined?(:Roebe) and
187
+ File.directory?(Roebe.log_dir?) and
188
+ is_on_roebe?
189
+ into = "#{Roebe.log_dir?}opened_files.yml"
190
+ array = []
191
+ if File.exist? into
192
+ array << YAML.load_file(into)
193
+ end
194
+ array.flatten!
195
+ array << i unless array.include?(i)
196
+ what = YAML.dump(array)
197
+ unless Object.const_defined?(:SaveFile)
198
+ require 'save_file'
199
+ end
200
+ SaveFile.write_what_into(what, into)
201
+ end
202
+ end
203
+
204
+ # ========================================================================= #
205
+ # === verbose_notify_the_user_that_a_default_delay_will_be_used_next
206
+ # ========================================================================= #
207
+ def verbose_notify_the_user_that_a_default_delay_will_be_used_next
208
+ opne "More than #{steelblue('3 arguments')} were given, thus we will "\
209
+ "use a small delay of #{simp(N_DELAY.to_s)} seconds."
210
+ end
211
+
212
+ # ========================================================================= #
213
+ # === menu (menu tag)
214
+ # ========================================================================= #
215
+ def menu(
216
+ i = commandline_arguments?
217
+ )
218
+ if i.is_a? Array
219
+ i.each {|entry| menu(entry) }
220
+ else
221
+ case i # (case tag)
222
+ # ======================================================================= #
223
+ # === open_in_editor --show-help
224
+ # ======================================================================= #
225
+ when /help$/
226
+ show_help
227
+ exit
228
+ # ======================================================================= #
229
+ # === open_in_editor --editor?
230
+ # ======================================================================= #
231
+ when /^-?-?editor\??$/i
232
+ show_the_editor_in_use
233
+ exit
234
+ end
235
+ end
236
+ end
237
+
238
+ # ========================================================================= #
239
+ # === show_the_editor_in_use
240
+ #
241
+ # Invocation example:
242
+ #
243
+ # open_in_editor --editor?
244
+ #
245
+ # ========================================================================= #
246
+ def show_the_editor_in_use
247
+ e steelblue(::Open.editor?)
248
+ end
160
249
 
161
250
  # ========================================================================= #
162
- # === start_editor_in_background
251
+ # === show_help (help tag)
163
252
  # ========================================================================= #
164
- def start_editor_in_background
165
- system "#{@use_this_editor} &"
253
+ def show_help
254
+ e 'The following help-options are documented:'
255
+ e
256
+ e ' --editor? # show the current main editor in use'
257
+ e
166
258
  end
167
259
 
168
260
  # ========================================================================= #
169
- # === use_which_delay?
261
+ # === consider_opening_files
170
262
  # ========================================================================= #
171
- def use_which_delay?
172
- Open.use_which_delay?.to_f
263
+ def consider_opening_files(
264
+ array = work_on_these_files?,
265
+ use_this_delay_by_default = 0
266
+ )
267
+ if array.empty?
268
+ opne 'No argument was given - thus, starting the primary editor in the background.'
269
+ start_the_editor_in_the_background
270
+ else
271
+ if array.size > 3
272
+ verbose_notify_the_user_that_a_default_delay_will_be_used_next
273
+ use_this_delay_by_default = N_DELAY
274
+ # Old code in use prior to the rewrite in June 2023 was:
275
+ # case use_this_editor?
276
+ # when 'bluefish'
277
+ # sleep(use_which_delay?) if array.size > 3 # To prevent bluefish from acting silly.
278
+ # end
279
+ end
280
+ array.each {|entry|
281
+ open_this_file_in_the_editor(entry, use_this_delay_by_default)
282
+ }
283
+ end
173
284
  end
174
285
 
175
286
  # ========================================================================= #
176
- # === open_in_editor
287
+ # === open_this_file_in_the_editor
177
288
  #
178
289
  # The optional second argument allows us to wait a little before
179
290
  # opening something in the editor.
180
291
  # ========================================================================= #
181
- def open_in_editor(
182
- i, optional_delay = nil
292
+ def open_this_file_in_the_editor(
293
+ i,
294
+ optional_delay = nil
183
295
  )
296
+ use_this_editor = use_which_editor?
297
+ i = i.to_s.dup # So to avoid frozen strings here.
298
+ i = sanitize_global_environment(i) if i.include? '$'
299
+ i = rds(i) # Get rid of // again, just in case.
300
+ # ======================================================================= #
301
+ # Next, we chop off '?' characters. This is, however had, not good if
302
+ # this is part of the filename. So we must check if the file exists,
303
+ # prior to doing this check.
304
+ # ======================================================================= #
305
+ if i.include?('?') and !File.exist?(i)
306
+ i = i[0..i.index('?')]
307
+ end
308
+ # ======================================================================= #
309
+ # === Handle fake "Symbols" next:
310
+ # ======================================================================= #
311
+ if i.start_with?(':') # If this is a "symbol" we assume to do a special action.
312
+ name = i[1 .. -1] # Get rid of the leading ':' here.
313
+ # ======================================================================= #
314
+ # Since as of March 2023 we will distinguish two use cases here
315
+ # for such fake-symbols:
316
+ #
317
+ # (1) first, we will try to use the dataset in the file called
318
+ # shortcuts.yml. If the input is part of a key in that file
319
+ # then the key will be fetched, and the associated files
320
+ # will be opened in the editor
321
+ #
322
+ # (2) otherwise we will look through RUBY_SRC and simply open
323
+ # the project-specific .rb file instead
324
+ #
325
+ # These shortcuts are defined in the .yml file at:
326
+ #
327
+ # open/yaml/shortcuts.yml
328
+ #
329
+ # ======================================================================= #
330
+ base_dir = RUBY_SRC+name
331
+ if File.exist?(FILE_SHORTCUTS) # Load the dataset next.
332
+ dataset = YAML.load_file(FILE_SHORTCUTS)
333
+ end
334
+ # ======================================================================= #
335
+ # The next clause may turn i into an Array - both if and elsif
336
+ # clauses:
337
+ # ======================================================================= #
338
+ if dataset and dataset.has_key?(name) # Invoke via: openineditors :gamebooks
339
+ i = dataset[name]
340
+ elsif File.directory? base_dir
341
+ target = base_dir+'/lib/'+name+'/*.rb' # This is, sort of, the special action.
342
+ i = Dir[target] # This will make it an Array.
343
+ end
344
+ end
184
345
  if i.is_a? Array
185
- i.each {|entry|
186
- open_in_editor(entry, optional_delay)
187
- if @use_this_editor == 'bluefish'
188
- sleep(use_which_delay?) if i.size > 3 # To prevent bluefish from acting silly.
189
- end
190
- }
346
+ use_this_delay = 0
347
+ if i.size > 3
348
+ verbose_notify_the_user_that_a_default_delay_will_be_used_next
349
+ use_this_delay = N_DELAY
350
+ end
351
+ i.each {|entry| open_this_file_in_the_editor(entry, use_this_delay) }
191
352
  else
192
- i = i.to_s.dup # So to avoid frozen strings here.
353
+ # ======================================================================= #
354
+ # We never want to have localhost entries:
355
+ # ======================================================================= #
193
356
  if i.include? 'localhost'
194
- i.gsub!(/^http\:\/\/localhost\//, MY_DATA+'/')
357
+ i.sub!(/^http\:\/\/localhost\//, MY_DATA+'/')
358
+ end
359
+ if i.respond_to?(:start_with?) and i.start_with?('file://')
360
+ i[0, 'file://'.size] = ''
195
361
  end
196
362
  if i.end_with?(':') and !File.exist?(i)
197
- i[-1,1] = ''
198
- elsif i =~ /(:\d+)/ # Has a : and a number
363
+ i.chop! # Chop off the last character in this case.
364
+ elsif i =~ /(:\d+)/ # Has a : and also number, such as ":5".
199
365
  i.gsub!(/#{$1.to_s.dup}/,'')
200
366
  end
201
- i = sanitize(i) if i.include? '$'
202
- if i.count('/home') > 1
367
+ if i.include? '#' # Then chop off. It is probably not necessary, though.
368
+ # =================================================================== #
369
+ # In December 2023 it was noticed that there may be files that
370
+ # are called "foo#bar.itm". So we need to make a check, for the
371
+ # file existing or not. If it exists then we will not truncate
372
+ # it.
373
+ # =================================================================== #
374
+ i = i[0 .. i.index('#')] unless File.exist?(i)
375
+ end
376
+ if i.count('/home') > 1 # We have more than one entry of '/home'.
203
377
  i.gsub!(/#{MY_DATA}#{MY_DATA}/, MY_DATA)
204
378
  end
205
379
  if i.start_with?('http:') and !File.exist?(i)
206
380
  i.delete_prefix!('http:')
207
381
  end
382
+ # ======================================================================= #
383
+ # First check whether the file at `i` exists or whether it does not.
384
+ # ======================================================================= #
208
385
  if File.exist? i
209
386
  # =================================================================== #
210
- # e 'Yes file exists here, we can thus open it.'
387
+ # The file exists, so we can open it in our editor next. We will
388
+ # work on the absolute path to it since as of June 2023.
211
389
  # =================================================================== #
212
- esystem "#{editor?} #{i}"
390
+ i = File.absolute_path(i)
391
+ # =================================================================== #
392
+ # Make an exception for .cpp files but only for roebe-systems:
393
+ # =================================================================== #
394
+ case File.extname(i).delete('.')
395
+ when 'cpp'
396
+ if is_on_roebe?
397
+ if ENV.has_key?('CPP_EDITOR')
398
+ use_this_editor = ENV['CPP_EDITOR'].to_s.dup
399
+ else
400
+ use_this_editor = 'geany' # We use geany for cpp files.
401
+ end
402
+ end
403
+ end
404
+ if i.include?("'") and !i.include?('"')
405
+ i = '"'+i+'"'
406
+ end
407
+ if i.include? '('
408
+ i = '"'+i+'"'
409
+ end
410
+ esystem "#{use_this_editor} #{i}"
411
+ do_save_this_file_into_a_local_yaml_file(i) # Only on roebe-systems though.
412
+ sleep(optional_delay) if optional_delay # In this case we will also sleep.
213
413
  else # Ok, the file does not exist at this point.
214
- # First try a purl.
215
- _ = BeautifulUrl::BeautifulUrl.new(i, replace: true)
216
- if _.url_was_found
217
- esystem "#{editor?} #{_.url_as_string}"
218
- elsif Dir[i+'*'].size > 0 # Try to find matches
219
- e 'Did not find '+sfile(i)+' but we may have found '+
220
- 'at least one other entry.'
221
- open_in_editor(Dir[i+'*'].reject {|entry| File.directory? entry })
222
- elsif result = try_to_find_expanded_alias_for(i)
223
- open_in_editor(result) if result
224
- # ================================================================= #
414
+ # ======================================================================= #
415
+ # Next assume it is a local link.
416
+ # ======================================================================= #
417
+ if BeautifulUrl.is_a_local_link?(i)
418
+ i = BeautifulUrl.local_menu(i)
419
+ else
420
+ # ================================================================= #
421
+ # First try a purl.
422
+ # ================================================================= #
423
+ _ = BeautifulUrl::BeautifulUrl.new(i, replace: true)
424
+ end
425
+ if _ and _.url_was_found
426
+ esystem "#{use_this_editor} #{_.url_as_string}"
427
+ elsif Dir["#{i}*"].size > 0 # Try to find matches.
428
+ # ================================================================= #
429
+ # Here we have to be careful, as we may hit an infinite loop:
430
+ # ================================================================= #
431
+ opne "#{rev}Did not find #{sfile(i)}#{rev}"
432
+ opne "#{rev}but we may have found at least one other entry."
433
+ new_selection = Dir["#{i}*"].reject {|entry|
434
+ File.directory?(entry) or
435
+ entry.include?('.tar')
436
+ }
437
+ # ================================================================= #
438
+ # We will thus select one random entry:
439
+ # ================================================================= #
440
+ open_in_editor(new_selection.sample)
441
+ # =================================================================== #
442
+ # === Run through the expanded-aliases next:
443
+ # =================================================================== #
444
+ elsif try_to_find_expanded_alias_for(i)
445
+ i = sanitize_global_environment(i) if i and i.include?('$')
446
+ if i.include? ' ' # For instance, when it includes a ' &'.
447
+ i = i[0, i.index(' ')]
448
+ end if i
449
+ if Object.const_defined?(:Roebe) and
450
+ Roebe.const_defined?(:FindExpandedAlias)
451
+ expanded_alias = Roebe::FindExpandedAlias.new(i) { :be_quiet }
452
+ i = expanded_alias[i]
453
+ end
454
+ open_in_editor(i) if i and !i.empty? # Recursive call.
455
+ # =================================================================== #
225
456
  # Now the string can include 'project_', in which case we
226
457
  # will handle it in a special way.
227
- # ================================================================= #
458
+ # =================================================================== #
228
459
  elsif i.include? 'project_'
229
460
  i.gsub!(/project_/,'')
230
461
  i << 'task'
@@ -241,57 +472,13 @@ class InEditor < Base # === Open::InEditor
241
472
  end
242
473
  end
243
474
  end
244
- sleep(optional_delay) if optional_delay
245
- end
246
-
247
- # ========================================================================= #
248
- # === set_editor
249
- # ========================================================================= #
250
- def set_editor(i = use_which_editor?)
251
- @use_this_editor = i
252
- end; alias editor= set_editor # === editor=
253
-
254
- # ========================================================================= #
255
- # === input?
256
- # ========================================================================= #
257
- def input?
258
- @input
259
- end
260
-
261
- # ========================================================================= #
262
- # === consider_opening_files
263
- # ========================================================================= #
264
- def consider_opening_files(
265
- i = input?
266
- )
267
- if i.is_a? Array
268
- i.flatten!
269
- i.map! {|file|
270
- file.chop! if file.end_with? ':'
271
- file
272
- }
273
- if i.empty?
274
- start_editor_in_background
275
- else
276
- optional_delay = 0
277
- if i.size > 3
278
- opn; e "More than 3 arguments were given, thus we will use "\
279
- "a delay of #{simp(N_DELAY.to_s)} seconds."
280
- optional_delay = N_DELAY
281
- end
282
- i.each {|entry|
283
- open_in_editor(entry, optional_delay)
284
- }
285
- end
286
- else
287
- open_in_editor(i)
288
- end
289
- end
475
+ end; alias open_in_editor open_this_file_in_the_editor # === open_in_editor
290
476
 
291
477
  # ========================================================================= #
292
478
  # === run (run tag)
293
479
  # ========================================================================= #
294
480
  def run
481
+ menu
295
482
  consider_opening_files
296
483
  end
297
484
 
@@ -309,21 +496,39 @@ end
309
496
  # =========================================================================== #
310
497
  # === Open.in_editor
311
498
  #
499
+ # Note that the behaviour of Open.in_editor() is in-sync with the
500
+ # method Open.in_browser(), in regards to joinable arguments
501
+ # (typically an Array as input). If you do not want this behaviour
502
+ # then you may have to prepare for this in your own code, such
503
+ # as by having an Array and iterating over it before passing
504
+ # the individual entries into Open.in_editor().
505
+ #
312
506
  # Usage examples:
313
507
  #
314
508
  # Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
315
509
  #
316
- # Or theb lock variant:
510
+ # Or the lock variant:
317
511
  #
318
512
  # Open.in_editor {{
319
513
  # this_file: first_argument?,
320
514
  # use_this_editor: :nano
321
515
  # }}
322
516
  #
517
+ # Which may also look like this:
518
+ #
519
+ # ::Open.in_editor {{
520
+ # this_file: _,
521
+ # use_this_editor: :bluefish
522
+ # }}
523
+ #
323
524
  # =========================================================================== #
324
525
  def self.in_editor(
325
- i = ARGV, &block
526
+ i = ARGV,
527
+ &block
326
528
  )
529
+ if i.respond_to? :join
530
+ i.join(' ').strip
531
+ end
327
532
  ::Open::InEditor.new(i, &block)
328
533
  end
329
534
 
@@ -333,9 +538,9 @@ end
333
538
  # === open_in_editor
334
539
  # =========================================================================== #
335
540
  def open_in_editor(i, &block)
336
- Open.in_editor(i, &block)
541
+ ::Open.in_editor(i, &block)
337
542
  end
338
543
 
339
544
  if __FILE__ == $PROGRAM_NAME
340
- Open::InEditor.new(ARGV)
341
- end # openineditor rorg
545
+ ARGV.each {|entry| Open.in_editor(entry) }
546
+ end # openineditor localruby