source: trunk/minix/commands/elle/eef3.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 6.4 KB
Line 
1/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
5 */
6/*
7 * EEF3 Various Functions (Yanking, Indentation, miscellaneous)
8 */
9
10#include "elle.h"
11
12#if FX_APPNKILL
13/* EFUN: "Append Next Kill" */
14f_appnkill()
15{ this_cmd = KILLCMD; /* Fake out next call to ed_kill */
16}
17#endif /*FX_APPNKILL*/
18
19#if FX_UNKILL
20/* EFUN: "Un-kill" */
21f_unkill()
22{ register SBSTR *sd;
23
24 if((sd = kill_ring[kill_ptr]) == 0)
25 { ring_bell();
26 return;
27 }
28 mark_dot = cur_dot; /* Set mark at old location */
29 mark_p = 1; /* Mark's been set */
30 sb_sins((SBBUF *)cur_buf,sbs_cpy(sd)); /* Insert copy of stuff */
31 cur_dot = e_dot(); /* We're now after the new stuff */
32 buf_tmat(mark_dot); /* Say modified from here to cur_dot*/
33 this_cmd = YANKCMD;
34}
35#endif /*FX_UNKILL*/
36
37#if FX_UNKPOP
38/* EFUN: "Un-kill Pop" */
39f_unkpop()
40{ register SBSTR *sd;
41 register int i;
42
43 if (last_cmd != YANKCMD)
44 { ring_bell ();
45 return;
46 }
47 ed_delete(cur_dot,mark_dot);
48 if(cur_dot > mark_dot)
49 cur_dot = mark_dot;
50 i = KILL_LEN;
51 do {
52 if(--kill_ptr < 0)
53 kill_ptr = KILL_LEN-1;
54 if(sd = kill_ring[kill_ptr])
55 break;
56 } while(--i);
57
58 /* kill_ptr now pointing to right place; effect the yank. */
59 e_gocur(); /* Make sure point at right place too! */
60 return(f_unkill());
61}
62#endif /*FX_UNKPOP*/
63
64
65/* Indentation routines - still not polished */
66
67#if FX_INDATM
68/* EFUN: "Indent According to Mode" */
69/* In Fundamental mode, just inserts a tab.
70*/
71f_indatm()
72{ f_insself(TAB); /* This takes care of mode checking */
73}
74#endif /*FX_INDATM*/
75
76#if FX_INDNL
77/* EFUN: "Indent New Line" */
78f_indnl() /* execute CR followed by tab */
79{
80#if IMAGEN
81 /* Not dispatch-based, but rather hard-wired to do Gosmacs thing */
82 ed_crins();
83 f_indund();
84#else
85 cmd_xct(CR);
86 cmd_xct(TAB);
87#endif /*-IMAGEN*/
88}
89#endif /*FX_INDNL*/
90
91
92#if FX_BACKIND
93/* EFUN: "Back to Indentation"
94** Moves to end of current line's indentation.
95*/
96f_backind()
97{ e_gobol(); /* First move to beg of line */
98 e_gofwsp(); /* Then forward over whitespace */
99 ed_setcur();
100}
101#endif /*FX_BACKIND*/
102
103
104#if FX_INDCOMM
105
106static char *comm_beg = "/* ";
107static char *comm_end = " */";
108
109/* EFUN: "Indent for Comment" */
110f_indcomm()
111{
112 f_endline();
113 if(indtion(cur_dot) < ev_ccolumn)
114 ed_indto(ev_ccolumn);
115 else ed_sins(" ");
116 ed_sins (comm_beg);
117 ed_sins (comm_end);
118 e_igoff(-strlen (comm_end)); /* back over end string */
119 e_setcur();
120}
121#endif /*FX_INDCOMM*/
122
123#if FX_INDREL
124/* EFUN: "Indent Relative" */
125/* This used to mistakenly be called Indent Under.
126** Still not fully implemented.
127** If at beginning of line, looks back at previous indented line,
128** and indents this line that much. If there is no preceding indented
129** line or not at beginning of line, insert a tab.
130*/
131f_indrel()
132{ register int c;
133 register n;
134#if IMAGEN
135 chroff savdot;
136#endif /*IMAGEN*/
137#if ICONOGRAPHICS
138 chroff savdot;
139 int curind, newind, morebuf;
140#endif /*ICONOGRAPHICS*/
141
142 if((c = e_rgetc()) == EOF)
143#if IMAGEN
144 return(f_insself(TAB)); /* Do mode-based tabbing */
145#else
146 return(ed_insert(TAB));
147#endif /*-IMAGEN*/
148
149 if(c == LF)
150 { e_gobol();
151 e_gofwsp();
152 n = d_curind();
153 e_gonl(); /* Return to orig pos */
154 if(n)
155 { ed_indto(n);
156#if IMAGEN
157 savdot = e_dot();
158 e_gofwsp();
159 ed_delete(savdot, e_dot());
160#endif /*IMAGEN*/
161 return;
162 }
163 }
164#if ICONOGRAPHICS
165 else
166 { e_igoff (1);
167 curind = indtion (savdot = e_dot ());
168 /* get current dot and indentation */
169 while (1) /* find a prev line that extends rightward */
170 { morebuf = e_gopl ();
171 e_goeol ();
172 if ((newind = d_curind()) > curind) break;
173 if (morebuf == 0) /* hit beginning of buffer */
174 { e_go (savdot);
175 f_delspc();
176 return (1);
177 }
178 }
179
180 e_gobol ();
181 e_igoff (inindex (e_dot (), curind));
182 if (d_curind() > curind)
183 e_rgetc (); /* pushed ahead by tab */
184
185 while (c_wsp (e_getc ()) == 0) ;
186 e_backc ();
187 e_fwsp ();
188 newind = d_curind();
189 e_go (savdot);
190 f_delspc();
191 ed_indto (newind);
192 }
193#else
194 else e_getc();
195#if IMAGEN
196 f_insself(TAB); /* Do mode-based tabbing */
197#else
198 ed_insert(TAB);
199#endif /*-IMAGEN*/
200#endif /*-ICONOGRAPHICS*/
201}
202#endif /*FX_INDREL*/
203
204
205
206/* Paren matching stuff. Note that this stuff will be very painful unless
207** tinwait() works properly.
208*/
209#if 0
210/* EFUN: "Self-Insert and Match" (intended to be bound to brackets) */
211/* (KLH: Evidently this was never finished)
212*/
213insertmatch(c)
214register int c;
215{
216
217}
218#endif
219
220/* Should change this to Matching Paren */
221#if FX_MATCHBRACK
222/* EFUN: "Match Bracket" (not EMACS) - from IMAGEN config
223 * Show the matching bracket for the character right before dot
224 */
225f_matchbrack()
226{
227 chroff savdot;
228 register int i, mc, secs;
229
230 if (exp_p)
231 secs = exp;
232 else
233 secs = 1;
234 savdot = cur_dot; /* Save our location */
235 mc = e_rgetc(); /* Pick up character before dot */
236 if (mc != ')' && mc != ']' && mc != '}')
237 { e_getc(); /* Nothing, try at dot instead */
238 e_getc();
239 mc = e_rgetc();
240 if (mc != ')' && mc != ']' && mc != '}')
241 { ding("What bracket?");
242 e_go(savdot);
243 return;
244 }
245 }
246 if (! matchonelevel(mc))
247 ring_bell();
248 else
249 { ed_setcur();
250 if (d_line(cur_dot) < 0)
251 secs = 10; /* Wait longer if off-screen */
252 redisplay(); /* Wish it were simple upd_wind() */
253 for (i = 1; i <= secs; ++i)
254 { if (tinwait())
255 break;
256 sleep(1);
257 }
258 }
259 e_gosetcur(savdot); /* Back to origin */
260 redp(RD_MOVE); /* Cursor has moved */
261}
262
263
264/* Try to match 'mc', return true iff found it */
265matchonelevel(mc)
266register int mc;
267{
268 register int c;
269
270 while ((c = e_rgetc()) != EOF)
271 { if (c == /*[*/ ']' || c == /*(*/ ')' || c == /*{*/ '}')
272 { if (! matchonelevel(c))
273 break;
274 }
275 else if (c == '(' /*)*/)
276 return(mc == /*(*/ ')');
277 else if (c == '[' /*]*/)
278 return(mc == /*[*/ ']');
279 else if (c == '{' /*}*/)
280 return(mc == /*{*/ '}');
281 }
282 return(0);
283}
284#endif /*FX_MATCHBRACK*/
Note: See TracBrowser for help on using the repository browser.