mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-04 22:20:20 +09:00
Add tabsToSpaces option
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user