lib/textbringer/commands/files.rb in textbringer-1.2.0 vs lib/textbringer/commands/files.rb in textbringer-1.3.0
- old
+ new
@@ -141,7 +141,22 @@
|dir_name = read_file_name("Make directory: ",
default: Buffer.current.file_name &&
File.dirname(Buffer.current.file_name))|
FileUtils.mkdir_p(dir_name)
end
+
+ define_command(:find_source, doc: "Open the source file.") do
+ |obj = read_object("Object or Class: ")|
+ klass = obj.is_a?(Module) ? obj : obj.class
+ method_name = klass.instance_methods(false).first
+ if method_name.nil?
+ raise EditorError, "Source not found"
+ end
+ method = klass.instance_method(method_name)
+ file_name = method.source_location.first
+ if !File.exist?(file_name)
+ raise EditorError, "Source not found"
+ end
+ find_file(method.source_location.first)
+ end
end
end