mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 14:40:20 +09:00
Fix fileformat
This commit is contained in:
@@ -163,6 +163,13 @@ func NewBuffer(reader io.Reader, size int64, path string, cursorPosition []strin
|
||||
b.EventHandler = NewEventHandler(b.SharedBuffer, b.cursors)
|
||||
}
|
||||
|
||||
switch b.Endings {
|
||||
case FFUnix:
|
||||
b.Settings["fileformat"] = "unix"
|
||||
case FFDos:
|
||||
b.Settings["fileformat"] = "dos"
|
||||
}
|
||||
|
||||
b.Path = path
|
||||
b.AbsPath = absPath
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ type FileFormat byte
|
||||
// and delete in it
|
||||
type LineArray struct {
|
||||
lines []Line
|
||||
endings FileFormat
|
||||
Endings FileFormat
|
||||
initsize uint64
|
||||
}
|
||||
|
||||
@@ -95,11 +95,12 @@ func NewLineArray(size uint64, endings FileFormat, reader io.Reader) *LineArray
|
||||
if dlen > 1 && data[dlen-2] == '\r' {
|
||||
data = append(data[:dlen-2], '\n')
|
||||
if endings == FFAuto {
|
||||
la.endings = FFDos
|
||||
la.Endings = FFDos
|
||||
}
|
||||
dlen = len(data)
|
||||
} else if dlen > 0 {
|
||||
if endings == FFAuto {
|
||||
la.endings = FFUnix
|
||||
la.Endings = FFUnix
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +144,7 @@ func (la *LineArray) Bytes() []byte {
|
||||
for i, l := range la.lines {
|
||||
str = append(str, l.data...)
|
||||
if i != len(la.lines)-1 {
|
||||
if la.endings == FFDos {
|
||||
if la.Endings == FFDos {
|
||||
str = append(str, '\r')
|
||||
}
|
||||
str = append(str, '\n')
|
||||
|
||||
@@ -107,7 +107,7 @@ func (b *Buffer) SaveAs(filename string) error {
|
||||
|
||||
// end of line
|
||||
var eol []byte
|
||||
if b.Settings["fileformat"] == "dos" {
|
||||
if b.Endings == FFDos {
|
||||
eol = []byte{'\r', '\n'}
|
||||
} else {
|
||||
eol = []byte{'\n'}
|
||||
|
||||
@@ -30,6 +30,12 @@ func (b *Buffer) SetOption(option, value string) error {
|
||||
} else if option == "filetype" {
|
||||
b.UpdateRules()
|
||||
} else if option == "fileformat" {
|
||||
switch b.Settings["fileformat"].(string) {
|
||||
case "unix":
|
||||
b.Endings = FFUnix
|
||||
case "dos":
|
||||
b.Endings = FFDos
|
||||
}
|
||||
b.isModified = true
|
||||
} else if option == "syntax" {
|
||||
if !nativeValue.(bool) {
|
||||
|
||||
Reference in New Issue
Block a user