示例#1
0
/*
 * Mark whole buffer by first traversing to end-of-buffer
 * and then to beginning-of-buffer. Mark, dot are implicitly
 * set to eob, bob respectively during traversal.
 */
int
markbuffer(int f, int n)
{
	if (gotoeob(f,n) == FALSE)
		return (FALSE);
	if (gotobob(f,n) == FALSE)
		return (FALSE);
	return (TRUE);
}
示例#2
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Go to the beginning of the current section (or paragraph if no section
 * marker found).
 */
int
gotobosec(int f, int n)
{
#if OPT_STUTTER_SEC_CMD
    if (!getstutter())
	return FALSE;
#endif
    if (findpat(f, n, b_val_rexp(curbp, VAL_SECTIONS)->reg,
		REVERSE) != TRUE) {
	(void) gotobob(f, n);
    }
    return TRUE;
}
示例#3
0
/*
 * Scroll completions up.
 */
void
completion_scroll_up (void)
{
  Window *wp, *old_wp = cur_wp;
  Point pt;

  wp = find_window ("*Completions*");
  assert (wp != NULL);
  set_current_window (wp);
  pt = get_buffer_pt (cur_bp);
  if (pt.n >= get_buffer_last_line (cur_bp) - get_window_eheight (cur_wp) || !FUNCALL (scroll_up))
    gotobob ();
  set_current_window (old_wp);

  term_redisplay ();
}
示例#4
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Go to the beginning of the current paragraph.
 */
int
gotobop(int f, int n)
{
    MARK odot;
    int was_on_empty;
    int fc;

    n = need_a_count(f, n, 1);

    was_on_empty = is_empty_line(DOT);
    odot = DOT;

    fc = firstchar(DOT.l);
    if (doingopcmd &&
	((fc >= 0 && DOT.o <= fc) || fc < 0) &&
	!is_first_line(DOT, curbp)) {
	backchar(TRUE, DOT.o + 1);
	pre_op_dot = DOT;
    }
    while (n) {
	if (findpat(TRUE, 1, b_val_rexp(curbp, VAL_PARAGRAPHS)->reg,
		    REVERSE) != TRUE) {
	    (void) gotobob(f, n);
	} else if (is_empty_line(DOT)) {
	    /* special case -- if we found an empty line,
	       and it's adjacent to where we started,
	       skip all adjacent empty lines, and try again */
	    if ((was_on_empty && lforw(DOT.l) == odot.l) ||
		(n > 0 && llength(lforw(DOT.l)) == 0)) {
		/* then we haven't really found what we
		   wanted.  keep going */
		skipblanksb();
		continue;
	    }
	}
	n--;
    }
    if (doingopcmd) {
	fc = firstchar(DOT.l);
	if (!sameline(DOT, odot) &&
	    (pre_op_dot.o > lastchar(pre_op_dot.l)) &&
	    ((fc >= 0 && DOT.o <= fc) || fc < 0)) {
	    regionshape = rgn_FULLLINE;
	}
    }
    return TRUE;
}
示例#5
0
文件: select.c 项目: ricksladkey/vile
/* select all text in curbp and yank to unnamed register */
int
sel_all(int f GCC_UNUSED, int n GCC_UNUSED)
{
    int rc;
    MARK savedot;

    savedot = DOT;
    gotobob(0, 0);
    sel_begin();
    gotoeob(0, 0);
    gotoeol(0, 0);
    (void) sel_setshape(rgn_EXACT);
    rc = sel_extend(TRUE, TRUE);
    DOT = savedot;
    if (rc)
	sel_yank(0);
    return (rc);
}
示例#6
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Go to the beginning of the current sentence. If we skip into an empty line
 * (from a non-empty line), return at that point -- that's what vi does.
 */
