<commit_before>module Textbringer
  TOP_LEVEL_TAG = Object.new
  RECURSIVE_EDIT_TAG = Object.new

  class Controller
    attr_reader :this_command_keys
    attr_accessor :this_command, :last_command, :overriding_map
    attr_accessor :prefix_arg, :current_prefix_arg
    attr_reader :key_sequence, :last_key, :recursive_edit_level
    attr_reader :last_keyboard_macro

    @@current = nil

    def self.current
      @@current
    end

    def self.current=(controller)
      @@current = controller
    end

    def initialize
      @top_self = eval("self", TOPLEVEL_BINDING)
      @key_sequence = []
      @last_key = nil
      @recursive_edit_level = 0
      @this_command_keys = nil
      @this_command = nil
      @last_command = nil
      @overriding_map = nil
      @prefix_arg = nil
      @current_prefix_arg = nil
      @echo_immediately = false
      @recording_keyboard_macro = nil
      @last_keyboard_macro = nil
      @executing_keyboard_macro = nil
      @next_tick_queue = []
      @next_tick_queue_mutex = Mutex.new
      @next_tick_input, @next_tick_output = IO.pipe
    end

    def close
      @next_tick_input.close
      @next_tick_output.close
    end

    def command_loop(tag)
      catch(tag) do
        loop do
          begin
            echo_input
            c = read_event
            break if c.nil?
            Window.echo_area.clear_message
            @last_key = c
            @key_sequence << @last_key
            cmd = key_binding(@key_sequence)
            if cmd.nil?
              keys = Keymap.key_sequence_string(@key_sequence)
              @key_sequence.clear
              @prefix_arg = nil
              message("#{keys} is undefined")
            elsif cmd.is_a?(Keymap)
              # multi-stroke key binding?
            else
              @this_command_keys = @key_sequence
              @key_sequence = []
              @this_command = cmd
              @current_prefix_arg = @prefix_arg
              @prefix_arg = nil
              begin
                run_hooks(:pre_command_hook, remove_on_error: true)
                if cmd.is_a?(Symbol)
                  @top_self.send(cmd)
                else
                  cmd.call
                end
              ensure
                run_hooks(:post_command_hook, remove_on_error: true)
                @last_command = @this_command
                @this_command = nil
              end
            end
            Window.redisplay
          rescue Exception => e<commit_msg>Beep when no key binding found<commit_after>module Textbringer
  TOP_LEVEL_TAG = Object.new
  RECURSIVE_EDIT_TAG = Object.new

  class Controller
    attr_reader :this_command_keys
    attr_accessor :this_command, :last_command, :overriding_map
    attr_accessor :prefix_arg, :current_prefix_arg
    attr_reader :key_sequence, :last_key, :recursive_edit_level
    attr_reader :last_keyboard_macro

    @@current = nil

    def self.current
      @@current
    end

    def self.current=(controller)
      @@current = controller
    end

    def initialize
      @top_self = eval("self", TOPLEVEL_BINDING)
      @key_sequence = []
      @last_key = nil
      @recursive_edit_level = 0
      @this_command_keys = nil
      @this_command = nil
      @last_command = nil
      @overriding_map = nil
      @prefix_arg = nil
      @current_prefix_arg = nil
      @echo_immediately = false
      @recording_keyboard_macro = nil
      @last_keyboard_macro = nil
      @executing_keyboard_macro = nil
      @next_tick_queue = []
      @next_tick_queue_mutex = Mutex.new
      @next_tick_input, @next_tick_output = IO.pipe
    end

    def close
      @next_tick_input.close
      @next_tick_output.close
    end

    def command_loop(tag)
      catch(tag) do
        loop do
          begin
            echo_input
            c = read_event
            break if c.nil?
            Window.echo_area.clear_message
            @last_key = c
            @key_sequence << @last_key
            cmd = key_binding(@key_sequence)
            if cmd.nil?
              keys = Keymap.key_sequence_string(@key_sequence)
              @key_sequence.clear
              @prefix_arg = nil
              message("#{keys} is undefined")
              Window.beep
            elsif cmd.is_a?(Keymap)
              # multi-stroke key binding?
            else
              @this_command_keys = @key_sequence
              @key_sequence = []
              @this_command = cmd
              @current_prefix_arg = @prefix_arg
              @prefix_arg = nil
              begin
                run_hooks(:pre_command_hook, remove_on_error: true)
                if cmd.is_a?(Symbol)
                  @top_self.send(cmd)
                else
                  cmd.call
                end
              ensure
                run_hooks(:post_command_hook, remove_on_error: true)
                @last_command = @this_command
                @this_command = nil
              end
            end
            Window.redisplay
          rescue Exception => e
{'fraction_non_alphanumeric': 0.06847674186464364, 'fraction_numerical': 0.0003992812936713915, 'mean_word_length': 1.719869706840391, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1528691', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1446, 'n_words': 295}