Add tabsToSpaces option

This commit is contained in:
Zachary Yedidia
2016-04-18 13:01:39 -04:00
parent fa7808b4ae
commit c7f8584d84
4 changed files with 37 additions and 13 deletions

View File

@@ -122,10 +122,13 @@ Micro has a few options which you can set:
* colorscheme
* tabsize
* syntax
* tabsToSpaces
To set an option run Ctrl-e to execute a command, and type `set option value`, so to set the tabsize to 8 it would be `set tabsize 8`.
To set an option run Ctrl-e to execute a command, and type `set option value`, so to set the tabsize to 8 it would be `set tabsize 8`. The default is 4.
The syntax option can simply be on or off, so for example to turn syntax highlighting off, run `set syntax off`.
The syntax option can simply be on or off, so for example to turn syntax highlighting off, run `set syntax off`. The default is on.
The tabsToSpaces option is on or off. It specifies whether to use spaces instead of tabs or not. The default is off.
The colorscheme can be selected from all the files in the `ConfigDir/colorschemes/` directory. Micro comes by default with three colorschemes:

View File

@@ -63,6 +63,9 @@ tabsize: sets the tab size to 'option'
syntax: turns syntax on or off
default value: 'on'
tabsToSpaces: use spaces instead of tabs
default value: 'off'
`
// DisplayHelp displays the help txt

View File

@@ -12,14 +12,15 @@ import (
var settings Settings
// All the possible settings
var possibleSettings = []string{"colorscheme", "tabsize", "autoindent", "syntax"}
var possibleSettings = []string{"colorscheme", "tabsize", "autoindent", "syntax", "tabsToSpaces"}
// 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"`
Colorscheme string `json:"colorscheme"`
TabSize int `json:"tabsize"`
AutoIndent bool `json:"autoindent"`
Syntax bool `json:"syntax"`
TabsToSpaces bool `json:"tabsToSpaces"`
}
// InitSettings initializes the options map and sets all options to their default values
@@ -55,10 +56,11 @@ func WriteSettings(filename string) error {
// DefaultSettings returns the default settings for micro
func DefaultSettings() Settings {
return Settings{
Colorscheme: "default",
TabSize: 4,
AutoIndent: true,
Syntax: true,
Colorscheme: "default",
TabSize: 4,
AutoIndent: true,
Syntax: true,
TabsToSpaces: false,
}
}
@@ -92,6 +94,15 @@ func SetOption(view *View, args []string) {
}
LoadSyntaxFiles()
view.buf.UpdateRules()
} else if option == "tabsToSpaces" {
if value == "on" {
settings.TabsToSpaces = true
} else if value == "off" {
settings.TabsToSpaces = false
} else {
messenger.Error("Invalid value for " + option)
return
}
}
err := WriteSettings(filename)
if err != nil {

View File

@@ -424,8 +424,15 @@ func (v *View) HandleEvent(event tcell.Event) {
v.cursor.DeleteSelection()
v.cursor.ResetSelection()
}
v.eh.Insert(v.cursor.Loc(), "\t")
v.cursor.Right()
if settings.TabsToSpaces {
v.eh.Insert(v.cursor.Loc(), Spaces(settings.TabSize))
for i := 0; i < settings.TabSize; i++ {
v.cursor.Right()
}
} else {
v.eh.Insert(v.cursor.Loc(), "\t")
v.cursor.Right()
}
v.UpdateLines(v.cursor.y, v.cursor.y)
case tcell.KeyCtrlS:
v.Save()