9fans archive / 2001 / 03 / 221 /    prev next

From: "Douglas A. Gwyn" <DAGwyn@nul...>
Subject: [9fans] sam mod for delete-forward
Date: Mon, 26 Mar 2001 08:45:18 GMT

Recently I got tired of not being able to delete in front of the cursor
with DEL the way most other text editors work these days, so I changed
"samterm" to do that.  I made it conditional on DELFWD so you can compile
it to work either way; this could be made an environmental switch or
command-line option instead.  Or, my preference, officially change sam
to always work this way.

term% diff main.BAK main.c
488d487
< 			case '\b':
489a489,494
> #ifdef DELFWD	/* DAG -- want DEL key to delete forward, not backward */
> 				l->p0 = a;
> 				l->p1 = a<l->origin+l->f.nchars? a+1 : a;
> 				break;
> #endif
> 			case '\b':
490a496
> 				l->p1 = a;
493a500
> 				l->p1 = a;
496a504
> 				l->p1 = a;
499d506
< 			l->p1 = a;

Here is what the updated section of /sys/src/cmd/samterm/main.c looks like:

	}else if(backspacing && !hostlock){
		if(l->f.p0>0 && a>0){
			switch(c){
			case 0x7F:	/* del */
#ifdef DELFWD	/* DAG -- want DEL key to delete forward, not backward */
				l->p0 = a;
				l->p1 = a<l->origin+l->f.nchars? a+1 : a;
				break;
#endif
			case '\b':
				l->p0 = a-1;
				l->p1 = a;
				break;
			case 0x15:	/* ctrl-u */
				l->p0 = ctlu(&t->rasp, l->origin, a);
				l->p1 = a;
				break;
			case 0x17:	/* ctrl-w */
				l->p0 = ctlw(&t->rasp, l->origin, a);
				l->p1 = a;
				break;
			}
			if(l->p1 != l->p0){
				/* cut locally if possible */