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

📄 editcmd.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    edit_cursor_move (edit, cursor - edit->curs1);}void edit_block_copy_cmd (WEdit * edit){    long start_mark, end_mark, current = edit->curs1;    int size, x;    unsigned char *copy_buf;    edit_update_curs_col (edit);    x = edit->curs_col;    if (eval_marks (edit, &start_mark, &end_mark))	return;    if (column_highlighting)	if ((x >= edit->column1 && x < edit->column2) || (x > edit->column2 && x <= edit->column1))	    return;    copy_buf = edit_get_block (edit, start_mark, end_mark, &size);/* all that gets pushed are deletes hence little space is used on the stack */    edit_push_markers (edit);    if (column_highlighting) {	edit_insert_column_of_text (edit, copy_buf, size, abs (edit->column2 - edit->column1));    } else {	while (size--)	    edit_insert_ahead (edit, copy_buf[size]);    }    free (copy_buf);    edit_scroll_screen_over_cursor (edit);    if (column_highlighting) {	edit_set_markers (edit, 0, 0, 0, 0);	edit_push_action (edit, COLUMN_ON);	column_highlighting = 0;    } else if (start_mark < current && end_mark > current)	edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0);    edit->force |= REDRAW_PAGE;}void edit_block_move_cmd (WEdit * edit){    long count;    long current;    unsigned char *copy_buf;    long start_mark, end_mark;    int deleted = 0;    int x = 0;    if (eval_marks (edit, &start_mark, &end_mark))	return;    if (column_highlighting) {	edit_update_curs_col (edit);	x = edit->curs_col;	if (start_mark <= edit->curs1 && end_mark >= edit->curs1)	    if ((x > edit->column1 && x < edit->column2) || (x > edit->column2 && x < edit->column1))		return;    } else if (start_mark <= edit->curs1 && end_mark >= edit->curs1)	return;    if ((end_mark - start_mark) > option_max_undo / 2)	if (edit_query_dialog2 (_ (" Warning "), _ (" Block is large, you may not be able to undo this action. "), _ ("Continue"), _ ("Cancel")))	    return;    edit_push_markers (edit);    current = edit->curs1;    if (column_highlighting) {	int size, c1, c2, line;	line = edit->curs_line;	if (edit->mark2 < 0)	    edit_mark_cmd (edit, 0);	c1 = min (edit->column1, edit->column2);	c2 = max (edit->column1, edit->column2);	copy_buf = edit_get_block (edit, start_mark, end_mark, &size);	if (x < c2) {	    edit_block_delete_cmd (edit);	    deleted = 1;	}	edit_move_to_line (edit, line);	edit_cursor_move (edit, edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0) - edit->curs1);	edit_insert_column_of_text (edit, copy_buf, size, c2 - c1);	if (!deleted) {	    line = edit->curs_line;	    edit_update_curs_col (edit);	    x = edit->curs_col;	    edit_block_delete_cmd (edit);	    edit_move_to_line (edit, line);	    edit_cursor_move (edit, edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0) - edit->curs1);	}	edit_set_markers (edit, 0, 0, 0, 0);	edit_push_action (edit, COLUMN_ON);	column_highlighting = 0;    } else {	copy_buf = malloc (end_mark - start_mark);	edit_cursor_move (edit, start_mark - edit->curs1);	edit_scroll_screen_over_cursor (edit);	count = start_mark;	while (count < end_mark) {	    copy_buf[end_mark - count - 1] = edit_delete (edit);	    count++;	}	edit_scroll_screen_over_cursor (edit);	edit_cursor_move (edit, current - edit->curs1 - (((current - edit->curs1) > 0) ? end_mark - start_mark : 0));	edit_scroll_screen_over_cursor (edit);	while (count-- > start_mark)	    edit_insert_ahead (edit, copy_buf[end_mark - count - 1]);	edit_set_markers (edit, edit->curs1, edit->curs1 + end_mark - start_mark, 0, 0);    }    edit_scroll_screen_over_cursor (edit);    free (copy_buf);    edit->force |= REDRAW_PAGE;}void edit_cursor_to_bol (WEdit * edit);void edit_delete_column_of_text (WEdit * edit){    long p, q, r, m1, m2;    int b, c, d;    int n;    eval_marks (edit, &m1, &m2);    n = edit_move_forward (edit, m1, 0, m2) + 1;    c = edit_move_forward3 (edit, edit_bol (edit, m1), 0, m1);    d = edit_move_forward3 (edit, edit_bol (edit, m2), 0, m2);    b = min (c, d);    c = max (c, d);    while (n--) {	r = edit_bol (edit, edit->curs1);	p = edit_move_forward3 (edit, r, b, 0);	q = edit_move_forward3 (edit, r, c, 0);	if (p < m1)	    p = m1;	if (q > m2)	    q = m2;	edit_cursor_move (edit, p - edit->curs1);	while (q > p) {		/* delete line between margins */	    if (edit_get_byte (edit, edit->curs1) != '\n')		edit_delete (edit);	    q--;	}	if (n)			/* move to next line except on the last delete */	    edit_cursor_move (edit, edit_move_forward (edit, edit->curs1, 1, 0) - edit->curs1);    }}int edit_block_delete (WEdit * edit){    long count;    long start_mark, end_mark;    if (eval_marks (edit, &start_mark, &end_mark))	return 0;    if (column_highlighting && edit->mark2 < 0)	edit_mark_cmd (edit, 0);    if ((end_mark - start_mark) > option_max_undo / 2)/* Warning message with a query to continue or cancel the operation */	if (edit_query_dialog2 (_ (" Warning "), _ (" Block is large, you may not be able to undo this action. "), _ (" Continue "), _ (" Cancel ")))	    return 1;    edit_push_markers (edit);    edit_cursor_move (edit, start_mark - edit->curs1);    edit_scroll_screen_over_cursor (edit);    count = start_mark;    if (start_mark < end_mark) {	if (column_highlighting) {	    if (edit->mark2 < 0)		edit_mark_cmd (edit, 0);	    edit_delete_column_of_text (edit);	} else {	    while (count < end_mark) {		edit_delete (edit);		count++;	    }	}    }    edit_set_markers (edit, 0, 0, 0, 0);    edit->force |= REDRAW_PAGE;    return 0;}/* returns 1 if canceelled by user */int edit_block_delete_cmd (WEdit * edit){    long start_mark, end_mark;    if (eval_marks (edit, &start_mark, &end_mark)) {	edit_delete_line (edit);	return 0;    }    return edit_block_delete (edit);}#ifdef MIDNIGHT#define INPUT_INDEX 9#define SEARCH_DLG_WIDTH 58#define SEARCH_DLG_HEIGHT 10#define REPLACE_DLG_WIDTH 58#define REPLACE_DLG_HEIGHT 15#define CONFIRM_DLG_WIDTH 79#define CONFIRM_DLG_HEIGTH 6#define B_REPLACE_ALL B_USER+1#define B_REPLACE_ONE B_USER+2#define B_SKIP_REPLACE B_USER+3int edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos){    QuickWidget quick_widgets[] =    {/* NLS  for hotkeys? */	{quick_button, 63, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("&Cancel"),	 0, B_CANCEL, 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_button, 50, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("o&Ne"),	 0, B_REPLACE_ONE, 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_button, 37, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("al&L"),	 0, B_REPLACE_ALL, 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_button, 21, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("&Skip"),	 0, B_SKIP_REPLACE, 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_button, 4, CONFIRM_DLG_WIDTH, 3, CONFIRM_DLG_HEIGTH, N_ ("&Replace"),	 0, B_ENTER, 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_label, 2, CONFIRM_DLG_WIDTH, 2, CONFIRM_DLG_HEIGTH, 0,	 0, 0, 0, XV_WLAY_DONTCARE, 0},	{0}};    quick_widgets[4].text = catstrs (_ (" Replace with: "), replace_text, 0);    {	QuickDialog Quick_input =	{CONFIRM_DLG_WIDTH, CONFIRM_DLG_HEIGTH, 0, 0, N_ (" Confirm replace "),	 "[Input Line Keys]", "quick_input", 0 /*quick_widgets */ };	Quick_input.widgets = quick_widgets;	Quick_input.xpos = xpos;	Quick_input.ypos = ypos;	return quick_dialog (&Quick_input);    }}void edit_replace_dialog (WEdit * edit, char **search_text, char **replace_text, char **arg_order){    int treplace_scanf = replace_scanf;    int treplace_regexp = replace_regexp;    int treplace_all = replace_all;    int treplace_prompt = replace_prompt;    int treplace_backwards = replace_backwards;    int treplace_whole = replace_whole;    int treplace_case = replace_case;    char *tsearch_text;    char *treplace_text;    char *targ_order;    QuickWidget quick_widgets[] =    {	{quick_button, 6, 10, 12, REPLACE_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0,	 0, XV_WLAY_DONTCARE, NULL},	{quick_button, 2, 10, 12, REPLACE_DLG_HEIGHT, N_("&Ok"), 0, B_ENTER, 0,	 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("scanf &Expression"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("replace &All"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("pr&Ompt on replace"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 4, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("&Backwards"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 4, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Regular expression"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 4, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("&Whole words only"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 4, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_input,    3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, "", 52, 0, 0,	 0, XV_WLAY_BELOWCLOSE, "edit-argord"},	{quick_label, 2, REPLACE_DLG_WIDTH, 6, REPLACE_DLG_HEIGHT, N_(" Enter replacement argument order eg. 3,2,1,4 "), 0, 0,	 0, 0, XV_WLAY_DONTCARE, 0},	{quick_input, 3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT, "", 52, 0, 0,	 0, XV_WLAY_BELOWCLOSE, "edit-replace"},	{quick_label, 2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT, N_(" Enter replacement string:"), 0, 0, 0,	 0, XV_WLAY_DONTCARE, 0},	{quick_input, 3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT, "", 52, 0, 0,	 0, XV_WLAY_BELOWCLOSE, "edit-search"},	{quick_label, 2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT, N_(" Enter search string:"), 0, 0, 0,	 0, XV_WLAY_DONTCARE, 0},	{0}};    quick_widgets[2].result = &treplace_scanf;    quick_widgets[3].result = &treplace_all;    quick_widgets[4].result = &treplace_prompt;    quick_widgets[5].result = &treplace_backwards;    quick_widgets[6].result = &treplace_regexp;    quick_widgets[7].result = &treplace_whole;    quick_widgets[8].result = &treplace_case;    quick_widgets[9].str_result = &targ_order;    quick_widgets[9].text = *arg_order;    quick_widgets[11].str_result = &treplace_text;    quick_widgets[11].text = *replace_text;    quick_widgets[13].str_result = &tsearch_text;    quick_widgets[13].text = *search_text;    {	QuickDialog Quick_input =	{REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, 0, N_(" Replace "),	 "[Input Line Keys]", "quick_input", 0 /*quick_widgets */ };	Quick_input.widgets = quick_widgets;	if (quick_dialog (&Quick_input) != B_CANCEL) {	    *arg_order = *(quick_widgets[INPUT_INDEX].str_result);	    *replace_text = *(quick_widgets[INPUT_INDEX + 2].str_result);	    *search_text = *(quick_widgets[INPUT_INDEX + 4].str_result);	    replace_scanf = treplace_scanf;	    replace_backwards = treplace_backwards;	    replace_regexp = treplace_regexp;	    replace_all = treplace_all;	    replace_prompt = treplace_prompt;	    replace_whole = treplace_whole;	    replace_case = treplace_case;	    return;	} else {	    *arg_order = NULL;	    *replace_text = NULL;	    *search_text = NULL;	    return;	}    }}void edit_search_dialog (WEdit * edit, char **search_text){    int treplace_scanf = replace_scanf;    int treplace_regexp = replace_regexp;    int treplace_whole = replace_whole;    int treplace_case = replace_case;    int treplace_backwards = replace_backwards;    char *tsearch_text;    QuickWidget quick_widgets[] =    {	{quick_button, 6, 10, 7, SEARCH_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0,	 0, XV_WLAY_DONTCARE, NULL},	{quick_button, 2, 10, 7, SEARCH_DLG_HEIGHT, N_("&Ok"), 0, B_ENTER, 0,	 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("scanf &Expression"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL },	{quick_checkbox, 33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("&Backwards"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 4, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Regular expression"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 4, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("&Whole words only"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_checkbox, 4, SEARCH_DLG_WIDTH, 4, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), 0, 0,	 0, 0, XV_WLAY_DONTCARE, NULL},	{quick_input, 3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, "", 52, 0, 0,	 0, XV_WLAY_BELOWCLOSE, "edit-search"},	{quick_label, 2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:"), 0, 0, 0,	 0, XV_WLAY_DONTCARE, 0},	{0}};    quick_widgets[2].result = &treplace_scanf;    quick_widgets[3].result = &treplace_backwards;    quick_widgets[4].result = &treplace_regexp;    quick_widgets[5].result = &treplace_whole;    quick_widgets[6].result = &treplace_case;    quick_widgets[7].str_result = &tsearch_text;    quick_widgets[7].text = *search_text;    {	QuickDialog Quick_input =	{SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, 0, N_(" Search "),	 "[Input Line Keys]", "quick_input", 0 /*quick_widgets */ };	Quick_input.widgets = quick_widgets;	if (quick_dialog (&Quick_input) != B_CANCEL) {	    *search_text = *(quick_widgets[7].str_result);	    replace_scanf = treplace_scanf;	    replace_backwards = treplace_backwards;	    replace_regexp = treplace_regexp;	    replace_whole = treplace_whole;	    replace_case = treplace_case;	    return;	} else {	    *search_text = NULL;	    return;	}    }}#else#define B_ENTER 0#define B_SKIP_REPLACE 1#define B_REPLACE_ALL 2#define B_REPLACE_ONE 3#define B_CANCEL 4extern CWidget *wedit;#ifndef GTKvoid edit_backspace_tab (WEdit * edit, int whole_tabs_only);static inline int my_is_blank (int c){    return c == ' ' || c == '\t';}void edit_indent_left_right_paragraph (WEdit * edit){    char id[33];    int width = 0, lines, c;    XEvent xevent;    KeySym k;    char *r;    CState s;    CWidget *w, *p = 0, *i;    long start_mark, end_mark;    strcpy (id, CIdentOf (edit->widget));    strcat (id, ".text");    w = CIdent (id);    if (!w)	return;    if (eval_marks (edit, &start_mark, &end_mark)) {	edit_error_dialog (_(" Error "),			   _			   (" No text highlighted - highlight text, run command again, then use arrow keys. "));	return;    }    r = 0;    CBackupState (&s);    CDisable ("*");    p =	CDrawText ("status_prompt", edit->widget->parentid, CXof (w), CYof (w), "%s",		   _(" <---  ---> (this eats your undo stack) "));    width = CWidthOf (p);    i = CDrawTextInput ("status_input", edit->widget->parentid, CXof (w) + width, CYof (w),			CWidthOf (edit->widget) - width, AUTO_HEIGHT, 1, "");    CFocus (i);    edit_set_markers (edit, edit_bol (edit, start_mark), edit_eol (edit, end_mark), -1, -1);    edit->force |= REDRAW_PAGE;    edit_render_keypress (edit);    edit_push_action (edit, KEY_PRESS + edit->start_display);    for (;;) {	XEvent xev;	CEvent cev;	CNextEvent (&xev, &cev);	if (xev.type == KeyPress) {	    if (eval_marks (edit, &start_mark, &end_mark))		break;	    lines = edit_count_lines (edit, start_mark, end_mark);	    k = CKeySym (&xevent);	    if (cev.command == CK_Right || cev.command == CK_Tab) {		long s;		for (c = 0, s = start_mark; c <= lines; s = edit_eol (edit, s) + 1, c++) {		    while (my_is_blank (edit_get_byte (edit, s)) && s < edit->last_byte)			s++;		    edit_cursor_move (edit, s - edit->curs1);		    edit_tab_cmd (edit);		    s = edit->curs1;		}		edit->force |= REDRAW_PAGE;		edit_render_keypress (edit);		edit_push_action (edit, KEY_PRESS + edit->start_display);	    } else if (cev.command == CK_Left || cev.command == CK_BackSpace) {		long s;		for (c = 0, s = start_mark; c <= lines; s = edit_eol (edit, s) + 1, c++) {		    while (my_is_blank (edit_get_byte (edit, s)) && s < edit->last_byte)			s++;		    edit_cursor_move (edit, s - edit->curs1);		    edit_backspace_tab (edit, 1);		    s = edit->curs1;		}		edit->force |= REDRAW_PAGE;		edit_render_keypress (edit);		edit_push_action (edit, KEY_PRESS + edit->start_display);	    } else {

⌨️ 快捷键说明

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