mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 14:55:38 -04:00
buffer: Store the encoding
inside the buffer
This commit is contained in:
parent
fe134b92d5
commit
8b21724c6e
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/zyedidia/micro/v2/internal/screen"
|
"github.com/zyedidia/micro/v2/internal/screen"
|
||||||
"github.com/zyedidia/micro/v2/internal/util"
|
"github.com/zyedidia/micro/v2/internal/util"
|
||||||
"github.com/zyedidia/micro/v2/pkg/highlight"
|
"github.com/zyedidia/micro/v2/pkg/highlight"
|
||||||
|
"golang.org/x/text/encoding"
|
||||||
"golang.org/x/text/encoding/htmlindex"
|
"golang.org/x/text/encoding/htmlindex"
|
||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
@ -87,6 +88,8 @@ type SharedBuffer struct {
|
|||||||
// LocalSettings customized by the user for this buffer only
|
// LocalSettings customized by the user for this buffer only
|
||||||
LocalSettings map[string]bool
|
LocalSettings map[string]bool
|
||||||
|
|
||||||
|
encoding encoding.Encoding
|
||||||
|
|
||||||
Suggestions []string
|
Suggestions []string
|
||||||
Completions []string
|
Completions []string
|
||||||
CurSuggestion int
|
CurSuggestion int
|
||||||
@ -337,9 +340,9 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
|||||||
}
|
}
|
||||||
config.UpdatePathGlobLocals(b.Settings, absPath)
|
config.UpdatePathGlobLocals(b.Settings, absPath)
|
||||||
|
|
||||||
enc, err := htmlindex.Get(b.Settings["encoding"].(string))
|
b.encoding, err = htmlindex.Get(b.Settings["encoding"].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
enc = unicode.UTF8
|
b.encoding = unicode.UTF8
|
||||||
b.Settings["encoding"] = "utf-8"
|
b.Settings["encoding"] = "utf-8"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +353,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
|||||||
return NewBufferFromString("", "", btype)
|
return NewBufferFromString("", "", btype)
|
||||||
}
|
}
|
||||||
if !hasBackup {
|
if !hasBackup {
|
||||||
reader := bufio.NewReader(transform.NewReader(r, enc.NewDecoder()))
|
reader := bufio.NewReader(transform.NewReader(r, b.encoding.NewDecoder()))
|
||||||
|
|
||||||
var ff FileFormat = FFAuto
|
var ff FileFormat = FFAuto
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/zyedidia/micro/v2/internal/config"
|
"github.com/zyedidia/micro/v2/internal/config"
|
||||||
"github.com/zyedidia/micro/v2/internal/screen"
|
"github.com/zyedidia/micro/v2/internal/screen"
|
||||||
"github.com/zyedidia/micro/v2/internal/util"
|
"github.com/zyedidia/micro/v2/internal/util"
|
||||||
"golang.org/x/text/encoding/htmlindex"
|
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -118,12 +117,7 @@ func openFile(name string, withSudo bool) (wrappedFile, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wf wrappedFile) Write(b *Buffer) (int, error) {
|
func (wf wrappedFile) Write(b *Buffer) (int, error) {
|
||||||
enc, err := htmlindex.Get(b.Settings["encoding"].(string))
|
file := bufio.NewWriter(transform.NewWriter(wf.writeCloser, b.encoding.NewEncoder()))
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
file := bufio.NewWriter(transform.NewWriter(wf.writeCloser, enc.NewEncoder()))
|
|
||||||
|
|
||||||
b.Lock()
|
b.Lock()
|
||||||
defer b.Unlock()
|
defer b.Unlock()
|
||||||
@ -142,7 +136,7 @@ func (wf wrappedFile) Write(b *Buffer) (int, error) {
|
|||||||
|
|
||||||
if !wf.withSudo {
|
if !wf.withSudo {
|
||||||
f := wf.writeCloser.(*os.File)
|
f := wf.writeCloser.(*os.File)
|
||||||
err = f.Truncate(0)
|
err := f.Truncate(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"github.com/zyedidia/micro/v2/internal/config"
|
"github.com/zyedidia/micro/v2/internal/config"
|
||||||
ulua "github.com/zyedidia/micro/v2/internal/lua"
|
ulua "github.com/zyedidia/micro/v2/internal/lua"
|
||||||
"github.com/zyedidia/micro/v2/internal/screen"
|
"github.com/zyedidia/micro/v2/internal/screen"
|
||||||
|
"golang.org/x/text/encoding/htmlindex"
|
||||||
|
"golang.org/x/text/encoding/unicode"
|
||||||
luar "layeh.com/gopher-luar"
|
luar "layeh.com/gopher-luar"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,6 +99,12 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
|
|||||||
b.UpdateRules()
|
b.UpdateRules()
|
||||||
}
|
}
|
||||||
} else if option == "encoding" {
|
} else if option == "encoding" {
|
||||||
|
enc, err := htmlindex.Get(b.Settings["encoding"].(string))
|
||||||
|
if err != nil {
|
||||||
|
enc = unicode.UTF8
|
||||||
|
b.Settings["encoding"] = "utf-8"
|
||||||
|
}
|
||||||
|
b.encoding = enc
|
||||||
b.isModified = true
|
b.isModified = true
|
||||||
} else if option == "readonly" && b.Type.Kind == BTDefault.Kind {
|
} else if option == "readonly" && b.Type.Kind == BTDefault.Kind {
|
||||||
b.Type.Readonly = nativeValue.(bool)
|
b.Type.Readonly = nativeValue.(bool)
|
||||||
|
Loading…
Reference in New Issue
Block a user