Start of edit buffers refactoring.

Move buffers to separate class.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2013-02-15 13:02:00 +04:00
parent 23c2df198c
commit f56de22de5
10 changed files with 417 additions and 330 deletions

View File

@ -9,8 +9,9 @@ endif
libedit_la_SOURCES = \ libedit_la_SOURCES = \
bookmark.c \ bookmark.c \
choosesyntax.c \ choosesyntax.c \
edit.c edit.h \
edit-impl.h \ edit-impl.h \
edit.c edit.h \
editbuffer.c editbuffer.h \
editcmd.c \ editcmd.c \
editcmd_dialogs.c editcmd_dialogs.h \ editcmd_dialogs.c editcmd_dialogs.h \
editdraw.c \ editdraw.c \

View File

@ -39,33 +39,6 @@
#define EDIT_TOP_EXTREME option_edit_top_extreme #define EDIT_TOP_EXTREME option_edit_top_extreme
#define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
/*
* The editor keeps data in two arrays of buffers.
* All buffers have the same size, which must be a power of 2.
*/
/* Configurable: log2 of the buffer size in bytes */
#ifndef S_EDIT_BUF_SIZE
#define S_EDIT_BUF_SIZE 16
#endif
/* Size of the buffer */
#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
/* Buffer mask (used to find cursor position relative to the buffer) */
#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
/*
* Configurable: Maximal allowed number of buffers in each buffer array.
* This number can be increased for systems with enough physical memory.
*/
#ifndef MAXBUFF
#define MAXBUFF 1024
#endif
/* Maximal length of file that can be opened */
#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
/* Initial size of the undo stack, in bytes */ /* Initial size of the undo stack, in bytes */
#define START_STACK_SIZE 32 #define START_STACK_SIZE 32

View File

