Class: VimDo::CLI
Instance Method Summary collapse
- #autocomplete ⇒ Object
- #commands(*cmd) ⇒ Object
- #diff(from, to) ⇒ Object
- #diffpatch(file) ⇒ Object
- #edit(filename) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #merge(local, merge, remote, base = nil) ⇒ Object
- #normal(keys = "") ⇒ Object
Constructor Details
Instance Method Details
#autocomplete ⇒ Object
143 144 145 |
# File 'lib/vimdo/cli.rb', line 143 def autocomplete() raise UndefinedCommandError, "autocomplete should be intercepted." end |
#commands(*cmd) ⇒ Object
51 52 53 |
# File 'lib/vimdo/cli.rb', line 51 def commands(*cmd) vim.normal(":<C-u>#{cmd.join(' <Bar> ')}<CR>") end |
#diff(from, to) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/vimdo/cli.rb', line 78 def diff(from, to) [from, to].each do |f| raise PathError "#{f} is not readable!" unless File.readable?(f) end from, to = [from, to].map {|f| File.(f) } commands("tabedit #{path(from)}", "diffsplit #{path(to)}") vim.foreground end |
#diffpatch(file) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/vimdo/cli.rb', line 94 def diffpatch(file) patch = [:patch] [file, patch].each do |f| unless File.readable?(f) raise PathError "#{f} is not readable!" end end file, patch = [file, patch].map {|f| File.(f) } commands("edit #{path(file)}", "vertical diffpatch #{path(patch)}") vim.foreground end |
#edit(filename) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vimdo/cli.rb', line 62 def edit(filename) linenr = nil if /(.*):(\d+):?/.match(filename) f = File.($1) linenr = $2 else f = File.(filename) end raise PathError "#{f} is not readable!" unless File.readable?(f) vim.edit(f) commands(linenr) if linenr vim.foreground end |
#merge(local, merge, remote, base = nil) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vimdo/cli.rb', line 113 def merge(local, merge, remote, base = nil) [local, merge, remote].each do |f| unless File.readable?(f) raise PathError "#{f} is not readable!" end end raise PathError "#{base} is not readable!" unless File.readable?(base) or base.nil? local, merge, remote = [local, merge, remote].map {|f| File.(f) } merge_command = "tabnew<Bar>edit #{path(local)}" + "<Bar>diffsplit #{path(merge)}" + "<Bar>diffsplit #{path(remote)}" if base base_split_command = "<Bar>diffsplit #{path(File.(base))}<Bar>wincmd J" else base_split_command = '' end switch_command = "<Bar>2wincmd w" commands(merge_command + base_split_command + switch_command) vim.foreground end |
#normal(keys = "") ⇒ Object
56 57 58 |
# File 'lib/vimdo/cli.rb', line 56 def normal(keys = "") vim.normal(keys) end |