pub enum Range {
Span {
start: RangeBound,
end: RangeBound,
},
CurrentLine,
Whole,
Selection,
Custom(RangeId),
}Expand description
A vim range argument: which lines an ex-command or operator covers, before it is resolved against a document.
Symbolic on purpose: % or '<,'> means different lines in different
buffers and at different times, so the value is carried unresolved (in a
crate::CommandInvocation, a recorded macro, a plugin call) and each
consumer resolves it at apply time.
Resolution coverage is uneven today. The dispatcher’s operator path
resolves CurrentLine, Whole and Selection and rejects Span /
Custom with crate::CommandError::InvalidArgs; :narrow resolves
every form (patterns fall back to the cursor line, Custom to the
cursor line). No parser in the tree produces Span or Custom yet.
§Examples
use lattice_grammar::{Range, RangeBound};
// `:.,+10` -- from the cursor line to ten lines below it.
let r = Range::Span {
start: RangeBound::CurrentLine,
end: RangeBound::Offset {
base: Box::new(RangeBound::CurrentLine),
delta: 10,
},
};
assert!(matches!(r, Range::Span { .. }));
// `:'<,'>` -- the last Visual selection, via its marks.
let visual = Range::Span {
start: RangeBound::Mark('<'),
end: RangeBound::Mark('>'),
};
assert_ne!(visual, Range::Selection); // same lines, different formVariants§
Span
:1,5, :'<,'>, :.,+10, etc. Both ends inclusive; a consumer
that resolves start below end swaps them (vim asks, lattice
swaps silently).
Fields
start: RangeBoundFirst line of the range.
end: RangeBoundLast line of the range (inclusive).
CurrentLine
:. – the cursor’s line.
Whole
:% – every line of the buffer.
Selection
The current Visual / active region (the default range while Visual is active). Unlike the other forms it keeps Visual’s shape: the dispatcher resolves it charwise (head-inclusive), linewise or blockwise according to the selection’s mode.
Custom(RangeId)
Plugin-registered custom range (e.g., a git-hunk-range plugin), identified by its registry id.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Range
impl<'de> Deserialize<'de> for Range
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Range
impl StructuralPartialEq for Range
Auto Trait Implementations§
impl Freeze for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnsafeUnpin for Range
impl UnwindSafe for Range
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.