@ -135,37 +135,8 @@ static const struct edit_filters
/* *INDENT-ON* */ /* *INDENT-ON* */
}; };
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/*-
*
* here's a quick sketch of the layout: (don't run this through indent.)
*
* (b1 is buffers1 and b2 is buffers2)
*
* |
* \0\0\0\0\0m e _ f i l e . \nf i n . \n|T h i s _ i s _ s o\0\0\0\0\0\0\0\0\0
* ______________________________________|______________________________________
* |
* ... | b2[2] | b2[1] | b2[0] | b1[0] | b1[1] | b1[2] | ...
* |-> |-> |-> |-> |-> |-> |
* |
* _<------------------------->|<----------------->_
* WEdit->curs2 | WEdit->curs1
* ^ | ^
* | ^|^ |
* cursor ||| cursor
* |||
* file end|||file beginning
* |
* |
*
* _
* This_is_some_file
* fin.
*/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Initialize the buffers for an empty files. * Initialize the buffers for an empty files.
@ -178,13 +149,13 @@ edit_init_buffers (WEdit * edit)
for (j = 0; j <= MAXBUFF; j++) for (j = 0; j <= MAXBUFF; j++)
{ {
edit->buffers1[j] = NULL; edit->buffer.buffers1[j] = NULL;
edit->buffers2[j] = NULL; edit->buffer.buffers2[j] = NULL;
} }
edit->curs1 = 0; edit->buffer.curs1 = 0;
edit->curs2 = 0; edit->buffer.curs2 = 0;
edit->buffers2[0] = g_malloc0 (EDIT_BUF_SIZE); edit->buffer.buffers2[0] = g_malloc0 (EDIT_BUF_SIZE);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -214,23 +185,23 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
return FALSE; return FALSE;
} }
edit->curs2 = edit->last_byte; edit->buffer.curs2 = edit->last_byte;
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE; buf2 = edit->buffer.curs2 >> S_EDIT_BUF_SIZE;
if (edit->buffers2[buf2] == NULL) if (edit->buffer.buffers2[buf2] == NULL)
edit->buffers2[buf2] = g_malloc0 (EDIT_BUF_SIZE); edit->buffer.buffers2[buf2] = g_malloc0 (EDIT_BUF_SIZE);
if (mc_read (file, if (mc_read (file,
(char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (char *) edit->buffer.buffers2[buf2] + EDIT_BUF_SIZE -
(edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE) < 0) (edit->buffer.curs2 & M_EDIT_BUF_SIZE), edit->buffer.curs2 & M_EDIT_BUF_SIZE) < 0)
goto done; goto done;
for (buf = buf2 - 1; buf >= 0; buf--) for (buf = buf2 - 1; buf >= 0; buf--)
{ {
/* edit->buffers2[0] is already allocated */ /* edit->buffer.buffers2[0] is already allocated */
if (edit->buffers2[buf] == NULL) if (edit->buffer.buffers2[buf] == NULL)
edit->buffers2[buf] = g_malloc0 (EDIT_BUF_SIZE); edit->buffer.buffers2[buf] = g_malloc0 (EDIT_BUF_SIZE);
if (mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) < 0) if (mc_read (file, (char *) edit->buffer.buffers2[buf], EDIT_BUF_SIZE) < 0)
goto done; goto done;
} }
@ -484,12 +455,12 @@ edit_load_position (WEdit * edit)
{ {
edit_cursor_move (edit, offset); edit_cursor_move (edit, offset);
line = edit->curs_line; line = edit->curs_line;
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
} }
book_mark_restore (edit, BOOK_MARK_COLOR); book_mark_restore (edit, BOOK_MARK_COLOR);
edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1)); edit_move_to_prev_col (edit, edit_bol (edit, edit->buffer.curs1));
edit_move_display (edit, line - (WIDGET (edit)->lines / 2)); edit_move_display (edit, line - (WIDGET (edit)->lines / 2));
} }
@ -504,7 +475,7 @@ edit_save_position (WEdit * edit)
return; return;
book_mark_serialize (edit, BOOK_MARK_COLOR); book_mark_serialize (edit, BOOK_MARK_COLOR);
save_file_position (edit->filename_vpath, edit->curs_line + 1, edit->curs_col, edit->curs1, save_file_position (edit->filename_vpath, edit->curs_line + 1, edit->curs_col, edit->buffer.curs1,
edit->serialized_bookmarks); edit->serialized_bookmarks);
edit->serialized_bookmarks = NULL; edit->serialized_bookmarks = NULL;
} }
@ -629,19 +600,19 @@ edit_modification (WEdit * edit)
static char * static char *
edit_get_byte_ptr (const WEdit * edit, off_t byte_index) edit_get_byte_ptr (const WEdit * edit, off_t byte_index)
{ {
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) if (byte_index >= (edit->buffer.curs1 + edit->buffer.curs2) || byte_index < 0)
return NULL; return NULL;
if (byte_index >= edit->curs1) if (byte_index >= edit->buffer.curs1)
{ {
off_t p; off_t p;
p = edit->curs1 + edit->curs2 - byte_index - 1; p = edit->buffer.curs1 + edit->buffer.curs2 - byte_index - 1;
return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] + return (char *) (edit->buffer.buffers2[p >> S_EDIT_BUF_SIZE] +
(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1)); (EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
} }
return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] + return (char *) (edit->buffer.buffers1[byte_index >> S_EDIT_BUF_SIZE] +
(byte_index & M_EDIT_BUF_SIZE)); (byte_index & M_EDIT_BUF_SIZE));
} }
@ -656,7 +627,7 @@ edit_get_prev_utf (const WEdit * edit, off_t byte_index, int *char_width)
gchar *str; gchar *str;
gchar *cursor_buf_ptr; gchar *cursor_buf_ptr;
if (byte_index > (edit->curs1 + edit->curs2) || byte_index <= 0) if (byte_index > (edit->buffer.curs1 + edit->buffer.curs2) || byte_index <= 0)
{ {
*char_width = 0; *char_width = 0;
return 0; return 0;
@ -707,7 +678,7 @@ is_in_indent (const WEdit * edit)
{ {
off_t p; off_t p;
for (p = edit_bol (edit, edit->curs1); p < edit->curs1; p++) for (p = edit_bol (edit, edit->buffer.curs1); p < edit->buffer.curs1; p++)
if (strchr (" \t", edit_get_byte (edit, p)) == NULL) if (strchr (" \t", edit_get_byte (edit, p)) == NULL)
return FALSE; return FALSE;
@ -755,7 +726,7 @@ edit_find_line (WEdit * edit, long line)
memset (edit->line_offsets, 0, sizeof (edit->line_offsets)); memset (edit->line_offsets, 0, sizeof (edit->line_offsets));
/* three offsets that we *know* are line 0 at 0 and these two: */ /* three offsets that we *know* are line 0 at 0 and these two: */
edit->line_numbers[1] = edit->curs_line; edit->line_numbers[1] = edit->curs_line;
edit->line_offsets[1] = edit_bol (edit, edit->curs1); edit->line_offsets[1] = edit_bol (edit, edit->buffer.curs1);
edit->line_numbers[2] = edit->total_lines; edit->line_numbers[2] = edit->total_lines;
edit->line_offsets[2] = edit_bol (edit, edit->last_byte); edit->line_offsets[2] = edit_bol (edit, edit->last_byte);
edit->caches_valid = TRUE; edit->caches_valid = TRUE;
@ -891,7 +862,7 @@ edit_move_to_top (WEdit * edit)
{ {
if (edit->curs_line) if (edit->curs_line)
{ {
edit_cursor_move (edit, -edit->curs1); edit_cursor_move (edit, -edit->buffer.curs1);
edit_move_to_prev_col (edit, 0); edit_move_to_prev_col (edit, 0);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
edit->search_start = 0; edit->search_start = 0;
@ -922,8 +893,8 @@ edit_move_to_bottom (WEdit * edit)
static void static void
edit_cursor_to_bol (WEdit * edit) edit_cursor_to_bol (WEdit * edit)
{ {
edit_cursor_move (edit, edit_bol (edit, edit->curs1) - edit->curs1); edit_cursor_move (edit, edit_bol (edit, edit->buffer.curs1) - edit->buffer.curs1);
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
edit->prev_col = edit_get_col (edit); edit->prev_col = edit_get_col (edit);
edit->over_col = 0; edit->over_col = 0;
} }
@ -934,8 +905,8 @@ edit_cursor_to_bol (WEdit * edit)
static void static void
edit_cursor_to_eol (WEdit * edit) edit_cursor_to_eol (WEdit * edit)
{ {
edit_cursor_move (edit, edit_eol (edit, edit->curs1) - edit->curs1); edit_cursor_move (edit, edit_eol (edit, edit->buffer.curs1) - edit->buffer.curs1);
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
edit->prev_col = edit_get_col (edit); edit->prev_col = edit_get_col (edit);
edit->over_col = 0; edit->over_col = 0;
} }
@ -993,13 +964,13 @@ edit_left_word_move (WEdit * edit, int s)
if (edit->column_highlight if (edit->column_highlight
&& edit->mark1 != edit->mark2 && edit->mark1 != edit->mark2
&& edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1)) && edit->over_col == 0 && edit->buffer.curs1 == edit_bol (edit, edit->buffer.curs1))
break; break;
edit_cursor_move (edit, -1); edit_cursor_move (edit, -1);
if (edit->curs1 == 0) if (edit->buffer.curs1 == 0)
break; break;
c1 = edit_get_byte (edit, edit->curs1 - 1); c1 = edit_get_byte (edit, edit->buffer.curs1 - 1);
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->buffer.curs1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if ((my_type_of (c1) & my_type_of (c2)) == 0) if ((my_type_of (c1) & my_type_of (c2)) == 0)
@ -1031,13 +1002,13 @@ edit_right_word_move (WEdit * edit, int s)
if (edit->column_highlight if (edit->column_highlight
&& edit->mark1 != edit->mark2 && edit->mark1 != edit->mark2
&& edit->over_col == 0 && edit->curs1 == edit_eol (edit, edit->curs1)) && edit->over_col == 0 && edit->buffer.curs1 == edit_eol (edit, edit->buffer.curs1))
break; break;
edit_cursor_move (edit, 1); edit_cursor_move (edit, 1);
if (edit->curs1 >= edit->last_byte) if (edit->buffer.curs1 >= edit->last_byte)
break; break;
c1 = edit_get_byte (edit, edit->curs1 - 1); c1 = edit_get_byte (edit, edit->buffer.curs1 - 1);
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->buffer.curs1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if ((my_type_of (c1) & my_type_of (c2)) == 0) if ((my_type_of (c1) & my_type_of (c2)) == 0)
@ -1068,14 +1039,14 @@ edit_right_char_move_cmd (WEdit * edit)
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (edit->utf8) if (edit->utf8)
{ {
c = edit_get_utf (edit, edit->curs1, &cw); c = edit_get_utf (edit, edit->buffer.curs1, &cw);
if (cw < 1) if (cw < 1)
cw = 1; cw = 1;
} }
else else
#endif #endif
{ {
c = edit_get_byte (edit, edit->curs1); c = edit_get_byte (edit, edit->buffer.curs1);
} }
if (option_cursor_beyond_eol && c == '\n') if (option_cursor_beyond_eol && c == '\n')
{ {
@ -1096,12 +1067,12 @@ edit_left_char_move_cmd (WEdit * edit)
if (edit->column_highlight if (edit->column_highlight
&& option_cursor_beyond_eol && option_cursor_beyond_eol
&& edit->mark1 != edit->mark2 && edit->mark1 != edit->mark2
&& edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1)) && edit->over_col == 0 && edit->buffer.curs1 == edit_bol (edit, edit->buffer.curs1))
return; return;
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (edit->utf8) if (edit->utf8)
{ {
edit_get_prev_utf (edit, edit->curs1, &cw); edit_get_prev_utf (edit, edit->buffer.curs1, &cw);
if (cw < 1) if (cw < 1)
cw = 1; cw = 1;
} }
@ -1143,25 +1114,25 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi
else else
edit_scroll_downward (edit, lines); edit_scroll_downward (edit, lines);
} }
p = edit_bol (edit, edit->curs1); p = edit_bol (edit, edit->buffer.curs1);
p = direction ? edit_move_backward (edit, p, lines) : edit_move_forward (edit, p, lines, 0); p = direction ? edit_move_backward (edit, p, lines) : edit_move_forward (edit, p, lines, 0);
edit_cursor_move (edit, p - edit->curs1); edit_cursor_move (edit, p - edit->buffer.curs1);
edit_move_to_prev_col (edit, p); edit_move_to_prev_col (edit, p);
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
/* search start of current multibyte char (like CJK) */ /* search start of current multibyte char (like CJK) */
if (edit->curs1 > 0 && edit->curs1 + 1 < edit->last_byte if (edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->last_byte
&& edit_get_byte (edit, edit->curs1) >= 256 ) && edit_get_byte (edit, edit->buffer.curs1) >= 256 )
{ {
edit_right_char_move_cmd (edit); edit_right_char_move_cmd (edit);
edit_left_char_move_cmd (edit); edit_left_char_move_cmd (edit);
} }
#endif #endif
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
edit->found_len = 0; edit->found_len = 0;
} }
@ -1170,12 +1141,12 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi
static void static void
edit_right_delete_word (WEdit * edit) edit_right_delete_word (WEdit * edit)
{ {
while (edit->curs1 < edit->last_byte) while (edit->buffer.curs1 < edit->last_byte)
{ {
int c1, c2; int c1, c2;
c1 = edit_delete (edit, TRUE); c1 = edit_delete (edit, TRUE);
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->buffer.curs1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if ((isspace (c1) == 0) != (isspace (c2) == 0)) if ((isspace (c1) == 0) != (isspace (c2) == 0))
@ -1190,12 +1161,12 @@ edit_right_delete_word (WEdit * edit)
static void static void
edit_left_delete_word (WEdit * edit) edit_left_delete_word (WEdit * edit)
{ {
while (edit->curs1 > 0) while (edit->buffer.curs1 > 0)
{ {
int c1, c2; int c1, c2;
c1 = edit_backspace (edit, TRUE); c1 = edit_backspace (edit, TRUE);
c2 = edit_get_byte (edit, edit->curs1 - 1); c2 = edit_get_byte (edit, edit->buffer.curs1 - 1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if ((isspace (c1) == 0) != (isspace (c2) == 0)) if ((isspace (c1) == 0) != (isspace (c2) == 0))
@ -1389,7 +1360,7 @@ edit_group_undo (WEdit * edit)
static void static void
edit_delete_to_line_end (WEdit * edit) edit_delete_to_line_end (WEdit * edit)
{ {
while (edit_get_byte (edit, edit->curs1) != '\n' && edit->curs2 != 0) while (edit_get_byte (edit, edit->buffer.curs1) != '\n' && edit->buffer.curs2 != 0)
edit_delete (edit, TRUE); edit_delete (edit, TRUE);
} }
@ -1398,7 +1369,7 @@ edit_delete_to_line_end (WEdit * edit)
static void static void
edit_delete_to_line_begin (WEdit * edit) edit_delete_to_line_begin (WEdit * edit)
{ {
while (edit_get_byte (edit, edit->curs1 - 1) != '\n' && edit->curs1 != 0) while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n' && edit->buffer.curs1 != 0)
edit_backspace (edit, TRUE); edit_backspace (edit, TRUE);
} }
@ -1422,7 +1393,7 @@ right_of_four_spaces (WEdit * edit)
int i, ch = 0; int i, ch = 0;
for (i = 1; i <= HALF_TAB_SIZE; i++) for (i = 1; i <= HALF_TAB_SIZE; i++)
ch |= edit_get_byte (edit, edit->curs1 - i); ch |= edit_get_byte (edit, edit->buffer.curs1 - i);
return (ch == ' ' && is_aligned_on_a_tab (edit)); return (ch == ' ' && is_aligned_on_a_tab (edit));
} }
@ -1435,7 +1406,7 @@ left_of_four_spaces (WEdit * edit)
int i, ch = 0; int i, ch = 0;
for (i = 0; i < HALF_TAB_SIZE; i++) for (i = 0; i < HALF_TAB_SIZE; i++)
ch |= edit_get_byte (edit, edit->curs1 + i); ch |= edit_get_byte (edit, edit->buffer.curs1 + i);
return (ch == ' ' && is_aligned_on_a_tab (edit)); return (ch == ' ' && is_aligned_on_a_tab (edit));
} }
@ -1448,7 +1419,7 @@ edit_auto_indent (WEdit * edit)
off_t p; off_t p;
char c; char c;
p = edit->curs1; p = edit->buffer.curs1;
/* use the previous line as a template */ /* use the previous line as a template */
p = edit_move_backward (edit, p, 1); p = edit_move_backward (edit, p, 1);
/* copy the leading whitespace of the line */ /* copy the leading whitespace of the line */
@ -1467,7 +1438,7 @@ static inline void
edit_double_newline (WEdit * edit) edit_double_newline (WEdit * edit)
{ {
edit_insert (edit, '\n'); edit_insert (edit, '\n');
if (edit_get_byte (edit, edit->curs1) == '\n' || edit_get_byte (edit, edit->curs1 - 2) == '\n') if (edit_get_byte (edit, edit->buffer.curs1) == '\n' || edit_get_byte (edit, edit->buffer.curs1 - 2) == '\n')
return; return;
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
edit_insert (edit, '\n'); edit_insert (edit, '\n');
@ -1535,7 +1506,7 @@ check_and_wrap_line (WEdit * edit)
edit_update_curs_col (edit); edit_update_curs_col (edit);
if (edit->curs_col < option_word_wrap_line_length) if (edit->curs_col < option_word_wrap_line_length)
return; return;
curs = edit->curs1; curs = edit->buffer.curs1;
while (TRUE) while (TRUE)
{ {
curs--; curs--;
@ -1547,10 +1518,10 @@ check_and_wrap_line (WEdit * edit)
} }
if (c == ' ' || c == '\t') if (c == ' ' || c == '\t')
{ {
off_t current = edit->curs1; off_t current = edit->buffer.curs1;
edit_cursor_move (edit, curs - edit->curs1 + 1); edit_cursor_move (edit, curs - edit->buffer.curs1 + 1);
edit_insert (edit, '\n'); edit_insert (edit, '\n');
edit_cursor_move (edit, current - edit->curs1 + 1); edit_cursor_move (edit, current - edit->buffer.curs1 + 1);
return; return;
} }
} }
@ -1574,7 +1545,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack
unsigned long j = 0; unsigned long j = 0;
off_t q; off_t q;
edit_update_curs_row (edit); edit_update_curs_row (edit);
c = edit_get_byte (edit, edit->curs1); c = edit_get_byte (edit, edit->buffer.curs1);
p = strchr (b, c); p = strchr (b, c);
/* no limit */ /* no limit */
if (!furthest_bracket_search) if (!furthest_bracket_search)
@ -1587,7 +1558,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack
/* going left or right? */ /* going left or right? */
if (strchr ("{[(", c)) if (strchr ("{[(", c))
inc = 1; inc = 1;
for (q = edit->curs1 + inc;; q += inc) for (q = edit->buffer.curs1 + inc;; q += inc)
{ {
/* out of buffer? */ /* out of buffer? */
if (q >= edit->last_byte || q < 0) if (q >= edit->last_byte || q < 0)
@ -1626,9 +1597,9 @@ edit_goto_matching_bracket (WEdit * edit)
q = edit_get_bracket (edit, 0, 0); q = edit_get_bracket (edit, 0, 0);
if (q >= 0) if (q >= 0)
{ {
edit->bracket = edit->curs1; edit->bracket = edit->buffer.curs1;
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
edit_cursor_move (edit, q - edit->curs1); edit_cursor_move (edit, q - edit->buffer.curs1);
} }
} }
@ -1648,14 +1619,14 @@ edit_move_block_to_right (WEdit * edit)
do do
{ {
edit_cursor_move (edit, cur_bol - edit->curs1); edit_cursor_move (edit, cur_bol - edit->buffer.curs1);
if (!edit_line_is_blank (edit, edit->curs_line)) if (!edit_line_is_blank (edit, edit->curs_line))
{ {
if (option_fill_tabs_with_spaces) if (option_fill_tabs_with_spaces)
insert_spaces_tab (edit, option_fake_half_tabs); insert_spaces_tab (edit, option_fake_half_tabs);
else else
edit_insert (edit, '\t'); edit_insert (edit, '\t');
edit_cursor_move (edit, edit_bol (edit, cur_bol) - edit->curs1); edit_cursor_move (edit, edit_bol (edit, cur_bol) - edit->buffer.curs1);
} }
if (cur_bol == 0) if (cur_bol == 0)
@ -1688,14 +1659,14 @@ edit_move_block_to_left (WEdit * edit)
int del_tab_width; int del_tab_width;
int next_char; int next_char;
edit_cursor_move (edit, cur_bol - edit->curs1); edit_cursor_move (edit, cur_bol - edit->buffer.curs1);
if (option_fake_half_tabs) if (option_fake_half_tabs)
del_tab_width = HALF_TAB_SIZE; del_tab_width = HALF_TAB_SIZE;
else else
del_tab_width = option_tab_spacing; del_tab_width = option_tab_spacing;
next_char = edit_get_byte (edit, edit->curs1); next_char = edit_get_byte (edit, edit->buffer.curs1);
if (next_char == '\t') if (next_char == '\t')
edit_delete (edit, TRUE); edit_delete (edit, TRUE);
else if (next_char == ' ') else if (next_char == ' ')
@ -1703,7 +1674,7 @@ edit_move_block_to_left (WEdit * edit)
{ {
if (next_char == ' ') if (next_char == ' ')
edit_delete (edit, TRUE); edit_delete (edit, TRUE);
next_char = edit_get_byte (edit, edit->curs1); next_char = edit_get_byte (edit, edit->buffer.curs1);
} }
if (cur_bol == 0) if (cur_bol == 0)
@ -1745,7 +1716,7 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t *
off_t blocklen = -1, width = 0; off_t blocklen = -1, width = 0;
unsigned char *data; unsigned char *data;
cursor = edit->curs1; cursor = edit->buffer.curs1;
col = edit_get_col (edit); col = edit_get_col (edit);
data = g_malloc0 (TEMP_BUF_LEN); data = g_malloc0 (TEMP_BUF_LEN);
@ -1766,15 +1737,15 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t *
long l; long l;
off_t p; off_t p;
if (edit_get_byte (edit, edit->curs1) != '\n') if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width) for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width)
edit_insert (edit, ' '); edit_insert (edit, ' ');
for (p = edit->curs1;; p++) for (p = edit->buffer.curs1;; p++)
{ {
if (p == edit->last_byte) if (p == edit->last_byte)
{ {
edit_cursor_move (edit, edit->last_byte - edit->curs1); edit_cursor_move (edit, edit->last_byte - edit->buffer.curs1);
edit_insert_ahead (edit, '\n'); edit_insert_ahead (edit, '\n');
p++; p++;
break; break;
@ -1786,7 +1757,7 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t *
} }
} }
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1); edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1);
for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) for (l = col - edit_get_col (edit); l >= space_width; l -= space_width)
edit_insert (edit, ' '); edit_insert (edit, ' ');
@ -1796,8 +1767,8 @@ edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t *
*col1 = col; *col1 = col;
*col2 = col + width; *col2 = col + width;
*start_pos = cursor; *start_pos = cursor;
*end_pos = edit->curs1; *end_pos = edit->buffer.curs1;
edit_cursor_move (edit, cursor - edit->curs1); edit_cursor_move (edit, cursor - edit->buffer.curs1);
g_free (data); g_free (data);
return blocklen; return blocklen;
@ -1821,7 +1792,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
block_file = mc_config_get_full_path (EDIT_BLOCK_FILE); block_file = mc_config_get_full_path (EDIT_BLOCK_FILE);
block_file_vpath = vfs_path_from_str (block_file); block_file_vpath = vfs_path_from_str (block_file);
curs = edit->curs1; curs = edit->buffer.curs1;
nomark = eval_marks (edit, &start_mark, &end_mark); nomark = eval_marks (edit, &start_mark, &end_mark);
if (nomark == 0) if (nomark == 0)
edit_save_block (edit, block_file, start_mark, end_mark); edit_save_block (edit, block_file, start_mark, end_mark);
@ -1853,7 +1824,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
g_free (block_file); g_free (block_file);
vfs_path_free (block_file_vpath); vfs_path_free (block_file_vpath);
edit_cursor_move (edit, curs - edit->curs1); edit_cursor_move (edit, curs - edit->buffer.curs1);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
widget_redraw (WIDGET (edit)); widget_redraw (WIDGET (edit));
} }
@ -1883,7 +1854,7 @@ edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width)
int width = 0; int width = 0;
gchar utf8_buf[UTF8_CHAR_LEN + 1]; gchar utf8_buf[UTF8_CHAR_LEN + 1];
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) if (byte_index >= (edit->buffer.curs1 + edit->buffer.curs2) || byte_index < 0)
{ {
*char_width = 0; *char_width = 0;
return '\n'; return '\n';
@ -2112,7 +2083,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
off_t ins_len = 0; off_t ins_len = 0;
p = edit_get_filter (filename_vpath); p = edit_get_filter (filename_vpath);
current = edit->curs1; current = edit->buffer.curs1;
if (p != NULL) if (p != NULL)
{ {
@ -2126,7 +2097,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
/* Place cursor at the end of text selection */ /* Place cursor at the end of text selection */
if (!option_cursor_after_inserted_block) if (!option_cursor_after_inserted_block)
{ {
ins_len = edit->curs1 - current; ins_len = edit->buffer.curs1 - current;
edit_cursor_move (edit, -ins_len); edit_cursor_move (edit, -ins_len);
} }
if (pclose (f) > 0) if (pclose (f) > 0)
@ -2178,7 +2149,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
long c1, c2; long c1, c2;
blocklen = edit_insert_column_from_file (edit, file, &mark1, &mark2, &c1, &c2); blocklen = edit_insert_column_from_file (edit, file, &mark1, &mark2, &c1, &c2);
edit_set_markers (edit, edit->curs1, mark2, c1, c2); edit_set_markers (edit, edit->buffer.curs1, mark2, c1, c2);
/* highlight inserted text then not persistent blocks */ /* highlight inserted text then not persistent blocks */
if (!option_persistent_selections && edit->modified) if (!option_persistent_selections && edit->modified)
@ -2200,7 +2171,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
/* highlight inserted text then not persistent blocks */ /* highlight inserted text then not persistent blocks */
if (!option_persistent_selections && edit->modified) if (!option_persistent_selections && edit->modified)
{ {
edit_set_markers (edit, edit->curs1, current, 0, 0); edit_set_markers (edit, edit->buffer.curs1, current, 0, 0);
if (edit->column_highlight) if (edit->column_highlight)
edit_push_undo_action (edit, COLUMN_ON); edit_push_undo_action (edit, COLUMN_ON);
edit->column_highlight = 0; edit->column_highlight = 0;
@ -2209,7 +2180,7 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
/* Place cursor at the end of text selection */ /* Place cursor at the end of text selection */
if (!option_cursor_after_inserted_block) if (!option_cursor_after_inserted_block)
{ {
ins_len = edit->curs1 - current; ins_len = edit->buffer.curs1 - current;
edit_cursor_move (edit, -ins_len); edit_cursor_move (edit, -ins_len);
} }
} }
@ -2358,8 +2329,8 @@ edit_clean (WEdit * edit)
book_mark_flush (edit, -1); book_mark_flush (edit, -1);
for (; j <= MAXBUFF; j++) for (; j <= MAXBUFF; j++)
{ {
g_free (edit->buffers1[j]); g_free (edit->buffer.buffers1[j]);
g_free (edit->buffers2[j]); g_free (edit->buffer.buffers2[j]);
} }
g_free (edit->undo_stack); g_free (edit->undo_stack);
@ -2673,7 +2644,7 @@ edit_insert (WEdit * edit, int c)
return; return;
/* first we must update the position of the display window */ /* first we must update the position of the display window */
if (edit->curs1 < edit->start_display) if (edit->buffer.curs1 < edit->start_display)
{ {
edit->start_display++; edit->start_display++;
if (c == '\n') if (c == '\n')
@ -2700,23 +2671,23 @@ edit_insert (WEdit * edit, int c)
else else
edit_push_undo_action (edit, BACKSPACE_BR); edit_push_undo_action (edit, BACKSPACE_BR);
/* update markers */ /* update markers */
edit->mark1 += (edit->mark1 > edit->curs1); edit->mark1 += (edit->mark1 > edit->buffer.curs1);
edit->mark2 += (edit->mark2 > edit->curs1); edit->mark2 += (edit->mark2 > edit->buffer.curs1);
edit->last_get_rule += (edit->last_get_rule > edit->curs1); edit->last_get_rule += (edit->last_get_rule > edit->buffer.curs1);
/* add a new buffer if we've reached the end of the last one */ /* add a new buffer if we've reached the end of the last one */
if (!(edit->curs1 & M_EDIT_BUF_SIZE)) if (!(edit->buffer.curs1 & M_EDIT_BUF_SIZE))
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
/* perform the insertion */ /* perform the insertion */
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE][edit->buffer.curs1 & M_EDIT_BUF_SIZE]
= (unsigned char) c; = (unsigned char) c;
/* update file length */ /* update file length */
edit->last_byte++; edit->last_byte++;
/* update cursor position */ /* update cursor position */
edit->curs1++; edit->buffer.curs1++;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -2728,7 +2699,7 @@ edit_insert_ahead (WEdit * edit, int c)
if (edit->last_byte >= SIZE_LIMIT) if (edit->last_byte >= SIZE_LIMIT)
return; return;
if (edit->curs1 < edit->start_display) if (edit->buffer.curs1 < edit->start_display)
{ {
edit->start_display++; edit->start_display++;
if (c == '\n') if (c == '\n')
@ -2747,17 +2718,17 @@ edit_insert_ahead (WEdit * edit, int c)
else else
edit_push_undo_action (edit, DELCHAR_BR); edit_push_undo_action (edit, DELCHAR_BR);
edit->mark1 += (edit->mark1 >= edit->curs1); edit->mark1 += (edit->mark1 >= edit->buffer.curs1);
edit->mark2 += (edit->mark2 >= edit->curs1); edit->mark2 += (edit->mark2 >= edit->buffer.curs1);
edit->last_get_rule += (edit->last_get_rule >= edit->curs1); edit->last_get_rule += (edit->last_get_rule >= edit->buffer.curs1);
if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) if (!((edit->buffer.curs2 + 1) & M_EDIT_BUF_SIZE))
edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); edit->buffer.buffers2[(edit->buffer.curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]
[EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; [EDIT_BUF_SIZE - (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1] = c;
edit->last_byte++; edit->last_byte++;
edit->curs2++; edit->buffer.curs2++;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -2782,14 +2753,14 @@ edit_delete (WEdit * edit, gboolean byte_delete)
int cw = 1; int cw = 1;
int i; int i;
if (edit->curs2 == 0) if (edit->buffer.curs2 == 0)
return 0; return 0;
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
/* if byte_delete == TRUE then delete only one byte not multibyte char */ /* if byte_delete == TRUE then delete only one byte not multibyte char */
if (edit->utf8 && !byte_delete) if (edit->utf8 && !byte_delete)
{ {
edit_get_utf (edit, edit->curs1, &cw); edit_get_utf (edit, edit->buffer.curs1, &cw);
if (cw < 1) if (cw < 1)
cw = 1; cw = 1;
} }
@ -2802,27 +2773,27 @@ edit_delete (WEdit * edit, gboolean byte_delete)
for (i = 1; i <= cw; i++) for (i = 1; i <= cw; i++)
{ {
if (edit->mark1 > edit->curs1) if (edit->mark1 > edit->buffer.curs1)
{ {
edit->mark1--; edit->mark1--;
edit->end_mark_curs--; edit->end_mark_curs--;
} }
if (edit->mark2 > edit->curs1) if (edit->mark2 > edit->buffer.curs1)
edit->mark2--; edit->mark2--;
if (edit->last_get_rule > edit->curs1) if (edit->last_get_rule > edit->buffer.curs1)
edit->last_get_rule--; edit->last_get_rule--;
p = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - p = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE -
((edit->curs2 - ((edit->buffer.curs2 -
1) & M_EDIT_BUF_SIZE) - 1]; 1) & M_EDIT_BUF_SIZE) - 1];
if (!(edit->curs2 & M_EDIT_BUF_SIZE)) if (!(edit->buffer.curs2 & M_EDIT_BUF_SIZE))
{ {
g_free (edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]); g_free (edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]);
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = NULL; edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE] = NULL;
} }
edit->last_byte--; edit->last_byte--;
edit->curs2--; edit->buffer.curs2--;
edit_push_undo_action (edit, p + 256); edit_push_undo_action (edit, p + 256);
} }
@ -2833,7 +2804,7 @@ edit_delete (WEdit * edit, gboolean byte_delete)
edit->total_lines--; edit->total_lines--;
edit->force |= REDRAW_AFTER_CURSOR; edit->force |= REDRAW_AFTER_CURSOR;
} }
if (edit->curs1 < edit->start_display) if (edit->buffer.curs1 < edit->start_display)
{ {
edit->start_display--; edit->start_display--;
if (p == '\n') if (p == '\n')
@ -2852,7 +2823,7 @@ edit_backspace (WEdit * edit, gboolean byte_delete)
int cw = 1; int cw = 1;
int i; int i;
if (edit->curs1 == 0) if (edit->buffer.curs1 == 0)
return 0; return 0;
if (edit->mark2 != edit->mark1) if (edit->mark2 != edit->mark1)
@ -2861,7 +2832,7 @@ edit_backspace (WEdit * edit, gboolean byte_delete)
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (edit->utf8 && !byte_delete) if (edit->utf8 && !byte_delete)
{ {
edit_get_prev_utf (edit, edit->curs1, &cw); edit_get_prev_utf (edit, edit->buffer.curs1, &cw);
if (cw < 1) if (cw < 1)
cw = 1; cw = 1;
} }
@ -2871,25 +2842,25 @@ edit_backspace (WEdit * edit, gboolean byte_delete)
for (i = 1; i <= cw; i++) for (i = 1; i <= cw; i++)
{ {
if (edit->mark1 >= edit->curs1) if (edit->mark1 >= edit->buffer.curs1)
{ {
edit->mark1--; edit->mark1--;
edit->end_mark_curs--; edit->end_mark_curs--;
} }
if (edit->mark2 >= edit->curs1) if (edit->mark2 >= edit->buffer.curs1)
edit->mark2--; edit->mark2--;
if (edit->last_get_rule >= edit->curs1) if (edit->last_get_rule >= edit->buffer.curs1)
edit->last_get_rule--; edit->last_get_rule--;
p = *(edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE] + p = *(edit->buffer.buffers1[(edit->buffer.curs1 - 1) >> S_EDIT_BUF_SIZE] +
((edit->curs1 - 1) & M_EDIT_BUF_SIZE)); ((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE));
if (((edit->curs1 - 1) & M_EDIT_BUF_SIZE) == 0) if (((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE) == 0)
{ {
g_free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]); g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]);
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = NULL; edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL;
} }
edit->last_byte--; edit->last_byte--;
edit->curs1--; edit->buffer.curs1--;
edit_push_undo_action (edit, p); edit_push_undo_action (edit, p);
} }
edit_modification (edit); edit_modification (edit);
@ -2901,7 +2872,7 @@ edit_backspace (WEdit * edit, gboolean byte_delete)
edit->force |= REDRAW_AFTER_CURSOR; edit->force |= REDRAW_AFTER_CURSOR;
} }
if (edit->curs1 < edit->start_display) if (edit->buffer.curs1 < edit->start_display)
{ {
edit->start_display--; edit->start_display--;
if (p == '\n') if (p == '\n')
@ -2924,25 +2895,25 @@ edit_cursor_move (WEdit * edit, off_t increment)
{ {
for (; increment < 0; increment++) for (; increment < 0; increment++)
{ {
if (edit->curs1 == 0) if (edit->buffer.curs1 == 0)
return; return;
edit_push_undo_action (edit, CURS_RIGHT); edit_push_undo_action (edit, CURS_RIGHT);
c = edit_get_byte (edit, edit->curs1 - 1); c = edit_get_byte (edit, edit->buffer.curs1 - 1);
if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) if (!((edit->buffer.curs2 + 1) & M_EDIT_BUF_SIZE))
edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); edit->buffer.buffers2[(edit->buffer.curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE -
(edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1] = c;
edit->curs2++; edit->buffer.curs2++;
c = edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->curs1 - c = edit->buffer.buffers1[(edit->buffer.curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->buffer.curs1 -
1) & M_EDIT_BUF_SIZE]; 1) & M_EDIT_BUF_SIZE];
if (!((edit->curs1 - 1) & M_EDIT_BUF_SIZE)) if (!((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE))
{ {
g_free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]); g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]);
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = NULL; edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL;
} }
edit->curs1--; edit->buffer.curs1--;
if (c == '\n') if (c == '\n')
{ {
edit->curs_line--; edit->curs_line--;
@ -2955,25 +2926,25 @@ edit_cursor_move (WEdit * edit, off_t increment)
{ {
for (; increment > 0; increment--) for (; increment > 0; increment--)
{ {
if (edit->curs2 == 0) if (edit->buffer.curs2 == 0)
return; return;
edit_push_undo_action (edit, CURS_LEFT); edit_push_undo_action (edit, CURS_LEFT);
c = edit_get_byte (edit, edit->curs1); c = edit_get_byte (edit, edit->buffer.curs1);
if (!(edit->curs1 & M_EDIT_BUF_SIZE)) if (!(edit->buffer.curs1 & M_EDIT_BUF_SIZE))
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = c; edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE][edit->buffer.curs1 & M_EDIT_BUF_SIZE] = c;
edit->curs1++; edit->buffer.curs1++;
c = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - c = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE -
((edit->curs2 - ((edit->buffer.curs2 -
1) & M_EDIT_BUF_SIZE) - 1]; 1) & M_EDIT_BUF_SIZE) - 1];
if (!(edit->curs2 & M_EDIT_BUF_SIZE)) if (!(edit->buffer.curs2 & M_EDIT_BUF_SIZE))
{ {
g_free (edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]); g_free (edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]);
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = 0; edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE] = 0;
} }
edit->curs2--; edit->buffer.curs2--;
if (c == '\n') if (c == '\n')
{ {
edit->curs_line++; edit->curs_line++;
@ -3151,7 +3122,7 @@ edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto)
long long
edit_get_col (const WEdit * edit) edit_get_col (const WEdit * edit)
{ {
return (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1); return (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, edit->buffer.curs1);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -3169,7 +3140,7 @@ edit_update_curs_row (WEdit * edit)
void void
edit_update_curs_col (WEdit * edit) edit_update_curs_col (WEdit * edit)
{ {
edit->curs_col = (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1); edit->curs_col = (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0, edit->buffer.curs1);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -3256,14 +3227,14 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
long prev = edit->prev_col; long prev = edit->prev_col;
long over = edit->over_col; long over = edit->over_col;
edit_cursor_move (edit, edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->curs1); edit_cursor_move (edit, edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1);
if (option_cursor_beyond_eol) if (option_cursor_beyond_eol)
{ {
long line_len; long line_len;
line_len = (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, line_len = (long) edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0,
edit_eol (edit, edit->curs1)); edit_eol (edit, edit->buffer.curs1));
if (line_len < prev + edit->over_col) if (line_len < prev + edit->over_col)
{ {
edit->over_col = prev + over - line_len; edit->over_col = prev + over - line_len;
@ -3293,11 +3264,11 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
q = edit->curs_col; q = edit->curs_col;
edit->curs_col -= (edit->curs_col % fake_half_tabs); edit->curs_col -= (edit->curs_col % fake_half_tabs);
p = edit_bol (edit, edit->curs1); p = edit_bol (edit, edit->buffer.curs1);
edit_cursor_move (edit, edit_cursor_move (edit,
edit_move_forward3 (edit, p, edit->curs_col, 0) - edit->curs1); edit_move_forward3 (edit, p, edit->curs_col, 0) - edit->buffer.curs1);
if (!left_of_four_spaces (edit)) if (!left_of_four_spaces (edit))
edit_cursor_move (edit, edit_move_forward3 (edit, p, q, 0) - edit->curs1); edit_cursor_move (edit, edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1);
} }
} }
} }
@ -3381,14 +3352,14 @@ edit_mark_cmd (WEdit * edit, gboolean unmark)
else if (edit->mark2 >= 0) else if (edit->mark2 >= 0)
{ {
edit->end_mark_curs = -1; edit->end_mark_curs = -1;
edit_set_markers (edit, edit->curs1, -1, edit->curs_col + edit->over_col, edit_set_markers (edit, edit->buffer.curs1, -1, edit->curs_col + edit->over_col,
edit->curs_col + edit->over_col); edit->curs_col + edit->over_col);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
} }
else else
{ {
edit->end_mark_curs = edit->curs1; edit->end_mark_curs = edit->buffer.curs1;
edit_set_markers (edit, edit->mark1, edit->curs1, edit->column1, edit_set_markers (edit, edit->mark1, edit->buffer.curs1, edit->column1,
edit->curs_col + edit->over_col); edit->curs_col + edit->over_col);
} }
} }
@ -3401,7 +3372,7 @@ edit_mark_current_word_cmd (WEdit * edit)
{ {
long pos; long pos;
for (pos = edit->curs1; pos != 0; pos--) for (pos = edit->buffer.curs1; pos != 0; pos--)
{ {
int c1, c2; int c1, c2;
@ -3435,7 +3406,7 @@ edit_mark_current_word_cmd (WEdit * edit)
void void
edit_mark_current_line_cmd (WEdit * edit) edit_mark_current_line_cmd (WEdit * edit)
{ {
long pos = edit->curs1; long pos = edit->buffer.curs1;
edit->mark1 = edit_bol (edit, pos); edit->mark1 = edit_bol (edit, pos);
edit->mark2 = edit_eol (edit, pos); edit->mark2 = edit_eol (edit, pos);
@ -3453,7 +3424,7 @@ edit_delete_line (WEdit * edit)
* Note that edit_get_byte() returns '\n' when byte position is * Note that edit_get_byte() returns '\n' when byte position is
* beyond EOF. * beyond EOF.
*/ */
while (edit_get_byte (edit, edit->curs1) != '\n') while (edit_get_byte (edit, edit->buffer.curs1) != '\n')
(void) edit_delete (edit, TRUE); (void) edit_delete (edit, TRUE);
/* /*
@ -3467,7 +3438,7 @@ edit_delete_line (WEdit * edit)
* Delete left part of the line. * Delete left part of the line.
* Note, that edit_get_byte() returns '\n' when byte position is < 0. * Note, that edit_get_byte() returns '\n' when byte position is < 0.
*/ */
while (edit_get_byte (edit, edit->curs1 - 1) != '\n') while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n')
(void) edit_backspace (edit, TRUE); (void) edit_backspace (edit, TRUE);
} }
@ -3663,7 +3634,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
edit_group_undo (edit); edit_group_undo (edit);
edit->found_len = 0; edit->found_len = 0;
edit->prev_col = edit_get_col (edit); edit->prev_col = edit_get_col (edit);
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
return; return;
} }
/* check for redo */ /* check for redo */
@ -3673,7 +3644,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
edit_do_redo (edit); edit_do_redo (edit);
edit->found_len = 0; edit->found_len = 0;
edit->prev_col = edit_get_col (edit); edit->prev_col = edit_get_col (edit);
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
return; return;
} }
@ -3692,7 +3663,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (!mc_global.utf8_display || edit->charpoint == 0) if (!mc_global.utf8_display || edit->charpoint == 0)
#endif #endif
if (edit_get_byte (edit, edit->curs1) != '\n') if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
edit_delete (edit, FALSE); edit_delete (edit, FALSE);
} }
@ -3735,7 +3706,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
check_and_wrap_line (edit); check_and_wrap_line (edit);
edit->found_len = 0; edit->found_len = 0;
edit->prev_col = edit_get_col (edit); edit->prev_col = edit_get_col (edit);
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
edit_find_bracket (edit); edit_find_bracket (edit);
return; return;
} }
@ -3801,7 +3772,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
edit->over_col--; edit->over_col--;
else if (option_backspace_through_tabs && is_in_indent (edit)) else if (option_backspace_through_tabs && is_in_indent (edit))
{ {
while (edit_get_byte (edit, edit->curs1 - 1) != '\n' && edit->curs1 > 0) while (edit_get_byte (edit, edit->buffer.curs1 - 1) != '\n' && edit->buffer.curs1 > 0)
edit_backspace (edit, TRUE); edit_backspace (edit, TRUE);
} }
else if (option_fake_half_tabs && is_in_indent (edit) && right_of_four_spaces (edit)) else if (option_fake_half_tabs && is_in_indent (edit) && right_of_four_spaces (edit))
@ -4297,13 +4268,13 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
case CK_ScrollDown: case CK_ScrollDown:
case CK_MarkScrollDown: case CK_MarkScrollDown:
case CK_MarkColumnScrollDown: case CK_MarkColumnScrollDown:
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
edit->found_len = 0; edit->found_len = 0;
break; break;
default: default:
edit->found_len = 0; edit->found_len = 0;
edit->prev_col = edit_get_col (edit); edit->prev_col = edit_get_col (edit);
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
} }
edit_find_bracket (edit); edit_find_bracket (edit);

