forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / fish / microemacs / rainbo.h
blob20937d1a81a9557754ba2490bdaa78283caa19ab
2 /*
3 * Rainbow keyboard function key definitions
4 */
6 #define Function_Key 0x0100
7 #define Shift 0x0200
8 #define Control 0x0400
10 #define Help_Key 0x0100
11 #define Do_Key 0x0101
12 #define Compose_Key 0x0102
13 #define Print_Scr_Key 0x0103
14 #define F4_Key 0x0105
15 #define Interrupt_Key 0x0107
16 #define Resume_Key 0x0109
17 #define Cancel_Key 0x010B
18 #define Main_Scr_Key 0x010D
19 #define Exit_Key 0x010F
20 #define Options_Key 0x0111
21 #define F17_Key 0x0113
22 #define F18_Key 0x0115
23 #define F19_Key 0x0117
24 #define F20_Key 0x0119
25 #define Find_Key 0x011B
26 #define Insert_Key 0x011D
27 #define Remove_Key 0x011F
28 #define Select_Key 0x0121
29 #define Prev_Scr_Key 0x0123
30 #define Next_Scr_Key 0x0125
31 #define Up_Key 0x0127
32 #define Down_Key 0x0129
33 #define Right_Key 0x012B
34 #define Left_Key 0x012D
35 #define Keypad_0 0x012F
36 #define Keypad_1 0x0132
37 #define Keypad_2 0x0135
38 #define Keypad_3 0x0138
39 #define Keypad_4 0x013B
40 #define Keypad_5 0x013E
41 #define Keypad_6 0x0141
42 #define Keypad_7 0x0144
43 #define Keypad_8 0x0147
44 #define Keypad_9 0x014A
45 #define Keypad_Dash 0x014D
46 #define Keypad_Comma 0x0150
47 #define Keypad_Period 0x0153
48 #define Keypad_Enter 0x0156
49 #define Keypad_PF1 0x0159
50 #define Keypad_PF2 0x015C
51 #define Keypad_PF3 0x015F
52 #define Keypad_PF4 0x0162
53 #define Break_Key 0x0165
54 \x1a
57 dir *.-h- random.c 2914:829:999 random.c
59 * This file contains the command processing functions for a number of random
60 * commands. There is no functional grouping here, for sure.
63 #include <stdio.h>
64 #include "ed.h"
66 int tabsize; /* Tab size (0: use real tabs) */
69 * Set fill column to n.
71 setfillcol(f, n)
73 fillcol = n;
74 return(TRUE);
78 * Display the current position of the cursor, in origin 1 X-Y coordinates,
79 * the character that is under the cursor (in octal), and the fraction of the
80 * text that is before the cursor. The displayed column is not the current
81 * column, but the column that would be used on an infinite width display.
82 * Normally this is bound to "C-X =".
84 showcpos(f, n)
86 register LINE *clp;
87 register long nch;
88 register int cbo;
89 register long nbc;
90 register int cac;
91 register int ratio;
92 register int col;
93 register int i;
94 register int c;
96 clp = lforw(curbp->b_linep); /* Grovel the data. */
97 cbo = 0;
98 nch = 0;
99 for (;;) {
100 if (clp==curwp->w_dotp && cbo==curwp->w_doto) {
101 nbc = nch;
102 if (cbo == llength(clp))
103 cac = '\n';
104 else
105 cac = lgetc(clp, cbo);
107 if (cbo == llength(clp)) {
108 if (clp == curbp->b_linep)
109 break;
110 clp = lforw(clp);
111 cbo = 0;
112 } else
113 ++cbo;
114 ++nch;
116 col = getccol(FALSE); /* Get real column. */
117 ratio = 0; /* Ratio before dot. */
118 if (nch != 0)
119 ratio = (100L*nbc) / nch;
120 mlwrite("X=%d Y=%d CH=0x%x .=%D (%d%% of %D)",
121 col+1, currow+1, cac, nbc, ratio, nch);
122 return (TRUE);
126 * Return current column. Stop at first non-blank given TRUE argument.
128 getccol(bflg)
129 int bflg;
131 register int c, i, col;
132 col = 0;
133 for (i=0; i<curwp->w_doto; ++i) {
134 c = lgetc(curwp->w_dotp, i);
135 if (c!=' ' && c!='\t' && bflg)
136 break;
137 if (c == '\t')
138 col |= 0x07;
139 else if (c<0x20 || c==0x7F)
140 ++col;
141 ++col;
143 return(col);
147 * Twiddle the two characters on either side of dot. If dot is at the end of
148 * the line twiddle the two characters before it. Return with an error if dot
149 * is at the beginning of line; it seems to be a bit pointless to make this
150 * work. This fixes up a very common typo with a single stroke. Normally bound
151 * to "C-T". This always works within a line, so "WFEDIT" is good enough.
153 twiddle(f, n)
155 register LINE *dotp;
156 register int doto;
157 register int cl;
158 register int cr;
160 dotp = curwp->w_dotp;
161 doto = curwp->w_doto;
162 if (doto==llength(dotp) && --doto<0)
163 return (FALSE);
164 cr = lgetc(dotp, doto);
165 if (--doto < 0)
166 return (FALSE);
167 cl = lgetc(dotp, doto);
168 lputc(dotp, doto+0, cr);
169 lputc(dotp, doto+1, cl);
170 lchange(WFEDIT);
171 return (TRUE);
175 * Quote the next character, and insert it into the buffer. All the characters
176 * are taken literally, with the exception of the newline, which always has
177 * its line splitting meaning. The character is always read, even if it is
178 * inserted 0 times, for regularity. Bound to "M-Q" (for me) and "C-Q" (for
179 * Rich, and only on terminals that don't need XON-XOFF).
181 quote(f, n)
183 register int s;
184 register int c;
186 c = (*term.t_getchar)();
187 if (n < 0)
188 return (FALSE);
189 if (n == 0)
190 return (TRUE);
191 if (c == '\n') {
192 do {
193 s = lnewline();
194 } while (s==TRUE && --n);
195 return (s);
197 return (linsert(n, c));
201 * Set tab size if given non-default argument (n <> 1). Otherwise, insert a
202 * tab into file. If given argument, n, of zero, change to true tabs.
203 * If n > 1, simulate tab stop every n-characters using spaces. This has to be
204 * done in this slightly funny way because the tab (in ASCII) has been turned
205 * into "C-I" (in 10 bit code) already. Bound to "C-I".
207 tab(f, n)
209 if (n < 0)
210 return (FALSE);
211 if (n == 0 || n > 1) {
212 tabsize = n;
213 return(TRUE);
215 if (! tabsize)
216 return(linsert(1, '\t'));
217 return(linsert(tabsize - (getccol(FALSE) % tabsize), ' '));
221 * Open up some blank space. The basic plan is to insert a bunch of newlines,
222 * and then back up over them. Everything is done by the subcommand
223 * procerssors. They even handle the looping. Normally this is bound to "C-O".
225 openline(f, n)
227 register int i;
228 register int s;
230 if (n < 0)
231 return (FALSE);
232 if (n == 0)
233 return (TRUE);
234 i = n; /* Insert newlines. */
235 do {
236 s = lnewline();
237 } while (s==TRUE && --i);
238 if (s == TRUE) /* Then back up overtop */
239 s = backchar(f, n); /* of them all. */
240 return (s);
244 * Insert a newline. Bound to "C-M". If you are at the end of the line and the
245 * next line is a blank line, just move into the blank line. This makes "C-O"
246 * and "C-X C-O" work nicely, and reduces the ammount of screen update that
247 * has to be done. This would not be as critical if screen update were a lot
248 * more efficient.
250 newline(f, n)
252 int nicol;
253 register LINE *lp;
254 register int s;
256 if (n < 0)
257 return (FALSE);
258 while (n--) {
259 lp = curwp->w_dotp;
260 if (llength(lp) == curwp->w_doto
261 && lp != curbp->b_linep
262 && llength(lforw(lp)) == 0) {
263 if ((s=forwchar(FALSE, 1)) != TRUE)
264 return (s);
265 } else if ((s=lnewline()) != TRUE)
266 return (s);
268 return (TRUE);
272 * Delete blank lines around dot. What this command does depends if dot is
273 * sitting on a blank line. If dot is sitting on a blank line, this command
274 * deletes all the blank lines above and below the current line. If it is
275 * sitting on a non blank line then it deletes all of the blank lines after
276 * the line. Normally this command is bound to "C-X C-O". Any argument is
277 * ignored.
279 deblank(f, n)
281 register LINE *lp1;
282 register LINE *lp2;
283 register int nld;
285 lp1 = curwp->w_dotp;
286 while (llength(lp1)==0 && (lp2=lback(lp1))!=curbp->b_linep)
287 lp1 = lp2;
288 lp2 = lp1;
289 nld = 0;
290 while ((lp2=lforw(lp2))!=curbp->b_linep && llength(lp2)==0)
291 ++nld;
292 if (nld == 0)
293 return (TRUE);
294 curwp->w_dotp = lforw(lp1);
295 curwp->w_doto = 0;
296 return (ldelete(nld));
300 * Insert a newline, then enough tabs and spaces to duplicate the indentation
301 * of the previous line. Assumes tabs are every eight characters. Quite simple.
302 * Figure out the indentation of the current line. Insert a newline by calling
303 * the standard routine. Insert the indentation by inserting the right number
304 * of tabs and spaces. Return TRUE if all ok. Return FALSE if one of the
305 * subcomands failed. Normally bound to "C-J".
307 indent(f, n)
309 register int nicol;
310 register int c;
311 register int i;
313 if (n < 0)
314 return (FALSE);
315 while (n--) {
316 nicol = 0;
317 for (i=0; i<llength(curwp->w_dotp); ++i) {
318 c = lgetc(curwp->w_dotp, i);
319 if (c!=' ' && c!='\t')
320 break;
321 if (c == '\t')
322 nicol |= 0x07;
323 ++nicol;
325 if (lnewline() == FALSE
326 || ((i=nicol/8)!=0 && linsert(i, '\t')==FALSE)
327 || ((i=nicol%8)!=0 && linsert(i, ' ')==FALSE))
328 return (FALSE);
330 return (TRUE);
334 * Delete forward. This is real easy, because the basic delete routine does
335 * all of the work. Watches for negative arguments, and does the right thing.
336 * If any argument is present, it kills rather than deletes, to prevent loss
337 * of text if typed with a big argument. Normally bound to "C-D".
339 forwdel(f, n)
341 if (n < 0)
342 return (backdel(f, -n));
343 if (f != FALSE) { /* Really a kill. */
344 if ((lastflag&CFKILL) == 0)
345 kdelete();
346 thisflag |= CFKILL;
348 return (ldelete(n, f));
352 * Delete backwards. This is quite easy too, because it's all done with other
353 * functions. Just move the cursor back, and delete forwards. Like delete
354 * forward, this actually does a kill if presented with an argument. Bound to
355 * both "RUBOUT" and "C-H".
357 backdel(f, n)
359 register int s;
361 if (n < 0)
362 return (forwdel(f, -n));
363 if (f != FALSE) { /* Really a kill. */
364 if ((lastflag&CFKILL) == 0)
365 kdelete();
366 thisflag |= CFKILL;
368 if ((s=backchar(f, n)) == TRUE)
369 s = ldelete(n, f);
370 return (s);
374 * Kill text. If called without an argument, it kills from dot to the end of
375 * the line, unless it is at the end of the line, when it kills the newline.
376 * If called with an argument of 0, it kills from the start of the line to dot.
377 * If called with a positive argument, it kills from dot forward over that
378 * number of newlines. If called with a negative argument it kills backwards
379 * that number of newlines. Normally bound to "C-K".
381 kill(f, n)
383 register int chunk;
384 register LINE *nextp;
386 if ((lastflag&CFKILL) == 0) /* Clear kill buffer if */
387 kdelete(); /* last wasn't a kill. */
388 thisflag |= CFKILL;
389 if (f == FALSE) {
390 chunk = llength(curwp->w_dotp)-curwp->w_doto;
391 if (chunk == 0)
392 chunk = 1;
393 } else if (n == 0) {
394 chunk = curwp->w_doto;
395 curwp->w_doto = 0;
396 } else if (n > 0) {
397 chunk = llength(curwp->w_dotp)-curwp->w_doto+1;
398 nextp = lforw(curwp->w_dotp);
399 while (--n) {
400 if (nextp == curbp->b_linep)
401 return (FALSE);
402 chunk += llength(nextp)+1;
403 nextp = lforw(nextp);
405 } else {
406 mlwrite("neg kill");
407 return (FALSE);
409 return (ldelete(chunk, TRUE));
413 * Yank text back from the kill buffer. This is really easy. All of the work
414 * is done by the standard insert routines. All you do is run the loop, and
415 * check for errors. Bound to "C-Y". The blank lines are inserted with a call
416 * to "newline" instead of a call to "lnewline" so that the magic stuff that
417 * happens when you type a carriage return also happens when a carriage return
418 * is yanked back from the kill buffer.
420 yank(f, n)
422 register int c;
423 register int i;
424 extern int kused;
426 if (n < 0)
427 return (FALSE);
428 while (n--) {
429 i = 0;
430 while ((c=kremove(i)) >= 0) {
431 if (c == '\n') {
432 if (newline(FALSE, 1) == FALSE)
433 return (FALSE);
434 } else {
435 if (linsert(1, c) == FALSE)
436 return (FALSE);
438 ++i;
441 return (TRUE);