"bytes"
"crypto/md5"
"errors"
+ "fmt"
"io"
"io/ioutil"
- "log"
"os"
+ "path"
"path/filepath"
"strconv"
"strings"
BTRaw = BufType{4, false, true, false}
// BTInfo is a buffer for inputting information
BTInfo = BufType{5, false, true, false}
+ // BTStdout is a buffer that only writes to stdout
+ // when closed
+ BTStdout = BufType{6, false, true, true}
// ErrFileTooLarge is returned when the file is too large to hash
// (fastdirty is automatically enabled)
// Name of the buffer on the status line
name string
+ toStdout bool
+
// Settings customized by the user
Settings map[string]interface{}
b.LineArray.insert(pos, value)
inslines := bytes.Count(value, []byte{'\n'})
- log.Println("insert", string(value), pos.Y, pos.Y+inslines)
b.MarkModified(pos.Y, pos.Y+inslines)
}
func (b *SharedBuffer) remove(start, end Loc) []byte {
return
}
- log.Println("Modified", start, end, len(b.lines))
start = util.Clamp(start, 0, len(b.lines))
end = util.Clamp(end, 0, len(b.lines))
l := -1
- log.Println("Modified", start, end)
for i := start; i <= end; i++ {
l = util.Max(b.Highlighter.ReHighlightStates(b, i), l)
}
b.LineArray = NewLineArray(uint64(size), FFAuto, reader)
}
b.EventHandler = NewEventHandler(b.SharedBuffer, b.cursors)
+
+ // The last time this file was modified
+ b.UpdateModTime()
}
if b.Settings["readonly"].(bool) && b.Type == BTDefault {
b.Type.Readonly = true
}
- // The last time this file was modified
- b.UpdateModTime()
-
switch b.Endings {
case FFUnix:
b.Settings["fileformat"] = "unix"
b.AddCursor(NewCursor(b, b.StartCursor))
b.GetActiveCursor().Relocate()
- if !b.Settings["fastdirty"].(bool) {
+ if !b.Settings["fastdirty"].(bool) && !found {
if size > LargeFileThreshold {
// If the file is larger than LargeFileThreshold fastdirty needs to be on
b.Settings["fastdirty"] = true
b.Serialize()
}
b.RemoveBackup()
+
+ if b.Type == BTStdout {
+ fmt.Fprint(util.Stdout, string(b.Bytes()))
+ }
}
// GetName returns the name that should be displayed in the statusline
// for this buffer
func (b *Buffer) GetName() string {
- if b.name == "" {
+ name := b.name
+ if name == "" {
if b.Path == "" {
return "No name"
}
- return b.Path
+ name = b.Path
}
- return b.name
+ if b.Settings["basename"].(bool) {
+ return path.Base(name)
+ }
+ return name
}
//SetName changes the name for this buffer
return
}
syntaxFile := ""
+ foundDef := false
var header *highlight.Header
+ // search for the syntax file in the user's custom syntax files
+ for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
+ data, err := f.Data()
+ if err != nil {
+ screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
+ continue
+ }
+
+ header, err = highlight.MakeHeaderYaml(data)
+ file, err := highlight.ParseFile(data)
+ if err != nil {
+ screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
+ continue
+ }
+
+ if ((ft == "unknown" || ft == "") && highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data)) || header.FileType == ft {
+ syndef, err := highlight.ParseDef(file, header)
+ if err != nil {
+ screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
+ continue
+ }
+ b.SyntaxDef = syndef
+ syntaxFile = f.Name()
+ foundDef = true
+ break
+ }
+ }
+
+ // search in the default syntax files
for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
data, err := f.Data()
if err != nil {
}
}
- if syntaxFile == "" {
- // search for the syntax file in the user's custom syntax files
- for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
- log.Println("real runtime file", f.Name())
- data, err := f.Data()
- if err != nil {
- screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
- continue
- }
-
- header, err = highlight.MakeHeaderYaml(data)
- file, err := highlight.ParseFile(data)
- if err != nil {
- screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
- continue
- }
-
- if ((ft == "unknown" || ft == "") && highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data)) || header.FileType == ft {
- syndef, err := highlight.ParseDef(file, header)
- if err != nil {
- screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
- continue
- }
- b.SyntaxDef = syndef
- break
- }
- }
- } else {
+ if syntaxFile != "" && !foundDef {
+ // we found a syntax file using a syntax header file
for _, f := range config.ListRuntimeFiles(config.RTSyntax) {
if f.Name() == syntaxFile {
data, err := f.Data()
b.UpdateCursors()
b.curCursor = 0
b.GetActiveCursor().ResetSelection()
- log.Println("Cleared cursors:", len(b.cursors))
}
// MoveLinesUp moves the range of lines up one row