summaryrefslogtreecommitdiff
path: root/word.c
blob: 6d7f43195e1f6a6262d5261e7ce43fc36346402f (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
*       Word mode commands.
* The routines in this file
* implement commands that work unit at
* a time. There are all sorts of unit mode
* commands. If I do any sentence and/or paragraph
* mode commands, they are likely to be put in
* this file.
*/
#include    "def.h"

extern BUFFER sav_buf;
char forwunit ();

/*
* Move the cursor backward by
* "n" units. All of the details of motion
* are performed by the "backchar" and "forwchar"
* routines. Error if you try to move beyond
* the buffers.
*/
char
backunit (f, n, k)
    int f, n, k;
{
    char ret = 0;

    if (n < 0)
	return (forwunit (f, -n, KRANDOM));

    curwp->w_unit_offset = 0;
    while (n--)
    {
	ret = move_ptr (curwp, -(long) R_B_PER_U (curwp), TRUE, TRUE, TRUE);
    }
    wind_on_dot (curwp);
    curwp->w_flag |= WFMODE;	/* update mode line */
    return (ret);
}

/*
* Move the cursor forward by
* the specified number of units. All of the
* motion is done by "forwchar". Error if you
* try and move beyond the buffer's end.
*/
char
forwunit (f, n, k)
    int f, n, k;
{

    if (n < 0)
	return (backunit (f, -n, KRANDOM));

    curwp->w_unit_offset = 0;
    while (n--)
    {
	move_ptr (curwp, (long) R_B_PER_U (curwp), TRUE, TRUE, TRUE);
    }
    wind_on_dot (curwp);
    curwp->w_flag |= WFMODE;	/* update mode line */
    return (TRUE);
}

/*
* Kill forward by "n" units. The rules for final
* status are now different. It is not considered an error
* to delete fewer units than you asked. This lets you say
* "kill lots of units" and have the command stop in a reasonable
* way when it hits the end of the buffer.
*/
bool
delfunit (f, n, k)
    int f, n, k;
{
    if (n < 0)
	return (FALSE);
    if ((lastflag & CFKILL) == 0)	/* Purge kill buffer.   */
	bclear (&sav_buf);
    thisflag |= CFKILL;
    while (n--)
    {
	ldelete ((A32) (R_B_PER_U (curwp)), TRUE);
    }
    curwp->w_flag |= WFHARD;
    curwp->w_unit_offset = 0;
    return (TRUE);
}

/*
* Kill backwards by "n" units. The rules
* for success and failure are now different, to prevent
* strange behavior at the start of the buffer. The command
* only fails if something goes wrong with the actual delete
* of the characters. It is successful even if no characters
* are deleted, or if you say delete 5 units, and there are
* only 4 units left. I considered making the first call
* to "backchar" special, but decided that that would just
* be wierd. Normally this is bound to "M-Rubout" and
* to "M-Backspace".
*/
bool
delbunit (f, n, k)
    int f, n, k;
{
    int size;

    if (n < 0)
	return (FALSE);
    if ((lastflag & CFKILL) == 0)	/* Purge kill buffer.   */
	bclear (&sav_buf);
    thisflag |= CFKILL;
    size = R_B_PER_U (curwp);
    while (n--)
    {
	if (move_ptr (curwp, -((long) size), TRUE, TRUE, TRUE))
	    ldelete ((A32) size, TRUE);
    }
    curwp->w_flag |= WFHARD;
    return (TRUE);
}