void inschar(char c) { register char *p; register char *pend; if (last_command == 'R' && (gchar(Curschar) != NUL)) { pchar(Curschar, c); } else { /* make room for the new char. */ if (!canincrease(1)) return; p = &Curschar->linep->s[strlen(Curschar->linep->s) + 1]; pend = &Curschar->linep->s[Curschar->index]; for (; p > pend; p--) *p = *(p - 1); *p = c; } if (RedrawingDisabled) { Curschar->index++; return; } /* * If we're in insert mode and showmatch mode is set, then check for * right parens and braces. If there isn't a match, then beep. If there * is a match AND it's on the screen, then flash to it briefly. If it * isn't on the screen, don't do anything. */ if (P(P_SM) && State == INSERT && (c == ')' || c == '}' || c == ']')) { LPtr *lpos, csave; if ((lpos = showmatch()) == NULL) /* no match, so beep */ beep(); else if (LINEOF(lpos) >= LINEOF(Topchar)) { /* show the new char first */ s_refresh(VALID_TO_CURSCHAR); csave = *Curschar; *Curschar = *lpos; /* move to matching char */ cursupdate(UPDATE_CURSOR); windgoto(Cursrow, Curscol); delay(); /* brief pause */ *Curschar = csave; /* restore cursor position */ cursupdate(UPDATE_ALL); } } inc(Curschar); CHANGED; }
void cursupdate() { LPTR *p; int inc, c, nlines; int i; int didinc; if (bufempty()) { /* special case - file is empty */ *Topchar = *Filemem; *Curschar = *Filemem; } else if ( LINEOF(Curschar) < LINEOF(Topchar) ) { nlines = cntllines(Curschar,Topchar); /* if the cursor is above the top of */ /* the screen, put it at the top of the screen.. */ *Topchar = *Curschar; Topchar->index = 0; /* ... and, if we weren't very close to begin with, */ /* we scroll so that the line is close to the middle. */ if ( nlines > Rows/3 ) { for (i=0, p = Topchar; i < Rows/3 ;i++, *Topchar = *p) if ((p = prevline(p)) == NULL) break; } else s_ins(0, nlines-1); updatescreen(); } else if (LINEOF(Curschar) >= LINEOF(Botchar)) { nlines = cntllines(Botchar,Curschar); /* If the cursor is off the bottom of the screen, */ /* put it at the top of the screen.. */ /* ... and back up */ if ( nlines > Rows/3 ) { p = Curschar; for (i=0; i < (2*Rows)/3 ;i++) if ((p = prevline(p)) == NULL) break; *Topchar = *p; } else { scrollup(nlines); } updatescreen(); } Cursrow = Curscol = Cursvcol = 0; for ( p=Topchar; p->linep != Curschar->linep ;p = nextline(p) ) Cursrow += plines(p); Cline_row = Cursrow; Cline_size = plines(p); for (i=0; i <= Curschar->index ;i++) { c = Curschar->linep->s[i]; /* A tab gets expanded, depending on the current column */ if ( c == TAB && !P(P_LS) ) inc = P(P_TS) - (Curscol % P(P_TS)); else inc = chars[(unsigned)(c & 0xff)].ch_size; Curscol += inc; Cursvcol += inc; if ( Curscol >= Columns ) { Curscol -= Columns; Cursrow++; didinc = TRUE; } else didinc = FALSE; } if (didinc) Cursrow--; if (c == TAB && State == NORMAL && !P(P_LS)) { Curscol--; Cursvcol--; } else { Curscol -= inc; Cursvcol -= inc; } if (Curscol < 0) Curscol += Columns; if (set_want_col) { Curswant = Cursvcol; set_want_col = FALSE; } }