pub struct YankRing { /* private fields */ }Expand description
A bounded history of everything that has been yanked or deleted.
Beside UnnamedRegister rather than in lattice-grammar (where the
slice plan proposed it) because that is where the entry type it holds
already lives; the grammar does not read the ring.
Deletes push too, and the system clipboard still does not take
them. That looks like a contradiction of clipboard.md §5, which
keeps deletes out of the clipboard on purpose — vim’s unnamedplus
wart, where an incidental x clobbers what you copied from a browser.
The two stores have different blast radii. The clipboard is shared
with every other application, so a stray write there destroys
something the editor never owned; the ring is internal, bounded and
additive, so an x landing in it costs one slot and destroys
nothing. “Get back the line I just deleted” is also among the most
common reasons to open the picker at all, and a ring holding only
yanks would decline the question users most want to ask it.
Implementations§
Source§impl YankRing
impl YankRing
pub fn new() -> Self
pub fn is_empty(&self) -> bool
Sourcepub fn iter(&self) -> impl Iterator<Item = &UnnamedRegister>
pub fn iter(&self) -> impl Iterator<Item = &UnnamedRegister>
Entries newest-first. The picker shows yanks and deletes alike, so this does not filter.
Sourcepub fn nth(&self, n: usize) -> Option<&UnnamedRegister>
pub fn nth(&self, n: usize) -> Option<&UnnamedRegister>
The nth newest entry, 0-based. nth(0) is the most recent.
Sourcepub fn newest_yank(&self) -> Option<&UnnamedRegister>
pub fn newest_yank(&self) -> Option<&UnnamedRegister>
YR.2: "0 — the newest yank.
Not nth(0): an intervening delete must not shadow the last
thing you deliberately copied, which is the whole reason vim
keeps "0 distinct from "".
Sourcepub fn nth_delete(&self, n: usize) -> Option<&UnnamedRegister>
pub fn nth_delete(&self, n: usize) -> Option<&UnnamedRegister>
YR.2: "1–"9 — the nth newest delete, 0-based.
nth_delete(0) is "1. Yanks are skipped rather than counted,
so "1 is always “the last thing I deleted” no matter how many
yanks happened in between.
Sourcepub fn push(&mut self, entry: UnnamedRegister, yanked: bool, capacity: usize)
pub fn push(&mut self, entry: UnnamedRegister, yanked: bool, capacity: usize)
Record a yank or a delete, trimming to capacity.
Two duplicate rules, and they are deliberately different:
- A consecutive repeat collapses.
yypressed twice, or a re-yank of an unchanged line, otherwise produces two identical rows the picker cannot help you tell apart. The existing front entry is left in place rather than removed and re-pushed, so the ring does not churn on a held key. - A non-consecutive repeat is promoted. Re-yanking something from an hour ago is a real event, and moving it to the top is the useful answer — it is what you are about to paste. Adding a second row for it would not be.
Eviction is oldest-first, which is what lets YR.2’s "0–"9
projection be sound: the numbered registers read the newest
entries, so dropping from the back can never change what "9
means.
capacity is passed in rather than held on the ring because it
is a live option (yank.ring.size) — reading it at push time is
what makes lowering it take effect on the next yank instead of at
the next restart. A capacity of 0 disables the ring.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for YankRing
impl RefUnwindSafe for YankRing
impl Send for YankRing
impl Sync for YankRing
impl Unpin for YankRing
impl UnsafeUnpin for YankRing
impl UnwindSafe for YankRing
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more