pub struct Buffer {
pub opts: BufferOpts,
/* private fields */
}Expand description
The widget that is used to print and edit buffers.
Fields§
§opts: BufferOptsThe PrintOpts of this Buffer.
This object, much like PrintOpts, implements Copy, which
makes it convenient for moving it around without borrowing the
Buffer.
You can use this member to change the way this Buffer will
be printed specifically.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn moment_for(&self, ns: Ns) -> Moment
pub fn moment_for(&self, ns: Ns) -> Moment
Get the latest Moment for a given namespace
This Moment contains every change that took place since the
last call with the same Ns. On the first call, it is assumed
that you don’t care about previous Changes, so the
returned Moment will be empty.
This means that, in order to use this properly, you might want to add a hook like this:
use duat::prelude::*;
let my_plugin_ns = Ns::new();
hook::add::<BufferOpened>(move |pa, buffer| _ = buffer.read(pa).moment_for(my_plugin_ns));This way, you “register” the Buffer, telling it “yes, I
henceforth care about the future Changes”.
§Note: Why is this necessary?
You might reason that the first call to this function should
return a Moment with all prior Changes.
However, one thing to note is that
Sourcepub fn ranges_to_update_for(&self, ns: Ns) -> RangesToUpdate
pub fn ranges_to_update_for(&self, ns: Ns) -> RangesToUpdate
Returns a struct that keeps track of which byte ranges need to
be updated for a given Ns.
Source§impl Buffer
impl Buffer
Sourcepub fn path(&self) -> PathBuf
pub fn path(&self) -> PathBuf
The full path of the buffer.
If there is no set path, returns "*scratch buffer*#{id}".
Sourcepub fn path_set(&self) -> Option<PathBuf>
pub fn path_set(&self) -> Option<PathBuf>
The full path of the buffer.
Returns None if the path has not been set yet, i.e., if
the buffer is a scratch buffer.
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
The buffer’s name.
If there is no set path, returns "*scratch buffer #{id}*".
Sourcepub fn name_set(&self) -> Option<String>
pub fn name_set(&self) -> Option<String>
The buffer’s name.
Returns None if the path has not been set yet, i.e., if
the buffer is a scratch buffer.
Sourcepub fn name_txt(&self) -> Text
pub fn name_txt(&self) -> Text
A Text from the name of this PathKind
The name of a Buffer widget is the same as the path, but
it strips away the current directory. If it can’t, it will
try to strip away the home directory, replacing it with
"~". If that also fails, it will just show the full
path.
§Formatting
If the buffer’s name was set:
[buffer]{name}If the buffer’s name was not set:
[buffer.new.scratch]*scratch buffer #{id}*Sourcepub fn path_kind(&self) -> PathKind
pub fn path_kind(&self) -> PathKind
The type of PathBuf
This represents the three possible states for a Buffer’s
PathBuf, as it could either represent a real Buffer,
not exist, or not have been defined yet.
Sourcepub fn buffer_id(&self) -> BufferId
pub fn buffer_id(&self) -> BufferId
A unique identifier for this Buffer.
This is more robust than identifying it by its path or name,
or event PathKind, since those could change, but this
cannot.
Sourcepub fn text(&self) -> &Text
pub fn text(&self) -> &Text
The Text of this Buffer
This is the same as Widget::text, but doesn’t need the
Widget trait to be in scope.
Sourcepub fn text_mut(&mut self) -> TextMut<'_>
pub fn text_mut(&mut self) -> TextMut<'_>
The mutable TextMut of this Buffer
This is the same as Widget::text_mut, but doesn’t need the
Widget trait to be in scope.
Sourcepub fn text_parts(&mut self) -> TextParts<'_>
pub fn text_parts(&mut self) -> TextParts<'_>
Sourcepub fn selections(&self) -> &Selections
pub fn selections(&self) -> &Selections
The Selections that are used on the Text.
Sourcepub fn selections_mut(&mut self) -> &mut Selections
pub fn selections_mut(&mut self) -> &mut Selections
A mutable reference to the Selections.
Sourcepub fn was_reloaded(&self) -> bool
pub fn was_reloaded(&self) -> bool
Wether this buffer came from a previous reload cycle.
You should use this function to decide on things that persist
across reload cycles (i.e. the crate::process and
crate::storage modules).