|
65 | 65 | // BTStdout is a buffer that only writes to stdout |
66 | 66 | // when closed |
67 | 67 | BTStdout = BufType{6, false, true, true} |
68 | | - |
69 | | - // ErrFileTooLarge is returned when the file is too large to hash |
70 | | - // (fastdirty is automatically enabled) |
71 | | - ErrFileTooLarge = errors.New("File is too large to hash") |
72 | 68 | ) |
73 | 69 |
|
74 | 70 | // SharedBuffer is a struct containing info that is shared among buffers |
@@ -555,7 +551,11 @@ func (b *Buffer) ReOpen() error { |
555 | 551 |
|
556 | 552 | err = b.UpdateModTime() |
557 | 553 | if !b.Settings["fastdirty"].(bool) { |
558 | | - calcHash(b, &b.origHash) |
| 554 | + if len(data) > LargeFileThreshold { |
| 555 | + b.Settings["fastdirty"] = true |
| 556 | + } else { |
| 557 | + calcHash(b, &b.origHash) |
| 558 | + } |
559 | 559 | } |
560 | 560 | b.isModified = false |
561 | 561 | b.RelocateCursors() |
@@ -650,37 +650,23 @@ func (b *Buffer) Size() int { |
650 | 650 | } |
651 | 651 |
|
652 | 652 | // calcHash calculates md5 hash of all lines in the buffer |
653 | | -func calcHash(b *Buffer, out *[md5.Size]byte) error { |
| 653 | +func calcHash(b *Buffer, out *[md5.Size]byte) { |
654 | 654 | h := md5.New() |
655 | 655 |
|
656 | | - size := 0 |
657 | 656 | if len(b.lines) > 0 { |
658 | | - n, e := h.Write(b.lines[0].data) |
659 | | - if e != nil { |
660 | | - return e |
661 | | - } |
662 | | - size += n |
| 657 | + h.Write(b.lines[0].data) |
663 | 658 |
|
664 | 659 | for _, l := range b.lines[1:] { |
665 | | - n, e = h.Write([]byte{'\n'}) |
666 | | - if e != nil { |
667 | | - return e |
668 | | - } |
669 | | - size += n |
670 | | - n, e = h.Write(l.data) |
671 | | - if e != nil { |
672 | | - return e |
| 660 | + if b.Endings == FFDos { |
| 661 | + h.Write([]byte{'\r', '\n'}) |
| 662 | + } else { |
| 663 | + h.Write([]byte{'\n'}) |
673 | 664 | } |
674 | | - size += n |
| 665 | + h.Write(l.data) |
675 | 666 | } |
676 | 667 | } |
677 | 668 |
|
678 | | - if size > LargeFileThreshold { |
679 | | - return ErrFileTooLarge |
680 | | - } |
681 | | - |
682 | 669 | h.Sum((*out)[:0]) |
683 | | - return nil |
684 | 670 | } |
685 | 671 |
|
686 | 672 | func parseDefFromFile(f config.RuntimeFile, header *highlight.Header) *highlight.Def { |
@@ -1373,17 +1359,19 @@ func (b *Buffer) FindMatchingBrace(start Loc) (Loc, bool, bool) { |
1373 | 1359 | } |
1374 | 1360 | } |
1375 | 1361 |
|
1376 | | - // failed to find matching brace for the given location, so try to find matching |
1377 | | - // brace for the location one character left of it |
1378 | | - if start.X-1 >= 0 && start.X-1 < len(curLine) { |
1379 | | - leftChar := curLine[start.X-1] |
1380 | | - left := Loc{start.X - 1, start.Y} |
| 1362 | + if b.Settings["matchbraceleft"].(bool) { |
| 1363 | + // failed to find matching brace for the given location, so try to find matching |
| 1364 | + // brace for the location one character left of it |
| 1365 | + if start.X-1 >= 0 && start.X-1 < len(curLine) { |
| 1366 | + leftChar := curLine[start.X-1] |
| 1367 | + left := Loc{start.X - 1, start.Y} |
1381 | 1368 |
|
1382 | | - for _, bp := range BracePairs { |
1383 | | - if leftChar == bp[0] || leftChar == bp[1] { |
1384 | | - mb, found := b.findMatchingBrace(bp, left, leftChar) |
1385 | | - if found { |
1386 | | - return mb, true, true |
| 1369 | + for _, bp := range BracePairs { |
| 1370 | + if leftChar == bp[0] || leftChar == bp[1] { |
| 1371 | + mb, found := b.findMatchingBrace(bp, left, leftChar) |
| 1372 | + if found { |
| 1373 | + return mb, true, true |
| 1374 | + } |
1387 | 1375 | } |
1388 | 1376 | } |
1389 | 1377 | } |
|
0 commit comments