File: insert.c

package info (click to toggle)
jove 4.17.5.5-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,476 kB
  • sloc: ansic: 29,235; makefile: 534; sh: 428; python: 45
file content (910 lines) | stat: -rw-r--r-- 17,577 bytes parent folder | download
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
/**************************************************************************
 * This program is Copyright (C) 1986-2002 by Jonathan Payne.  JOVE is    *
 * provided by Jonathan and Jovehacks without charge and without          *
 * warranty.  You may copy, modify, and/or distribute JOVE, provided that *
 * this notice is included in all the source files and documentation.     *
 **************************************************************************/

#include "jove.h"
#include "jctype.h"
#include "list.h"
#include "chars.h"
#include "disp.h"
#include "abbrev.h"
#include "ask.h"
#include "c.h"
#include "delete.h"
#include "insert.h"
#include "fmt.h"
#include "macros.h"
#include "marks.h"
#include "misc.h"
#include "move.h"
#include "para.h"
#include "screen.h"	/* for tabstop */
#include "sysprocs.h"
#include "proc.h"
#include "wind.h"

private void
	DoNewline proto((jbool indentp));

#ifdef LISP
private Bufpos
	*lisp_indent proto((void));
#endif

/* Make a new line after "after" in buffer "buf", unless "after" is NULL,
 * in which case we insert the new line before first line.
 */
LinePtr
listput(buf, after)
register Buffer	*buf;
register LinePtr	after;
{
	register LinePtr	newline = nbufline();

	newline->l_prev = after;
	if (after == NULL) {	/* Before the first line */
		newline->l_next = buf->b_first;
		buf->b_first = newline;
	} else {
		newline->l_next = after->l_next;
		after->l_next = newline;
	}
	if (newline->l_next != NULL)
		newline->l_next->l_prev = newline;
	else if (buf != NULL)
		buf->b_last = newline;
	if (buf && buf->b_dot == NULL)
		buf->b_dot = newline;
	return newline;
}

/* Divide the current line and move the current line to the next one */

void
LineInsert(num)
register long	num;
{
	char	newline[LBSIZE];
	register LinePtr	newdot,
			olddot;
	int	oldchar;

	olddot = curline;
	oldchar = curchar;

	newdot = curline;
	while (--num >= 0) {
		newdot = listput(curbuf, newdot);
		SavLine(newdot, NullStr);
	}

	modify();
	if (curchar != 0) {
		strcpy(newline, &linebuf[curchar]);
		linebuf[curchar] = '\0';	/* Shorten this line */
		SavLine(curline, linebuf);
		strcpy(linebuf, newline);
	} else {	/* Redisplay optimization */
		newdot->l_dline = curline->l_dline;
		SavLine(curline, NullStr);
	}

	makedirty(curline);
	curline = newdot;
	curchar = 0;
	makedirty(curline);
	IFixMarks(olddot, oldchar, curline, curchar);
}

/* Inserts tabs and spaces to move the cursor to column GOAL.  It
 * Uses the most optimal number of tabs and spaces no matter what
 * was there beforehand.
 */
void
n_indent(goal)
register int	goal;
{
	int	dotcol;

	DelWtSpace();
	dotcol = calc_pos(linebuf, curchar);

	if (tabstop != 0) {
		for (;;) {
			int	incrmt = TABDIST(dotcol);

			if (dotcol + incrmt > goal)
				break;

			insert_c('\t', 1);
			dotcol += incrmt;
		}
	}
	if (dotcol != goal)
		insert_c(' ', (goal - dotcol));
}

#ifdef ABBREV
void
MaybeAbbrevExpand()
{
	if (MinorMode(Abbrev) && !jisident(LastKeyStruck)
	&& !bolp() && jisident(linebuf[curchar - 1]))
		AbbrevExpand();
}
#endif

private void
Insert(c)
char	c;
{
	if (c == CTL('J'))
		LineInsert(arg_value());
	else
		insert_c(c, arg_value());
}

void
overwrite(c, n)
DAPchar	c;
int	n;
{
	register int	i;

	for (i = 0; i < n; i++) {
		/* Delete one *column* forward (except that we don't
		 * notice that control characters take two columns).
		 */
		if (!eolp() && (linebuf[curchar] != '\t' || tabstop == 0
		  || TABDIST(calc_pos(linebuf, curchar)) == 1))
		{
			del_char(FORWARD, 1, NO);
		}
		insert_c(c, 1);
	}
}

void
SelfInsert()
{
#ifdef ABBREV
	MaybeAbbrevExpand();
#endif
	if (LastKeyStruck != CTL('J') && MinorMode(OverWrite))
		overwrite(LastKeyStruck, arg_value());
	else
		Insert(LastKeyStruck);

	/* If we are in fill mode and at or beyond the right margin,
	 * we break the line.  However, we won't do this if the new
	 * character is whitespace and we are at the end of the line:
	 * DoJustify would discard the trailing space.
	 */
	if (MinorMode(Fill) && calc_pos(linebuf, curchar) >= RMargin
	&& !(jiswhite(LastKeyStruck) && eolp()))
	{
		int margin;
		Bufpos save;

		if (MinorMode(Indent)) {
			DOTsave(&save);
			ToIndent();
			margin = calc_pos(linebuf, curchar);
			SetDot(&save);
		} else {
			margin = LMargin;
		}
		DoJustify(curline, 0, curline,
			  curchar + (int)strlen(&linebuf[curchar]), YES, margin);
	}
}

/* insert character C N times at point */
void
insert_c(c, n)
DAPchar	c;
int	n;
{
	if (n > 0) {
		modify();
		makedirty(curline);
		ins_c(c, linebuf, curchar, n, LBSIZE);
		IFixMarks(curline, curchar, curline, curchar + n);
		curchar += n;
	}
}

/* Tab in to the right place for C mode */

void
Tab()
{
#ifdef LISP
	if (MajorMode(LISPMODE) && (bolp() || !eolp())) {
		int	dotchar = curchar;

		ToIndent();
		if (dotchar > curchar) {
			Mark	*m = MakeMark(curline, dotchar);

			(void) lisp_indent();
			ToMark(m);
			DelMark(m);
		} else {
			(void) lisp_indent();
			ToIndent();
		}
		return;
	}
#endif
	if (MajorMode(CMODE)) {
		if (within_indent())
			(void) c_indent(NO);
		else {
			int	curpos,
				tabbed_pos;

			skip_wht_space();
			curpos = calc_pos(linebuf, curchar);
			tabbed_pos = curpos + (CIndIncrmt - (curpos % CIndIncrmt));
			n_indent(tabbed_pos);
		}
	} else
		SelfInsert();
}

void
QuotChar()
{
	ZXchar	c = ask_ks();

	if (c == '\0') {
		int	n = arg_value();

		while (n-- > 0)
			ins_str("^@");
	} else {
		Insert(c);
#ifdef PCNONASCII
		if (c == PCNONASCII) {
			c = waitchar();
			if (c == '\0') {
				int	n = arg_value();

				while (n-- > 0)
					ins_str("^@");
			} else {
				Insert(c);
			}
		}
#endif
	}
}

/* Insert the paren.  If in C mode and c is a '}' then insert the
 * '}' in the "right" place for C indentation; that is indented
 * the same amount as the matching '{' is indented.
 */
int	PDelay = 5,		/* VAR: paren flash delay in tenths of a second */
	CIndIncrmt = 8;	/* VAR: how much each indentation level pushes over in C mode */

void
DoParen()
{
	Bufpos	*bp = NULL;	/* avoid uninitialized complaint from gcc -W */
	ZXchar	c = LastKeyStruck;
	jbool	tried = NO;

	if (!jisclosep(c)) {
		SelfInsert();
		return;
	}

	if (MajorMode(CMODE) && c == '}' && within_indent()) {
		bp = c_indent(YES);
		tried = YES;
	}
#ifdef LISP
	if (MajorMode(LISPMODE) && c == ')' && blnkp(linebuf)) {
		bp = lisp_indent();
		tried = YES;
	}
#endif
	SelfInsert();

	if (MinorMode(ShowMatch)
#ifndef MAC
	&& !PreEmptOutput()
#endif
	&& !in_macro())
	{
		b_char(1);	/* Back onto the ')' */
		if (!tried)
			bp = m_paren(c, BACKWARD, NO, YES);
		f_char(1);
		if (bp != NULL) {
			int	nx = in_window(curwind, bp->p_line);

			if (nx != -1) {		/* is visible */
				Bufpos	b;

				DOTsave(&b);
				SetDot(bp);
				SitFor(PDelay);
				SetDot(&b);
			} else
				s_mess("%s", lcontents(bp->p_line));
		}
		mp_error();	/* display error message */
	}
}

void
LineAI()
{
	DoNewline(YES);
}

void
Newline()
{
	DoNewline(MinorMode(Indent));
}

private void
DoNewline(indentp)
jbool	indentp;
{
	Bufpos	save;
	int	indent;

	/* first we calculate the indent of the current line */
	DOTsave(&save);
	ToIndent();
	indent = calc_pos(linebuf, curchar);
	SetDot(&save);

#ifdef ABBREV
	MaybeAbbrevExpand();
#endif
	if (
#ifdef LISP
	    MajorMode(LISPMODE) ||
#endif
	    indentp)
	{
		DelWtSpace();
	}

	/* If there is more than 2 blank lines in a row then don't make
	 * a newline, just move down one.
	 */
	if (arg_value() == 1 && eolp() && TwoBlank())
		SetLine(curline->l_next);
	else
		LineInsert(arg_value());

	if (indentp) {
#ifdef LISP
		if (MajorMode(LISPMODE))
			(void) lisp_indent();
		else
#endif
		{
			Bol();
			n_indent((LMargin == 0) ? indent : LMargin);
		}
	}
}

void
ins_str(str)
const char *str;
{
	ins_str_wrap(str, NO, LBSIZE-1);
}

void
ins_str_wrap(str, ok_nl, wrap_off)
const char *str;
jbool ok_nl;
int wrap_off;
{
	register char c;
	Bufpos save;
	int llen;

	if (*str == '\0')
		return;		/* ain't nothing to insert! */

	if (wrap_off > LBSIZE-1)
		wrap_off = LBSIZE-1;
	DOTsave(&save);
	llen = strlen(linebuf);
	while ((c = *str++) != '\0') {
		if (c == '\n' || (ok_nl && llen >= wrap_off)) {
			IFixMarks(save.p_line, save.p_char, curline, curchar);
			modify();
			makedirty(curline);
			LineInsert(1);
			DOTsave(&save);
			llen = strlen(linebuf);
		}
		if (c != '\n') {
			ins_c(c, linebuf, curchar++, 1, LBSIZE);
			llen += 1;
		}
	}
	IFixMarks(save.p_line, save.p_char, curline, curchar);
	modify();
	makedirty(curline);
}

void
open_lines(n)
long	n;
{
	Bufpos	dot;

	DOTsave(&dot);
	LineInsert(n);	/* Open the lines... */
	SetDot(&dot);
}

void
OpenLine()
{
	open_lines(arg_value());
}

/* Take the region FLINE/FCHAR to TLINE/TCHAR and insert it at
 * ATLINE/ATCHAR in WHATBUF.
 */
Bufpos *
DoYank(fline, fchar, tline, tchar, atline, atchar, whatbuf)
LinePtr	fline,
	tline,
	atline;
int	fchar,
	tchar,
	atchar;
Buffer	*whatbuf;
{
	register LinePtr	newline;
	static Bufpos	bp;
	char	save[LBSIZE],
		buf[LBSIZE];
	LinePtr	startline = atline;
	int	startchar = atchar;

	lsave();
	if (whatbuf != NULL)
		modify();
	(void) ltobuf(atline, genbuf);
	strcpy(save, &genbuf[atchar]);

	(void) ltobuf(fline, buf);
	if (fline == tline)
		buf[tchar] = '\0';

	linecopy(genbuf, atchar, &buf[fchar]);
	atline->l_dline = jputline(genbuf);
	makedirty(atline);

	fline = fline->l_next;
	while (fline != tline->l_next) {
		newline = listput(whatbuf, atline);
		newline->l_dline = fline->l_dline;
		makedirty(newline);
		fline = fline->l_next;
		atline = newline;
		atchar = 0;
	}

	jgetline(atline->l_dline, genbuf);
	atchar += tchar;
	linecopy(genbuf, atchar, save);
	atline->l_dline = jputline(genbuf);
	makedirty(atline);
	IFixMarks(startline, startchar, atline, atchar);
	bp.p_line = atline;
	bp.p_char = atchar;
	if (whatbuf != NULL)
		this_cmd = YANKCMD;
	getDOT();			/* Whatever used to be in linebuf */
	return &bp;
}

void
YankPop()
{
	Mark	*mp = CurMark();
	LinePtr	line,
		last;
	Bufpos	*dot;

	switch (last_cmd) {
	case YANKCMD:
		{
			/* Direction to rotate the ring */
			int	dir = arg_value() < 0? 1 : NUMKILLS - 1;

			/* Now must find a recently killed region. */
			do {
				killptr = (killptr+dir) % NUMKILLS;
			} while (killbuf[killptr] == NULL);
		}
		break;
	case UNDOABLECMD:
		break;
	default:
		complain("Yank something first!");
		/*NOTREACHED*/
	}
	lfreelist(reg_delete(mp->m_line, mp->m_char, curline, curchar));
	line = killbuf[killptr];
	last = lastline(line);
	dot = DoYank(line, 0, last, length(last), curline, curchar, curbuf);
	MarkSet(CurMark(), curline, curchar);
	SetDot(dot);
	if (last_cmd == UNDOABLECMD)
		this_cmd = OTHER_CMD;
}

/* This is an attempt to reduce the amount of memory taken up by each line.
 * Without this each malloc of a line uses sizeof (line) + sizeof(HEADER)
 * where line is 3 words and HEADER is 1 word.
 * This is going to allocate memory in chucks of CHUNKSIZE * sizeof (line)
 * and divide each chuck into Lines.  A line is free in a chunk when its
 * line->l_dline == NULL_DADDR, so freeline sets l_dline to NULL_DADDR.
 */

#define CHUNKSIZE	300

#ifdef FAR_LINES
# ifdef __BORLANDC__
#  include <alloc.h>	/* Borland farmalloc() */
# else
#  ifdef OWCDOS
#   include <malloc.h>
#   define farmalloc(sz)	_fmalloc(sz)
#   define farfree(x)	_ffree(x)
#  else
#   include <dos.h>	/* Zortech farmalloc(), MSC (?) */
#  endif
# endif
typedef struct chunk _far	*ChunkPtr;
# define CHUNKMALLOC(s)	((ChunkPtr) farmalloc(s))
# define CHUNKFREE(c)	farfree((void _far *) (c))
#else
typedef struct chunk	*ChunkPtr;
# define CHUNKMALLOC(s)	((ChunkPtr) malloc(s))
# define CHUNKFREE(c)	free((UnivPtr) (c))
#endif

struct chunk {
	ChunkPtr	c_nextchunk;	/* Next chunk of lines */
	int	c_nlines;	/* Number of lines in this chunk (so they
				   don't all have to be CHUNKSIZE long). */
	struct line	c_block[1 /* or larger */];	/* Chunk of memory */
};

private ChunkPtr	fchunk = NULL;	/* first chunk */
private LinePtr	ffline = NULL;	/* First free line */
private LinePtr	faline = NULL;	/* First available line */

private void
freeline(line)
register LinePtr	line;
{
	line->l_dline = NULL_DADDR;
	line->l_next = ffline;
	if (ffline)
		ffline->l_prev = line;
	line->l_prev = NULL;
	ffline = line;
}

/* Make sure that there are no dangling references to lines in the free list,
 * then move them to the end of the avail list.
 */

private void
RecycleLines()
{
	if (ffline == NULL)
		return;	/* nothing to do */

	ChkErrorLines();
	/* ChkWindowLines(); -- nothing needs attention */
	/* ChkBufLines(); -- nothing needs attention */

	if (faline == NULL) {
		faline = ffline;
	} else {
		LinePtr	laline = lastline(faline);

		laline->l_next = ffline;
		ffline->l_prev = laline;
	}
	ffline = NULL;
}

void
lfreelist(first)
register LinePtr	first;
{
	if (first != NULL)
		lfreereg(first, lastline(first));
}

/* Append region from line1 to line2 onto the free list of lines */

void
lfreereg(line1, line2)
register LinePtr	line1,
		line2;
{
	register LinePtr	next,
			last = line2->l_next;

	while (line1 != last) {
		next = line1->l_next;
		freeline(line1);
		line1 = next;
	}
}

private jbool
newchunk()
{
	register LinePtr	newline;
	register long	i;
	ChunkPtr	f;
	long	nlines = CHUNKSIZE;
	jbool	done_gc = NO;

	for (;;) {
		f = CHUNKMALLOC(sizeof(struct chunk) + sizeof(struct line) * (nlines-1));
		if (f != NULL)
			break;

		if (!done_gc) {
			GCchunks();
			done_gc = YES;
		} else {
			nlines /= 2;
			if (nlines <= 0)
				return NO;
		}
	}

	f->c_nlines = nlines;
	for (i = 0, newline = f->c_block; i < nlines; newline++, i++) {
		newline->l_dline = NULL_DADDR;
		newline->l_next = faline;
		if (faline)
			faline->l_prev = newline;
		newline->l_prev = NULL;
		faline = newline;
	}
	f->c_nextchunk = fchunk;
	fchunk = f;
	return YES;
}

/* New BUFfer LINE */

LinePtr
nbufline()
{
	register LinePtr	newline;

	if (faline == NULL) {
		RecycleLines();
		if (faline == NULL) {
			if (!newchunk()) {
				complain("[Out of lines] ");
				/* NOTREACHED */
			}
		}
	}
	newline = faline;
	faline = newline->l_next;
	if (faline)
		faline->l_prev = NULL;
	return newline;
}

/* Remove the free lines, in chunk c, from the free list because they are
 * no longer free.
 */
private void
remfreelines(c)
register ChunkPtr	c;
{
	register LinePtr	lp;
	register long	i;

	for (lp = c->c_block, i = c->c_nlines; i != 0 ; lp++, i--) {
		if (lp->l_prev == NULL)
			faline = lp->l_next;
		else
			lp->l_prev->l_next = lp->l_next;
		if (lp->l_next != NULL)
			lp->l_next->l_prev = lp->l_prev;
	}
}

/* This is used to garbage collect the chunks of lines when malloc fails
 * and we are NOT looking for a new buffer line.  This goes through each
 * chunk, and if every line in a given chunk is not allocated, the entire
 * chunk is `free'd by "free()".
 */
/* ??? I think that this WILL be called when we are looking for a new
 * buffer line: nbufline() => newchunk() => GCchunks() -- DHR
 */

void
GCchunks()
{
	register ChunkPtr	cp;
	ChunkPtr	prev = NULL,
			next;
	register long	i;
	register LinePtr	newline;

	RecycleLines();
	for (cp = fchunk; cp != NULL; cp = next) {
		next = cp->c_nextchunk;
		for (i = cp->c_nlines, newline = cp->c_block; ; newline++, i--) {
			if (i == 0) {
				/* Empty: unlink and free it!!! */
				if (prev == NULL)
					fchunk = cp->c_nextchunk;
				else
					prev->c_nextchunk = cp->c_nextchunk;
				remfreelines(cp);
				CHUNKFREE(cp);
				break;
			}
			if (newline->l_dline != NULL_DADDR) {
				/* it's a keeper */
				prev = cp;
				break;
			}
		}
	}
}

#ifdef LISP

#include "re.h"

/* Grind S-Expr */

void
GSexpr()
{
	Bufpos	dot,
		end;

	if (linebuf[curchar] != '(') {
		complain((char *)NULL);
		/* NOTREACHED */
	}
	DOTsave(&dot);
	FSexpr();
	DOTsave(&end);
	SetDot(&dot);
	for (;;) {
		if (curline == end.p_line)
			break;

		line_move(FORWARD, 1, NO);
		if (!blnkp(linebuf))
			(void) lisp_indent();
	}
	SetDot(&dot);
}

/* lisp_indent() indents a new line in Lisp Mode, according to where
 * the matching close-paren would go if we typed that (sort of).
 */
private List	*specials = NULL;

private void
init_specials()
{
	static const char *const words[] = {
		"case",
		"def",
		"dolist",
		"fluid-let",
		"lambda",
		"let",
		"lexpr",
		"macro",
		"named-l",	/* named-let and named-lambda */
		"nlambda",
		"prog",
		"selectq",
		NULL
	};
	const char	*const *wordp = words;

	while (*wordp != NULL)
		list_push(&specials, (UnivPtr) *wordp++);
}

void
AddSpecial()
{
	const char	*word;
	register List	*lp;

	if (specials == NULL)
		init_specials();
	word = ask((char *)NULL, ProcFmt);
	for (lp = specials; lp != NULL; lp = list_next(lp))
		if (strcmp((char *) list_data(lp), word) == 0)
			return;		/* already in list */
	(void) list_push(&specials, (UnivPtr) copystr(word));
}

private Bufpos *
lisp_indent()
{
	Bufpos	*bp,
		savedot;
	int	goal;

	bp = m_paren(')', BACKWARD, NO, YES);

	if (bp == NULL)
		return NULL;

	/* We want to end up
     *
	 *	(atom atom atom ...
	 *	      ^ here.
	 */
	DOTsave(&savedot);
	SetDot(bp);
	f_char(1);
	if (linebuf[curchar] != '(') {
		register List	*lp;

		if (specials == NULL)
			init_specials();
		for (lp = specials; lp != NULL; lp = list_next(lp))
			if (caseeqn((char *) list_data(lp),
				     &linebuf[curchar],
				     strlen((char *) list_data(lp))))
				break;
		if (lp == NULL) {	/* not special */
			int	c_char = curchar;

			while (jisident(linebuf[curchar]))
				curchar += 1;
			if (LookingAt("[ \t]*;\\|[ \t]*$", linebuf, curchar)) {
				curchar = c_char;
			} else {
				while (linebuf[curchar] == ' ')
					curchar += 1;
			}
		} else {
			curchar += 1;
		}
	}
	goal = calc_pos(linebuf, curchar);
	SetDot(&savedot);
	Bol();
	n_indent(goal);

	return bp;
}
#endif /* LISP */