Struct ftd::render::SS [−][src]
pub struct SS { /* fields omitted */ }
Methods from Deref<Target = SyntaxSet>
The list of syntaxes in the set
Finds a syntax by its default scope, for example source.regexp
finds the regex syntax.
This and all similar methods below do a linear search of syntaxes, this should be fast because there aren’t many syntaxes, but don’t think you can call it a bajillion times per second.
Searches for a syntax first by extension and then by case-insensitive name
This is useful for things like Github-flavoured-markdown code block highlighting where all you have to go on is a short token given by the user
Try to find the syntax for a file based on its first line
This uses regexes that come with some sublime syntax grammars for matching things like
shebangs and mode lines like -*- Mode: C -*-
Searches for a syntax by it’s original file path when it was first loaded from disk
This is primarily useful for syntax tests. Some may specify a
Packages/PackageName/SyntaxName.sublime-syntax
path, and others may just have
SyntaxName.sublime-syntax
. This caters for these by matching the end of the path of the
loaded syntax definition files
pub fn find_syntax_for_file<P>(
&self,
path_obj: P
) -> Result<Option<&SyntaxReference>, Error> where
P: AsRef<Path>,
pub fn find_syntax_for_file<P>(
&self,
path_obj: P
) -> Result<Option<&SyntaxReference>, Error> where
P: AsRef<Path>,
Convenience method that tries to find the syntax for a file path, first by extension/name and then by first line of the file if that doesn’t work.
May IO Error because it sometimes tries to read the first line of the file.
Examples
When determining how to highlight a file, use this in combination with a fallback to plain text:
use syntect::parsing::SyntaxSet;
let ss = SyntaxSet::load_defaults_newlines();
let syntax = ss.find_syntax_for_file("testdata/highlight_test.erb")
.unwrap() // for IO errors, you may want to use try!() or another plain text fallback
.unwrap_or_else(|| ss.find_syntax_plain_text());
assert_eq!(syntax.name, "HTML (Rails)");
Finds a syntax for plain text, which usually has no highlighting rules.
This is good as a fallback when you can’t find another syntax but you still want to use the same highlighting pipeline code.
This syntax should always be present, if not this method will panic. If the way you load
syntaxes doesn’t create one, use add_plain_text_syntax
.
Examples
use syntect::parsing::SyntaxSetBuilder;
let mut builder = SyntaxSetBuilder::new();
builder.add_plain_text_syntax();
let ss = builder.build();
let syntax = ss.find_syntax_by_token("rs").unwrap_or_else(|| ss.find_syntax_plain_text());
assert_eq!(syntax.name, "Plain Text");