<commit_before>require "editorconfig"

module Textbringer
  module Commands
    define_command(:find_file, doc: "Open or create a file.") do
      |file_name = read_file_name("Find file: ")|
      config = EditorConfig.load_file(file_name)
      buffer = Buffer.find_file(file_name)
      if buffer.new_file?
        message("New file")
      end
      switch_to_buffer(buffer)
      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)
      if config.key?("charset")
        Buffer.current.file_encoding = config["charset"]
      end
      if config.key?("end_of_line")
        Buffer.current.file_format =
          case config["end_of_line"]
          when "lf"
            :unix
          when "crlf"
            :dos
          when "cr"
            :mac
          end
      end<commit_msg>Show dirname in find_file prompt<commit_after>require "editorconfig"

module Textbringer
  module Commands
    define_command(:find_file, doc: "Open or create a file.") do
      |file_name = read_file_name("Find file: ", default: (Buffer.current.file_name ? File.dirname(Buffer.current.file_name) : Dir.pwd) + "/")|
      config = EditorConfig.load_file(file_name)
      buffer = Buffer.find_file(file_name)
      if buffer.new_file?
        message("New file")
      end
      switch_to_buffer(buffer)
      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)
      if config.key?("charset")
        Buffer.current.file_encoding = config["charset"]
      end
      if config.key?("end_of_line")
        Buffer.current.file_format =
          case config["end_of_line"]
          when "lf"
            :unix
          when "crlf"
            :dos
          when "cr"
            :mac
          end
      end
{'fraction_non_alphanumeric': 0.11106574111882402, 'fraction_numerical': 0.0008166598611678236, 'mean_word_length': 2.215223097112861, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4102472', 'n_tokens_mistral': 782, 'n_tokens_neox': 771, 'n_words': 137}