lib/textbringer/commands.rb in textbringer-0.1.3 vs lib/textbringer/commands.rb in textbringer-0.1.4
- old
+ new
@@ -50,11 +50,10 @@
[
:beginning_of_line,
:end_of_line,
:beginning_of_buffer,
:end_of_buffer,
- :set_mark,
:exchange_point_and_mark,
:copy_region,
:kill_region,
:yank,
:newline,
@@ -64,10 +63,15 @@
define_command(name) do
Buffer.current.send(name)
end
end
+ define_command(:set_mark_command) do
+ Buffer.current.set_mark
+ message("Mark set")
+ end
+
define_command(:goto_char) do
|n = read_from_minibuffer("Go to char: ")|
Buffer.current.goto_char(n.to_i)
Window.current.recenter_if_needed
end
@@ -123,10 +127,17 @@
default: RE_SEARCH_STATUS[:last_regexp])|
RE_SEARCH_STATUS[:last_regexp] = s
Buffer.current.re_search_forward(s)
end
+ define_command(:re_search_backward) do
+ |s = read_from_minibuffer("RE search backward: ",
+ default: RE_SEARCH_STATUS[:last_regexp])|
+ RE_SEARCH_STATUS[:last_regexp] = s
+ Buffer.current.re_search_backward(s)
+ end
+
def match_beginning(n)
Buffer.current.match_beginning(n)
end
def match_end(n)
@@ -141,11 +152,11 @@
Buffer.current.replace_match(s)
end
define_command(:query_replace_regexp) do
|regexp = read_from_minibuffer("Query replace regexp: "),
- to_str = read_from_minibuffer("Query replace regexp #{regexp} with: ")|
+ to_str = read_from_minibuffer("with: ")|
n = 0
begin
loop do
re_search_forward(regexp)
Window.current.recenter_if_needed
@@ -253,13 +264,19 @@
buffer = Buffer.find_file(file_name)
if buffer.new_file?
message("New file")
end
switch_to_buffer(buffer)
- mode = Mode.list.find { |mode|
- mode.file_name_pattern &&
- mode.file_name_pattern =~ File.basename(buffer.file_name)
+ shebang = buffer.save_excursion {
+ buffer.beginning_of_buffer
+ buffer.looking_at?(/#!.*$/) ? buffer.match_string(0) : nil
+ }
+ mode = Mode.list.find { |m|
+ (m.file_name_pattern &&
+ m.file_name_pattern =~ File.basename(buffer.file_name)) ||
+ (m.interpreter_name_pattern &&
+ m.interpreter_name_pattern =~ shebang)
} || FundamentalMode
send(mode.command_name)
end
define_command(:switch_to_buffer) do
@@ -628,19 +645,25 @@
buffer.read_only = false
buffer.clear
Window.redisplay
signals = [:INT, :TERM, :KILL]
begin
- Open3.popen2e(cmd, pgroup: true) do |input, output, wait_thread|
+ if /mswin32|mingw32/ =~ RUBY_PLATFORM
+ opts = {}
+ else
+ opts = {pgroup: true}
+ end
+ Open3.popen2e(cmd, opts) do |input, output, wait_thread|
input.close
loop do
status = output.wait_readable(0.5)
if status == false
break # EOF
end
if status
begin
- s = output.read_nonblock(1024)
+ s = output.read_nonblock(1024).force_encoding("utf-8").
+ scrub("\u{3013}").gsub(/\r\n/, "\n")
buffer.insert(s)
Window.redisplay
rescue EOFError
break
rescue Errno::EAGAIN, Errno::EWOULDBLOCK