aboutsummaryrefslogtreecommitdiff
path: root/rprt-engine/src/selection_functions/function_end.rs
blob: 75b4c96ad53c8b0ef44c8d2727d837c4d39c6c68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate::{
    dispatch_selection_function,
    selection::Selection,
    selection_function,
    selection_functions::types::{SFArguments, SFError, SFResult, get_buffer},
    state::EditorState,
};

selection_function! {
    name: end,
    param_type: (),
    niladic: |(_, es): ((), &EditorState)| {
        let buf = get_buffer(es, es.current_buffer_id)?;
        Ok(Selection::Scalar {
            buffer_id: es.current_buffer_id,
            pos: buf.max_pos(),
        })
    },
    monadic_rank0: |_, buffer_id, pos | Ok(Selection::Scalar { buffer_id, pos }),
    monadic_rank1: |_, buffer_id, int | Ok(Selection::Scalar { buffer_id, pos: int.end })
}

selection_function! {
    name: reverse_end,
    param_type: (),
    niladic: |(_, es): ((), &EditorState)| {
        Ok(Selection::Scalar {
            buffer_id: es.current_buffer_id,
            pos: 0,
        })
    },
    monadic_rank0: |_, buffer_id, pos | Ok(Selection::Scalar { buffer_id, pos }),
    monadic_rank1: |_, buffer_id, int | Ok(Selection::Scalar { buffer_id, pos: int.start })
}

selection_function! {
    name: sequential_end,
    param_type: (),
    niladic: |_| Err(SFError::NoNiladicForm(";$").into()),
    monadic_rank0: |_, buffer_id, pos| Ok(Selection::Scalar { buffer_id, pos }),
    monadic_rank1: |(_, es), buffer_id, _| {
        let buf = get_buffer(es, buffer_id)?;
        Ok(Selection::Scalar { buffer_id, pos: buf.max_pos() })
    }
}

selection_function! {
    name: sequential_reverse_end,
    param_type: (),
    niladic: |_| Err(SFError::NoNiladicForm(";'$").into()),
    monadic_rank0: |_, buffer_id, pos| {
        Ok(Selection::Scalar { buffer_id, pos })
    },
    monadic_rank1: |_, buffer_id, interval| {
        Ok(Selection::Scalar {
            buffer_id,
            pos: interval.end,
        })
    }
}

selection_function! {
    name: reverse_sequential_end,
    param_type: (),
    niladic: |_| Err(SFError::NoNiladicForm("';$").into()),
    monadic_rank0: |_, buffer_id, pos| {
        Ok(Selection::Scalar { buffer_id, pos })
    },
    monadic_rank1: |_, buffer_id, interval| {
        Ok(Selection::Scalar {
            buffer_id,
            pos: interval.end,
        })
    }
}

dispatch_selection_function!(
    name: selection_function_end,
    param_type: (),
    base: end,
    sequential: sequential_end,
    reverse: reverse_end,
    sequential_reverse: sequential_reverse_end,
    reverse_sequential: reverse_sequential_end,
);