87
src/editor/editbuffer.c Normal file
View File

@ -0,0 +1,87 @@
/*
Editor text keep buffer.
Copyright (C) 2013
The Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru> 2013
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* \brief Source: editor text keep buffer.
* \author Andrew Borodin
* \date 2013
*/
#include <config.h>
#include "lib/global.h"
#include "editbuffer.h"
/* --------------------------------------------------------------------------------------------- */
/*-
*
* here's a quick sketch of the layout: (don't run this through indent.)
*
* (b1 is buffers1 and b2 is buffers2)
*
* |
* \0\0\0\0\0m e _ f i l e . \nf i n . \n|T h i s _ i s _ s o\0\0\0\0\0\0\0\0\0
* ______________________________________|______________________________________
* |
* ... | b2[2] | b2[1] | b2[0] | b1[0] | b1[1] | b1[2] | ...
* |-> |-> |-> |-> |-> |-> |
* |
* _<------------------------->|<----------------->_
* curs2 | curs1
* ^ | ^
* | ^|^ |
* cursor ||| cursor
* |||
* file end|||file beginning
* |
* |
*
* _
* This_is_some_file
* fin.
*
*
* This is called a "gab buffer".
* See also:
* http://en.wikipedia.org/wiki/Gap_buffer
* http://stackoverflow.com/questions/4199694/data-structure-for-text-editor
*/
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */

