mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-16 22:07:09 +09:00
@@ -542,6 +542,40 @@ func (v *View) ParagraphNext(usePlugin bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (v *View) Retab(usePlugin bool) bool {
|
||||
if usePlugin && !PreActionCall("Retab", v) {
|
||||
return false
|
||||
}
|
||||
|
||||
toSpaces := v.Buf.Settings["tabstospaces"].(bool)
|
||||
tabsize := int(v.Buf.Settings["tabsize"].(float64))
|
||||
dirty := false
|
||||
|
||||
for i := 0; i < v.Buf.NumLines; i++ {
|
||||
l := v.Buf.Line(i)
|
||||
|
||||
ws := GetLeadingWhitespace(l)
|
||||
if ws != "" {
|
||||
if toSpaces {
|
||||
ws = strings.Replace(ws, "\t", Spaces(tabsize), -1)
|
||||
} else {
|
||||
ws = strings.Replace(ws, Spaces(tabsize), "\t", -1)
|
||||
}
|
||||
}
|
||||
|
||||
l = strings.TrimLeft(l, " \t")
|
||||
v.Buf.lines[i].data = []byte(ws + l)
|
||||
dirty = true
|
||||
}
|
||||
|
||||
v.Buf.IsModified = dirty
|
||||
|
||||
if usePlugin {
|
||||
return PostActionCall("Retab", v)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// CursorStart moves the cursor to the start of the buffer
|
||||
func (v *View) CursorStart(usePlugin bool) bool {
|
||||
if usePlugin && !PreActionCall("CursorStart", v) {
|
||||
|
||||
@@ -55,6 +55,7 @@ func init() {
|
||||
"Open": Open,
|
||||
"TabSwitch": TabSwitch,
|
||||
"MemUsage": MemUsage,
|
||||
"Retab": Retab,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +111,7 @@ func DefaultCommands() map[string]StrCommand {
|
||||
"open": {"Open", []Completion{FileCompletion}},
|
||||
"tabswitch": {"TabSwitch", []Completion{NoCompletion}},
|
||||
"memusage": {"MemUsage", []Completion{NoCompletion}},
|
||||
"retab": {"Retab", []Completion{NoCompletion}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +198,10 @@ func PluginCmd(args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func Retab(args []string) {
|
||||
CurView().Retab(true)
|
||||
}
|
||||
|
||||
// TabSwitch switches to a given tab either by name or by number
|
||||
func TabSwitch(args []string) {
|
||||
if len(args) > 0 {
|
||||
|
||||
@@ -76,6 +76,9 @@ Here are the possible commands that you can use.
|
||||
|
||||
* `open filename`: Open a file in the current buffer.
|
||||
|
||||
* `retab`: Replaces all leading tabs with spaces or leading spaces with tabs
|
||||
depending on the value of `tabstospaces`.
|
||||
|
||||
---
|
||||
|
||||
The following commands are provided by the default plugins:
|
||||
|
||||
Reference in New Issue
Block a user