📄 block.c
字号:
ll = window->ll->next; while (ll->len != EOF && is_line_blank( ll->line, ll->len, tabs )) { lnum++; ll = ll->next; } file->block_er = lnum - 1; } else { i = first_non_blank( ll->line, ll->len, tabs, tab_size ); do { lnum--; ll = ll->prev; } while (!is_line_blank( ll->line, ll->len, tabs ) && (!indent || i <= first_non_blank( ll->line,ll->len,tabs,tab_size ))); file->block_br = lnum + 1; lnum = window->rline + 1; ll = window->ll->next; while (!is_line_blank( ll->line, ll->len, tabs ) && (!indent || i <= first_non_blank( ll->line,ll->len, tabs,tab_size ))) { lnum++; ll = ll->next; } file->block_er = lnum - 1; } }}/* * Name: do_multi_stream_mark * Purpose: to mark a paragraph * Author: Jason Hood * Date: May 7, 1999 * Passed: window: pointer to current window * * jmh 020913: second will mark a line (without leading space); third will * now mark a paragraph. */static void do_multi_stream_mark( TDE_WIN *window ){long lnum;register file_infos *file; /* temporary file variable */line_list_ptr ll;int tabs;int tab_size; if (g_status.command_count > 2) return; file = window->file_info; tabs = file->inflate_tabs; tab_size = file->ptab_size; lnum = window->rline; ll = window->ll; if (g_status.command_count == 1) file->block_br = file->block_er = lnum; else { do { lnum--; ll = ll->prev; } while (!is_line_blank( ll->line, ll->len, tabs )); ll = ll->next; file->block_br = lnum + 1; } file->block_bc = first_non_blank( ll->line, ll->len, tabs, tab_size ); if (g_status.command_count == 2) { ll = window->ll->next; lnum = window->rline + 1; while (!is_line_blank( ll->line, ll->len, tabs )) { lnum++; ll = ll->next; } ll = ll->prev; file->block_er = lnum - 1; } file->block_ec = find_end( ll->line, ll->len, tabs, tab_size ) - 1;}/* * Name: move_mark * Purpose: move the block mark to the cursor * Author: Jason Hood * Date: July 10, 2005 * Passed: window: pointer to current window * Notes: BOX and LINE blocks are made relative the cursor position; * STREAM block begins at the cursor, but ends the same. */int move_mark( TDE_WIN *window ){register file_infos *file; /* temporary file variable */register TDE_WIN *win; /* put window pointer in a register */int bc, ec;long br, er; if (!g_status.marked || window->ll->len == EOF) return( ERROR ); win = window; file = win->file_info; bc = g_status.marked_file->block_bc; br = g_status.marked_file->block_br; ec = g_status.marked_file->block_ec; er = g_status.marked_file->block_er; file->block_type = g_status.marked_file->block_type; file->block_bc = win->rcol; file->block_br = win->rline; file->block_er = win->rline + er - br; if (file->block_er > file->length) file->block_er = file->length; if (file->block_type == STREAM && (er != br || ec == -1)) { if (win->rline + er - br > file->length) file->block_ec = -1; else file->block_ec = ec; } else file->block_ec = win->rcol + ec - bc; file->dirty = GLOBAL; if (file != g_status.marked_file) { g_status.marked_file->dirty = GLOBAL; g_status.marked_file->block_type = -g_status.marked_file->block_type; g_status.marked_file = file; } return( OK );}/* * Name: unmark_block * Class: primary editor function * Purpose: To set all block information to NULL or 0 * Date: June 5, 1991 * Modified: August 9, 1997, Jason Hood - remove block beginning/end markers * Passed: window: pointer to current window * Notes: Reset all block variables if marked, otherwise return. * If a marked block is unmarked then redraw the screen(s). * jmh: October 2, 1997 - I'm sometimes too hasty in unmarking blocks, so * I'd like to be able to re-mark it. Don't reset the markers, and * remember the globals (in static variables, 'cos I don't want to * add even more global status variables). Don't re-mark in a macro * though, because it might require a block to be set (this is how * I did DeleteWordBack before I wrote the function). * * jmh: November 26 - made old_file global so it won't re-mark a closed * file. (I'll add it to g_status when I feel like recompiling * everything.) (January 24, 1998 - done.) * * jmh 980728: re-mark the block in the current file, using a negative value * when unmarking to remember the type. This removes the need * for old_file and allows "multiple" blocks. * Remove markers. */int unmark_block( TDE_WIN *window ){register file_infos *marked_file = NULL; if (g_status.marked == TRUE) { marked_file = g_status.marked_file; g_status.marked_file = NULL; } else if (!mode.record && !g_status.macro_executing) { marked_file = window->file_info; if (marked_file->block_type < NOTMARKED) g_status.marked_file = marked_file; else marked_file = NULL; } if (marked_file != NULL) { g_status.marked = !g_status.marked; marked_file->dirty = GLOBAL; marked_file->block_type = -marked_file->block_type; } return( OK );}/* * Name: restore_marked_block * Class: helper function * Purpose: To restore block beginning and ending row after an editing function * Date: June 5, 1991 * Passed: window: pointer to current window * net_change: number of lines added or subtracted * Notes: If a change has been made before the marked block then the * beginning and ending row need to be adjusted by the number of * lines added or subtracted from file. * jmh: November 26, 1997 - adjust the beginning/end markers (how did I * miss this the first time?). * jmh 980728: Remove markers. * jmh 980821: update unmarked ("hidden") blocks, too. * jmh 990421: corrected marked beyond end of file bug. */void restore_marked_block( TDE_WIN *window, int net_change ){long length;register file_infos *marked_file;int update;int updated;int type;long rline; if (net_change != 0) { marked_file = window->file_info; type = abs( marked_file->block_type ); rline = window->rline; if (type != NOTMARKED && rline <= marked_file->block_er) { update = (g_status.marked && g_status.marked_file == marked_file); updated = FALSE; /* * if cursor is before marked block then adjust block by net change. */ if (rline < marked_file->block_br) { marked_file->block_br += net_change; marked_file->block_er += net_change; updated = TRUE; /* * if cursor is somewhere in marked block don't restore, do redisplay */ } else if (rline > marked_file->block_br && rline < marked_file->block_er) { marked_file->block_er += net_change; updated = TRUE; /* * if the cursor is on the beginning and/or end of the block, * does the block change? */ } else { if (rline == marked_file->block_br && rline == marked_file->block_er) { if (net_change < 0) { if (g_status.command == DeleteLine) { if (update) unmark_block( window ); } else { marked_file->block_br += net_change; marked_file->block_er += net_change; marked_file->block_bc += window->rcol; marked_file->block_ec += window->rcol; updated = TRUE; } } else if (g_status.command != AddLine && g_status.command != DuplicateLine) { if (type == LINE) { marked_file->block_er += net_change; updated = TRUE; } else { if (window->rcol <= marked_file->block_bc) { marked_file->block_br += net_change; marked_file->block_er += net_change; marked_file->block_bc -= window->rcol; marked_file->block_ec -= window->rcol; updated = TRUE; } else if (window->rcol <= marked_file->block_ec) { marked_file->block_ec = window->rcol; updated = TRUE; } } } } else if (rline == marked_file->block_br) { marked_file->block_er += net_change; updated = TRUE; if (net_change > 0) { if (type != LINE && window->rcol <= marked_file->block_bc) { marked_file->block_br += net_change; if (type == STREAM) marked_file->block_bc -= window->rcol; } } else if (g_status.command == DeleteLine) { if (type == STREAM) { marked_file->block_bc = 0; if (marked_file->block_ec == -1 && marked_file->block_br == marked_file->block_er) { marked_file->block_ec = 0; marked_file->block_type = (marked_file->block_type < 0) ? -LINE : LINE; } } } else if (type != BOX) { marked_file->block_br += net_change; marked_file->block_bc += window->rcol; } } else /* rline == marked_file->block_er */ { if (net_change < 0) { marked_file->block_er += net_change; updated = TRUE; if (type == STREAM) { if (g_status.command == DeleteLine) marked_file->block_ec = -1; else if (marked_file->block_ec != -1) marked_file->block_ec += window->rcol; } } else if (g_status.command != AddLine && g_status.command != DuplicateLine) { if (type == LINE) { marked_file->block_er += net_change; updated = TRUE; } else if (window->rcol <= marked_file->block_ec) { updated = TRUE; if (type == STREAM) { marked_file->block_er += net_change; marked_file->block_ec -= window->rcol; } else if (window->rcol <= marked_file->block_bc) marked_file->block_er += net_change; } } } } /* * check for lines of marked block beyond end of file */ length = marked_file->length; if (marked_file->block_br > length) { if (update) unmark_block( window ); } else if (marked_file->block_er > length) { marked_file->block_er = length; if (type == STREAM) marked_file->block_ec = -1; updated = TRUE; } if (updated) marked_file->dirty = GLOBAL; } }}/* * Name: shift_tabbed_block * Class: helper function * Purpose: to prepare shift_block() for a line containing real tabs * Author: Jason Hood * Date: October 10, 1999 * Passed: file: pointer to file containing block * Returns: sets local globals * Notes: the line being modified should be in the buffer. * Needs to be called before the modification. * Is overly complicated to handle blocks defined inside a tab, or * beyond the end of the line. */void shift_tabbed_block( file_infos *file ){ tabbed_bc = tabbed_ec = -1; if (file->inflate_tabs == 2 && mode.insert && memchr( g_status.line_buff, '\t', g_status.line_buff_len ) != NULL) { tabbed_bc = entab_adjust_rcol( g_status.line_buff, g_status.line_buff_len, file->block_bc, file->ptab_size ); if (file->block_ec != -1) tabbed_ec = entab_adjust_rcol( g_status.line_buff, g_status.line_buff_len, file->block_ec, file->ptab_size ); tabbed_bc_ofs = tabbed_ec_ofs = 0; if (tabbed_bc >= g_status.line_buff_len) { tabbed_bc_ofs = tabbed_bc - g_status.line_buff_len; tabbed_bc = g_status.line_buff_len; } else if (g_status.line_buff[tabbed_bc] == '\t') { if (file->block_bc != detab_adjust_rcol( g_status.line_buff, tabbed_bc, file->ptab_size )) tabbed_bc_ofs = file->block_bc - detab_adjust_rcol( g_status.line_buff, ++tabbed_bc, file->ptab_size ); } if (tabbed_ec != -1) { if (tabbed_ec >= g_status.line_buff_len) { tabbed_ec_ofs = tabbed_ec - g_status.line_buff_len; tabbed_ec = g_status.line_buff_len; } else if (g_status.line_buff[tabbed_ec] == '\t') { tabbed_ec_ofs = file->block_ec - detab_adjust_rcol( g_status.line_buff, tabbed_ec, file->ptab_size ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -