mtree: no more /lib and /lib/i386.
[minix.git] / commands / elle / eef3.c
blobbbf8a193d1c118a68e8a6ebed9b04a41482a5a8b
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 */
10 #include "elle.h"
12 #if FX_APPNKILL
13 /* EFUN: "Append Next Kill" */
14 f_appnkill()
15 { this_cmd = KILLCMD; /* Fake out next call to ed_kill */
17 #endif /*FX_APPNKILL*/
19 #if FX_UNKILL
20 /* EFUN: "Un-kill" */
21 f_unkill()
22 { register SBSTR *sd;
24 if((sd = kill_ring[kill_ptr]) == 0)
25 { ring_bell();
26 return;
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;
35 #endif /*FX_UNKILL*/
37 #if FX_UNKPOP
38 /* EFUN: "Un-kill Pop" */
39 f_unkpop()
40 { register SBSTR *sd;
41 register int i;
43 if (last_cmd != YANKCMD)
44 { ring_bell ();
45 return;
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);
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());
62 #endif /*FX_UNKPOP*/
64 /* Indentation routines - still not polished */
66 #if FX_INDATM
67 /* EFUN: "Indent According to Mode" */
68 /* In Fundamental mode, just inserts a tab.
70 f_indatm()
71 { f_insself(TAB); /* This takes care of mode checking */
73 #endif /*FX_INDATM*/
75 #if FX_INDNL
76 /* EFUN: "Indent New Line" */
77 f_indnl() /* execute CR followed by tab */
79 #if IMAGEN
80 /* Not dispatch-based, but rather hard-wired to do Gosmacs thing */
81 ed_crins();
82 f_indund();
83 #else
84 cmd_xct(CR);
85 cmd_xct(TAB);
86 #endif /*-IMAGEN*/
88 #endif /*FX_INDNL*/
91 #if FX_BACKIND
92 /* EFUN: "Back to Indentation"
93 ** Moves to end of current line's indentation.
95 f_backind()
96 { e_gobol(); /* First move to beg of line */
97 e_gofwsp(); /* Then forward over whitespace */
98 ed_setcur();
100 #endif /*FX_BACKIND*/
103 #if FX_INDCOMM
105 static char *comm_beg = "/* ";
106 static char *comm_end = " */";
108 /* EFUN: "Indent for Comment" */
109 f_indcomm()
111 f_endline();
112 if(indtion(cur_dot) < ev_ccolumn)
113 ed_indto(ev_ccolumn);
114 else ed_sins(" ");
115 ed_sins (comm_beg);
116 ed_sins (comm_end);
117 e_igoff(-strlen (comm_end)); /* back over end string */
118 e_setcur();
120 #endif /*FX_INDCOMM*/
122 #if FX_INDREL
123 /* EFUN: "Indent Relative" */
124 /* This used to mistakenly be called Indent Under.
125 ** Still not fully implemented.
126 ** If at beginning of line, looks back at previous indented line,
127 ** and indents this line that much. If there is no preceding indented
128 ** line or not at beginning of line, insert a tab.
130 f_indrel()
131 { register int c;
132 register n;
133 #if IMAGEN
134 chroff savdot;
135 #endif /*IMAGEN*/
136 #if ICONOGRAPHICS
137 chroff savdot;
138 int curind, newind, morebuf;
139 #endif /*ICONOGRAPHICS*/
141 if((c = e_rgetc()) == EOF)
142 #if IMAGEN
143 return(f_insself(TAB)); /* Do mode-based tabbing */
144 #else
145 return(ed_insert(TAB));
146 #endif /*-IMAGEN*/
148 if(c == LF)
149 { e_gobol();
150 e_gofwsp();
151 n = d_curind();
152 e_gonl(); /* Return to orig pos */
153 if(n)
154 { ed_indto(n);
155 #if IMAGEN
156 savdot = e_dot();
157 e_gofwsp();
158 ed_delete(savdot, e_dot());
159 #endif /*IMAGEN*/
160 return;
163 #if ICONOGRAPHICS
164 else
165 { e_igoff (1);
166 curind = indtion (savdot = e_dot ());
167 /* get current dot and indentation */
168 while (1) /* find a prev line that extends rightward */
169 { morebuf = e_gopl ();
170 e_goeol ();
171 if ((newind = d_curind()) > curind) break;
172 if (morebuf == 0) /* hit beginning of buffer */
173 { e_go (savdot);
174 f_delspc();
175 return (1);
179 e_gobol ();
180 e_igoff (inindex (e_dot (), curind));
181 if (d_curind() > curind)
182 e_rgetc (); /* pushed ahead by tab */
184 while (c_wsp (e_getc ()) == 0) ;
185 e_backc ();
186 e_fwsp ();
187 newind = d_curind();
188 e_go (savdot);
189 f_delspc();
190 ed_indto (newind);
192 #else
193 else e_getc();
194 #if IMAGEN
195 f_insself(TAB); /* Do mode-based tabbing */
196 #else
197 ed_insert(TAB);
198 #endif /*-IMAGEN*/
199 #endif /*-ICONOGRAPHICS*/
201 #endif /*FX_INDREL*/
204 /* Paren matching stuff. Note that this stuff will be very painful unless
205 ** tinwait() works properly.
207 #if 0
208 /* EFUN: "Self-Insert and Match" (intended to be bound to brackets) */
209 /* (KLH: Evidently this was never finished)
211 insertmatch(c)
212 register int c;
216 #endif
218 /* Should change this to Matching Paren */
219 #if FX_MATCHBRACK
220 /* EFUN: "Match Bracket" (not EMACS) - from IMAGEN config
221 * Show the matching bracket for the character right before dot
223 f_matchbrack()
225 chroff savdot;
226 register int i, mc, secs;
228 if (exp_p)
229 secs = exp;
230 else
231 secs = 1;
232 savdot = cur_dot; /* Save our location */
233 mc = e_rgetc(); /* Pick up character before dot */
234 if (mc != ')' && mc != ']' && mc != '}')
235 { e_getc(); /* Nothing, try at dot instead */
236 e_getc();
237 mc = e_rgetc();
238 if (mc != ')' && mc != ']' && mc != '}')
239 { ding("What bracket?");
240 e_go(savdot);
241 return;
244 if (! matchonelevel(mc))
245 ring_bell();
246 else
247 { ed_setcur();
248 if (d_line(cur_dot) < 0)
249 secs = 10; /* Wait longer if off-screen */
250 redisplay(); /* Wish it were simple upd_wind() */
251 for (i = 1; i <= secs; ++i)
252 { if (tinwait())
253 break;
254 sleep(1);
257 e_gosetcur(savdot); /* Back to origin */
258 redp(RD_MOVE); /* Cursor has moved */
262 /* Try to match 'mc', return true iff found it */
263 matchonelevel(mc)
264 register int mc;
266 register int c;
268 while ((c = e_rgetc()) != EOF)
269 { if (c == /*[*/ ']' || c == /*(*/ ')' || c == /*{*/ '}')
270 { if (! matchonelevel(c))
271 break;
273 else if (c == '(' /*)*/)
274 return(mc == /*(*/ ')');
275 else if (c == '[' /*]*/)
276 return(mc == /*[*/ ']');
277 else if (c == '{' /*}*/)
278 return(mc == /*{*/ '}');
280 return(0);
282 #endif /*FX_MATCHBRACK*/