### Integration Example: Applying Dark Scheme to View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md
Demonstrates applying a dark color scheme to a source view. This example initializes a view, gets a scheme, and sets it on the buffer.
```rust
use sourceview5::{View, StyleSchemeManager};
let view = View::builder()
.show_line_numbers(true)
.highlight_current_line(true)
.build();
let buffer = view.buffer();
let manager = StyleSchemeManager::default();
// Apply dark scheme
if let Some(scheme) = manager.scheme("builder-dark") {
buffer.set_property("style-scheme", &scheme);
}
```
--------------------------------
### Basic Cargo.toml Setup for Sourceview5
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Add the sourceview5 crate and its dependencies to your Cargo.toml file for basic integration.
```toml
[dependencies]
sourceview5 = "0.12.0-alpha"
gtk4 = "0.12.0-alpha"
glib = "0.23.0-alpha"
```
--------------------------------
### Common Configurations
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Examples of common search configurations.
```APIDOC
## Common Configurations
### Case-Insensitive Search
```rust
let settings = SearchSettings::new();
settings.set_search_text("error");
settings.set_case_sensitive(false);
```
### Regular Expression Search
```rust
let settings = SearchSettings::new();
settings.set_search_text(r"^fn\s+\w+\s*(");
settings.set_regex_enabled(true);
```
### Whole Word Search
```rust
let settings = SearchSettings::new();
settings.set_search_text("match");
settings.set_at_word_boundaries(true);
```
```
--------------------------------
### Complete Search Example with Sourceview5
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Demonstrates setting up a buffer, configuring SearchSettings for case-insensitive search, and iterating through matches using SearchContext.
```rust
use sourceview5::{SearchSettings, SearchContext, Buffer};
let buffer = Buffer::new(None);
buffer.set_text("Hello World\nhello world\nHELLO WORLD");
let settings = SearchSettings::builder()
.search_text("hello")
.case_sensitive(false)
.wrap_around(true)
.build();
let context = SearchContext::new(&buffer, Some(&settings));
let mut iter = buffer.start_iter();
while let Some((start, end, _)) = context.forward(&iter) {
println!("Match at {}..{}", start.offset(), end.offset());
iter = end;
}
```
--------------------------------
### Integration with View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme-manager.md
Example demonstrating how to integrate StyleSchemeManager with a View to set color schemes and languages.
```APIDOC
## Integration with View
```rust
use sourceview5::{View, StyleSchemeManager, Buffer, LanguageManager};
let view = View::new();
let buffer = view.buffer();
// Set a color scheme
let style_manager = StyleSchemeManager::default();
if let Some(scheme) = style_manager.scheme("builder-dark") {
buffer.set_property("style-scheme", &scheme);
}
// Set a language for syntax highlighting
let lang_manager = LanguageManager::default();
if let Some(lang) = lang_manager.language("rust") {
buffer.set_language(Some(&lang));
}
```
```
--------------------------------
### BackgroundPatternType Enum and Example
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/types.md
Specifies the background pattern for the editor. The example shows how to set the grid pattern when building a `View`.
```rust
pub enum BackgroundPatternType {
None,
Grid,
__Unknown(i32),
}
```
```rust
use sourceview5::{View, BackgroundPatternType};
let view = View::builder()
.background_pattern(BackgroundPatternType::Grid)
.build();
```
--------------------------------
### Documentation Hover Provider Example
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/hover.md
A sample implementation of a HoverProvider that displays documentation for a symbol at the cursor. It includes placeholder logic for looking up documentation.
```rust
pub struct DocsHoverProvider;
impl HoverProviderExt for DocsHoverProvider {
fn populate(
&self,
context: &HoverContext,
display: &HoverDisplay,
) -> bool {
// Extract symbol at cursor
let iter = context.iter();
let buffer = context.buffer();
// Look up documentation from language server or database
let docs = lookup_docs(iter, buffer); // Assuming lookup_docs is defined elsewhere
if !docs.is_empty() {
let label = gtk::Label::new(Some(&docs));
label.set_wrap(true);
display.append(&label);
true
} else {
false
}
}
}
```
--------------------------------
### Complete File Loading Workflow Example
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-loader.md
Demonstrates the full process of loading a file asynchronously, including querying file info, opening a stream, creating a buffer with language detection, and initiating the load.
```rust
use sourceview5::{Buffer, FileLoader, LanguageManager, StyleSchemeManager};
use gio::File;
let file_path = "src/main.rs";
let file = File::for_path(file_path);
// Query file information
let file_info = file.query_info(
"*",
gio::FileQueryInfoFlags::NONE,
None::<&gio::Cancellable>,
)?;
// Open file for reading
let stream = file.read(None::<&gio::Cancellable>)?;
// Create buffer with appropriate language
let buffer = {
let manager = LanguageManager::default();
let language = manager.guess_language(Some(file_path), None);
let buf = Buffer::new(None);
if let Some(lang) = language {
buf.set_language(Some(&lang));
}
buf
};
// Load file
let loader = FileLoader::new(&file_info, &stream, &buffer, &file);
loader.load_async(
gio::glib::PRIORITY_DEFAULT,
None,
|result| {
match result {
Ok(()) => println!("Loaded {}", file_path),
Err(e) => eprintln!("Failed to load {}: {}", file_path, e),
}
},
);
```
--------------------------------
### Cargo.toml Setup with Version Features
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Configure sourceview5 and its dependencies with specific version features in Cargo.toml to target particular GtkSourceView and GTK4 versions.
```toml
[dependencies]
sourceview5 = { version = "0.12.0-alpha", features = ["v5_18", "gtk_v4_18"] }
gtk4 = { version = "0.12.0-alpha", features = ["v4_18"] }
glib = "0.23.0-alpha"
```
--------------------------------
### Custom Color Schemes
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md
Explains how to create and use custom color schemes by providing an XML example and steps to integrate them.
```APIDOC
## Custom Color Schemes
Create custom schemes by adding `.xml` files to scheme search paths:
```xml
```
Then use:
```rust
let manager = StyleSchemeManager::default();
manager.prepend_search_path("/path/to/custom/schemes");
manager.force_rescan();
let scheme = manager.scheme("my-custom");
```
```
--------------------------------
### Constructing a SourceView5 View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/view.md
Use the ViewBuilder to configure various appearance and behavior properties, then call build() to create the View widget. This example demonstrates setting indentation, line numbering, right margin, and background pattern.
```rust
use sourceview5::{View, SmartHomeEndType, BackgroundPatternType, Buffer};
let view = View::builder()
.auto_indent(true)
.show_line_numbers(true)
.show_right_margin(true)
.right_margin_position(80)
.highlight_current_line(true)
.indent_width(2)
.indent_on_tab(true)
.insert_spaces_instead_of_tabs(true)
.smart_home_end(SmartHomeEndType::Before)
.background_pattern(BackgroundPatternType::Grid)
.build();
```
--------------------------------
### Retrieve a Specific StyleScheme by ID
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme-manager.md
Get a color scheme using its unique identifier. Returns None if the scheme is not found. Example uses 'builder-dark'.
```rust
use sourceview5::StyleSchemeManager;
let manager = StyleSchemeManager::default();
if let Some(dark) = manager.scheme("builder-dark") {
println!("Dark scheme found: {}", dark.name());
}
```
--------------------------------
### Function Definition Snippet Example
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/snippet.md
Demonstrates creating a common function definition snippet with placeholders for name, parameters, return type, and body.
```rust
use sourceview5::Snippet;
let snippet = Snippet::new(
Some("fn"),
"fn ${name}(${params}) -> ${return_type} {\n ${body}\n}",
);
snippet.set_description(Some("Function definition"));
```
--------------------------------
### Editor Setup with Language and Style Scheme
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language.md
Configures a SourceView editor by creating a View and Buffer, applying a specific programming language, and setting a color scheme.
```rust
use sourceview5::{Buffer, View, LanguageManager, StyleSchemeManager};
// Create editor setup
let manager = LanguageManager::default();
let style_manager = StyleSchemeManager::default();
let view = View::builder()
.show_line_numbers(true)
.show_right_margin(true)
.right_margin_position(80)
.build();
let buffer = view.buffer();
// Apply language
if let Some(lang) = manager.language("rust") {
buffer.set_language(Some(&lang));
}
// Apply color scheme
if let Some(scheme) = style_manager.scheme("builder-dark") {
buffer.set_property("style-scheme", &scheme);
}
```
--------------------------------
### ChangeCaseType Enum and Example
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/types.md
Defines text case transformation types. The example demonstrates converting buffer text to uppercase.
```rust
pub enum ChangeCaseType {
Lower,
Upper,
Toggle,
Title,
__Unknown(i32),
}
```
```rust
use sourceview5::{Buffer, ChangeCaseType};
let buffer = Buffer::new(None);
buffer.set_text("hello world");
let mut start = buffer.start_iter();
let mut end = buffer.end_iter();
buffer.change_case(ChangeCaseType::Upper, &mut start, &mut end);
// Result: "HELLO WORLD"
```
--------------------------------
### Create and Configure a Buffer using Builder Pattern
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/buffer.md
Use the Buffer.builder() method to create a new Buffer instance with custom configurations. This example demonstrates setting the language, style scheme, enabling syntax highlighting, undo functionality, and providing initial text content.
```rust
use sourceview5::{Buffer, LanguageManager, StyleSchemeManager};
let manager = LanguageManager::default();
let style_manager = StyleSchemeManager::default();
let python = manager.language("python").unwrap();
let dark_scheme = style_manager.scheme("builder-dark").unwrap();
let buffer = Buffer::builder()
.language(&python)
.style_scheme(&dark_scheme)
.highlight_syntax(true)
.enable_undo(true)
.text("print('Hello, World!')")
.build();
```
--------------------------------
### Initialize GTK4 and Sourceview5
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/README.md
GTK4 must be initialized before using sourceview5. This snippet shows the basic setup for a GTK application and demonstrates where it's safe to instantiate a sourceview5::View.
```rust
use gtk::prelude::*;
fn main() -> glib::ExitCode {
let app = gtk::Application::new(None, Default::default());
app.connect_activate(|app| {
// GTK initialized; safe to use sourceview5
let view = sourceview5::View::new();
// ...
});
app.run()
}
```
--------------------------------
### Create New SearchSettings
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Creates a new SearchSettings object with default values. Use this as a starting point for configuring search parameters.
```rust
use sourceview5::SearchSettings;
let settings = SearchSettings::new();
settings.set_search_text("pattern");
```
--------------------------------
### Retrieve Language Search Paths
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language-manager.md
Get the list of directories where language definitions are searched. This is useful for understanding the current configuration.
```rust
let manager = LanguageManager::default();
for path in manager.search_path() {
println!("Search path: {}", path);
}
```
--------------------------------
### Get StyleScheme Description
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md
Retrieves a description of the color scheme's characteristics. Returns None if no description is available.
```rust
if let Some(desc) = scheme.description() {
println!("Description: {}", desc);
}
```
--------------------------------
### Get and Set Matrix Visualization
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/space-drawer.md
Use `matrix()` to check if grid visualization is enabled and `set_matrix()` to enable or disable it. This affects how whitespace is displayed when enabled.
```rust
pub fn matrix(&self) -> bool
pub fn set_matrix(&self, enable_matrix: bool)
```
```rust
let drawer = view.space_drawer();
drawer.set_matrix(true); // Display as dots
```
--------------------------------
### Loop Structure Snippet Example
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/snippet.md
Provides a snippet for a common loop structure, with placeholders for the loop variable, iterator, and loop body.
```rust
let snippet = Snippet::new(
Some("for"),
"for ${var} in ${iter} {\n ${body}\n}",
);
```
--------------------------------
### Implement Custom Hover Provider
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/hover.md
Example of implementing a custom HoverProvider trait to provide contextual information. This involves defining a struct and implementing the populate method.
```rust
use sourceview5::{HoverProvider, HoverContext, HoverDisplay};
use gtk::{glib, prelude::*};
glib::wrapper! {
pub struct CustomHoverProvider(ObjectSubclass)
@extends HoverProvider;
}
pub struct CustomHoverProviderImp;
impl ObjectSubclass for CustomHoverProviderImp {
const NAME: &'static str = "CustomHoverProvider";
type Type = CustomHoverProvider;
type ParentType = HoverProvider;
}
impl ObjectImpl for CustomHoverProviderImp {}
impl HoverProviderImpl for CustomHoverProviderImp {
fn populate(&self, context: &HoverContext, display: &HoverDisplay) -> bool {
// Get context information
let iter = context.iter();
let line = iter.line();
// Populate display with content
display.append(>k::Label::new(Some(&format!("Line {}", line))));
true
}
}
```
--------------------------------
### Search for Text in Sourceview5 Buffer
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/README.md
Perform a forward search for specific text within a buffer using SearchContext and SearchSettings. This example searches for 'TODO' case-insensitively.
```rust
use sourceview5::{SearchContext, SearchSettings};
let settings = SearchSettings::new();
settings.set_search_text("TODO");
settings.set_case_sensitive(false);
let context = SearchContext::new(&buffer, Some(&settings));
// Find forward
if let Some((start, end, _wrapped)) = context.forward(&buffer.start_iter()) {
println!("Found match");
}
```
--------------------------------
### If/Else Block Snippet Example
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/snippet.md
Creates a snippet for an if/else block structure, including placeholders for the condition, true branch, and false branch.
```rust
let snippet = Snippet::new(
Some("if"),
"if ${condition} {\n ${true_branch}\n} else {\n ${false_branch}\n}",
);
```
--------------------------------
### Get Language Name
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language.md
Retrieves the human-readable name of the language. Requires a LanguageManager to get a Language object.
```rust
use sourceview5::LanguageManager;
let manager = LanguageManager::default();
if let Some(rust) = manager.language("rust") {
println!("Language: {}", rust.name()); // Output: Language: Rust
}
```
--------------------------------
### Initialize and Configure Sourceview View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/INDEX.md
Demonstrates how to create a new View, enable line numbers and highlight current line, and set the language for the buffer using LanguageManager.
```rust
use sourceview5::{View, LanguageManager, StyleSchemeManager};
let view = View::builder()
.show_line_numbers(true)
.highlight_current_line(true)
.build();
let manager = LanguageManager::default();
if let Some(lang) = manager.language("rust") {
view.buffer().set_language(Some(&lang));
}
```
--------------------------------
### Get StyleScheme ID
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md
Retrieves the unique identifier of the color scheme. Use this to get the scheme's internal name.
```rust
use sourceview5::StyleSchemeManager;
let manager = StyleSchemeManager::default();
if let Some(scheme) = manager.scheme("builder-dark") {
println!("Scheme ID: {}", scheme.id());
}
```
--------------------------------
### Create a Sourceview5 Editor with Options
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/README.md
Instantiate a new View with custom settings like line numbers and highlight current line. Configure syntax highlighting and color schemes.
```rust
use sourceview5::{View, LanguageManager, StyleSchemeManager};
// Create view with options
let view = View::builder()
.show_line_numbers(true)
.highlight_current_line(true)
.build();
// Set language for syntax highlighting
let manager = LanguageManager::default();
if let Some(lang) = manager.language("rust") {
view.buffer().set_language(Some(&lang));
}
// Set color scheme
let style_manager = StyleSchemeManager::default();
if let Some(scheme) = style_manager.scheme("builder-dark") {
view.buffer().set_property("style-scheme", &scheme);
}
```
--------------------------------
### Compression Type
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-saver.md
Gets or sets the file compression format. Supports None or Gzip.
```APIDOC
## Compression Type
### Description
Gets or sets the file compression format.
### Methods
- `compression_type()`: Returns the current `CompressionType`.
- `set_compression_type(compression_type: CompressionType)`: Sets the file compression format.
### Parameters
#### `set_compression_type` Parameters
- **compression_type** (`CompressionType`) - Required - None or Gzip
### Example
```rust
use sourceview5::{FileSaver, CompressionType};
saver.set_compression_type(CompressionType::None);
```
```
--------------------------------
### Encoding Metadata
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/encoding.md
Get encoding metadata such as display name, charset, and icon name.
```APIDOC
## Encoding Metadata
### Description
Get encoding metadata.
### Methods
- `name()`: Returns the display name of the encoding (e.g., "UTF-8").
- `charset()`: Returns the IANA charset name (e.g., "utf8").
- `icon_name()`: Returns the icon resource name, if available.
### Returns
- `name()`: `glib::GString`
- `charset()`: `glib::GString`
- `icon_name()`: `Option`
### Example
```rust
let enc = Encoding::utf8();
println!("Name: {}", enc.name()); // Output: UTF-8
println!("Charset: {}", enc.charset()); // Output: utf8
```
```
--------------------------------
### Retrieve Style Scheme Search Paths
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme-manager.md
Use this method to get a list of all directories where the Style Scheme Manager searches for color schemes. It returns a vector of GString objects, each representing a directory path.
```rust
let manager = StyleSchemeManager::default();
for path in manager.search_path() {
println!("Search path: {}", path);
}
```
--------------------------------
### Get StyleScheme Name
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md
Retrieves the human-readable name of the color scheme. Use this for display purposes.
```rust
if let Some(scheme) = manager.scheme("adwaita-dark") {
println!("Scheme name: {}", scheme.name());
}
```
--------------------------------
### Initialize GTK4 Application
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Shows the basic structure for initializing a GTK4 application, which is required before using Sourceview5.
```rust
use gtk::prelude::*;
fn main() -> glib::ExitCode {
let app = gtk::Application::new(
Some("com.example.MyApp"),
Default::default(),
);
app.connect_activate(|app| {
// GTK is now initialized; safe to use sourceview5
let window = gtk::ApplicationWindow::new(app);
let view = sourceview5::View::new();
window.set_child(Some(&view));
window.present();
});
app.run()
}
```
--------------------------------
### Encoding
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-saver.md
Gets or sets the character encoding for the saved file. Supports various encodings like UTF-8.
```APIDOC
## Encoding
### Description
Gets or sets the character encoding for the saved file.
### Methods
- `encoding()`: Returns the current `Encoding`.
- `set_encoding(encoding: &Encoding)`: Sets the character encoding.
### Parameters
#### `set_encoding` Parameters
- **encoding** (`&Encoding`) - Required - Character encoding (UTF-8, ISO-8859-1, etc.)
### Example
```rust
use sourceview5::{FileSaver, Encoding};
let encoding = Encoding::utf8();
saver.set_encoding(&encoding);
```
```
--------------------------------
### Configure Whitespace Visibility in SourceView5
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/space-drawer.md
Demonstrates how to initialize a View and configure its space drawer to show trailing whitespace. Ensure the `sourceview5` crate is included in your project.
```rust
use sourceview5::{View, SpaceTypeFlags, SpaceLocationFlags};
let view = View::builder()
.show_line_numbers(true)
.build();
// Configure whitespace visibility
let drawer = view.space_drawer();
drawer.set_types_flags(SpaceTypeFlags::TRAILING);
drawer.set_locations_flags(SpaceLocationFlags::TRAILING);
drawer.set_matrix(false);
```
--------------------------------
### at_word_boundaries
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Gets or sets the word boundary matching option. When enabled, the search will only match whole words.
```APIDOC
## at_word_boundaries
### Description
Gets or sets the word boundary matching option. When enabled, the search will only match whole words.
### Method
- `is_at_word_boundaries(&self) -> bool`: Checks if word boundary matching is enabled.
- `set_at_word_boundaries(&self, at_word_boundaries: bool)`: Sets the word boundary matching flag.
### Parameters
- `at_word_boundaries` (bool): True to match whole words only.
### Example
```rust
settings.set_at_word_boundaries(true); // Only match "fn" not "function"
```
```
--------------------------------
### View::new
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/view.md
Creates a new, empty source view widget with default settings.
```APIDOC
## View::new
### Description
Creates a new, empty source view widget.
### Method
Rust function
### Returns
`View` — A new view with default settings.
### Example
```rust
use sourceview5::View;
let view = View::new();
```
```
--------------------------------
### case_sensitive
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Gets or sets the case sensitivity flag for searches. When true, the search is case-sensitive; otherwise, it is case-insensitive.
```APIDOC
## case_sensitive
### Description
Gets or sets the case sensitivity flag for searches. When true, the search is case-sensitive; otherwise, it is case-insensitive.
### Method
- `is_case_sensitive(&self) -> bool`: Checks if case sensitivity is enabled.
- `set_case_sensitive(&self, case_sensitive: bool)`: Sets the case sensitivity flag.
### Parameters
- `case_sensitive` (bool): True for case-sensitive search, false for case-insensitive.
### Example
```rust
settings.set_case_sensitive(false); // Case-insensitive
```
```
--------------------------------
### page_size
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Gets the number of completion proposals displayed per page, controlling how many suggestions are shown at once.
```APIDOC
## page_size
### Description
Gets the number of completion proposals displayed per page.
### Method
`pub fn page_size(&self) -> u32`
### Returns
`u32` — Page size (default typically 10).
### Request Example
```rust
let size = completion.page_size();
println!("Showing {} proposals per page", size);
```
```
--------------------------------
### Initialize and Configure SearchSettings
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Create a new SearchSettings instance and set the search text. This is used to configure search parameters for a SearchContext.
```rust
let settings = SearchSettings::new();
settings.set_search_text("pattern");
let context = SearchContext::new(&buffer, Some(&settings));
// Use context to search
```
--------------------------------
### Completion Signals
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Signals emitted by the Completion API to indicate events such as starting, ending, or provider changes.
```APIDOC
## Signals
- **show**: Emitted when completion starts
- **hide**: Emitted when completion ends
- **provider-added**: Emitted when a provider is registered
- **provider-removed**: Emitted when a provider is unregistered
```
--------------------------------
### Get the Default StyleSchemeManager
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme-manager.md
Access the global singleton StyleSchemeManager. This is useful for retrieving available color schemes and their count.
```rust
use sourceview5::StyleSchemeManager;
let manager = StyleSchemeManager::default();
let ids = manager.scheme_ids();
println!("Available color schemes: {}", ids.len());
```
--------------------------------
### Flags
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-saver.md
Gets or sets save behavior flags for the file saver, such as ignoring invalid characters or creating backups.
```APIDOC
## Flags
### Description
Gets or sets save behavior flags.
### Methods
- `flags()`: Returns the current `FileSaverFlags`.
- `set_flags(flags: FileSaverFlags)`: Sets the save behavior flags.
### Parameters
#### `set_flags` Parameters
- **flags** (`FileSaverFlags`) - Required - Save behavior flags
### Flags
- `IGNORE_INVALID_CHARS` — Skip unencodable characters
- `IGNORE_MODIFICATION_TIME` — Don't verify external changes
- `BACKUP` — Create backup of original
### Example
```rust
use sourceview5::{FileSaver, FileSaverFlags};
let flags = FileSaverFlags::BACKUP;
saver.set_flags(flags);
```
```
--------------------------------
### Newline Type
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-saver.md
Gets or sets the line ending format for the saved file. Supports LF, CR, and CRLF.
```APIDOC
## Newline Type
### Description
Gets or sets the line ending format for the saved file.
### Methods
- `newline_type()`: Returns the current `NewlineType`.
- `set_newline_type(newline_type: NewlineType)`: Sets the line ending format.
### Parameters
#### `set_newline_type` Parameters
- **newline_type** (`NewlineType`) - Required - LF, CR, or CRLF
### Example
```rust
use sourceview5::{FileSaver, NewlineType};
saver.set_newline_type(NewlineType::Lf); // Unix style
```
```
--------------------------------
### Configure Search Settings
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Set up search parameters such as text, case sensitivity, word boundaries, regex usage, and wrap-around behavior. This is useful for customizing how text is searched within a buffer.
```rust
use sourceview5::{SearchSettings, SearchContext, Buffer};
let settings = SearchSettings::new();
settings.set_search_text("pattern");
settings.set_case_sensitive(false);
settings.set_at_word_boundaries(false);
settings.set_regex_enabled(false);
settings.set_wrap_around(true);
let context = SearchContext::new(&buffer, Some(&settings));
```
--------------------------------
### Create a FileSaver Instance
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-saver.md
Instantiate a FileSaver for a given buffer and target file. Ensure you have a Buffer and a gio::File object ready.
```rust
use sourceview5::{Buffer, FileSaver};
use gio::File;
let buffer = Buffer::new(None);
let file = File::for_path("document.rs");
let saver = FileSaver::new(&buffer, &file);
```
--------------------------------
### Configure Language Definition Paths
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Manages directories for language definition files. Use `prepend_search_path` or `append_search_path` to add custom directories, or `set_search_path` to define the complete list.
```rust
use sourceview5::LanguageManager;
let manager = LanguageManager::default();
// Add custom language definition paths
manager.prepend_search_path("/usr/local/share/gtksourceview/languages");
manager.append_search_path("/home/user/.local/share/gtksourceview/languages");
// Or set entirely
manager.set_search_path(&[
"/custom/languages",
"/usr/share/gtksourceview-5/language-specs",
]);
```
--------------------------------
### search_text
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Gets or sets the text pattern to search for. This method allows you to retrieve the current search pattern or update it.
```APIDOC
## search_text
### Description
Gets or sets the text pattern to search for. This method allows you to retrieve the current search pattern or update it.
### Method
- `search_text(&self) -> Option`: Gets the search text.
- `set_search_text(&self, search_text: Option<&str>)`: Sets the search text.
### Parameters
- `search_text` (Option<&str>): Pattern string to search for.
### Example
```rust
settings.set_search_text("function");
if let Some(text) = settings.search_text() {
println!("Searching for: {}", text);
}
```
```
--------------------------------
### Get Language ID
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language.md
Retrieves the unique identifier string for a programming language. This ID is used internally by the LanguageManager.
```rust
if let Some(lang) = manager.language("python") {
println!("ID: {}", lang.id()); // Output: ID: python
}
```
--------------------------------
### FileLoader::builder
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-loader.md
Creates a builder for configuring a FileLoader with custom settings. This allows for more advanced setup than the default constructor.
```APIDOC
## `FileLoader::builder`
### Description
Creates a builder for custom loader configuration.
### Returns
- FileLoaderBuilder - A builder object for configuring the FileLoader.
```
--------------------------------
### Configure Code Completion in Sourceview5
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/README.md
Set up code completion for the view, including page size and icon visibility. Adds a basic CompletionWords provider.
```rust
use sourceview5::{Completion, CompletionWords};
let completion = view.completion();
completion.set_page_size(10);
completion.set_show_icons(true);
let provider = CompletionWords::new();
completion.add_provider(&provider);
```
--------------------------------
### Applying a Scheme
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md
Demonstrates how to apply a StyleScheme to a Buffer in a View.
```APIDOC
## Applying a Scheme
```rust
use sourceview5::{View, Buffer, StyleSchemeManager};
// Get scheme
let manager = StyleSchemeManager::default();
let scheme = manager.scheme("builder-dark").expect("Scheme not found");
// Apply to buffer
let buffer = view.buffer();
buffer.set_property("style-scheme", &scheme);
```
```
--------------------------------
### Integrate StyleSchemeManager with View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme-manager.md
Demonstrates how to set a color scheme and a language for syntax highlighting on a View's buffer using StyleSchemeManager and LanguageManager.
```rust
use sourceview5::{View, StyleSchemeManager, Buffer, LanguageManager};
let view = View::new();
let buffer = view.buffer();
// Set a color scheme
let style_manager = StyleSchemeManager::default();
if let Some(scheme) = style_manager.scheme("builder-dark") {
buffer.set_property("style-scheme", &scheme);
}
// Set a language for syntax highlighting
let lang_manager = LanguageManager::default();
if let Some(lang) = lang_manager.language("rust") {
buffer.set_language(Some(&lang));
}
```
--------------------------------
### wrap_around
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Gets or sets the wrapping behavior for searches. When enabled, the search will wrap around to the beginning of the text after reaching the end.
```APIDOC
## wrap_around
### Description
Gets or sets the wrapping behavior for searches. When enabled, the search will wrap around to the beginning of the text after reaching the end.
### Method
- `is_wrap_around(&self) -> bool`: Checks if wrap-around is enabled.
- `set_wrap_around(&self, wrap_around: bool)`: Sets the wrap-around flag.
### Parameters
- `wrap_around` (bool): True to enable wrapping to the beginning when reaching the end.
### Example
```rust
settings.set_wrap_around(true);
```
```
--------------------------------
### Register a Completion Provider
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Use this method to add a new completion provider to the system. Ensure the provider implements the CompletionProvider trait.
```rust
use sourceview5::{Completion, CompletionWords};
let completion = view.completion();
let words_provider = CompletionWords::new();
completion.add_provider(&words_provider);
```
--------------------------------
### regex_enabled
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Gets or sets whether the search pattern should be interpreted as a regular expression. When enabled, the search pattern is treated as a regex.
```APIDOC
## regex_enabled
### Description
Gets or sets whether the search pattern should be interpreted as a regular expression. When enabled, the search pattern is treated as a regex.
### Method
- `is_regex_enabled(&self) -> bool`: Checks if regex matching is enabled.
- `set_regex_enabled(&self, regex_enabled: bool)`: Sets the regex enabled flag.
### Parameters
- `regex_enabled` (bool): True if the pattern is a regular expression.
### Example
```rust
settings.set_regex_enabled(true);
settings.set_search_text(r"fn\s+\w+");
```
```
--------------------------------
### Set Language Search Paths
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language-manager.md
Set the directories where language definitions are loaded from. Provide an array of strings, where each string is a directory path.
```rust
let manager = LanguageManager::default();
manager.set_search_path(&[
"/usr/share/gtksourceview-5/language-specs",
"/home/user/.local/share/gtksourceview/language-specs",
]);
```
--------------------------------
### Snippet::text
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/snippet.md
Gets or sets the template text for the snippet. This text can include placeholders for variable substitution and cursor positioning.
```APIDOC
## Snippet::text
### Description
Gets/sets the template text.
### Method
```rust
pub fn text(&self) -> glib::GString
pub fn set_text(&self, text: &str)
```
### Parameters
#### Path Parameters
- **text** (String) - Required - Template with placeholders
### Request Example
```rust
// Assuming 'snippet' is a mutable Snippet object
snippet.set_text("match ${expr} {\n ${pattern} => ${action},\n}");
```
```
--------------------------------
### Set and Get Search Text
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Configures the text pattern to be searched for. The pattern can be retrieved later to confirm the set value.
```rust
settings.set_search_text("function");
if let Some(text) = settings.search_text() {
println!("Searching for: {}", text);
}
```
--------------------------------
### Create View with Builder Pattern
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/map.md
Configures and builds a `View` widget using the builder pattern, enabling options like showing line numbers.
```rust
let view = View::builder()
.show_line_numbers(true)
.build();
```
--------------------------------
### Retrieve Gutter by Position
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/gutter.md
Get the left or right gutter of a View. This is the primary way to access the gutter object for manipulation.
```rust
use sourceview5::{View, ViewGutterPosition};
let view = View::new();
let left_gutter = view.gutter(ViewGutterPosition::Left);
let right_gutter = view.gutter(ViewGutterPosition::Right);
```
--------------------------------
### show
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Triggers the completion interface, showing available proposals to the user.
```APIDOC
## show
### Description
Triggers the completion interface, showing available proposals.
### Method
`pub fn show(&self)`
### Request Example
```rust
// In response to user action or timer
completion.show();
```
```
--------------------------------
### Create a new empty View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/view.md
Use this constructor to create a new, empty source view widget with default settings.
```rust
use sourceview5::View;
let view = View::new();
```
--------------------------------
### Snippet::trigger
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/snippet.md
Gets or sets the keyboard trigger keyword used to activate the snippet. This is the string users type to invoke the snippet.
```APIDOC
## Snippet::trigger
### Description
Gets/sets the keyboard trigger for activating the snippet.
### Method
```rust
pub fn trigger(&self) -> Option
pub fn set_trigger(&self, trigger: Option<&str>)
```
### Parameters
#### Path Parameters
- **trigger** (Option<&str>) - Optional - Activation keyword
### Request Example
```rust
// Assuming 'snippet' is a mutable Snippet object
snippet.set_trigger(Some("match"));
```
```
--------------------------------
### Configure Style Scheme Directories
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Manages directories for color scheme files. You can add custom theme paths or set the complete search path. `force_rescan()` should be called after adding new files.
```rust
use sourceview5::StyleSchemeManager;
let manager = StyleSchemeManager::default();
manager.prepend_search_path("/custom/themes");
manager.set_search_path(&[
"/home/user/.local/share/gtksourceview/styles",
"/usr/share/gtksourceview-5/styles",
]);
// Rescan after adding files
manager.force_rescan();
```
--------------------------------
### Get Associated View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Retrieves the `View` object associated with this completion instance. This provides access to the visual source view component.
```rust
let view = completion.view();
```
--------------------------------
### Get Active Hover Display
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/hover.md
Retrieves the HoverDisplay object when a hover is active. This allows querying properties of the currently displayed tooltip.
```rust
let display = hover.display_();
// Query hover display properties
```
--------------------------------
### Completion Builder
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Creates a builder for custom completion configuration. Use this to programmatically set up a completion instance with specific parameters.
```rust
pub fn builder() -> CompletionBuilder
```
--------------------------------
### File Type Detection using Filename and MIME Type
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language.md
Demonstrates how to use LanguageManager to guess the programming language based on a filename, a MIME type, or both.
```rust
let manager = LanguageManager::default();
// Use filename
if let Some(lang) = manager.guess_language(Some("Makefile"), None) {
println!("Makefile detected as: {}", lang.name());
}
// Use MIME type
if let Some(lang) = manager.guess_language(None, Some("text/x-python")) {
println!("MIME type text/x-python is: {}", lang.name());
}
// Use both
if let Some(lang) = manager.guess_language(Some("file.txt"), Some("text/plain")) {
println!("Detected: {}", lang.name());
}
```
--------------------------------
### Create a New SearchContext
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-context.md
Instantiate a SearchContext for a given buffer. You can provide custom SearchSettings or use default settings by passing None.
```rust
use sourceview5::{SearchContext, SearchSettings, Buffer, View};
let view = View::new();
let buffer = view.buffer();
// Simple search with defaults
let context = SearchContext::new(&buffer, None);
// Or with custom settings
let settings = SearchSettings::new();
settings.set_search_text("pattern");
let context = SearchContext::new(&buffer, Some(&settings));
```
--------------------------------
### Create a Buffer using the builder pattern
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/buffer.md
Constructs a Buffer instance using a fluent builder API, allowing optional properties like syntax highlighting and bracket matching to be configured before creation. This provides a flexible way to initialize the buffer with specific settings.
```rust
use sourceview5::Buffer;
let buffer = Buffer::builder()
.highlight_syntax(true)
.highlight_matching_brackets(true)
.build();
```
--------------------------------
### Register Custom Hover Provider
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Demonstrates how to add a custom hover provider to the Sourceview5 view.
```rust
use sourceview5::View;
let view = View::new();
let hover = view.hover();
// Register custom providers
let my_provider = MyCustomHoverProvider::new();
hover.add_provider(&my_provider);
```
--------------------------------
### Get Language Definition by ID
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language-manager.md
Retrieve a specific Language object using its string identifier. Returns None if the language ID is not found.
```rust
let manager = LanguageManager::default();
if let Some(rust) = manager.language("rust") {
println!("Rust language found: {}", rust.name());
}
```
--------------------------------
### Buffer::new
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/buffer.md
Creates a new source buffer. It can optionally be initialized with a custom GTK TextTagTable for managing text styles and tags.
```APIDOC
## Buffer::new
### Description
Creates a new source buffer, optionally with a custom tag table.
### Method
`Buffer::new`
### Parameters
#### Path Parameters
- **table** (Option<>k::TextTagTable>) - Optional - Custom text tag table; uses default if None
### Returns
`Buffer` — A new source buffer instance.
### Example
```rust
use sourceview5::Buffer;
use gtk::TextTagTable;
// Create with default tag table
let buffer = Buffer::new(None);
// Create with custom tag table
let tag_table = TextTagTable::new();
let buffer = Buffer::new(Some(&tag_table));
```
```
--------------------------------
### Get Completion Page Size
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Retrieves the current number of completion proposals displayed per page. The default value is typically 10.
```rust
let size = completion.page_size();
println!("Showing {} proposals per page", size);
```
--------------------------------
### Get Default LanguageManager Instance
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language-manager.md
Retrieve the global singleton LanguageManager. This is useful for accessing language information without creating a new instance.
```rust
use sourceview5::LanguageManager;
let manager = LanguageManager::default();
let ids = manager.language_ids();
println!("Available languages: {}", ids.len());
```
--------------------------------
### Create a View with a specific Buffer
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/view.md
Use this constructor to create a new view that displays a pre-existing buffer. Ensure the Buffer is properly initialized, potentially with a language.
```rust
use sourceview5::{View, Buffer, LanguageManager};
let buffer = {
let manager = LanguageManager::default();
let language = manager.language("rust").unwrap();
Buffer::with_language(&language)
};
let view = View::with_buffer(&buffer);
```
--------------------------------
### Load and Save Files with Sourceview5
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/README.md
Asynchronously load file content into a buffer and save buffer content back to a file using FileLoader and FileSaver.
```rust
use sourceview5::{FileLoader, FileSaver};
use gio::File;
// Load
let file = File::for_path("main.rs");
let info = file.query_info("*", gio::FileQueryInfoFlags::NONE, None)?;
let stream = file.read(None)?;
let loader = FileLoader::new(&info, &stream, &buffer, &file);
loader.load_async(gio::glib::PRIORITY_DEFAULT, None, |result| {
match result {
Ok(()) => println!("Loaded"),
Err(e) => eprintln!("Error: {}", e),
}
});
// Save
let saver = FileSaver::new(&buffer, &file);
saver.save_async(gio::glib::PRIORITY_DEFAULT, None, |result| {
match result {
Ok(()) => println!("Saved"),
Err(e) => eprintln!("Error: {}", e),
}
});
```
--------------------------------
### Configure Completion Behavior and Providers
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Customize the behavior of the completion widget, such as page size and visibility, and add custom completion providers like word completion and snippets. This allows for tailored code completion experiences.
```rust
use sourceview5::{View, CompletionWords, CompletionSnippets};
let view = View::new();
let completion = view.completion();
// Configure behavior
completion.set_page_size(15);
completion.set_show_icons(true);
completion.set_select_on_show(true);
completion.set_remember_info_visibility(false);
// Add providers
let words = CompletionWords::new();
let snippets = CompletionSnippets::new();
completion.add_provider(&words);
completion.add_provider(&snippets);
```
--------------------------------
### Configure Snippet Directories
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Manages directories for code snippet definitions. Use `prepend_search_path` to add custom snippet locations.
```rust
use sourceview5::SnippetManager;
let manager = SnippetManager::default();
manager.prepend_search_path("/custom/snippets");
```
--------------------------------
### Create a New StyleSchemeManager Instance
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme-manager.md
Instantiate a new StyleSchemeManager. This manager comes with built-in color schemes.
```rust
use sourceview5::StyleSchemeManager;
let manager = StyleSchemeManager::new();
```
--------------------------------
### Create New LanguageManager Instance
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language-manager.md
Instantiate a new LanguageManager. This manager will have built-in language definitions.
```rust
use sourceview5::LanguageManager;
let manager = LanguageManager::new();
```
--------------------------------
### Snippet::description
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/snippet.md
Gets or sets a descriptive text for the snippet, which is typically shown in completion menus to help users identify the snippet's purpose.
```APIDOC
## Snippet::description
### Description
Gets/sets the description shown in completion menus.
### Method
```rust
pub fn description(&self) -> Option
pub fn set_description(&self, description: Option<&str>)
```
### Parameters
#### Path Parameters
- **description** (Option<&str>) - Optional - Snippet description
### Request Example
```rust
// Assuming 'snippet' is a mutable Snippet object
snippet.set_description(Some("Function definition"));
```
```
--------------------------------
### Create SearchContext Builder
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-context.md
Creates a builder for constructing a SearchContext with custom properties. Use this when you need to configure the search context with specific settings before creating an instance.
```rust
pub fn builder() -> SearchContextBuilder
```
--------------------------------
### Get Associated Buffer
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/completion.md
Retrieves the `Buffer` object that the completion system is currently operating on. This allows direct manipulation or inspection of the buffer's content.
```rust
let buffer = completion.buffer();
```
--------------------------------
### Create a Map with an associated View
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/map.md
Creates a map widget and immediately connects it to a specified `View`. This is useful for setting up a map and its corresponding view together.
```rust
pub fn with_view(view: &impl IsA) -> Map
```
--------------------------------
### Get Language Metadata
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/language.md
Retrieves specific metadata for a language, such as associated MIME types or file globs. Useful for file type detection and configuration.
```rust
if let Some(rust) = manager.language("rust") {
if let Some(mime) = rust.metadata("mimetypes") {
println!("MIME types: {}", mime);
}
if let Some(globs) = rust.metadata("globs") {
println!("File patterns: {}", globs);
}
}
```
--------------------------------
### Select File Encoding with FileSaver
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-saver.md
Shows how to set different encodings for saving files using FileSaver. UTF-8 is recommended.
```rust
use sourceview5::{FileSaver, Encoding};
// UTF-8 (recommended)
saver.set_encoding(&Encoding::utf8());
// ISO-8859-1 (Latin-1)
saver.set_encoding(&Encoding::iso88591());
// UTF-16
saver.set_encoding(&Encoding::utf16());
```
--------------------------------
### Configure Buffer Properties and Language/Scheme
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md
Sets buffer properties such as syntax highlighting and undo functionality. It also demonstrates how to set the language and style scheme for the buffer using `LanguageManager` and `StyleSchemeManager`.
```rust
use sourceview5::{Buffer, LanguageManager, StyleSchemeManager};
let buffer = Buffer::builder()
.highlight_syntax(true)
.highlight_matching_brackets(true)
.implicit_trailing_newline(true)
.enable_undo(true)
.build();
// Set language
let manager = LanguageManager::default();
if let Some(lang) = manager.language("rust") {
buffer.set_language(Some(&lang));
}
// Set style scheme
let style_manager = StyleSchemeManager::default();
if let Some(scheme) = style_manager.scheme("builder-dark") {
buffer.set_property("style-scheme", &scheme);
}
```
--------------------------------
### Enable Backup Creation with FileSaver
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-saver.md
Configures FileSaver to create automatic backups of the saved file. The backup file will be named with a .bak extension.
```rust
use sourceview5::{FileSaver, FileSaverFlags};
let mut flags = FileSaverFlags::empty();
flags.insert(FileSaverFlags::BACKUP);
saver.set_flags(flags);
// Saves as: document.rs.bak
```
--------------------------------
### Create SearchSettings with Builder
Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md
Uses a builder pattern to configure and create SearchSettings. This is useful for setting multiple properties at once.
```rust
use sourceview5::SearchSettings;
let settings = SearchSettings::builder()
.search_text("TODO")
.case_sensitive(false)
.build();
```