"os/exec"
"os/signal"
"path/filepath"
+ "regexp"
"strconv"
"strings"
"time"
b.UpdateRules()
dir, _ := homedir.Dir()
b.Path = strings.Replace(filename, "~", dir, 1)
- str := b.String()
+ if b.Settings["rmtrailingws"].(bool) {
+ r, _ := regexp.Compile(`[ \t]+$`)
+ for lineNum, line := range b.Lines(0, b.NumLines) {
+ indices := r.FindStringIndex(line)
+ if indices == nil {
+ continue
+ }
+ startLoc := Loc{indices[0], lineNum}
+ b.deleteToEnd(startLoc)
+ }
+ b.Cursor.Relocate()
+ }
if b.Settings["eofnewline"].(bool) {
end := b.End()
if b.RuneAt(Loc{end.X - 1, end.Y}) != '\n' {
b.Insert(end, "\n")
}
}
+ str := b.String()
data := []byte(str)
err := ioutil.WriteFile(filename, data, 0644)
if err == nil {
b.Update()
return sub
}
+func (b *Buffer) deleteToEnd(start Loc) {
+ b.IsModified = true
+ b.LineArray.DeleteToEnd(start)
+ b.Update()
+}
// Start returns the location of the first character in the buffer
func (b *Buffer) Start() Loc {