UpdateRules updates the syntax rules and filetype for this buffer This is called when the colorscheme changes
()
| 815 | // UpdateRules updates the syntax rules and filetype for this buffer |
| 816 | // This is called when the colorscheme changes |
| 817 | func (b *Buffer) UpdateRules() { |
| 818 | if !b.Type.Syntax { |
| 819 | return |
| 820 | } |
| 821 | ft := b.Settings["filetype"].(string) |
| 822 | if ft == "off" { |
| 823 | b.ClearMatches() |
| 824 | b.SyntaxDef = nil |
| 825 | return |
| 826 | } |
| 827 | |
| 828 | b.SyntaxDef = nil |
| 829 | |
| 830 | // syntaxFileInfo is an internal helper structure |
| 831 | // to store properties of one single syntax file |
| 832 | type syntaxFileInfo struct { |
| 833 | header *highlight.Header |
| 834 | fileName string |
| 835 | syntaxDef *highlight.Def |
| 836 | } |
| 837 | |
| 838 | fnameMatches := []syntaxFileInfo{} |
| 839 | headerMatches := []syntaxFileInfo{} |
| 840 | syntaxFile := "" |
| 841 | foundDef := false |
| 842 | var header *highlight.Header |
| 843 | // search for the syntax file in the user's custom syntax files |
| 844 | for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) { |
| 845 | if f.Name() == "default" { |
| 846 | continue |
| 847 | } |
| 848 | |
| 849 | data, err := f.Data() |
| 850 | if err != nil { |
| 851 | screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error()) |
| 852 | continue |
| 853 | } |
| 854 | |
| 855 | header, err = highlight.MakeHeaderYaml(data) |
| 856 | if err != nil { |
| 857 | screen.TermMessage("Error parsing header for syntax file " + f.Name() + ": " + err.Error()) |
| 858 | continue |
| 859 | } |
| 860 | |
| 861 | matchedFileType := false |
| 862 | matchedFileName := false |
| 863 | matchedFileHeader := false |
| 864 | |
| 865 | if ft == "unknown" || ft == "" { |
| 866 | if header.MatchFileName(b.Path) { |
| 867 | matchedFileName = true |
| 868 | } |
| 869 | if len(fnameMatches) == 0 && header.MatchFileHeader(b.lines[0].data) { |
| 870 | matchedFileHeader = true |
| 871 | } |
| 872 | } else if header.FileType == ft { |
| 873 | matchedFileType = true |
| 874 | } |
no test coverage detected