static char rcsid[] = "$Id: cutbuf.c,v 1.1 1992/09/05 01:13:32 mike Exp $"; /* $Log: cutbuf.c,v $ * Revision 1.1 1992/09/05 01:13:32 mike * Initial revision * */ /* * CUTBUF.C : handle cut buffer */ /* Copyright 1990, 1991, 1992 Craig Durland * Distributed under the terms of the GNU General Public License. * Distributed "as is", without warranties of any kind, but comments, * suggestions and bug reports are welcome. */ #include "me2.h" Bag *cut_buffer; /* must be initialized very early! */ /* * Yank text back from the cut buffer. This is really easy. * Bound to "C-y". */ yank(f,n) int f,n; { if (n < 0) return FALSE; while (n--) if (!insert_bag(cut_buffer)) return FALSE; return TRUE; } /* Cut line(s) of text. * If called without an argument, it cuts from dot to the end of the line, * unless it is at the end of the line, where it cuts the newline. * If called with an argument: * 0: Cut from the start of the line to dot. * Positive: Cut from dot forward over that number of newlines. * Negative: Cut backwards that number of newlines. * Bound to "C-k". * Notes: * If n > number of lines left in the buffer, just cut those. This means * you can use a real big n to delete all text to the end of the buffer. * This also fixes a problem for Mutt programs that got a region (that * included the end-of-buffer) and tried to use cut-line to delete the * region. * Some of the end of buffer checking is pretty sloppy. I can get away * with this because ldelete() does good checking. For example, if you * try a big delete on the last line of the buffer, the code will roll * around to the top of the buffer and get a big delete count. Not a * big deal but it might be slow. */ cut_line(f,n) int f,n; { register int32 chunk; Line *nextp; /* Clear cut buffer if last wasn't a cut */ if (!(lastflag & CFCUT)) clear_bag(cut_buffer); thisflag |= CFCUT; if (f == FALSE) { chunk = llength(the_dot->line) -the_dot->offset; if (chunk == 0) chunk = 1; } else if (n == 0) { chunk = the_dot->offset; the_dot->offset = 0; } else if (n > 0) { chunk = llength(the_dot->line) -the_dot->offset +1; nextp = lforw(the_dot->line); while (--n) { if (nextp == BUFFER_LAST_LINE(curbp)) break; chunk += llength(nextp) +1; nextp = lforw(nextp); } } else { mlwrite("neg cut"); return FALSE; } return ldelete(chunk,TRUE); }