54
src/editor/editbuffer.h Normal file
View File

@ -0,0 +1,54 @@
/** \file
* \brief Header: text keep buffer for WEdit
*/
#ifndef MC__EDIT_BUFFER_H
#define MC__EDIT_BUFFER_H
/*** typedefs(not structures) and defined constants **********************************************/
/*
* The editor keeps data in two arrays of buffers.
* All buffers have the same size, which must be a power of 2.
*/
/* Configurable: log2 of the buffer size in bytes */
#ifndef S_EDIT_BUF_SIZE
#define S_EDIT_BUF_SIZE 16
#endif
/* Size of the buffer */
#define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
/* Buffer mask (used to find cursor position relative to the buffer) */
#define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
/*
* Configurable: Maximal allowed number of buffers in each buffer array.
* This number can be increased for systems with enough physical memory.
*/
#ifndef MAXBUFF
#define MAXBUFF 1024
#endif
/* Maximal length of file that can be opened */
#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct edit_buffer_struct {
off_t curs1; /* position of the cursor from the beginning of the file. */
off_t curs2; /* position from the end of the file */
unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */
unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */
} edit_buffer_t;
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
/*** inline functions ****************************************************************************/
#endif /* MC__EDIT_BUFFER_H */

View File

@ -312,9 +312,9 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
off_t buf; off_t buf;
buf = 0; buf = 0;
filelen = edit->last_byte; filelen = edit->last_byte;
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) while (buf <= (edit->buffer.curs1 >> S_EDIT_BUF_SIZE) - 1)
{ {
if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) if (mc_write (fd, (char *) edit->buffer.buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE)
{ {
mc_close (fd); mc_close (fd);
goto error_save; goto error_save;
@ -322,20 +322,20 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
buf++; buf++;
} }
if (mc_write if (mc_write
(fd, (char *) edit->buffers1[buf], (fd, (char *) edit->buffer.buffers1[buf],
edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE)) edit->buffer.curs1 & M_EDIT_BUF_SIZE) != (edit->buffer.curs1 & M_EDIT_BUF_SIZE))
{ {
filelen = -1; filelen = -1;
} }
else if (edit->curs2) else if (edit->buffer.curs2 != 0)
{ {
edit->curs2--; edit->buffer.curs2--;
buf = (edit->curs2 >> S_EDIT_BUF_SIZE); buf = (edit->buffer.curs2 >> S_EDIT_BUF_SIZE);
if (mc_write if (mc_write
(fd, (fd,
(char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (char *) edit->buffer.buffers2[buf] + EDIT_BUF_SIZE -
(edit->curs2 & M_EDIT_BUF_SIZE) - 1, (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1,
1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) 1 + (edit->buffer.curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->buffer.curs2 & M_EDIT_BUF_SIZE))
{ {
filelen = -1; filelen = -1;
} }
@ -343,14 +343,14 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
{ {
while (--buf >= 0) while (--buf >= 0)
{ {
if (mc_write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) if (mc_write (fd, (char *) edit->buffer.buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE)
{ {
filelen = -1; filelen = -1;
break; break;
} }
} }
} }
edit->curs2++; edit->buffer.curs2++;
} }
if (mc_close (fd)) if (mc_close (fd))
goto error_save; goto error_save;
@ -556,24 +556,24 @@ edit_delete_column_of_text (WEdit * edit)
while (n--) while (n--)
{ {
r = edit_bol (edit, edit->curs1); r = edit_bol (edit, edit->buffer.curs1);
p = edit_move_forward3 (edit, r, b, 0); p = edit_move_forward3 (edit, r, b, 0);
q = edit_move_forward3 (edit, r, c, 0); q = edit_move_forward3 (edit, r, c, 0);
if (p < m1) if (p < m1)
p = m1; p = m1;
if (q > m2) if (q > m2)
q = m2; q = m2;
edit_cursor_move (edit, p - edit->curs1); edit_cursor_move (edit, p - edit->buffer.curs1);
while (q > p) while (q > p)
{ {
/* delete line between margins */ /* delete line between margins */
if (edit_get_byte (edit, edit->curs1) != '\n') if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
edit_delete (edit, TRUE); edit_delete (edit, TRUE);
q--; q--;
} }
if (n) if (n)
/* move to next line except on the last delete */ /* move to next line except on the last delete */
edit_cursor_move (edit, edit_move_forward (edit, edit->curs1, 1, 0) - edit->curs1); edit_cursor_move (edit, edit_move_forward (edit, edit->buffer.curs1, 1, 0) - edit->buffer.curs1);
} }
} }
@ -615,7 +615,7 @@ edit_block_delete (WEdit * edit)
curs_pos = edit->curs_col + edit->over_col; curs_pos = edit->curs_col + edit->over_col;
/* move cursor to start of selection */ /* move cursor to start of selection */
edit_cursor_move (edit, start_mark - edit->curs1); edit_cursor_move (edit, start_mark - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
if (start_mark < end_mark) if (start_mark < end_mark)
@ -630,8 +630,8 @@ edit_block_delete (WEdit * edit)
/* move cursor to the saved position */ /* move cursor to the saved position */
edit_move_to_line (edit, curs_line); edit_move_to_line (edit, curs_line);
/* calculate line width and cursor position before cut */ /* calculate line width and cursor position before cut */
line_width = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, line_width = edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0,
edit_eol (edit, edit->curs1)); edit_eol (edit, edit->buffer.curs1));
if (option_cursor_beyond_eol && curs_pos > line_width) if (option_cursor_beyond_eol && curs_pos > line_width)
edit->over_col = curs_pos - line_width; edit->over_col = curs_pos - line_width;
} }
@ -858,7 +858,7 @@ editcmd_find (WEdit * edit, gsize * len)
else else
{ {
if (edit_search_options.backwards) if (edit_search_options.backwards)
end_mark = max (1, edit->curs1) - 1; end_mark = max (1, edit->buffer.curs1) - 1;
} }
/* search */ /* search */
@ -950,7 +950,7 @@ edit_do_search (WEdit * edit)
gsize len = 0; gsize len = 0;
if (edit->search == NULL) if (edit->search == NULL)
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
edit_push_undo_action (edit, KEY_PRESS + edit->start_display); edit_push_undo_action (edit, KEY_PRESS + edit->start_display);
@ -981,7 +981,7 @@ edit_do_search (WEdit * edit)
if (found == 0) if (found == 0)
edit_error_dialog (_("Search"), _("Search string not found")); edit_error_dialog (_("Search"), _("Search string not found"));
else else
edit_cursor_move (edit, edit->search_start - edit->curs1); edit_cursor_move (edit, edit->search_start - edit->buffer.curs1);
} }
else else
{ {
@ -998,7 +998,7 @@ edit_do_search (WEdit * edit)
edit->found_start = edit->search_start = edit->search->normal_offset; edit->found_start = edit->search_start = edit->search->normal_offset;
edit->found_len = len; edit->found_len = len;
edit->over_col = 0; edit->over_col = 0;
edit_cursor_move (edit, edit->search_start - edit->curs1); edit_cursor_move (edit, edit->search_start - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
if (edit_search_options.backwards) if (edit_search_options.backwards)
edit->search_start--; edit->search_start--;
@ -1007,7 +1007,7 @@ edit_do_search (WEdit * edit)
} }
else else
{ {
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
if (edit->search->error_str != NULL) if (edit->search->error_str != NULL)
edit_error_dialog (_("Search"), edit->search->error_str); edit_error_dialog (_("Search"), edit->search->error_str);
} }
@ -1125,10 +1125,10 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
off_t i; off_t i;
/* return if at begin of file */ /* return if at begin of file */
if (edit->curs1 <= 0) if (edit->buffer.curs1 <= 0)
return FALSE; return FALSE;
c = edit_get_byte (edit, edit->curs1 - 1); c = edit_get_byte (edit, edit->buffer.curs1 - 1);
/* return if not at end or in word */ /* return if not at end or in word */
if (is_break_char (c)) if (is_break_char (c))
return FALSE; return FALSE;
@ -1137,11 +1137,11 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
for (i = 2;; i++) for (i = 2;; i++)
{ {
/* return if at begin of file */ /* return if at begin of file */
if (edit->curs1 < i) if (edit->buffer.curs1 < i)
return FALSE; return FALSE;
last = c; last = c;
c = edit_get_byte (edit, edit->curs1 - i); c = edit_get_byte (edit, edit->buffer.curs1 - i);
if (is_break_char (c)) if (is_break_char (c))
{ {
@ -1149,7 +1149,7 @@ edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
if (isdigit (last)) if (isdigit (last))
return FALSE; return FALSE;
*word_start = edit->curs1 - (i - 1); /* start found */ *word_start = edit->buffer.curs1 - (i - 1); /* start found */
*word_len = (gsize) (i - 1); *word_len = (gsize) (i - 1);
break; break;
} }
@ -1318,7 +1318,7 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
off_t i, cursor; off_t i, cursor;
long col; long col;
cursor = edit->curs1; cursor = edit->buffer.curs1;
col = edit_get_col (edit); col = edit_get_col (edit);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
@ -1330,16 +1330,16 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
long l; long l;
off_t p; off_t p;
if (edit_get_byte (edit, edit->curs1) != '\n') if (edit_get_byte (edit, edit->buffer.curs1) != '\n')
{ {
for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width) for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width)
edit_insert (edit, ' '); edit_insert (edit, ' ');
} }
for (p = edit->curs1;; p++) for (p = edit->buffer.curs1;; p++)
{ {
if (p == edit->last_byte) if (p == edit->last_byte)
{ {
edit_cursor_move (edit, edit->last_byte - edit->curs1); edit_cursor_move (edit, edit->last_byte - edit->buffer.curs1);
edit_insert_ahead (edit, '\n'); edit_insert_ahead (edit, '\n');
p++; p++;
break; break;
@ -1350,7 +1350,7 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
break; break;
} }
} }
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1); edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1);
for (l = col - edit_get_col (edit); l >= space_width; l -= space_width) for (l = col - edit_get_col (edit); l >= space_width; l -= space_width)
edit_insert (edit, ' '); edit_insert (edit, ' ');
@ -1360,8 +1360,8 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long
*col1 = col; *col1 = col;
*col2 = col + width; *col2 = col + width;
*start_pos = cursor; *start_pos = cursor;
*end_pos = edit->curs1; *end_pos = edit->buffer.curs1;
edit_cursor_move (edit, cursor - edit->curs1); edit_cursor_move (edit, cursor - edit->buffer.curs1);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -2259,7 +2259,7 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark)
long end_mark_curs; long end_mark_curs;
if (edit->end_mark_curs < 0) if (edit->end_mark_curs < 0)
end_mark_curs = edit->curs1; end_mark_curs = edit->buffer.curs1;
else else
end_mark_curs = edit->end_mark_curs; end_mark_curs = edit->end_mark_curs;
@ -2311,7 +2311,7 @@ eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark)
void void
edit_block_copy_cmd (WEdit * edit) edit_block_copy_cmd (WEdit * edit)
{ {
off_t start_mark, end_mark, current = edit->curs1; off_t start_mark, end_mark, current = edit->buffer.curs1;
long col_delta = 0; long col_delta = 0;
off_t mark1, mark2; off_t mark1, mark2;
long c1, c2; long c1, c2;
@ -2349,7 +2349,7 @@ edit_block_copy_cmd (WEdit * edit)
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
if (edit->column_highlight) if (edit->column_highlight)
edit_set_markers (edit, edit->curs1, mark2, c1, c2); edit_set_markers (edit, edit->buffer.curs1, mark2, c1, c2);
else if (start_mark < current && end_mark > current) else if (start_mark < current && end_mark > current)
edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0); edit_set_markers (edit, start_mark, end_mark + end_mark - start_mark, 0, 0);
@ -2369,7 +2369,7 @@ edit_block_move_cmd (WEdit * edit)
if (eval_marks (edit, &start_mark, &end_mark)) if (eval_marks (edit, &start_mark, &end_mark))
return; return;
if (!edit->column_highlight && edit->curs1 > start_mark && edit->curs1 < end_mark) if (!edit->column_highlight && edit->buffer.curs1 > start_mark && edit->buffer.curs1 < end_mark)
return; return;
if (edit->mark2 < 0) if (edit->mark2 < 0)
@ -2393,10 +2393,10 @@ edit_block_move_cmd (WEdit * edit)
x2 = x + edit->over_col; x2 = x + edit->over_col;
/* do nothing when cursor inside first line of selected area */ /* do nothing when cursor inside first line of selected area */
if ((edit_eol (edit, edit->curs1) == edit_eol (edit, start_mark)) && x2 > c1 && x2 <= c2) if ((edit_eol (edit, edit->buffer.curs1) == edit_eol (edit, start_mark)) && x2 > c1 && x2 <= c2)
return; return;
if (edit->curs1 > start_mark && edit->curs1 < edit_eol (edit, end_mark)) if (edit->buffer.curs1 > start_mark && edit->buffer.curs1 < edit_eol (edit, end_mark))
{ {
if (x > c2) if (x > c2)
x -= b_width; x -= b_width;
@ -2411,8 +2411,8 @@ edit_block_move_cmd (WEdit * edit)
edit->over_col = max (0, edit->over_col - b_width); edit->over_col = max (0, edit->over_col - b_width);
/* calculate the cursor pos after delete block */ /* calculate the cursor pos after delete block */
current = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), x, 0); current = edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), x, 0);
edit_cursor_move (edit, current - edit->curs1); edit_cursor_move (edit, current - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
/* add TWS if need before block insertion */ /* add TWS if need before block insertion */
@ -2426,9 +2426,9 @@ edit_block_move_cmd (WEdit * edit)
{ {
off_t count, count_orig; off_t count, count_orig;
current = edit->curs1; current = edit->buffer.curs1;
copy_buf = g_malloc0 (end_mark - start_mark); copy_buf = g_malloc0 (end_mark - start_mark);
edit_cursor_move (edit, start_mark - edit->curs1); edit_cursor_move (edit, start_mark - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
for (count = start_mark; count < end_mark; count++) for (count = start_mark; count < end_mark; count++)
@ -2436,14 +2436,14 @@ edit_block_move_cmd (WEdit * edit)
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
edit_cursor_move (edit, edit_cursor_move (edit,
current - edit->curs1 - current - edit->buffer.curs1 -
(((current - edit->curs1) > 0) ? end_mark - start_mark : 0)); (((current - edit->buffer.curs1) > 0) ? end_mark - start_mark : 0));
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
count_orig = count; count_orig = count;
while (count-- > start_mark) while (count-- > start_mark)
edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); 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_set_markers (edit, edit->buffer.curs1, edit->buffer.curs1 + end_mark - start_mark, 0, 0);
/* Place cursor at the end of text selection */ /* Place cursor at the end of text selection */
if (option_cursor_after_inserted_block) if (option_cursor_after_inserted_block)
@ -2545,7 +2545,7 @@ edit_replace_cmd (WEdit * edit, int again)
edit->search = mc_search_new (input1, -1); edit->search = mc_search_new (input1, -1);
if (edit->search == NULL) if (edit->search == NULL)
{ {
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
goto cleanup; goto cleanup;
} }
edit->search->search_type = edit_search_options.type; edit->search->search_type = edit_search_options.type;
@ -2591,7 +2591,7 @@ edit_replace_cmd (WEdit * edit, int again)
edit->found_start = edit->search_start; edit->found_start = edit->search_start;
i = edit->found_len = len; i = edit->found_len = len;
edit_cursor_move (edit, edit->search_start - edit->curs1); edit_cursor_move (edit, edit->search_start - edit->buffer.curs1);
edit_scroll_screen_over_cursor (edit); edit_scroll_screen_over_cursor (edit);
if (edit->replace_mode == 0) if (edit->replace_mode == 0)
@ -2673,7 +2673,7 @@ edit_replace_cmd (WEdit * edit, int again)
else else
{ {
/* try and find from right here for next search */ /* try and find from right here for next search */
edit->search_start = edit->curs1; edit->search_start = edit->buffer.curs1;
edit_update_curs_col (edit); edit_update_curs_col (edit);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
@ -3525,7 +3525,7 @@ edit_suggest_current_word (WEdit * edit)
char *match_word; char *match_word;
/* search start of word to spell check */ /* search start of word to spell check */
match_word = edit_get_word_from_pos (edit, edit->curs1, &word_start, &word_len, &cut_len); match_word = edit_get_word_from_pos (edit, edit->buffer.curs1, &word_start, &word_len, &cut_len);
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (mc_global.source_codepage >= 0 && (mc_global.source_codepage != mc_global.display_codepage)) if (mc_global.source_codepage >= 0 && (mc_global.source_codepage != mc_global.display_codepage))
@ -3600,7 +3600,7 @@ edit_spellcheck_file (WEdit * edit)
{ {
if (edit->curs_line > 0) if (edit->curs_line > 0)
{ {
edit_cursor_move (edit, -edit->curs1); edit_cursor_move (edit, -edit->buffer.curs1);
edit_move_to_prev_col (edit, 0); edit_move_to_prev_col (edit, 0);
edit_update_curs_row (edit); edit_update_curs_row (edit);
} }
@ -3609,16 +3609,16 @@ edit_spellcheck_file (WEdit * edit)
{ {
int c1, c2; int c1, c2;
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->buffer.curs1);
do do
{ {
if (edit->curs1 >= edit->last_byte) if (edit->buffer.curs1 >= edit->last_byte)
return; return;
c1 = c2; c1 = c2;
edit_cursor_move (edit, 1); edit_cursor_move (edit, 1);
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->buffer.curs1);
} }
while (is_break_char (c1) || is_break_char (c2)); while (is_break_char (c1) || is_break_char (c2));
} }

View File

@ -7,7 +7,7 @@
Written by: Written by:
Paul Sheer, 1996, 1997 Paul Sheer, 1996, 1997
Andrew Borodin <aborodin@vmail.ru> 2012 Andrew Borodin <aborodin@vmail.ru> 2012, 2013
Slava Zanko <slavazanko@gmail.com>, 2013 Slava Zanko <slavazanko@gmail.com>, 2013
This file is part of the Midnight Commander. This file is part of the Midnight Commander.
@ -114,7 +114,7 @@ status_string (WEdit * edit, char *s, int w)
* otherwise print the current character as is (if printable), * otherwise print the current character as is (if printable),
* as decimal and as hex. * as decimal and as hex.
*/ */
if (edit->curs1 < edit->last_byte) if (edit->buffer.curs1 < edit->last_byte)
{ {
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
if (edit->utf8) if (edit->utf8)
@ -122,7 +122,7 @@ status_string (WEdit * edit, char *s, int w)
unsigned int cur_utf = 0; unsigned int cur_utf = 0;
int cw = 1; int cw = 1;
cur_utf = edit_get_utf (edit, edit->curs1, &cw); cur_utf = edit_get_utf (edit, edit->buffer.curs1, &cw);
if (cw > 0) if (cw > 0)
{ {
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X", g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
@ -130,7 +130,7 @@ status_string (WEdit * edit, char *s, int w)
} }
else else
{ {
cur_utf = edit_get_byte (edit, edit->curs1); cur_utf = edit_get_byte (edit, edit->buffer.curs1);
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X", g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
(int) cur_utf, (unsigned) cur_utf); (int) cur_utf, (unsigned) cur_utf);
} }
@ -140,7 +140,7 @@ status_string (WEdit * edit, char *s, int w)
{ {
unsigned char cur_byte = 0; unsigned char cur_byte = 0;
cur_byte = edit_get_byte (edit, edit->curs1); cur_byte = edit_get_byte (edit, edit->buffer.curs1);
g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X", g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
(int) cur_byte, (unsigned) cur_byte); (int) cur_byte, (unsigned) cur_byte);
} }
@ -160,7 +160,7 @@ status_string (WEdit * edit, char *s, int w)
edit->overwrite == 0 ? '-' : 'O', edit->overwrite == 0 ? '-' : 'O',
edit->curs_col + edit->over_col, edit->curs_col + edit->over_col,
edit->curs_line + 1, edit->curs_line + 1,
edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str, edit->total_lines + 1, (long) edit->buffer.curs1, (long) edit->last_byte, byte_str,
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) :
#endif #endif
@ -176,7 +176,7 @@ status_string (WEdit * edit, char *s, int w)
edit->start_line + 1, edit->start_line + 1,
edit->curs_row, edit->curs_row,
edit->curs_line + 1, edit->curs_line + 1,
edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str, edit->total_lines + 1, (long) edit->buffer.curs1, (long) edit->last_byte, byte_str,
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) :
#endif #endif
@ -292,7 +292,7 @@ edit_status_window (WEdit * edit)
edit_move (2, w->lines - 1); edit_move (2, w->lines - 1);
tty_printf ("%3ld %5ld/%ld %6ld/%ld", tty_printf ("%3ld %5ld/%ld %6ld/%ld",
edit->curs_col + edit->over_col, edit->curs_col + edit->over_col,
edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte); edit->curs_line + 1, edit->total_lines + 1, edit->buffer.curs1, edit->last_byte);
} }
/* /*
@ -303,7 +303,7 @@ edit_status_window (WEdit * edit)
if (cols > 46) if (cols > 46)
{ {
edit_move (32, w->lines - 1); edit_move (32, w->lines - 1);
if (edit->curs1 >= edit->last_byte) if (edit->buffer.curs1 >= edit->last_byte)
tty_print_string ("[<EOF> ]"); tty_print_string ("[<EOF> ]");
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
else if (edit->utf8) else if (edit->utf8)
@ -311,9 +311,9 @@ edit_status_window (WEdit * edit)
unsigned int cur_utf; unsigned int cur_utf;
int cw = 1; int cw = 1;
cur_utf = edit_get_utf (edit, edit->curs1, &cw); cur_utf = edit_get_utf (edit, edit->buffer.curs1, &cw);
if (cw <= 0) if (cw <= 0)
cur_utf = edit_get_byte (edit, edit->curs1); cur_utf = edit_get_byte (edit, edit->buffer.curs1);
tty_printf ("[%05d 0x%04X]", cur_utf, cur_utf); tty_printf ("[%05d 0x%04X]", cur_utf, cur_utf);
} }
#endif #endif
@ -321,7 +321,7 @@ edit_status_window (WEdit * edit)
{ {
unsigned char cur_byte; unsigned char cur_byte;
cur_byte = edit_get_byte (edit, edit->curs1); cur_byte = edit_get_byte (edit, edit->buffer.curs1);
tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte); tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte);
} }
} }
@ -583,7 +583,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
p->ch = 0; p->ch = 0;
p->style = 0; p->style = 0;
if (q == edit->curs1) if (q == edit->buffer.curs1)
p->style |= MOD_CURSOR; p->style |= MOD_CURSOR;
if (q >= m1 && q < m2) if (q >= m1 && q < m2)
{ {
@ -935,7 +935,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
} }
/* if (force & REDRAW_LINE) ---> default */ /* if (force & REDRAW_LINE) ---> default */
b = edit_bol (edit, edit->curs1); b = edit_bol (edit, edit->buffer.curs1);
if (curs_row >= start_row && curs_row <= end_row) if (curs_row >= start_row && curs_row <= end_row)
{ {
if (key_pending (edit)) if (key_pending (edit))
@ -960,7 +960,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1) if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
{ {
row = curs_row - 1; row = curs_row - 1;
b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1); b = edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), 1);
if (row >= start_row && row <= end_row) if (row >= start_row && row <= end_row)
{ {
if (key_pending (edit)) if (key_pending (edit))
@ -972,7 +972,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1) if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1)
{ {
row = curs_row + 1; row = curs_row + 1;
b = edit_bol (edit, edit->curs1); b = edit_bol (edit, edit->buffer.curs1);
b = edit_move_forward (edit, b, 1, 0); b = edit_move_forward (edit, b, 1, 0);
if (row >= start_row && row <= end_row) if (row >= start_row && row <= end_row)
{ {
@ -987,18 +987,18 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
{ {
/* with the new text highlighting, we must draw from the top down */ /* with the new text highlighting, we must draw from the top down */
edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column); edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column); edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);
} }
else else
{ {
edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column); edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);
edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column); edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
} }
edit->force = 0; edit->force = 0;
prev_curs_row = edit->curs_row; prev_curs_row = edit->curs_row;
prev_curs = edit->curs1; prev_curs = edit->buffer.curs1;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -529,8 +529,8 @@ edit_event (Gpm_Event * event, void *data)
edit->prev_col = local.x - edit->start_col - option_line_state_width - 1; edit->prev_col = local.x - edit->start_col - option_line_state_width - 1;
else else
{ {
long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->buffer.curs1), 0,
edit_eol (edit, edit->curs1)); edit_eol (edit, edit->buffer.curs1));
if (local.x > line_len) if (local.x > line_len)
{ {
@ -552,7 +552,7 @@ edit_event (Gpm_Event * event, void *data)
else if (local.y < (edit->curs_row + 1)) else if (local.y < (edit->curs_row + 1))
edit_move_up (edit, (edit->curs_row + 1) - local.y, 0); edit_move_up (edit, (edit->curs_row + 1) - local.y, 0);
else else
edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1)); edit_move_to_prev_col (edit, edit_bol (edit, edit->buffer.curs1));
if ((local.type & GPM_DOWN) != 0) if ((local.type & GPM_DOWN) != 0)
{ {

View File

@ -9,6 +9,7 @@
#include "lib/widget.h" /* Widget */ #include "lib/widget.h" /* Widget */
#include "edit-impl.h" #include "edit-impl.h"
#include "editbuffer.h"
/*** typedefs(not structures) and defined constants **********************************************/ /*** typedefs(not structures) and defined constants **********************************************/
@ -74,10 +75,7 @@ struct WEdit
vfs_path_t *dir_vpath; /* NULL if filename is absolute */ vfs_path_t *dir_vpath; /* NULL if filename is absolute */
/* dynamic buffers and cursor position for editor: */ /* dynamic buffers and cursor position for editor: */
off_t curs1; /* position of the cursor from the beginning of the file. */ edit_buffer_t buffer;
off_t curs2; /* position from the end of the file */
unsigned char *buffers1[MAXBUFF + 1]; /* all data up to curs1 */
unsigned char *buffers2[MAXBUFF + 1]; /* all data from end of file down to curs2 */
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
/* multibyte support */ /* multibyte support */

View File

@ -2,13 +2,14 @@
Word-processor mode for the editor: does dynamic Word-processor mode for the editor: does dynamic
paragraph formatting. paragraph formatting.
Copyright (C) 2011 Copyright (C) 2011, 2013
The Free Software Foundation, Inc. The Free Software Foundation, Inc.
Copyright (C) 1996 Paul Sheer Copyright (C) 1996 Paul Sheer
Writen by: Writen by:
Paul Sheer, 1996 Paul Sheer, 1996
Andrew Borodin <aborodin@vmail.ru>, 2013
This file is part of the Midnight Commander. This file is part of the Midnight Commander.
@ -30,6 +31,8 @@
* \brief Source: word-processor mode for the editor: does dynamic paragraph formatting * \brief Source: word-processor mode for the editor: does dynamic paragraph formatting
* \author Paul Sheer * \author Paul Sheer
* \date 1996 * \date 1996
* \author Andrew Borodin
* \date 2013
*/ */
#include <config.h> #include <config.h>
@ -75,7 +78,7 @@ line_start (WEdit * edit, long line)
long l; long l;
l = edit->curs_line; l = edit->curs_line;
p = edit->curs1; p = edit->buffer.curs1;
if (line < l) if (line < l)
p = edit_move_backward (edit, p, l - line); p = edit_move_backward (edit, p, l - line);
@ -140,7 +143,7 @@ begin_paragraph (WEdit * edit, int force)
} }
} }
} }
return edit_move_backward (edit, edit_bol (edit, edit->curs1), edit->curs_line - i); return edit_move_backward (edit, edit_bol (edit, edit->buffer.curs1), edit->curs_line - i);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -168,7 +171,7 @@ end_paragraph (WEdit * edit, int force)
} }
} }
return edit_eol (edit, return edit_eol (edit,
edit_move_forward (edit, edit_bol (edit, edit->curs1), edit_move_forward (edit, edit_bol (edit, edit->buffer.curs1),
i - edit->curs_line, 0)); i - edit->curs_line, 0));
} }
@ -346,7 +349,7 @@ format_this (unsigned char *t, int size, int indent)
static inline void static inline void
replace_at (WEdit * edit, long q, int c) replace_at (WEdit * edit, long q, int c)
{ {
edit_cursor_move (edit, q - edit->curs1); edit_cursor_move (edit, q - edit->buffer.curs1);
edit_delete (edit, TRUE); edit_delete (edit, TRUE);
edit_insert_ahead (edit, c); edit_insert_ahead (edit, c);
} }
@ -360,7 +363,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
long cursor; long cursor;
int i, c = 0; int i, c = 0;
cursor = edit->curs1; cursor = edit->buffer.curs1;
if (indent) if (indent)
while (strchr ("\t ", edit_get_byte (edit, p))) while (strchr ("\t ", edit_get_byte (edit, p)))
p++; p++;
@ -376,30 +379,30 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
else if (t[i - 1] == '\n') else if (t[i - 1] == '\n')
{ {
off_t curs; off_t curs;
edit_cursor_move (edit, p - edit->curs1); edit_cursor_move (edit, p - edit->buffer.curs1);
curs = edit->curs1; curs = edit->buffer.curs1;
edit_insert_indent (edit, indent); edit_insert_indent (edit, indent);
if (cursor >= curs) if (cursor >= curs)
cursor += edit->curs1 - p; cursor += edit->buffer.curs1 - p;
p = edit->curs1; p = edit->buffer.curs1;
} }
else if (c == '\n') else if (c == '\n')
{ {
edit_cursor_move (edit, p - edit->curs1); edit_cursor_move (edit, p - edit->buffer.curs1);
while (strchr ("\t ", edit_get_byte (edit, p))) while (strchr ("\t ", edit_get_byte (edit, p)))
{ {
edit_delete (edit, TRUE); edit_delete (edit, TRUE);
if (cursor > edit->curs1) if (cursor > edit->buffer.curs1)
cursor--; cursor--;
} }
p = edit->curs1; p = edit->buffer.curs1;
} }
} }
c = edit_get_byte (edit, p); c = edit_get_byte (edit, p);
if (c != t[i]) if (c != t[i])
replace_at (edit, p, t[i]); replace_at (edit, p, t[i]);
} }
edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */ edit_cursor_move (edit, cursor - edit->buffer.curs1); /* restore cursor position */
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */