9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Samterm up down key patch
@ 2006-11-14  1:02 Joey Makar
  2006-11-14 10:49 ` Martin Neubauer
  0 siblings, 1 reply; 51+ messages in thread
From: Joey Makar @ 2006-11-14  1:02 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]

Hello, attached is a patch to samterm to make the up and down arrow
keys move the cursor.

When the down arrow key is pressed it should go to the next newline
plus the number of characters from the previous newline, unless that
is beyond the next next newline, then go to that.

And for the up arrow key: go the previous previous newline plus the
number of characters from the previous newline, unless that is beyond
the previous newline, then go to that.

I'm relatively new to Plan9, any comments welcome.

Joey

[-- Attachment #2: samterm.h.patch --]
[-- Type: application/octet-stream, Size: 110 bytes --]

162a
Section	*lastsection(Rasp*, Section*);
long	prevnewline(Rasp*, long);
long	nextnewline(Rasp*, long);
.
w

[-- Attachment #3: main.c.patch --]
[-- Type: application/octet-stream, Size: 2402 bytes --]

663a
}

Section*
lastsection(Rasp *r, Section *s)
{
	Section *p;
	for(p=r->sect; p; p=p->next)
		if(p->next == s)
			return p;
	return 0;
}

long
prevnewline(Rasp *r, long from)
{
	Section *sect;
	Rune *text;
	long rp, sp;	/* Rasp, Section position */
			/* rp is the integer counterpart of text */

	if(!r->sect)
		return -1;

	/* Go to the from position. */
	sect = r->sect;
	rp = 0;
	while(rp + sect->nrunes < from){
		rp += sect->nrunes;
		sect = sect->next;
	}
	sp = from - rp;
	text = sect->text + sp;
	rp = from;

	/* Search backwards for a newline. */
	while(1){
		char ch[UTFmax];
		int rv;

		if(--sp < 0){
			sect = lastsection(r, sect);
			if(!sect)
				return -1;
			sp = sect->nrunes;
			text = sect->text + sp;
		}
		rp--;
		text--;

		rv = runetochar(ch, text);
		if(rv == 1 && ch[0] == '\n')
			return rp;
	}
}

long
nextnewline(Rasp *r, long from)
{
	Section *sect;
	Rune *text;
	long rp, sp;	/* Rasp, Section position */
			/* rp is the integer counterpart of text */

	if(!r->sect)
		return 0;

	/* Go to the from position. */
	sect = r->sect;
	rp = 0;
	while(rp + sect->nrunes < from){
		rp += sect->nrunes;
		sect = sect->next;
	}
	sp = from - rp;
	text = sect->text + sp;
	rp = from;

	/* Search for a newline. */
	while(1){
		char ch[UTFmax];
		int rv;

		rv = runetochar(ch, text);
		if(rv == 1 && ch[0] == '\n')
			return rp;

		if(++sp > sect->nrunes - 1){
			sect = sect->next;
			if(!sect)
				return r->nrunes;
			sp = 0;
			text = sect->text - 1;
		}
		rp++;
		text++;
	}

	return 0; /* Won't execute; silences a compiler warning. */
.
545a
	}else if(c == SCROLLKEY){
		long pn, nn, nnn;	/* Previous, next, next next newline */
		flushtyping(0);
		pn = prevnewline(&t->rasp, l->p0);
		nn = nextnewline(&t->rasp, l->p0);
		if(nn != t->rasp.nrunes)
			nnn = nextnewline(&t->rasp, nn + 1);
		else
			nnn = t->rasp.nrunes;
		/* pn may be -1. */
		a0 = (l->p0 - pn) + nn;
		a0 = a0 > nnn ? nnn : a0;
		flsetselect(l, a0, a0);
		center(l, a0);
	}else if(c == BACKSCROLLKEY){
		long ppn, pn;	/* Previous previous, previous newline */
		flushtyping(0);
		pn = prevnewline(&t->rasp, l->p0);
		if(pn != -1)
			ppn = prevnewline(&t->rasp, pn);
		else
			ppn = -1;
		if(pn == -1)
			a0 = 0;
		else{
			/* ppn may be -1. */
			a0 = (l->p0 - pn) + ppn;
			a0 = a0 > pn ? pn : a0;
		}
		flsetselect(l, a0, a0);
		center(l, a0);
.
526c
	}else if(c==PAGEUP){
.
522c
	if(c==PAGEDOWN){
.
w

^ permalink raw reply	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2007-01-30 11:45 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-14  1:02 [9fans] Samterm up down key patch Joey Makar
2006-11-14 10:49 ` Martin Neubauer
2006-11-14 13:04   ` erik quanstrom
2006-11-14 13:26     ` Martin Neubauer
2006-11-14 13:38       ` erik quanstrom
2006-11-14 18:04         ` David Leimbach
2006-11-14 13:25   ` ron minnich
2006-11-14 13:34     ` erik quanstrom
2006-11-14 13:44       ` ron minnich
2006-11-14 14:04         ` erik quanstrom
2006-11-14 14:16         ` Martin Neubauer
2006-11-14 14:42           ` maht
2006-11-14 16:48             ` Joel Salomon
2006-11-14 17:03               ` maht
2006-11-14 16:48             ` Joey Makar
2006-11-14 20:03             ` John Floren
2006-11-14 21:57               ` Russ Cox
2006-11-14 22:06                 ` David Leimbach
2006-11-15  9:40               ` Matt
2007-01-30  9:55               ` Harri Haataja
2007-01-30 11:34                 ` John Stalker
2006-11-14 18:10         ` David Leimbach
2006-11-14 18:21           ` Sape Mullender
2006-11-14 18:35             ` erik quanstrom
2006-11-14 18:52               ` Bruce Ellis
2006-11-14 19:14                 ` Sape Mullender
2006-11-14 19:18                   ` Paul Lalonde
2006-11-14 19:34                 ` rog
2006-11-14 19:40                   ` csant
2006-11-14 19:52                     ` Bruce Ellis
2006-11-14 18:22           ` Bruce Ellis
2006-11-15  4:43       ` Lyndon Nerenberg
2006-11-15  4:57         ` John Floren
2006-11-15  5:13           ` Russ Cox
2006-11-15  5:32             ` John Floren
2006-11-15  9:27               ` Gorka guardiola
2006-11-15 14:09             ` David Arnold
2006-11-16  2:49             ` erik quanstrom
2006-11-16 13:46               ` plan9
2006-11-16 13:55                 ` Abhey Shah
2006-11-17 16:44                 ` erik quanstrom
2006-11-20  5:48             ` Noah Evans
2007-01-30 11:28             ` Harri Haataja
2007-01-30 11:35               ` Russ Cox
2007-01-30 11:45                 ` Gabriel Diaz
2006-11-15  5:28         ` Lyndon Nerenberg
2006-11-15 16:26           ` David Leimbach
2006-11-14 14:08     ` Martin Neubauer
2006-11-14 14:20     ` Wes Kussmaul
2006-11-14 15:07       ` Wes Kussmaul
2006-11-14 18:03     ` David Leimbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).