995
|
1 /*
|
|
2 * This file contains the command processing functions for a number of random
|
|
3 * commands. There is no functional grouping here, for sure.
|
|
4 */
|
|
5
|
|
6 #include <stdio.h>
|
|
7 #include "ueed.h"
|
|
8
|
|
9 /*
|
|
10 * Insert a newline, then enough tabs and spaces to duplicate the indentation
|
|
11 * of the previous line. Assumes tabs are every eight characters. Quite simple.
|
|
12 * Figure out the indentation of the current line. Insert a newline by calling
|
|
13 * the standard routine. Insert the indentation by inserting the right number
|
|
14 * of tabs and spaces. Return TRUE if all ok. Return FALSE if one of the
|
|
15 * subcomands failed. Normally bound to "C-J".
|
|
16 */
|
|
17 indent(f, n)
|
|
18 {
|
|
19 register int nicol;
|
|
20 register int c;
|
|
21 register int i;
|
|
22
|
|
23 if (n < 0)
|
|
24 return (FALSE);
|
|
25 while (n--) {
|
|
26 nicol = 0;
|
|
27 for (i=0; i<llength(curwp->w_dotp); ++i) {
|
|
28 c = lgetc(curwp->w_dotp, i);
|
|
29 if (c!=' ' && c!='\t')
|
|
30 break;
|
|
31 if (c == '\t')
|
|
32 nicol |= 0x07;
|
|
33 ++nicol;
|
|
34 }
|
|
35 if (lnewline() == FALSE
|
|
36 || ((i=nicol/8)!=0 && linsert(i, '\t')==FALSE)
|
|
37 || ((i=nicol%8)!=0 && linsert(i, ' ')==FALSE))
|
|
38 return (FALSE);
|
|
39 }
|
|
40 return (TRUE);
|
|
41 }
|
|
42
|
|
43 /*
|
|
44 * Delete forward. This is real easy, because the basic delete routine does
|
|
45 * all of the work. Watches for negative arguments, and does the right thing.
|
|
46 * If any argument is present, it kills rather than deletes, to prevent loss
|
|
47 * of text if typed with a big arg
|
|
48 ument. Normally bound to "C-D".
|
|
49 */
|
|
50 forwdel(f, n)
|
|
51 {
|
|
52 if (n < 0)
|
|
53 return (backdel(f, -n));
|
|
54
|
|
55 if (f != FALSE) { /* Really a kill. */
|
|
56 if ((lastflag&CFKILL) == 0)
|
|
57 kdelete();
|
|
58 thisflag |= CFKILL;
|
|
59 }
|
|
60 return (ldelete(n, f));
|
|
61 }
|
|
62
|
|
63 /*
|
|
64 * Delete backwards. This is quite easy too, because it's all done with other
|
|
65 * functions. Just move the cursor back, and delete forwards. Like delete
|
|
66 * forward, this actually does a kill if presented with an argument. Bound to
|
|
67 * both "RUBOUT" and "C-H".
|
|
68 */
|
|
69 backdel(f, n)
|
|
70 {
|
|
71 register int s;
|
|
72
|
|
73 if (n < 0)
|
|
74 return (forwdel(f, -n));
|
|
75 if (f != FALSE) { /* Really a kill. */
|
|
76 if ((lastflag&CFKILL) == 0)
|
|
77 kdelete();
|
|
78 thisflag |= CFKILL;
|
|
79 }
|
|
80 if ((s=backchar(f, n)) == TRUE)
|
|
81 s = ldelete(n, f);
|
|
82 return (s);
|
|
83 }
|
|
84
|
|
85 /*
|
|
86 * Kill text. If called without an argument, it kills from dot to the end of
|
|
87 * the line, unless it is at the end of the line, when it kills the newline.
|
|
88 * If called with an argument of 0, it kills from the start of the line to dot.
|
|
89 * If called with a positive argument, it kills from dot forward over that
|
|
90 * number of newlines. If called with a negative argument it kills backwards
|
|
91 * that number of newlines. Normally bound to "C-K".
|
|
92 */
|
|
93 killer(f, n)
|
|
94 int f,n;
|
|
95 {
|
|
96 register int chunk;
|
|
97 register LINE *nextp;
|
|
98
|
|
99 if ((lastflag&CFKILL) == 0) /* Clear kill buffer if */
|
|
100 kdelete(); /* last wasn't a kill. */
|
|
101 thisflag |= CFKILL;
|
|
102 if (f == FALSE) {
|
|
103 chunk = llength(curwp->w_dotp)-curwp->w_doto;
|
|
104 if (chunk == 0)
|
|
105 chunk = 1;
|
|
106 } else if (n == 0) {
|
|
107 chunk = curwp->w_doto;
|
|
108 curwp->w_doto = 0;
|
|
109 } else if (n > 0) {
|
|
110 chunk = llength(curwp->w_dotp)-curwp->w_doto+1;
|
|
111 nextp = lforw(curwp->w_dotp);
|
|
112 while (--n) {
|
|
113 if (nextp == curbp->b_linep)
|
|
114 return (FALSE);
|
|
115 chunk += llength(nextp)+1;
|
|
116 nextp = lforw(nextp);
|
|
117 }
|
|
118 } else {
|
|
119 mlwrite("neg kill");
|
|
120 return (FALSE);
|
|
121 }
|
|
122 return (ldelete(chunk, TRUE));
|
|
123 }
|
|
124
|
|
125 /*
|
|
126 * Yank text back from the kill buffer. This is really easy. All of the work
|
|
127 * is done by the standard insert routines. All you do is run the loop, and
|
|
128 * check for errors. Bound to "C-Y". The blank lines are inserted with a call
|
|
129 * to "newline" instead of a call to "lnewline" so that the magic stuff that
|
|
130 * happens when you type a carriage return also happens when a carriage return
|
|
131 * is yanked back from the kill buffer.
|
|
132 */
|
|
133 yank(f, n)
|
|
134 {
|
|
135 register int c;
|
|
136 register int i;
|
|
137 extern int kused;
|
|
138
|
|
139 if (n < 0)
|
|
140 return (FALSE);
|
|
141 while (n--) {
|
|
142 i = 0;
|
|
143 while ((c=kremove(i)) >= 0) {
|
|
144 if (c == '\n') {
|
|
145 if (newline(FALSE, 1) == FALSE)
|
|
146 return (FALSE);
|
|
147 } else {
|
|
148 if (linsert(1, c) == FALSE)
|
|
149 return (FALSE);
|
|
150 }
|
|
151 ++i;
|
|
152 }
|
|
153 }
|
|
154 return (TRUE);
|
|
155 }
|
|
156
|