Module: Editors::Helpers::EditorSyntax

Included in:
Editors
Defined in:
lib/editors/helpers/editor_syntax.rb

Overview

Helpers for generating editor invocation commands

Author:

  • Jeff Sandberg

Instance Method Summary collapse

Instance Method Details

#blocking_flag_for_editor(blocking) ⇒ String, Nil

The blocking flag for this particular editor.

Parameters:

  • blocking (Boolean)

    If false, returns nothing

Returns:

  • (String, Nil)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/editors/helpers/editor_syntax.rb', line 15

def blocking_flag_for_editor(blocking)
  case editor_name
  when /^emacsclient/
    '--no-wait'
  when /^[gm]vim/
    '--nofork'
  when /^jedit/
    '-wait'
  when /^mate/, /^subl/, /^redcar/
    '-w'
  end if blocking
end

#editor_nameObject



7
8
9
# File 'lib/editors/helpers/editor_syntax.rb', line 7

def editor_name
  File.basename(default_editor).split(' ').first
end

#start_line_syntax_for_editor(file_name, line_number) ⇒ String

The starting line syntax for the user’s editor rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength

Parameters:

  • file_name (String)

    File name/path

  • line_number (Fixnum)

Returns:

  • (String)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/editors/helpers/editor_syntax.rb', line 34

def start_line_syntax_for_editor(file_name, line_number)
  return file_name if line_number <= 1

  case editor_name
  when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
    "+#{line_number} #{file_name}"
  when /^mate/, /^geany/
    "-l #{line_number} #{file_name}"
  when /^subl/
    "#{file_name}:#{line_number}"
  when /^uedit32/
    "#{file_name}/#{line_number}"
  when /^jedit/
    "#{file_name} +line:#{line_number}"
  when /^redcar/
    "-l#{line_number} #{file_name}"
  else
    if windows?
      "#{file_name}"
    else
      "+#{line_number} #{file_name}"
    end
  end
end