int
gotobosent(int f, int n)
{
    MARK savepos;
    int looped = 0;
    int extra;
    int empty = is_empty_line(DOT);
    regexp *exp;
    int s = TRUE;

    savepos = DOT;
    exp = b_val_rexp(curbp, VAL_SENTENCES)->reg;

    while (s && (is_at_end_of_line(DOT) || isSpace(CharAtDot()))) {
	s = backchar(TRUE, 1);
	if (is_empty_line(DOT) && !empty)
	    return TRUE;
    }
  top:
    extra = 0;
    if (findpat(f, n, exp, REVERSE) != TRUE) {
	return gotobob(f, n);
    }
    s = forwchar(TRUE, RegexpLen(exp));
    while (s && (is_at_end_of_line(DOT) || isSpace(CharAtDot()))) {
	s = forwchar(TRUE, 1);
	extra++;
    }
    if (n == 1 && samepoint(savepos, DOT)) {	/* try again */
	if (looped > 10)
	    return FALSE;
	s = backchar(TRUE, RegexpLen(exp) + extra + looped);
	while (s && is_at_end_of_line(DOT)) {
	    if (!empty && is_empty_line(DOT))
		return TRUE;
	    s = backchar(TRUE, 1);
	}
	looped++;
	goto top;

    }
    return TRUE;
}
示例#7
0
/* Justify the entire buffer instead of just a paragraph */
int
fillbuf(int f, int n)
{
    LINE *eobline;
    REGION region;

    if(curbp->b_mode&MDVIEW){		/* don't allow this command if	*/
	return(rdonly());		/* we are in read only mode	*/
    }
    else if (fillcol == 0) {		/* no fill column set */
	mlwrite_utf8("No fill column set", NULL);
	return(FALSE);
    }

    if((lastflag & CFFILL) && (lastflag & CFFLBF)){
	/* no use doing a full justify twice */
	thisflag |= (CFFLBF | CFFILL);
	return(TRUE);
    }

    /* record the pointer of the last line */
    if(gotoeob(FALSE, 1) == FALSE)
      return(FALSE);

    eobline = curwp->w_dotp;		/* last line of buffer */
    if(!llength(eobline))
      eobline = lback(eobline);

    /* and back to the beginning of the buffer */
    gotobob(FALSE, 1);

    thisflag |= CFFLBF; /* CFFILL also gets set in fillpara */

    if(!Pmaster)
      sgarbk = TRUE;
    
    curwp->w_flag |= WFMODE;

    /*
     * clear the kill buffer, that's where we'll store undo
     * information, we can't do the fill buffer because
     * fillpara relies on its contents
     */
    kdelete();
    curwp->w_doto = 0;
    getregion(&region, eobline, llength(eobline));

    /* Put full message in the kill buffer for undo */
    if(!ldelete(region.r_size, kinsert))
      return(FALSE);

    /* before yank'ing, clear lastflag so we don't just unjustify */
    lastflag &= ~(CFFLBF | CFFILL);

    /* Now in kill buffer, bring back text to use in fillpara */
    yank(FALSE, 1);

    gotobob(FALSE, 1);

    /* call fillpara until we're at the end of the buffer */
    while(curwp->w_dotp != curbp->b_linep)
      if(!(fillpara(FALSE, 1)))
	return(FALSE);
    
    return(TRUE);
}
示例#8
0
/*
 * spell() - check for potentially missspelled words and offer them for
 *           correction
 */
