9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Joey Makar" <makarjo@gmail.com>
To: 9fans@cse.psu.edu
Subject: [9fans] Samterm up down key patch
Date: Mon, 13 Nov 2006 20:02:48 -0500	[thread overview]
Message-ID: <a29ef4be0611131702xb52598ckfcb28bdfc686b484@mail.gmail.com> (raw)

[-- 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

             reply	other threads:[~2006-11-14  1:02 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-14  1:02 Joey Makar [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a29ef4be0611131702xb52598ckfcb28bdfc686b484@mail.gmail.com \
    --to=makarjo@gmail.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).