Struct scribe::Workspace [−][src]
An owned collection of buffers and associated path, representing a running editor environment.
Fields
path: PathBuf
syntax_set: SyntaxSet
Methods
impl Workspace
[src]
impl Workspace
pub fn new(path: &Path) -> Result<Workspace>
[src]
pub fn new(path: &Path) -> Result<Workspace>
Creates a new empty workspace for the specified path.
pub fn add_buffer(&mut self, buf: Buffer)
[src]
pub fn add_buffer(&mut self, buf: Buffer)
Adds a buffer to the workspace, inserting it after the
current buffer, populates its id
field with a unique
value (relative to the workspace), and selects it.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf);
pub fn open_buffer(&mut self, path: &Path) -> Result<()>
[src]
pub fn open_buffer(&mut self, path: &Path) -> Result<()>
Opens a buffer at the specified path, inserting it after the current buffer, and selects it. The path is converted to its canonical, absolute equivalent; if a buffer with the specified path already exists, it is selected, rather than opening a duplicate buffer. Any errors encountered while opening the buffer are returned.
Examples
use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Open a buffer in the workspace. workspace.open_buffer(file_path.clone());
pub fn current_buffer(&mut self) -> Option<&mut Buffer>
[src]
pub fn current_buffer(&mut self) -> Option<&mut Buffer>
Returns a mutable reference to the currently selected buffer, unless the workspace is empty.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Get a reference to the current buffer. let buffer_reference = workspace.current_buffer().unwrap();
pub fn current_buffer_path(&self) -> Option<&Path>
[src]
pub fn current_buffer_path(&self) -> Option<&Path>
Returns a reference to the current buffer's path.
If the path can be represented relative to the workspace path, a relative path will be returned. Otherwise, the buffer path is returned as-is.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); assert_eq!(workspace.current_buffer_path(), Some(Path::new("file")));
pub fn close_current_buffer(&mut self)
[src]
pub fn close_current_buffer(&mut self)
Removes the currently selected buffer from the collection. If the workspace is empty, this method does nothing.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Close the current buffer. workspace.close_current_buffer();
pub fn previous_buffer(&mut self)
[src]
pub fn previous_buffer(&mut self)
Selects the previous buffer in the workspace (buffers are ordered as they are added to the workspace). If the currently selected buffer is the first in the collection, this will wrap and select the last buffer.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Select the previous buffer. workspace.previous_buffer();
pub fn next_buffer(&mut self)
[src]
pub fn next_buffer(&mut self)
Selects the next buffer in the workspace (buffers are ordered as they are added to the workspace). If the currently selected buffer is the last in the collection, this will wrap and select the first buffer.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Select the next buffer. workspace.next_buffer();
pub fn contains_buffer_with_path(&self, path: &Path) -> bool
[src]
pub fn contains_buffer_with_path(&self, path: &Path) -> bool
Whether or not the workspace contains a buffer with the specified path. The path is converted to its canonical, absolute equivalent before comparison.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path.clone()).unwrap(); workspace.add_buffer(buf); assert!(workspace.contains_buffer_with_path(&file_path));
pub fn update_current_syntax(&mut self) -> Result<()>
[src]
pub fn update_current_syntax(&mut self) -> Result<()>
Updates the current buffer's syntax definition.
If a buffer is added to a workspace and is assigned a plain text syntax definition (because the buffer has no path or file extension, or because there is no better definition for its path extension), and its path is changed, this method can be used to attempt the assignment again, in hopes for a more accurate match.
Examples
extern crate syntect; extern crate scribe; use scribe::Buffer; use scribe::Workspace; use std::path::{Path, PathBuf}; // Create a workspace. let workspace_path = Path::new("tests/sample"); let mut workspace = Workspace::new(workspace_path).unwrap(); // Add a buffer without a path to the workspace. let buf = Buffer::new(); workspace.add_buffer(buf); assert_eq!( workspace.current_buffer().unwrap().syntax_definition.as_ref().unwrap().name, "Plain Text" ); // Add a path and update the syntax definition. let buffer_path = PathBuf::from("mod.rs"); workspace.current_buffer().unwrap().path = Some(buffer_path); workspace.update_current_syntax().unwrap(); assert_eq!( workspace.current_buffer().unwrap().syntax_definition.as_ref().unwrap().name, "Rust" );