int
spell(int f, int n)
{
    int    status, next, ret;
    char   ccb[NLINE], *sp, *fn, *lp, *wsp, c, spc[NLINE];
    UCS   *b;
    UCS    wb[NLINE], cb[NLINE];
    EML    eml;

    setimark(0, 1);
    emlwrite(_("Checking spelling..."), NULL); 	/* greetings */

    if(alt_speller)
      return(alt_editor(1, 0));			/* f == 1 means fork speller */

    if((fn = writetmp(0, NULL)) == NULL){
	emlwrite(_("Can't write temp file for spell checker"), NULL);
	return(-1);
    }

    if((sp = (char *)getenv("SPELL")) == NULL)
      sp = SPELLER;

    /* exists? */
    ret = (strlen(sp) + 1);
    snprintf(spc, sizeof(spc), "%s", sp);

    for(lp = spc, ret = FIOERR; *lp; lp++){
	if((wsp = strpbrk(lp, " \t")) != NULL){
	    c = *wsp;
	    *wsp = '\0';
	}

	if(strchr(lp, '/')){
	    ret = fexist(lp, "x", (off_t *)NULL);
	}
	else{
	    char *path, fname[MAXPATH+1];

	    if(!(path = getenv("PATH")))
	      path = ":/bin:/usr/bin";

	    ret = ~FIOSUC;
	    while(ret != FIOSUC && *path && pathcat(fname, &path, lp))
	      ret = fexist(fname, "x", (off_t *)NULL);
	}

	if(wsp)
	  *wsp = c;

	if(ret == FIOSUC)
	  break;
    }

    if(ret != FIOSUC){
	eml.s = sp;
        emlwrite(_("\007Spell-checking file \"%s\" not found"), &eml);
	return(-1);
    }

    snprintf(ccb, sizeof(ccb), "( %s ) < %s", sp, fn);
    if(P_open(ccb) != FIOSUC){ 		/* read output from command */
	our_unlink(fn);
	emlwrite(_("Can't fork spell checker"), NULL);
	return(-1);
    }

    ret = 1;
    while(ffgetline(wb, NLINE, NULL, 0) == FIOSUC && ret){
	if((b = ucs4_strchr(wb, (UCS) '\n')) != NULL)
	  *b = '\0';

	ucs4_strncpy(cb, wb, NLINE);
	cb[NLINE-1] = '\0';

	gotobob(0, 1);

	status = TRUE;
	next = 1;

	while(status){
	    if(next++)
	      if(movetoword(wb) != TRUE)
		break;

	    update();
	    (*term.t_rev)(1);
	    pputs(wb, 1);			/* highlight word */
	    (*term.t_rev)(0);

	    if(ucs4_strcmp(cb, wb)){
		char prompt[2*NLINE + 32];
		char *wbu, *cbu;

		wbu = ucs4_to_utf8_cpystr(wb);
		cbu = ucs4_to_utf8_cpystr(cb);

		snprintf(prompt, sizeof(prompt), _("Replace \"%s\" with \"%s\""), wbu, cbu);
		status=mlyesno_utf8(prompt, TRUE);
		if(wbu)
		  fs_give((void **) &wbu);
		if(cbu)
		  fs_give((void **) &cbu);
	    }
	    else{
		UCS *p;

		p = utf8_to_ucs4_cpystr(_("Edit a replacement: "));
		status=mlreplyd(p, cb, NLINE, QDEFLT, NULL);
		if(p)
		  fs_give((void **) &p);
	    }


	    curwp->w_flag |= WFMOVE;		/* put cursor back */
	    sgarbk = 0;				/* fake no-keymenu-change! */
	    update();
	    pputs(wb, 0);			/* un-highlight */

	    switch(status){
	      case TRUE:
		chword(wb, cb, 0);		/* correct word    */
	      case FALSE:
		update();			/* place cursor */
		break;
	      case ABORT:
		emlwrite(_("Spell Checking Cancelled"), NULL);
		ret = FALSE;
		status = FALSE;
		break;
	      case HELPCH:
		if(Pmaster){
		    VARS_TO_SAVE *saved_state;

		    saved_state = save_pico_state();
		    (*Pmaster->helper)(pinespellhelp, 
				       _("Help with Spelling Checker"), 1);
		    if(saved_state){
			restore_pico_state(saved_state);
			free_pico_state(saved_state);
		    }
		}
		else
		  pico_help(spellhelp, _("Help with Spelling Checker"), 1);

	      case (CTRL|'L'):
		next = 0;			/* don't get next word */
		sgarbf = TRUE;			/* repaint full screen */
		update();
		status = TRUE;
		continue;
	      default:
		emlwrite("Huh?", NULL);		/* shouldn't get here, but.. */
		status = TRUE;
		sleep(1);
		break;
	    }
	    
	    forwword(0, 1);			/* goto next word */
	}
    }

    P_close();					/* clean up */
    our_unlink(fn);
    swapimark(0, 1);
    curwp->w_flag |= WFHARD|WFMODE;
    sgarbk = TRUE;

    if(ret)
      emlwrite(_("Done checking spelling"), NULL);

    return(ret);
}
示例#9
0
int
forwsearch(int f, int n)
{
  int              status;
  int              wrapt = FALSE, wrapt2 = FALSE;
  int              repl_mode = FALSE;
  UCS              defpat[NPAT];
  int              search = FALSE;
  EML              eml;

    /* resolve the repeat count */
    if (n == 0)
      n = 1;

    if (n < 1)			/* search backwards */
      FWS_RETURN(0);

    defpat[0] = '\0';

    /* ask the user for the text of a pattern */
    while(1){

	if (gmode & MDREPLACE)
	  status = srpat("Search", defpat, NPAT, repl_mode);
	else
	  status = readpattern("Search", TRUE);

	switch(status){
	  case TRUE:                         /* user typed something */
	    search = TRUE;
	    break;

	  case HELPCH:			/* help requested */
	    if(Pmaster){
		VARS_TO_SAVE *saved_state;

		saved_state = save_pico_state();
		(*Pmaster->helper)(Pmaster->search_help,
				   _("Help for Searching"), 1);
		if(saved_state){
		    restore_pico_state(saved_state);
		    free_pico_state(saved_state);
		}
	    }
	    else
	      pico_help(SearchHelpText, _("Help for Searching"), 1);

	  case (CTRL|'L'):			/* redraw requested */
	    pico_refresh(FALSE, 1);
	    update();
	    break;

	  case  (CTRL|'V'):
	    gotoeob(0, 1);
	    mlerase();
	    FWS_RETURN(TRUE);

	  case (CTRL|'Y'):
	    gotobob(0, 1);
	    mlerase();
	    FWS_RETURN(TRUE); 

	  case (CTRL|'T') :
	    switch(status = readnumpat(_("Search to Line Number : "))){
	      case -1 :
		emlwrite(_("Search to Line Number Cancelled"), NULL);
		FWS_RETURN(FALSE);

	      case  0 :
		emlwrite(_("Line number must be greater than zero"), NULL);
		FWS_RETURN(FALSE);

	      case -2 :
		emlwrite(_("Line number must contain only digits"), NULL);
		FWS_RETURN(FALSE);
		
	      case -3 :
		continue;

	      default :
		gotoline(0, status);
		mlerase();
		FWS_RETURN(TRUE);
	    }

	    break;

	  case  (CTRL|'W'):
	    {
		LINE *linep = curwp->w_dotp;
		int   offset = curwp->w_doto;

		gotobop(0, 1);
		gotobol(0, 1);

		/*
		 * if we're asked to backup and we're already
		 *
		 */
		if((lastflag & CFSRCH)
		   && linep == curwp->w_dotp
		   && offset == curwp->w_doto
		   && !(offset == 0 && lback(linep) == curbp->b_linep)){
		    backchar(0, 1);
		    gotobop(0, 1);
		    gotobol(0, 1);
		}
	    }

	    mlerase();
	    FWS_RETURN(TRUE);

	  case  (CTRL|'O'):
	    if(curwp->w_dotp != curbp->b_linep){
		gotoeop(0, 1);
		forwchar(0, 1);
	    }

	    mlerase();
	    FWS_RETURN(TRUE);

	  case (CTRL|'U'):
	    fillbuf(0, 1);
	    mlerase();
	    FWS_RETURN(TRUE);

	  case  (CTRL|'R'):        /* toggle replacement option */
	    repl_mode = !repl_mode;
	    break;

	  default:
	    if(status == ABORT)
	      emlwrite(_("Search Cancelled"), NULL);
	    else
	      mlerase();

	    FWS_RETURN(FALSE);
	}

	/* replace option is disabled */
	if (!(gmode & MDREPLACE)){
	    ucs4_strncpy(defpat, pat, NPAT);
	    defpat[NPAT-1] = '\0';
	    break;
	}
	else if (search){  /* search now */
	    ucs4_strncpy(pat, defpat, NPAT);	/* remember this search for the future */
	    pat[NPAT-1] = '\0';
	    break;
	}
    }

    /*
     * This code is kind of dumb.  What I want is successive C-W 's to 
     * move dot to successive occurences of the pattern.  So, if dot is
     * already sitting at the beginning of the pattern, then we'll move
     * forward a char before beginning the search.  We'll let the
     * automatic wrapping handle putting the dot back in the right 
     * place...
     */
    status = 0;		/* using "status" as int temporarily! */
    while(1){
	if(defpat[status] == '\0'){
	    forwchar(0, 1);
	    break;		/* find next occurence! */
	}

	if(status + curwp->w_doto >= llength(curwp->w_dotp) ||
	   !eq(defpat[status],lgetc(curwp->w_dotp, curwp->w_doto + status).c))
	  break;		/* do nothing! */
	status++;
    }

    /* search for the pattern */
    
    while (n-- > 0) {
	if((status = forscan(&wrapt,defpat,NULL,0,PTBEG)) == FALSE)
	  break;
    }

    /* and complain if not there */
    if (status == FALSE){
      char *utf8;
      UCS x[1];

      x[0] = '\0';

      utf8 = ucs4_to_utf8_cpystr(defpat ? defpat : x); 
      /* TRANSLATORS: reporting the result of a failed search */
      eml.s = utf8;
      emlwrite(_("\"%s\" not found"), &eml);
      if(utf8)
	fs_give((void **) &utf8);
    }
    else if((gmode & MDREPLACE) && repl_mode == TRUE){
        status = replace_pat(defpat, &wrapt2);    /* replace pattern */
	if (wrapt == TRUE || wrapt2 == TRUE){
	    eml.s = (status == ABORT) ? "cancelled but wrapped" : "Wrapped";
	    emlwrite("Replacement %s", &eml);
	}
    }
    else if(wrapt == TRUE){
	emlwrite("Search Wrapped", NULL);
    }
    else if(status == TRUE){
	emlwrite("", NULL);
    }

    FWS_RETURN(status);
}
示例#10
0
文件: pico.c 项目: ctubio/alpine
/*
 * This function serves two purposes, 1) to strip white space when
 * Pmaster asks that the composition have its trailing white space
 * stripped, or 2) to prepare the text as flowed text, as Pmaster
 * is telling us that we're working with flowed text.
 *
 * What flowed currently means to us is stripping all trailing white
 * space, except for one space if the following line is a continuation
 * of the paragraph.  Also, we space-stuff all lines beginning
 * with white-space, and leave siglines alone.
 */
