MCPcopy
hub / github.com/micro-editor/micro / UpdateRules

Method UpdateRules

internal/buffer/buffer.go:817–1011  ·  view source on GitHub ↗

UpdateRules updates the syntax rules and filetype for this buffer This is called when the colorscheme changes

()

Source from the content-addressed store, hash-verified

815// UpdateRules updates the syntax rules and filetype for this buffer
816// This is called when the colorscheme changes
817func (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 }

Callers 4

ReloadSettingsMethod · 0.95
DoSetOptionNativeMethod · 0.95
doSetGlobalOptionNativeFunction · 0.80
NewBufferFunction · 0.80

Calls 15

ClearMatchesMethod · 0.95
MatchFileNameMethod · 0.95
MatchFileHeaderMethod · 0.95
ListRealRuntimeFilesFunction · 0.92
TermMessageFunction · 0.92
MakeHeaderYamlFunction · 0.92
ParseFileFunction · 0.92
ParseDefFunction · 0.92
ListRuntimeFilesFunction · 0.92
MakeHeaderFunction · 0.92
IntOptFunction · 0.92
NewHighlighterFunction · 0.92

Tested by

no test coverage detected