lib/textbringer/utils.rb in textbringer-1.2.0 vs lib/textbringer/utils.rb in textbringer-1.3.0
- old
+ new
@@ -1,6 +1,8 @@
require "rbconfig"
+require "irb"
+require "irb/completion"
module Textbringer
module Utils
module_function
@@ -319,9 +321,21 @@
key_sequence
else
keys = Keymap.key_sequence_string(key_sequence)
raise EditorError, "#{keys} is undefined"
end
+ end
+
+ def read_expression(prompt = "Expression: ")
+ f = ->(s) {
+ IRB::InputCompletor.retrieve_completion_data(s, bind: TOPLEVEL_BINDING).compact
+ }
+ read_from_minibuffer(prompt, completion_proc: f)
+ end
+
+ def read_object(prompt = "Object: ")
+ s = read_expression(prompt)
+ eval(s)
end
HOOKS = Hash.new { |h, k| h[k] = [] }
def add_hook(name, func = nil, &block)