int
cleanwhitespace(void)
{
    LINE *cursor_dotp = NULL, **lp = NULL;
    int i = 0, cursor_doto = 0, is_cursor_line = 0;
    int do_space_stuffing = 0;

    if(Pmaster && Pmaster->allow_flowed_text && !(*Pmaster->user_says_noflow)())
      do_space_stuffing++;

    cursor_dotp = curwp->w_dotp;
    cursor_doto = curwp->w_doto;
    gotobob(FALSE, 1);

    for(lp = &curwp->w_dotp; (*lp) != curbp->b_linep; (*lp) = lforw(*lp)){
	if(!(llength(*lp) == 3
	     && lgetc(*lp, 0).c == '-'
	     && lgetc(*lp, 1).c == '-'
	     && lgetc(*lp, 2).c == ' ')
	   && llength(*lp)){
	    is_cursor_line = (cursor_dotp == (*lp));
	    /* trim trailing whitespace, to be added back if flowing */
	    for(i = llength(*lp); i; i--)
	      if(!ucs4_isspace(lgetc(*lp, i - 1).c))
		break;
	    if(i != llength(*lp)){
		int flow_line = 0;

		if(Pmaster && !Pmaster->strip_ws_before_send
		   && lforw(*lp) != curbp->b_linep
		   && llength(lforw(*lp))
		   && !(ucs4_isspace(lgetc(lforw(*lp), 0).c)
			|| isquotedspace(lforw(*lp)))
		   && !(llength(lforw(*lp)) == 3
			&& lgetc(lforw(*lp), 0).c == '-'
			&& lgetc(lforw(*lp), 1).c == '-'
			&& lgetc(lforw(*lp), 2).c == ' '))
		  flow_line = 1;
		if(flow_line && i && lgetc(*lp, i).c == ' '){
		    /* flowed line ending with space */
		    i++;
		    if(i != llength(*lp)){
			curwp->w_doto = i;
			ldelete(llength(*lp) - i, NULL);
		    }
		}
		else if(flow_line && i && ucs4_isspace(lgetc(*lp, i).c)){
		    /* flowed line ending with whitespace other than space*/
		    curwp->w_doto = i;
		    ldelete(llength(*lp) - i, NULL);
		    linsert(1, ' ');
		}
		else{
		    curwp->w_doto = i;
		    ldelete(llength(*lp) - i, NULL);
		}
	    }
	    if(do_space_stuffing && llength(*lp) && ucs4_isspace(lgetc(*lp, 0).c)){
		/* space-stuff only if flowed */
		if(Pmaster)
		  Pmaster->space_stuffed = 1;
		curwp->w_doto = 0;
		if(is_cursor_line && cursor_doto)
		  cursor_doto++;
		linsert(1, ' ');
	    }
	    if(is_cursor_line)
	      cursor_dotp = (*lp);
	}
    }

    /* put the cursor back where we found it */
    gotobob(FALSE, 1);
    curwp->w_dotp = cursor_dotp;
    curwp->w_doto = (cursor_doto < llength(curwp->w_dotp))
      ? cursor_doto : llength(curwp->w_dotp) - 1;

    return(0);
}
示例#11
0
文件: random.c 项目: nysan/alpine
/*
 * Yank text back from the kill buffer. This is really easy. All of the work
 * is done by the standard insert routines. All you do is run the loop, and
 * check for errors. Bound to "C-Y".
 */
int
yank(int f, int n)
{
    int    c, i;
    REGION region, *added_region;
    LINE  *dotp;

    if (curbp->b_mode&MDVIEW)	/* don't allow this command if	*/
      return(rdonly());	/* we are in read only mode	*/

    if (n < 0)
      return (FALSE);

    if(TERM_OPTIMIZE && (curwp->w_dotp != curwp->w_bufp->b_linep)){
	int l;

	if(worthit(&l) && !(lastflag&CFFILL)){
	    register int  t = 0; 
	    register int  i = 0;
	    register int  ch;

	    while((ch=fremove(i++)) >= 0)
	      if(ch == '\n')
		t++;
	    if(t+l < curwp->w_toprow+curwp->w_ntrows)
	      scrolldown(curwp, l, t);
	}
    }

    if(lastflag & CFFILL){		/* if last command was fillpara() */
	if(lastflag & CFFLBF){
	    gotoeob(FALSE, 1);
	    dotp = curwp->w_dotp;
	    gotobob(FALSE, 1);
	    curwp->w_doto = 0;
	    getregion(&region, dotp, llength(dotp));
	}
	else{
	    added_region = get_last_region_added();
	    if(added_region){
		curwp->w_dotp = added_region->r_linep;
		curwp->w_doto = added_region->r_offset;
		region = (*added_region);
	    }
	    else
	      return(FALSE);
	}

	if(!ldelete(region.r_size, NULL))
	  return(FALSE);
    }					/* then splat out the saved buffer */

    while (n--) {
	i = 0;
	while ((c = ((lastflag&CFFILL)
		     ? ((lastflag & CFFLBF) ? kremove(i) : fremove(i))
		     : kremove(i))) >= 0) {
	    if (c == '\n') {
		if (lnewline() == FALSE)
		  return (FALSE);
	    } else {
		if (linsert(1, c) == FALSE)
		  return (FALSE);
	    }

	    ++i;
	}
    }

    if(lastflag&CFFLPA){            /* if last command was fill paragraph */
	curwp->w_dotp = lforw(curwp->w_dotp);
	curwp->w_doto = 0;

	curwp->w_flag |= WFMODE;
	
	if(!Pmaster){
	    sgarbk = TRUE;
	    emlwrite("", NULL);
	}
    }

    return (TRUE);
}