<commit_before>package main

import (
	"encoding/json"
	"github.com/mitchellh/go-homedir"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

// The options that the user can set
var settings Settings

// All the possible settings
var possibleSettings = []string{"colorscheme", "tabsize", "autoindent", "syntax"}

// The Settings struct contains the settings for micro
type Settings struct {
	Colorscheme string `json:"colorscheme"`
	TabSize     int    `json:"tabsize"`
	AutoIndent  bool   `json:"autoindent"`
	Syntax      bool   `json:"syntax"`
}

// InitSettings initializes the options map and sets all options to their default values
func InitSettings() {
	home, err := homedir.Dir()
	if err != nil {
		TermMessage("Error finding your home directory\nCan't load settings file")
		return
	}

	filename := home + "/.micro/settings.json"
	if _, e := os.Stat(filename); e == nil {
		input, err := ioutil.ReadFile(filename)
		if err != nil {
			TermMessage("Error reading settings.json file: " + err.Error())
			return
		}

		json.Unmarshal(input, &settings)
	} else {
		settings = DefaultSettings()
		err := WriteSettings(filename)
		if err != nil {
			TermMessage("Error writing settings.json file: " + err.Error())
		}
	}
}

// WriteSettings writes the settings to the specified filename as JSON
func WriteSettings(filename string) error {
	txt, _ := json.MarshalIndent(settings, "", "    ")
	err := ioutil.WriteFile(filename, txt, 0644)
	return err
}

// DefaultSettings returns the default settings for micro
func DefaultSettings() Settings {
	return Settings{
		Colorscheme: "default",
		TabSize:     4,
		AutoIndent:  true,
		Syntax:      true,
	}
}

// SetOption prompts the user to set an option and checks that the response is valid
func SetOption(view *View, args []string) {<commit_msg>Only use settings.json if ~/.micro exists<commit_after>package main

import (
	"encoding/json"
	"github.com/mitchellh/go-homedir"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

// The options that the user can set
var settings Settings

// All the possible settings
var possibleSettings = []string{"colorscheme", "tabsize", "autoindent", "syntax"}

// The Settings struct contains the settings for micro
type Settings struct {
	Colorscheme string `json:"colorscheme"`
	TabSize     int    `json:"tabsize"`
	AutoIndent  bool   `json:"autoindent"`
	Syntax      bool   `json:"syntax"`
}

// InitSettings initializes the options map and sets all options to their default values
func InitSettings() {
	home, err := homedir.Dir()
	if err != nil {
		TermMessage("Error finding your home directory\nCan't load settings file")
		return
	}

	filename := home + "/.micro/settings.json"
	if _, e := os.Stat(filename); e == nil {
		input, err := ioutil.ReadFile(filename)
		if err != nil {
			TermMessage("Error reading settings.json file: " + err.Error())
			return
		}

		json.Unmarshal(input, &settings)
	} else {
		settings = DefaultSettings()
		err := WriteSettings(filename)
		if err != nil {
			TermMessage("Error writing settings.json file: " + err.Error())
		}
	}
}

// WriteSettings writes the settings to the specified filename as JSON
func WriteSettings(filename string) error {
	var err error
	home, err := homedir.Dir()
	if err != nil {
		return err
	}
	if _, e := os.Stat(home + "/.micro"); e == nil {
		txt, _ := json.MarshalIndent(settings, "", "    ")
		err = ioutil.WriteFile(filename, txt, 0644)
	}
	return err
}

// DefaultSettings returns the default settings for micro
func DefaultSettings() Settings {
	return Settings{
		Colorscheme: "default",
		TabSize:     4,
		AutoIndent:  true,
		Syntax:      true,
	}
}

// SetOption prompts the user to set an option and checks that the response is valid
func SetOption(view *View, args []string) {
{'fraction_non_alphanumeric': 0.11964668094218416, 'fraction_numerical': 0.0026766595289079227, 'mean_word_length': 3.803341902313625, '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': '6091283', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1155, 'n_words': 380}