Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!ptsfa!lll-lcc!mordor!sri-spam!sri-unix!teknowledge-vaxc!uw-beaver!uw-june!entropy!dataio!bright From: bright@dataio.UUCP Newsgroups: net.sources Subject: microEmacs Message-ID: <1261@dataio.Data-IO.COM> Date: Mon, 2-Mar-87 13:54:38 EST Article-I.D.: dataio.1261 Posted: Mon Mar 2 13:54:38 1987 Date-Received: Tue, 3-Mar-87 23:08:21 EST Organization: Data I/O - FutureNet Corp., Redmond, WA Lines: 92 Here's a microEmacs function I wrote to add a toggling over parentheses and brackets command. Bind to your favorite keystroke and enjoy! /********************************* * Search for the next occurence of the character at dot. * If character is a (){}[]<>, search for matching bracket, taking * proper account of nesting. * Written by Walter Bright. */ int searchparen(f, n) { register LINE *clp; register int cbo; register int len; register int i; char chinc,chdec,ch; int count; int forward; static char bracket[][2] = {{'(',')'},{'<','>'},{'[',']'},{'{','}'}}; clp = curwp->w_dotp; /* get pointer to current line */ cbo = curwp->w_doto; /* and offset into that line */ count = 0; len = llength(clp); if (cbo >= len) chinc = '\n'; else chinc = lgetc(clp,cbo); forward = TRUE; /* assume search forward */ chdec = chinc; for (i = 0; i < 4; i++) if (bracket[i][0] == chinc) { chdec = bracket[i][1]; break; } for (i = 0; i < 4; i++) if (bracket[i][1] == chinc) { chdec = bracket[i][0]; forward = FALSE; /* search backwards */ break; } while (1) { if (forward) { if (cbo >= len) { /* proceed to next line */ clp = lforw(clp); if (clp == curbp->b_linep) /* if end of buffer */ break; len = llength(clp); cbo = 0; } else cbo++; } else /* backward */ { if (cbo == 0) { clp = lback(clp); if (clp == curbp->b_linep) break; len = llength(clp); cbo = len; } else --cbo; } ch = (cbo < len) ? lgetc(clp,cbo) : '\n'; if (eq(ch,chdec)) { if (count-- == 0) { /* We've found it */ curwp->w_dotp = clp; curwp->w_doto = cbo; curwp->w_flag |= WFMOVE; return (TRUE); } } else if (eq(ch,chinc)) count++; } mlwrite("Not found"); return (FALSE); }