⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edit.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
    } else {	for (; *c; c++)	    edit_insert (edit, *c);    }}long edit_backspace_wide (WEdit * edit){    int i;    long c = 0;    if (!edit->curs1)	return 0;    for (i = edit->curs1 - 1; i >= 0; i--)	if ((c = edit_get_wide_byte (edit, i)) != -1)	    break;    while (edit->curs1 > i)	edit_backspace (edit);    return c;}static int right_of_four_spaces (WEdit *edit);void edit_tab_cmd (WEdit * edit);void edit_backspace_tab (WEdit * edit, int whole_tabs_only){    int i;    if (whole_tabs_only) {	int indent;	/* count the number of columns of indentation */	indent = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1);	for (;;) {	    int c;	    c = edit_get_byte (edit, edit->curs1 - 1);	    if (!isspace (c) || c == '\n')		break;	    edit_backspace (edit);	}	while (edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1) <	       (indent - space_width * (option_fake_half_tabs ? HALF_TAB_SIZE : TAB_SIZE)))	    edit_tab_cmd (edit);	return;    }    if (option_fake_half_tabs && right_of_four_spaces (edit)) {	for (i = 0; i < HALF_TAB_SIZE; i++)	    edit_backspace (edit);	return;    }    edit_backspace (edit);}void edit_wide_char_align (WEdit * edit){    while (edit_get_wide_byte (edit, edit->curs1) == -1)	edit_cursor_move (edit, 1);}void edit_wide_char_align_left (WEdit * edit){    while (edit_get_wide_byte (edit, edit->curs1) == -1)	edit_cursor_move (edit, -1);}#ifdef FAST_MOVE_CURSORstatic void memqcpy (WEdit * edit, unsigned char *dest, unsigned char *src, int n){    unsigned long next;    while ((next = (unsigned long) memccpy (dest, src, '\n', n))) {	edit->curs_line--;	next -= (unsigned long) dest;	n -= next;	src += next;	dest += next;    }}int edit_move_backward_lots (WEdit * edit, long increment){    int r, s, t;    unsigned char *p;    if (increment > edit->curs1)	increment = edit->curs1;    if (increment <= 0)	return -1;    edit_push_action (edit, CURS_RIGHT_LOTS, increment);    t = r = EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE);    if (r > increment)	r = increment;    s = edit->curs1 & M_EDIT_BUF_SIZE;    p = 0;    if (s > r) {	memqcpy (edit, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - r,	      edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] + s - r, r);    } else {	if (s) {	    memqcpy (edit, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - s,		     edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE], s);	    p = edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE];	    edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = 0;	}	memqcpy (edit, edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t - r,		 edit->buffers1[(edit->curs1 >> S_EDIT_BUF_SIZE) - 1] + EDIT_BUF_SIZE - (r - s), r - s);    }    increment -= r;    edit->curs1 -= r;    edit->curs2 += r;    if (!(edit->curs2 & M_EDIT_BUF_SIZE)) {	if (p)	    edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p;	else	    edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE);    } else {	if (p)	    free (p);    }    s = edit->curs1 & M_EDIT_BUF_SIZE;    while (increment) {	p = 0;	r = EDIT_BUF_SIZE;	if (r > increment)	    r = increment;	t = s;	if (r < t)	    t = r;	memqcpy (edit,		 edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + EDIT_BUF_SIZE - t,		 edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] + s - t,		 t);	if (r >= s) {	    if (t) {		p = edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE];		edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = 0;	    }	    memqcpy (edit,		     edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + EDIT_BUF_SIZE - r,		     edit->buffers1[(edit->curs1 >> S_EDIT_BUF_SIZE) - 1] + EDIT_BUF_SIZE - (r - s),		     r - s);	}	increment -= r;	edit->curs1 -= r;	edit->curs2 += r;	if (!(edit->curs2 & M_EDIT_BUF_SIZE)) {	    if (p)		edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = p;	    else		edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE);	} else {	    if (p)		free (p);	}    }    return edit_get_byte (edit, edit->curs1);}#endif		/* ! FAST_MOVE_CURSOR *//* moves the cursor right or left: increment positive or negative respectively */int edit_cursor_move (WEdit * edit, long increment){/* this is the same as a combination of two of the above routines, with only one push onto the undo stack */    int c;#ifdef FAST_MOVE_CURSOR    if (increment < -256) {	edit->force |= REDRAW_PAGE;	return edit_move_backward_lots (edit, -increment);    }#endif		/* ! FAST_MOVE_CURSOR */    if (increment < 0) {	for (; increment < 0; increment++) {	    if (!edit->curs1)		return -1;	    edit_push_action (edit, CURS_RIGHT);	    c = edit_get_byte (edit, edit->curs1 - 1);	    if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE))		edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE);	    edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c;	    edit->curs2++;	    c = edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->curs1 - 1) & M_EDIT_BUF_SIZE];	    if (!((edit->curs1 - 1) & M_EDIT_BUF_SIZE)) {		free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]);		edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = NULL;	    }	    edit->curs1--;	    if (c == '\n') {		edit->curs_line--;		edit->force |= REDRAW_LINE_BELOW;	    }	}	return c;    } else if (increment > 0) {	for (; increment > 0; increment--) {	    if (!edit->curs2)		return -2;	    edit_push_action (edit, CURS_LEFT);	    c = edit_get_byte (edit, edit->curs1);	    if (!(edit->curs1 & M_EDIT_BUF_SIZE))		edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = malloc (EDIT_BUF_SIZE);	    edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = c;	    edit->curs1++;	    c = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((edit->curs2 - 1) & M_EDIT_BUF_SIZE) - 1];	    if (!(edit->curs2 & M_EDIT_BUF_SIZE)) {		free (edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]);		edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = 0;	    }	    edit->curs2--;	    if (c == '\n') {		edit->curs_line++;		edit->force |= REDRAW_LINE_ABOVE;	    }	}	return c;    } else	return -3;}/* These functions return positions relative to lines *//* returns index of last char on line + 1 */long edit_eol (WEdit * edit, long current){    if (current < edit->last_byte) {	for (;; current++)	    if (edit_get_byte (edit, current) == '\n')		break;    } else	return edit->last_byte;    return current;}/* returns index of first char on line */long edit_bol (WEdit * edit, long current){    if (current > 0) {	for (;; current--)	    if (edit_get_byte (edit, current - 1) == '\n')		break;    } else	return 0;    return current;}int edit_count_lines (WEdit * edit, long current, int upto){    int lines = 0;    if (upto > edit->last_byte)	upto = edit->last_byte;    if (current < 0)	current = 0;    while (current < upto)	if (edit_get_byte (edit, current++) == '\n')	    lines++;    return lines;}/* If lines is zero this returns the count of lines from current to upto. *//* If upto is zero returns index of lines forward current. */long edit_move_forward (WEdit * edit, long current, int lines, long upto){    if (upto) {	return edit_count_lines (edit, current, upto);    } else {	int next;	if (lines < 0)	    lines = 0;	while (lines--) {	    next = edit_eol (edit, current) + 1;	    if (next > edit->last_byte)		break;	    else		current = next;	}	return current;    }}/* Returns offset of 'lines' lines up from current */long edit_move_backward (WEdit * edit, long current, int lines){    if (lines < 0)	lines = 0;    current = edit_bol (edit, current);    while((lines--) && current != 0)	current = edit_bol (edit, current - 1);    return current;}#ifdef MIDNIGHT/* If cols is zero this returns the count of columns from current to upto. *//* If upto is zero returns index of cols across from current. */long edit_move_forward3 (WEdit * edit, long current, int cols, long upto){    long p, q;    int col = 0;    if (upto) {	q = upto;	cols = -10;    } else	q = edit->last_byte + 2;    for (col = 0, p = current; p < q; p++) {	int c;	if (cols != -10) {	    if (col == cols)		return p;	    if (col > cols)		return p - 1;	}	c = edit_get_byte (edit, p);	if (c == '\r')	    continue;	else	if (c == '\t')	    col += TAB_SIZE - col % TAB_SIZE;	else	    col++;	/*if(edit->nroff ... */	if (c == '\n') {	    if (upto)		return col;	    else		return p;	}    }    return (float) col;}#endif/* returns the current column position of the cursor */int edit_get_col (WEdit * edit){    return edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1);}/* Scrolling functions */void edit_update_curs_row (WEdit * edit){    edit->curs_row = edit->curs_line - edit->start_line;}void edit_update_curs_col (WEdit * edit){    edit->curs_col = edit_move_forward3(edit, edit_bol(edit, edit->curs1), 0, edit->curs1);}/*moves the display start position up by i lines */void edit_scroll_upward (WEdit * edit, unsigned long i){    int lines_above = edit->start_line;    if (i > lines_above)	i = lines_above;    if (i) {	edit->start_line -= i;	edit->start_display = edit_move_backward (edit, edit->start_display, i);	edit->force |= REDRAW_PAGE;	edit->force &= (0xfff - REDRAW_CHAR_ONLY);#ifndef MIDNIGHT#endif    }    edit_update_curs_row (edit);}/* returns 1 if could scroll, 0 otherwise */void edit_scroll_downward (WEdit * edit, int i){    int lines_below;    lines_below = edit->total_lines - edit->start_line - (edit->num_widget_lines - 1);    if (lines_below > 0) {	if (i > lines_below)	    i = lines_below;	edit->start_line += i;	edit->start_display = edit_move_forward (edit, edit->start_display, i, 0);	edit->force |= REDRAW_PAGE;	edit->force &= (0xfff - REDRAW_CHAR_ONLY);#ifndef MIDNIGHT#endif    }    edit_update_curs_row (edit);}void edit_scroll_right (WEdit * edit, int i){    edit->force |= REDRAW_PAGE;    edit->force &= (0xfff - REDRAW_CHAR_ONLY);    edit->start_col -= i;}void edit_scroll_left (WEdit * edit, int i){    if (edit->start_col) {	edit->start_col += i;	if (edit->start_col > 0)	    edit->start_col = 0;	edit->force |= REDRAW_PAGE;	edit->force &= (0xfff - REDRAW_CHAR_ONLY);    }}/* high level cursor movement commands */static int is_in_indent (WEdit *edit){    long p = edit_bol (edit, edit->curs1);    while (p < edit->curs1)	if (!strchr (" \t", edit_get_byte (edit, p++)))	    return 0;    return 1;}static int left_of_four_spaces (WEdit *edit);void edit_move_to_prev_col (WEdit * edit, long p){    edit_cursor_move (edit, edit_move_forward3 (edit, p, edit->prev_col, 0) - edit->curs1);    if (is_in_indent (edit) && option_fake_half_tabs) {	edit_update_curs_col (edit);	if (space_width)	if (edit->curs_col % (HALF_TAB_SIZE * space_width)) {	    int q = edit->curs_col;	    edit->curs_col -= (edit->curs_col % (HALF_TAB_SIZE * space_width));	    p = edit_bol (edit, edit->curs1);	    edit_cursor_move (edit, edit_move_forward3 (edit, p, edit->curs_col, 0) - edit->curs1);	    if (!left_of_four_spaces (edit))		edit_cursor_move (edit, edit_move_forward3 (edit, p, q, 0) - edit->curs1);	}    }}/* move i lines */void edit_move_up (WEdit * edit, unsigned long i, int scroll){    long p, l = edit->curs_line;    if (i > l)	i = l;    if (i) {	if (i > 1)	    edit->force |= REDRAW_PAGE;	if (scroll)	    edit_scroll_upward (edit, i);	p = edit_bol (edit, edit->curs1);	edit_cursor_move (edit, (p = edit_move_backward (edit, p, i)) - edit->curs1);	edit_move_to_prev_col (edit, p);	edit->search_start = edit->curs1;	edit->found_len = 0;    }}int is_blank (WEdit * edit, long offset){    long s, f;    int c;    s = edit_bol (edit, offset);    f = edit_eol (edit, offset) - 1;    while (s <= f) {	c = edit_get_byte (edit, s++);	if (!isspace (c))	    return 0;    }    return 1;}/* returns the offset of line i */long edit_find_line (WEdit * edit, int line){    int i, j = 0;    int m = 2000000000;    if (!edit->caches_valid) {	for (i = 0; i < N_LINE_CACHES; i++)	    edit->line_numbers[i] = edit->line_offsets[i] = 0;/* three offsets that we *know* are line 0 at 0 and these two: */	edit->line_numbers[1] = edit->curs_line;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -