mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Refactoring of functions that operate with editor buffer.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
506b3d4eee
commit
25924c77d9
@ -153,9 +153,7 @@ void edit_menu_cmd (WDialog * h);
|
|||||||
void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
|
void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
|
||||||
void edit_init_menu (struct WMenuBar *menubar);
|
void edit_init_menu (struct WMenuBar *menubar);
|
||||||
void edit_save_mode_cmd (void);
|
void edit_save_mode_cmd (void);
|
||||||
off_t edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto);
|
|
||||||
off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto);
|
off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto);
|
||||||
off_t edit_move_backward (const WEdit * edit, off_t current, long lines);
|
|
||||||
void edit_scroll_screen_over_cursor (WEdit * edit);
|
void edit_scroll_screen_over_cursor (WEdit * edit);
|
||||||
void edit_render_keypress (WEdit * edit);
|
void edit_render_keypress (WEdit * edit);
|
||||||
void edit_scroll_upward (WEdit * edit, long i);
|
void edit_scroll_upward (WEdit * edit, long i);
|
||||||
@ -221,8 +219,6 @@ gboolean edit_save_block (WEdit * edit, const char *filename, off_t start, off_t
|
|||||||
gboolean edit_save_block_cmd (WEdit * edit);
|
gboolean edit_save_block_cmd (WEdit * edit);
|
||||||
gboolean edit_insert_file_cmd (WEdit * edit);
|
gboolean edit_insert_file_cmd (WEdit * edit);
|
||||||
|
|
||||||
char *edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len,
|
|
||||||
gsize * cut);
|
|
||||||
off_t edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
|
off_t edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
|
||||||
gboolean edit_load_back_cmd (WEdit * edit);
|
gboolean edit_load_back_cmd (WEdit * edit);
|
||||||
gboolean edit_load_forward_cmd (WEdit * edit);
|
gboolean edit_load_forward_cmd (WEdit * edit);
|
||||||
|
@ -145,7 +145,7 @@ static const struct edit_filters
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
|
edit_load_file_fast (edit_buffer_t * buf, const vfs_path_t * filename_vpath)
|
||||||
{
|
{
|
||||||
int file;
|
int file;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
@ -162,9 +162,9 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (edit_buffer_read_file (&edit->buffer, file, edit->buffer.size) == edit->buffer.size);
|
ret = (edit_buffer_read_file (buf, file, buf->size) == buf->size);
|
||||||
if (ret)
|
if (ret)
|
||||||
edit->buffer.lines = edit_buffer_count_lines (&edit->buffer, 0, edit->buffer.size);
|
buf->lines = edit_buffer_count_lines (buf, 0, buf->size);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gchar *errmsg;
|
gchar *errmsg;
|
||||||
@ -362,7 +362,7 @@ edit_load_file (WEdit * edit)
|
|||||||
{
|
{
|
||||||
edit_buffer_init (&edit->buffer, edit->stat1.st_size);
|
edit_buffer_init (&edit->buffer, edit->stat1.st_size);
|
||||||
|
|
||||||
if (!edit_load_file_fast (edit, edit->filename_vpath))
|
if (!edit_load_file_fast (&edit->buffer, edit->filename_vpath))
|
||||||
{
|
{
|
||||||
edit_clean (edit);
|
edit_clean (edit);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -563,12 +563,12 @@ edit_modification (WEdit * edit)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_in_indent (const WEdit * edit)
|
is_in_indent (const edit_buffer_t * buf)
|
||||||
{
|
{
|
||||||
off_t p;
|
off_t p;
|
||||||
|
|
||||||
for (p = edit_buffer_get_current_bol (&edit->buffer); p < edit->buffer.curs1; p++)
|
for (p = edit_buffer_get_current_bol (buf); p < buf->curs1; p++)
|
||||||
if (strchr (" \t", edit_buffer_get_byte (&edit->buffer, p)) == NULL)
|
if (strchr (" \t", edit_buffer_get_byte (buf, p)) == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -584,16 +584,17 @@ is_in_indent (const WEdit * edit)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_blank (const WEdit * edit, off_t offset)
|
is_blank (const edit_buffer_t * buf, off_t offset)
|
||||||
{
|
{
|
||||||
off_t s, f;
|
off_t s, f;
|
||||||
int c;
|
|
||||||
|
|
||||||
s = edit_buffer_get_bol (&edit->buffer, offset);
|
s = edit_buffer_get_bol (buf, offset);
|
||||||
f = edit_buffer_get_eol (&edit->buffer, offset) - 1;
|
f = edit_buffer_get_eol (buf, offset) - 1;
|
||||||
while (s <= f)
|
while (s <= f)
|
||||||
{
|
{
|
||||||
c = edit_buffer_get_byte (&edit->buffer, s++);
|
int c;
|
||||||
|
|
||||||
|
c = edit_buffer_get_byte (buf, s++);
|
||||||
if (!isspace (c))
|
if (!isspace (c))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -644,10 +645,12 @@ edit_find_line (WEdit * edit, long line)
|
|||||||
i = 3 + (rand () % (N_LINE_CACHES - 3));
|
i = 3 + (rand () % (N_LINE_CACHES - 3));
|
||||||
if (line > edit->line_numbers[j])
|
if (line > edit->line_numbers[j])
|
||||||
edit->line_offsets[i] =
|
edit->line_offsets[i] =
|
||||||
edit_move_forward (edit, edit->line_offsets[j], line - edit->line_numbers[j], 0);
|
edit_buffer_move_forward (&edit->buffer, edit->line_offsets[j],
|
||||||
|
line - edit->line_numbers[j], 0);
|
||||||
else
|
else
|
||||||
edit->line_offsets[i] =
|
edit->line_offsets[i] =
|
||||||
edit_move_backward (edit, edit->line_offsets[j], edit->line_numbers[j] - line);
|
edit_buffer_move_backward (&edit->buffer, edit->line_offsets[j],
|
||||||
|
edit->line_numbers[j] - line);
|
||||||
edit->line_numbers[i] = line;
|
edit->line_numbers[i] = line;
|
||||||
return edit->line_offsets[i];
|
return edit->line_offsets[i];
|
||||||
}
|
}
|
||||||
@ -965,14 +968,11 @@ edit_left_char_move_cmd (WEdit * edit)
|
|||||||
cw = 1;
|
cw = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (option_cursor_beyond_eol && edit->over_col > 0)
|
if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||||
{
|
|
||||||
edit->over_col--;
|
edit->over_col--;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
edit_cursor_move (edit, -cw);
|
edit_cursor_move (edit, -cw);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -1003,7 +1003,8 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi
|
|||||||
edit_scroll_downward (edit, lines);
|
edit_scroll_downward (edit, lines);
|
||||||
}
|
}
|
||||||
p = edit_buffer_get_current_bol (&edit->buffer);
|
p = edit_buffer_get_current_bol (&edit->buffer);
|
||||||
p = direction ? edit_move_backward (edit, p, lines) : edit_move_forward (edit, p, lines, 0);
|
p = direction ? edit_buffer_move_backward (&edit->buffer, p, lines) :
|
||||||
|
edit_buffer_move_forward (&edit->buffer, p, lines, 0);
|
||||||
edit_cursor_move (edit, p - edit->buffer.curs1);
|
edit_cursor_move (edit, p - edit->buffer.curs1);
|
||||||
edit_move_to_prev_col (edit, p);
|
edit_move_to_prev_col (edit, p);
|
||||||
|
|
||||||
@ -1308,7 +1309,7 @@ edit_auto_indent (WEdit * edit)
|
|||||||
|
|
||||||
p = edit->buffer.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_buffer_move_backward (&edit->buffer, p, 1);
|
||||||
/* copy the leading whitespace of the line */
|
/* copy the leading whitespace of the line */
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{ /* no range check - the line _is_ \n-terminated */
|
{ /* no range check - the line _is_ \n-terminated */
|
||||||
@ -1359,7 +1360,7 @@ insert_spaces_tab (WEdit * edit, gboolean half)
|
|||||||
static inline void
|
static inline void
|
||||||
edit_tab_cmd (WEdit * edit)
|
edit_tab_cmd (WEdit * edit)
|
||||||
{
|
{
|
||||||
if (option_fake_half_tabs && is_in_indent (edit))
|
if (option_fake_half_tabs && is_in_indent (&edit->buffer))
|
||||||
{
|
{
|
||||||
/* insert a half tab (usually four spaces) unless there is a
|
/* insert a half tab (usually four spaces) unless there is a
|
||||||
half tab already behind, then delete it and insert a
|
half tab already behind, then delete it and insert a
|
||||||
@ -1850,43 +1851,6 @@ is_break_char (char c)
|
|||||||
return (isspace (c) || strchr ("{}[]()<>=|/\\!?~-+`'\",.;:#$%^&*", c));
|
return (isspace (c) || strchr ("{}[]()<>=|/\\!?~-+`'\",.;:#$%^&*", c));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
char *
|
|
||||||
edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len,
|
|
||||||
gsize * cut)
|
|
||||||
{
|
|
||||||
off_t word_start;
|
|
||||||
long cut_len = 0;
|
|
||||||
GString *match_expr;
|
|
||||||
int c1, c2;
|
|
||||||
|
|
||||||
for (word_start = start_pos; word_start != 0; word_start--, cut_len++)
|
|
||||||
{
|
|
||||||
c1 = edit_buffer_get_byte (&edit->buffer, word_start);
|
|
||||||
c2 = edit_buffer_get_byte (&edit->buffer, word_start - 1);
|
|
||||||
|
|
||||||
if (is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
match_expr = g_string_sized_new (16);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
c1 = edit_buffer_get_byte (&edit->buffer, word_start + match_expr->len);
|
|
||||||
c2 = edit_buffer_get_byte (&edit->buffer, word_start + match_expr->len + 1);
|
|
||||||
g_string_append_c (match_expr, c1);
|
|
||||||
}
|
|
||||||
while (!(is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n'));
|
|
||||||
|
|
||||||
*len = match_expr->len;
|
|
||||||
*start = word_start;
|
|
||||||
*cut = cut_len;
|
|
||||||
|
|
||||||
return g_string_free (match_expr, FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/** inserts a file at the cursor, returns count of inserted bytes on success */
|
/** inserts a file at the cursor, returns count of inserted bytes on success */
|
||||||
|
|
||||||
@ -2226,7 +2190,6 @@ edit_set_codeset (WEdit * edit)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2360,6 +2323,8 @@ edit_push_undo_action (WEdit * edit, long c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
edit_push_redo_action (WEdit * edit, long c)
|
edit_push_redo_action (WEdit * edit, long c)
|
||||||
{
|
{
|
||||||
@ -2708,46 +2673,6 @@ edit_cursor_move (WEdit * edit, off_t increment)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
/* If lines is zero this returns the count of lines from current to upto. */
|
|
||||||
/* If upto is zero returns index of lines forward current. */
|
|
||||||
|
|
||||||
off_t
|
|
||||||
edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto)
|
|
||||||
{
|
|
||||||
if (upto != 0)
|
|
||||||
return (off_t) edit_buffer_count_lines (&edit->buffer, current, upto);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
long next;
|
|
||||||
if (lines < 0)
|
|
||||||
lines = 0;
|
|
||||||
while (lines-- != 0)
|
|
||||||
{
|
|
||||||
next = edit_buffer_get_eol (&edit->buffer, current) + 1;
|
|
||||||
if (next > edit->buffer.size)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
current = next;
|
|
||||||
}
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
/** Returns offset of 'lines' lines up from current */
|
|
||||||
|
|
||||||
off_t
|
|
||||||
edit_move_backward (const WEdit * edit, off_t current, long lines)
|
|
||||||
{
|
|
||||||
if (lines < 0)
|
|
||||||
lines = 0;
|
|
||||||
current = edit_buffer_get_bol (&edit->buffer, current);
|
|
||||||
while (lines-- != 0 && current != 0)
|
|
||||||
current = edit_buffer_get_bol (&edit->buffer, current - 1);
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* If cols is zero this returns the count of columns from current to upto. */
|
/* If cols is zero this returns the count of columns from current to upto. */
|
||||||
/* If upto is zero returns index of cols across from current. */
|
/* If upto is zero returns index of cols across from current. */
|
||||||
@ -2869,7 +2794,7 @@ edit_scroll_upward (WEdit * edit, long i)
|
|||||||
if (i != 0)
|
if (i != 0)
|
||||||
{
|
{
|
||||||
edit->start_line -= i;
|
edit->start_line -= i;
|
||||||
edit->start_display = edit_move_backward (edit, edit->start_display, i);
|
edit->start_display = edit_buffer_move_backward (&edit->buffer, edit->start_display, i);
|
||||||
edit->force |= REDRAW_PAGE;
|
edit->force |= REDRAW_PAGE;
|
||||||
edit->force &= (0xfff - REDRAW_CHAR_ONLY);
|
edit->force &= (0xfff - REDRAW_CHAR_ONLY);
|
||||||
}
|
}
|
||||||
@ -2890,7 +2815,7 @@ edit_scroll_downward (WEdit * edit, long i)
|
|||||||
if (i > lines_below)
|
if (i > lines_below)
|
||||||
i = lines_below;
|
i = lines_below;
|
||||||
edit->start_line += i;
|
edit->start_line += i;
|
||||||
edit->start_display = edit_move_forward (edit, edit->start_display, i, 0);
|
edit->start_display = edit_buffer_move_forward (&edit->buffer, edit->start_display, i, 0);
|
||||||
edit->force |= REDRAW_PAGE;
|
edit->force |= REDRAW_PAGE;
|
||||||
edit->force &= (0xfff - REDRAW_CHAR_ONLY);
|
edit->force &= (0xfff - REDRAW_CHAR_ONLY);
|
||||||
}
|
}
|
||||||
@ -2956,7 +2881,7 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
edit->over_col = 0;
|
edit->over_col = 0;
|
||||||
if (option_fake_half_tabs && is_in_indent (edit))
|
if (option_fake_half_tabs && is_in_indent (&edit->buffer))
|
||||||
{
|
{
|
||||||
long fake_half_tabs;
|
long fake_half_tabs;
|
||||||
|
|
||||||
@ -2991,7 +2916,7 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
|
|||||||
gboolean
|
gboolean
|
||||||
edit_line_is_blank (WEdit * edit, long line)
|
edit_line_is_blank (WEdit * edit, long line)
|
||||||
{
|
{
|
||||||
return is_blank (edit, edit_find_line (edit, line));
|
return is_blank (&edit->buffer, edit_find_line (edit, line));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -3442,13 +3367,14 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
|||||||
edit_block_delete_cmd (edit);
|
edit_block_delete_cmd (edit);
|
||||||
else if (option_cursor_beyond_eol && edit->over_col > 0)
|
else if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||||
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->buffer))
|
||||||
{
|
{
|
||||||
while (edit_buffer_get_previous_byte (&edit->buffer) != '\n'
|
while (edit_buffer_get_previous_byte (&edit->buffer) != '\n'
|
||||||
&& edit->buffer.curs1 > 0)
|
&& 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->buffer)
|
||||||
|
&& right_of_four_spaces (edit))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -3467,7 +3393,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
|||||||
if (option_cursor_beyond_eol && edit->over_col > 0)
|
if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||||
edit_insert_over (edit);
|
edit_insert_over (edit);
|
||||||
|
|
||||||
if (option_fake_half_tabs && is_in_indent (edit) && left_of_four_spaces (edit))
|
if (option_fake_half_tabs && is_in_indent (&edit->buffer) && left_of_four_spaces (edit))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -3533,7 +3459,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
|||||||
edit->column_highlight = 1;
|
edit->column_highlight = 1;
|
||||||
case CK_Left:
|
case CK_Left:
|
||||||
case CK_MarkLeft:
|
case CK_MarkLeft:
|
||||||
if (option_fake_half_tabs && is_in_indent (edit) && right_of_four_spaces (edit))
|
if (option_fake_half_tabs && is_in_indent (&edit->buffer) && right_of_four_spaces (edit))
|
||||||
{
|
{
|
||||||
if (option_cursor_beyond_eol && edit->over_col > 0)
|
if (option_cursor_beyond_eol && edit->over_col > 0)
|
||||||
edit->over_col--;
|
edit->over_col--;
|
||||||
@ -3548,7 +3474,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
|||||||
edit->column_highlight = 1;
|
edit->column_highlight = 1;
|
||||||
case CK_Right:
|
case CK_Right:
|
||||||
case CK_MarkRight:
|
case CK_MarkRight:
|
||||||
if (option_fake_half_tabs && is_in_indent (edit) && left_of_four_spaces (edit))
|
if (option_fake_half_tabs && is_in_indent (&edit->buffer) && left_of_four_spaces (edit))
|
||||||
{
|
{
|
||||||
edit_cursor_move (edit, HALF_TAB_SIZE);
|
edit_cursor_move (edit, HALF_TAB_SIZE);
|
||||||
edit->force &= (0xFFF - REDRAW_CHAR_ONLY);
|
edit->force &= (0xFFF - REDRAW_CHAR_ONLY);
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include "lib/vfs/vfs.h"
|
#include "lib/vfs/vfs.h"
|
||||||
|
|
||||||
|
#include "edit-impl.h"
|
||||||
#include "editbuffer.h"
|
#include "editbuffer.h"
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -373,6 +374,52 @@ edit_buffer_get_eol (const edit_buffer_t * buf, off_t current)
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Get word from specified offset.
|
||||||
|
*
|
||||||
|
* @param buf editor buffer
|
||||||
|
* @param current start_pos offset
|
||||||
|
* @param start actual start word ofset
|
||||||
|
* @param cut
|
||||||
|
*
|
||||||
|
* @return word as newly allocated object
|
||||||
|
*/
|
||||||
|
|
||||||
|
GString *
|
||||||
|
edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start,
|
||||||
|
gsize * cut)
|
||||||
|
{
|
||||||
|
off_t word_start;
|
||||||
|
long cut_len = 0;
|
||||||
|
GString *match_expr;
|
||||||
|
int c1, c2;
|
||||||
|
|
||||||
|
for (word_start = start_pos; word_start != 0; word_start--, cut_len++)
|
||||||
|
{
|
||||||
|
c1 = edit_buffer_get_byte (buf, word_start);
|
||||||
|
c2 = edit_buffer_get_byte (buf, word_start - 1);
|
||||||
|
|
||||||
|
if (is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
match_expr = g_string_sized_new (16);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
c1 = edit_buffer_get_byte (buf, word_start + match_expr->len);
|
||||||
|
c2 = edit_buffer_get_byte (buf, word_start + match_expr->len + 1);
|
||||||
|
g_string_append_c (match_expr, c1);
|
||||||
|
}
|
||||||
|
while (!(is_break_char (c1) != is_break_char (c2) || c1 == '\n' || c2 == '\n'));
|
||||||
|
|
||||||
|
*start = word_start;
|
||||||
|
*cut = cut_len;
|
||||||
|
|
||||||
|
return match_expr;
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* Basic low level single character buffer alterations and movements at the cursor: insert character
|
* Basic low level single character buffer alterations and movements at the cursor: insert character
|
||||||
@ -503,6 +550,65 @@ edit_buffer_backspace (edit_buffer_t * buf)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Calculate forward offset with specified number of lines.
|
||||||
|
*
|
||||||
|
* @param buf editor buffer
|
||||||
|
* @param current current offset
|
||||||
|
* @param lines number of lines to move forward
|
||||||
|
* @param upto offset to count lines between current and upto.
|
||||||
|
*
|
||||||
|
* @return If lines is zero returns the count of lines from current to upto.
|
||||||
|
* If upto is zero returns offset of lines forward current.
|
||||||
|
* Else returns forward offset with specified number of lines
|
||||||
|
*/
|
||||||
|
|
||||||
|
off_t
|
||||||
|
edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, off_t upto)
|
||||||
|
{
|
||||||
|
long next;
|
||||||
|
|
||||||
|
if (upto != 0)
|
||||||
|
return (off_t) edit_buffer_count_lines (buf, current, upto);
|
||||||
|
|
||||||
|
lines = max (lines, 0);
|
||||||
|
|
||||||
|
while (lines-- != 0)
|
||||||
|
{
|
||||||
|
next = edit_buffer_get_eol (buf, current) + 1;
|
||||||
|
if (next > buf->size)
|
||||||
|
break;
|
||||||
|
current = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Calculate backward offset with specified number of lines.
|
||||||
|
*
|
||||||
|
* @param buf editor buffer
|
||||||
|
* @param current current offset
|
||||||
|
* @param lines number of lines to move bacward
|
||||||
|
*
|
||||||
|
* @return backward offset with specified number of lines.
|
||||||
|
*/
|
||||||
|
|
||||||
|
off_t
|
||||||
|
edit_buffer_move_backward (const edit_buffer_t * buf, off_t current, long lines)
|
||||||
|
{
|
||||||
|
lines = max (lines, 0);
|
||||||
|
current = edit_buffer_get_bol (buf, current);
|
||||||
|
|
||||||
|
while (lines-- != 0 && current != 0)
|
||||||
|
current = edit_buffer_get_bol (buf, current - 1);
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* Load file into editor buffer
|
* Load file into editor buffer
|
||||||
|
@ -64,12 +64,17 @@ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *
|
|||||||
long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last);
|
long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last);
|
||||||
off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current);
|
off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current);
|
||||||
off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current);
|
off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current);
|
||||||
|
GString *edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start,
|
||||||
|
gsize * cut);
|
||||||
|
|
||||||
void edit_buffer_insert (edit_buffer_t * buf, int c);
|
void edit_buffer_insert (edit_buffer_t * buf, int c);
|
||||||
void edit_buffer_insert_ahead (edit_buffer_t * buf, int c);
|
void edit_buffer_insert_ahead (edit_buffer_t * buf, int c);
|
||||||
int edit_buffer_delete (edit_buffer_t * buf);
|
int edit_buffer_delete (edit_buffer_t * buf);
|
||||||
int edit_buffer_backspace (edit_buffer_t * buf);
|
int edit_buffer_backspace (edit_buffer_t * buf);
|
||||||
|
|
||||||
|
off_t edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, off_t upto);
|
||||||
|
off_t edit_buffer_move_backward (const edit_buffer_t * buf, off_t current, long lines);
|
||||||
|
|
||||||
off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size);
|
off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size);
|
||||||
off_t edit_buffer_write_file (edit_buffer_t * buf, int fd);
|
off_t edit_buffer_write_file (edit_buffer_t * buf, int fd);
|
||||||
|
|
||||||
|
@ -393,13 +393,13 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
edit_check_newline (WEdit * edit)
|
edit_check_newline (const edit_buffer_t * buf)
|
||||||
{
|
{
|
||||||
return !(option_check_nl_at_eof && edit->buffer.size > 0
|
return !(option_check_nl_at_eof && buf->size > 0
|
||||||
&& edit_buffer_get_byte (&edit->buffer, edit->buffer.size - 1) != '\n'
|
&& edit_buffer_get_byte (buf, buf->size - 1) != '\n'
|
||||||
&& edit_query_dialog2 (_("Warning"),
|
&& edit_query_dialog2 (_("Warning"),
|
||||||
_("The file you are saving is not finished with a newline"),
|
_("The file you are saving is not finished with a newline"),
|
||||||
_("C&ontinue"), _("&Cancel")));
|
_("C&ontinue"), _("&Cancel")) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -511,7 +511,7 @@ edit_delete_column_of_text (WEdit * edit)
|
|||||||
long b, c, d;
|
long b, c, d;
|
||||||
|
|
||||||
eval_marks (edit, &m1, &m2);
|
eval_marks (edit, &m1, &m2);
|
||||||
n = edit_move_forward (edit, m1, 0, m2) + 1;
|
n = edit_buffer_move_forward (&edit->buffer, m1, 0, m2) + 1;
|
||||||
c = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m1), 0, m1);
|
c = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m1), 0, m1);
|
||||||
d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2), 0, m2);
|
d = (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, m2), 0, m2);
|
||||||
b = max (min (c, d), min (edit->column1, edit->column2));
|
b = max (min (c, d), min (edit->column1, edit->column2));
|
||||||
@ -536,7 +536,8 @@ edit_delete_column_of_text (WEdit * edit)
|
|||||||
}
|
}
|
||||||
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->buffer.curs1, 1, 0) - edit->buffer.curs1);
|
edit_cursor_move (edit, edit_buffer_move_forward (&edit->buffer, edit->buffer.curs1, 1, 0) -
|
||||||
|
edit->buffer.curs1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,7 +660,7 @@ edit_get_search_line_type (mc_search_t * search)
|
|||||||
/**
|
/**
|
||||||
* Calculating the start position of next line.
|
* Calculating the start position of next line.
|
||||||
*
|
*
|
||||||
* @param edit editor object
|
* @param buf editor buffer object
|
||||||
* @param current_pos current position
|
* @param current_pos current position
|
||||||
* @param max_pos max position
|
* @param max_pos max position
|
||||||
* @param end_string_symbol end of line symbol
|
* @param end_string_symbol end of line symbol
|
||||||
@ -667,7 +668,7 @@ edit_get_search_line_type (mc_search_t * search)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static off_t
|
static off_t
|
||||||
edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_pos,
|
edit_calculate_start_of_next_line (const edit_buffer_t * buf, off_t current_pos, off_t max_pos,
|
||||||
char end_string_symbol)
|
char end_string_symbol)
|
||||||
{
|
{
|
||||||
off_t i;
|
off_t i;
|
||||||
@ -675,7 +676,7 @@ edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_po
|
|||||||
for (i = current_pos; i < max_pos; i++)
|
for (i = current_pos; i < max_pos; i++)
|
||||||
{
|
{
|
||||||
current_pos++;
|
current_pos++;
|
||||||
if (edit_buffer_get_byte (&edit->buffer, i) == end_string_symbol)
|
if (edit_buffer_get_byte (buf, i) == end_string_symbol)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,19 +687,19 @@ edit_calculate_start_of_next_line (WEdit * edit, off_t current_pos, off_t max_po
|
|||||||
/**
|
/**
|
||||||
* Calculating the end position of previous line.
|
* Calculating the end position of previous line.
|
||||||
*
|
*
|
||||||
* @param edit editor object
|
* @param buf editor buffer object
|
||||||
* @param current_pos current position
|
* @param current_pos current position
|
||||||
* @param end_string_symbol end of line symbol
|
* @param end_string_symbol end of line symbol
|
||||||
* @return end position of previous line
|
* @return end position of previous line
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static off_t
|
static off_t
|
||||||
edit_calculate_end_of_previous_line (WEdit * edit, off_t current_pos, char end_string_symbol)
|
edit_calculate_end_of_previous_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol)
|
||||||
{
|
{
|
||||||
off_t i;
|
off_t i;
|
||||||
|
|
||||||
for (i = current_pos - 1; i >= 0; i--)
|
for (i = current_pos - 1; i >= 0; i--)
|
||||||
if (edit_buffer_get_byte (&edit->buffer, i) == end_string_symbol)
|
if (edit_buffer_get_byte (buf, i) == end_string_symbol)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
@ -708,17 +709,17 @@ edit_calculate_end_of_previous_line (WEdit * edit, off_t current_pos, char end_s
|
|||||||
/**
|
/**
|
||||||
* Calculating the start position of previous line.
|
* Calculating the start position of previous line.
|
||||||
*
|
*
|
||||||
* @param edit editor object
|
* @param buf editor buffer object
|
||||||
* @param current_pos current position
|
* @param current_pos current position
|
||||||
* @param end_string_symbol end of line symbol
|
* @param end_string_symbol end of line symbol
|
||||||
* @return start position of previous line
|
* @return start position of previous line
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline off_t
|
static inline off_t
|
||||||
edit_calculate_start_of_previous_line (WEdit * edit, off_t current_pos, char end_string_symbol)
|
edit_calculate_start_of_previous_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol)
|
||||||
{
|
{
|
||||||
current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol);
|
current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol);
|
||||||
current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol);
|
current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol);
|
||||||
|
|
||||||
return (current_pos + 1);
|
return (current_pos + 1);
|
||||||
}
|
}
|
||||||
@ -727,16 +728,16 @@ edit_calculate_start_of_previous_line (WEdit * edit, off_t current_pos, char end
|
|||||||
/**
|
/**
|
||||||
* Calculating the start position of current line.
|
* Calculating the start position of current line.
|
||||||
*
|
*
|
||||||
* @param edit editor object
|
* @param buf editor buffer object
|
||||||
* @param current_pos current position
|
* @param current_pos current position
|
||||||
* @param end_string_symbol end of line symbol
|
* @param end_string_symbol end of line symbol
|
||||||
* @return start position of current line
|
* @return start position of current line
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline off_t
|
static inline off_t
|
||||||
edit_calculate_start_of_current_line (WEdit * edit, off_t current_pos, char end_string_symbol)
|
edit_calculate_start_of_current_line (const edit_buffer_t * buf, off_t current_pos, char end_string_symbol)
|
||||||
{
|
{
|
||||||
current_pos = edit_calculate_end_of_previous_line (edit, current_pos, end_string_symbol);
|
current_pos = edit_calculate_end_of_previous_line (buf, current_pos, end_string_symbol);
|
||||||
|
|
||||||
return (current_pos + 1);
|
return (current_pos + 1);
|
||||||
}
|
}
|
||||||
@ -802,15 +803,13 @@ editcmd_find (WEdit * edit, gsize * len)
|
|||||||
&& (start_mark != 0 || edit_buffer_get_byte (&edit->buffer, start_mark - 1) != end_string_symbol))
|
&& (start_mark != 0 || edit_buffer_get_byte (&edit->buffer, start_mark - 1) != end_string_symbol))
|
||||||
{
|
{
|
||||||
start_mark =
|
start_mark =
|
||||||
edit_calculate_start_of_next_line (edit, start_mark, edit->buffer.size,
|
edit_calculate_start_of_next_line (&edit->buffer, start_mark, edit->buffer.size,
|
||||||
end_string_symbol);
|
end_string_symbol);
|
||||||
}
|
}
|
||||||
if ((edit->search_line_type & AT_END_LINE) != 0
|
if ((edit->search_line_type & AT_END_LINE) != 0
|
||||||
&& (end_mark - 1 != edit->buffer.size
|
&& (end_mark - 1 != edit->buffer.size
|
||||||
|| edit_buffer_get_byte (&edit->buffer, end_mark) != end_string_symbol))
|
|| edit_buffer_get_byte (&edit->buffer, end_mark) != end_string_symbol))
|
||||||
{
|
end_mark = edit_calculate_end_of_previous_line (&edit->buffer, end_mark, end_string_symbol);
|
||||||
end_mark = edit_calculate_end_of_previous_line (edit, end_mark, end_string_symbol);
|
|
||||||
}
|
|
||||||
if (start_mark >= end_mark)
|
if (start_mark >= end_mark)
|
||||||
{
|
{
|
||||||
edit->search->error = MC_SEARCH_E_NOTFOUND;
|
edit->search->error = MC_SEARCH_E_NOTFOUND;
|
||||||
@ -832,7 +831,7 @@ editcmd_find (WEdit * edit, gsize * len)
|
|||||||
|
|
||||||
if ((edit->search_line_type & AT_START_LINE) != 0)
|
if ((edit->search_line_type & AT_START_LINE) != 0)
|
||||||
search_start =
|
search_start =
|
||||||
edit_calculate_start_of_current_line (edit, search_start, end_string_symbol);
|
edit_calculate_start_of_current_line (&edit->buffer, search_start, end_string_symbol);
|
||||||
|
|
||||||
while (search_start >= start_mark)
|
while (search_start >= start_mark)
|
||||||
{
|
{
|
||||||
@ -850,7 +849,7 @@ editcmd_find (WEdit * edit, gsize * len)
|
|||||||
|
|
||||||
if ((edit->search_line_type & AT_START_LINE) != 0)
|
if ((edit->search_line_type & AT_START_LINE) != 0)
|
||||||
search_start =
|
search_start =
|
||||||
edit_calculate_start_of_previous_line (edit, search_start, end_string_symbol);
|
edit_calculate_start_of_previous_line (&edit->buffer, search_start, end_string_symbol);
|
||||||
else
|
else
|
||||||
search_start--;
|
search_start--;
|
||||||
}
|
}
|
||||||
@ -861,7 +860,7 @@ editcmd_find (WEdit * edit, gsize * len)
|
|||||||
/* forward search */
|
/* forward search */
|
||||||
if ((edit->search_line_type & AT_START_LINE) != 0 && search_start != start_mark)
|
if ((edit->search_line_type & AT_START_LINE) != 0 && search_start != start_mark)
|
||||||
search_start =
|
search_start =
|
||||||
edit_calculate_start_of_next_line (edit, search_start, end_mark, end_string_symbol);
|
edit_calculate_start_of_next_line (&edit->buffer, search_start, end_mark, end_string_symbol);
|
||||||
return mc_search_run (edit->search, (void *) edit, search_start, end_mark, len);
|
return mc_search_run (edit->search, (void *) edit, search_start, end_mark, len);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1050,7 +1049,7 @@ edit_save_block_to_clip_file (WEdit * edit, off_t start, off_t finish)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pipe_mail (WEdit * edit, char *to, char *subject, char *cc)
|
pipe_mail (const edit_buffer_t * buf, char *to, char *subject, char *cc)
|
||||||
{
|
{
|
||||||
FILE *p = 0;
|
FILE *p = 0;
|
||||||
char *s;
|
char *s;
|
||||||
@ -1063,17 +1062,18 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc)
|
|||||||
g_free (subject);
|
g_free (subject);
|
||||||
g_free (cc);
|
g_free (cc);
|
||||||
|
|
||||||
if (s)
|
if (s != NULL)
|
||||||
{
|
{
|
||||||
p = popen (s, "w");
|
p = popen (s, "w");
|
||||||
g_free (s);
|
g_free (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p)
|
if (p != NULL)
|
||||||
{
|
{
|
||||||
off_t i;
|
off_t i;
|
||||||
for (i = 0; i < edit->buffer.size; i++)
|
|
||||||
fputc (edit_buffer_get_byte (&edit->buffer, i), p);
|
for (i = 0; i < buf->size; i++)
|
||||||
|
fputc (edit_buffer_get_byte (buf, i), p);
|
||||||
pclose (p);
|
pclose (p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1082,16 +1082,16 @@ pipe_mail (WEdit * edit, char *to, char *subject, char *cc)
|
|||||||
/** find first character of current word */
|
/** find first character of current word */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
edit_find_word_start (WEdit * edit, off_t * word_start, gsize * word_len)
|
edit_find_word_start (const edit_buffer_t * buf, off_t * word_start, gsize * word_len)
|
||||||
{
|
{
|
||||||
int c, last;
|
int c, last;
|
||||||
off_t i;
|
off_t i;
|
||||||
|
|
||||||
/* return if at begin of file */
|
/* return if at begin of file */
|
||||||
if (edit->buffer.curs1 <= 0)
|
if (buf->curs1 <= 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
c = edit_buffer_get_previous_byte (&edit->buffer);
|
c = edit_buffer_get_previous_byte (buf);
|
||||||
/* 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;
|
||||||
@ -1100,11 +1100,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->buffer.curs1 < i)
|
if (buf->curs1 < i)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
last = c;
|
last = c;
|
||||||
c = edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - i);
|
c = edit_buffer_get_byte (buf, buf->curs1 - i);
|
||||||
|
|
||||||
if (is_break_char (c))
|
if (is_break_char (c))
|
||||||
{
|
{
|
||||||
@ -1112,7 +1112,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->buffer.curs1 - (i - 1); /* start found */
|
*word_start = buf->curs1 - (i - 1); /* start found */
|
||||||
*word_len = (gsize) (i - 1);
|
*word_len = (gsize) (i - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1627,7 +1627,7 @@ edit_save_as_cmd (WEdit * edit)
|
|||||||
int save_lock = 0;
|
int save_lock = 0;
|
||||||
int different_filename = 0;
|
int different_filename = 0;
|
||||||
|
|
||||||
if (!edit_check_newline (edit))
|
if (!edit_check_newline (&edit->buffer))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
exp_vpath = edit_get_save_file_as (edit);
|
exp_vpath = edit_get_save_file_as (edit);
|
||||||
@ -2009,7 +2009,7 @@ edit_save_confirm_cmd (WEdit * edit)
|
|||||||
if (edit->filename_vpath == NULL)
|
if (edit->filename_vpath == NULL)
|
||||||
return edit_save_as_cmd (edit);
|
return edit_save_as_cmd (edit);
|
||||||
|
|
||||||
if (!edit_check_newline (edit))
|
if (!edit_check_newline (&edit->buffer))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (edit_confirm_save)
|
if (edit_confirm_save)
|
||||||
@ -2760,7 +2760,7 @@ edit_ok_to_exit (WEdit * edit)
|
|||||||
|
|
||||||
if (!mc_global.midnight_shutdown)
|
if (!mc_global.midnight_shutdown)
|
||||||
{
|
{
|
||||||
if (!edit_check_newline (edit))
|
if (!edit_check_newline (&edit->buffer))
|
||||||
{
|
{
|
||||||
g_free (fname);
|
g_free (fname);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -3230,7 +3230,7 @@ edit_mail_dialog (WEdit * edit)
|
|||||||
mail_cc_last = tmail_cc;
|
mail_cc_last = tmail_cc;
|
||||||
mail_subject_last = tmail_subject;
|
mail_subject_last = tmail_subject;
|
||||||
mail_to_last = tmail_to;
|
mail_to_last = tmail_to;
|
||||||
pipe_mail (edit, mail_to_last, mail_subject_last, mail_cc_last);
|
pipe_mail (&edit->buffer, mail_to_last, mail_subject_last, mail_cc_last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3254,7 +3254,7 @@ edit_complete_word_cmd (WEdit * edit)
|
|||||||
GString *compl[MAX_WORD_COMPLETIONS]; /* completions */
|
GString *compl[MAX_WORD_COMPLETIONS]; /* completions */
|
||||||
|
|
||||||
/* search start of word to be completed */
|
/* search start of word to be completed */
|
||||||
if (!edit_find_word_start (edit, &word_start, &word_len))
|
if (!edit_find_word_start (&edit->buffer, &word_start, &word_len))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* prepare match expression */
|
/* prepare match expression */
|
||||||
@ -3434,7 +3434,7 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* search start of word to be completed */
|
/* search start of word to be completed */
|
||||||
if (!edit_find_word_start (edit, &word_start, &word_len))
|
if (!edit_find_word_start (&edit->buffer, &word_start, &word_len))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* prepare match expression */
|
/* prepare match expression */
|
||||||
@ -3487,29 +3487,31 @@ edit_suggest_current_word (WEdit * edit)
|
|||||||
gsize word_len = 0;
|
gsize word_len = 0;
|
||||||
off_t word_start = 0;
|
off_t word_start = 0;
|
||||||
int retval = B_SKIP_WORD;
|
int retval = B_SKIP_WORD;
|
||||||
char *match_word;
|
GString *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->buffer.curs1, &word_start, &word_len, &cut_len);
|
match_word = edit_buffer_get_word_from_pos (&edit->buffer, edit->buffer.curs1, &word_start,
|
||||||
|
&cut_len);
|
||||||
|
word_len = match_word->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))
|
||||||
{
|
{
|
||||||
GString *tmp_word;
|
GString *tmp_word;
|
||||||
|
|
||||||
tmp_word = str_convert_to_display (match_word);
|
tmp_word = str_convert_to_display (match_word->str);
|
||||||
g_free (match_word);
|
g_string_free (match_word, TRUE);
|
||||||
match_word = g_string_free (tmp_word, FALSE);
|
match_word = tmp_word;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!aspell_check (match_word, (int) word_len))
|
if (!aspell_check (match_word->str, (int) word_len))
|
||||||
{
|
{
|
||||||
GArray *suggest;
|
GArray *suggest;
|
||||||
unsigned int res;
|
unsigned int res;
|
||||||
|
|
||||||
suggest = g_array_new (TRUE, FALSE, sizeof (char *));
|
suggest = g_array_new (TRUE, FALSE, sizeof (char *));
|
||||||
|
|
||||||
res = aspell_suggest (suggest, match_word, (int) word_len);
|
res = aspell_suggest (suggest, match_word->str, (int) word_len);
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
{
|
{
|
||||||
char *new_word = NULL;
|
char *new_word = NULL;
|
||||||
@ -3520,7 +3522,7 @@ edit_suggest_current_word (WEdit * edit)
|
|||||||
edit_scroll_screen_over_cursor (edit);
|
edit_scroll_screen_over_cursor (edit);
|
||||||
edit_render_keypress (edit);
|
edit_render_keypress (edit);
|
||||||
|
|
||||||
retval = spell_dialog_spell_suggest_show (edit, match_word, &new_word, suggest);
|
retval = spell_dialog_spell_suggest_show (edit, match_word->str, &new_word, suggest);
|
||||||
edit_cursor_move (edit, word_len - cut_len);
|
edit_cursor_move (edit, word_len - cut_len);
|
||||||
|
|
||||||
if (retval == B_ENTER && new_word != NULL)
|
if (retval == B_ENTER && new_word != NULL)
|
||||||
@ -3547,14 +3549,14 @@ edit_suggest_current_word (WEdit * edit)
|
|||||||
g_free (cp_word);
|
g_free (cp_word);
|
||||||
}
|
}
|
||||||
else if (retval == B_ADD_WORD && match_word != NULL)
|
else if (retval == B_ADD_WORD && match_word != NULL)
|
||||||
aspell_add_to_dict (match_word, (int) word_len);
|
aspell_add_to_dict (match_word->str, (int) word_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_array_free (suggest, TRUE);
|
g_array_free (suggest, TRUE);
|
||||||
edit->found_start = 0;
|
edit->found_start = 0;
|
||||||
edit->found_len = 0;
|
edit->found_len = 0;
|
||||||
}
|
}
|
||||||
g_free (match_word);
|
g_string_free (match_word, TRUE);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,13 +903,13 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
|||||||
if ((force & REDRAW_PAGE) != 0)
|
if ((force & REDRAW_PAGE) != 0)
|
||||||
{
|
{
|
||||||
row = start_row;
|
row = start_row;
|
||||||
b = edit_move_forward (edit, edit->start_display, start_row, 0);
|
b = edit_buffer_move_forward (&edit->buffer, edit->start_display, start_row, 0);
|
||||||
while (row <= end_row)
|
while (row <= end_row)
|
||||||
{
|
{
|
||||||
if (key_pending (edit))
|
if (key_pending (edit))
|
||||||
return;
|
return;
|
||||||
edit_draw_this_line (edit, b, row, start_column, end_column);
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
||||||
b = edit_move_forward (edit, b, 1, 0);
|
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -928,7 +928,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
|||||||
if (key_pending (edit))
|
if (key_pending (edit))
|
||||||
return;
|
return;
|
||||||
edit_draw_this_line (edit, b, row, start_column, end_column);
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
||||||
b = edit_move_forward (edit, b, 1, 0);
|
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -944,13 +944,13 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
|||||||
if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
|
if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
|
||||||
{
|
{
|
||||||
row = curs_row + 1 < start_row ? start_row : curs_row + 1;
|
row = curs_row + 1 < start_row ? start_row : curs_row + 1;
|
||||||
b = edit_move_forward (edit, b, 1, 0);
|
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
|
||||||
while (row <= end_row)
|
while (row <= end_row)
|
||||||
{
|
{
|
||||||
if (key_pending (edit))
|
if (key_pending (edit))
|
||||||
return;
|
return;
|
||||||
edit_draw_this_line (edit, b, row, start_column, end_column);
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
||||||
b = edit_move_forward (edit, b, 1, 0);
|
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -958,7 +958,8 @@ 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_buffer_get_current_bol (&edit->buffer), 1);
|
b = edit_buffer_move_backward (&edit->buffer,
|
||||||
|
edit_buffer_get_current_bol (&edit->buffer), 1);
|
||||||
if (row >= start_row && row <= end_row)
|
if (row >= start_row && row <= end_row)
|
||||||
{
|
{
|
||||||
if (key_pending (edit))
|
if (key_pending (edit))
|
||||||
@ -971,7 +972,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
|||||||
{
|
{
|
||||||
row = curs_row + 1;
|
row = curs_row + 1;
|
||||||
b = edit_buffer_get_current_bol (&edit->buffer);
|
b = edit_buffer_get_current_bol (&edit->buffer);
|
||||||
b = edit_move_forward (edit, b, 1, 0);
|
b = edit_buffer_move_forward (&edit->buffer, b, 1, 0);
|
||||||
if (row >= start_row && row <= end_row)
|
if (row >= start_row && row <= end_row)
|
||||||
{
|
{
|
||||||
if (key_pending (edit))
|
if (key_pending (edit))
|
||||||
|
@ -72,21 +72,21 @@
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static off_t
|
static off_t
|
||||||
line_start (WEdit * edit, long line)
|
line_start (const edit_buffer_t * buf, long line)
|
||||||
{
|
{
|
||||||
off_t p;
|
off_t p;
|
||||||
long l;
|
long l;
|
||||||
|
|
||||||
l = edit->buffer.curs_line;
|
l = buf->curs_line;
|
||||||
p = edit->buffer.curs1;
|
p = buf->curs1;
|
||||||
|
|
||||||
if (line < l)
|
if (line < l)
|
||||||
p = edit_move_backward (edit, p, l - line);
|
p = edit_buffer_move_backward (buf, p, l - line);
|
||||||
else if (line > l)
|
else if (line > l)
|
||||||
p = edit_move_forward (edit, p, line - l, 0);
|
p = edit_buffer_move_forward (buf, p, line - l, 0);
|
||||||
|
|
||||||
p = edit_buffer_get_bol (&edit->buffer, p);
|
p = edit_buffer_get_bol (buf, p);
|
||||||
while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL)
|
while (strchr ("\t ", edit_buffer_get_byte (buf, p)) != NULL)
|
||||||
p++;
|
p++;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -94,22 +94,22 @@ line_start (WEdit * edit, long line)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
bad_line_start (WEdit * edit, off_t p)
|
bad_line_start (const edit_buffer_t * buf, off_t p)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = edit_buffer_get_byte (&edit->buffer, p);
|
c = edit_buffer_get_byte (buf, p);
|
||||||
if (c == '.')
|
if (c == '.')
|
||||||
{
|
{
|
||||||
/* `...' is acceptable */
|
/* `...' is acceptable */
|
||||||
return !(edit_buffer_get_byte (&edit->buffer, p + 1) == '.'
|
return !(edit_buffer_get_byte (buf, p + 1) == '.'
|
||||||
&& edit_buffer_get_byte (&edit->buffer, p + 2) == '.');
|
&& edit_buffer_get_byte (buf, p + 2) == '.');
|
||||||
}
|
}
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
{
|
{
|
||||||
/* `---' is acceptable */
|
/* `---' is acceptable */
|
||||||
return !(edit_buffer_get_byte (&edit->buffer, p + 1) == '-'
|
return !(edit_buffer_get_byte (buf, p + 1) == '-'
|
||||||
&& edit_buffer_get_byte (&edit->buffer, p + 2) == '-');
|
&& edit_buffer_get_byte (buf, p + 2) == '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
return (strchr (NO_FORMAT_CHARS_START, c) != NULL);
|
return (strchr (NO_FORMAT_CHARS_START, c) != NULL);
|
||||||
@ -128,13 +128,14 @@ begin_paragraph (WEdit * edit, gboolean force)
|
|||||||
|
|
||||||
for (i = edit->buffer.curs_line - 1; i >= 0; i--)
|
for (i = edit->buffer.curs_line - 1; i >= 0; i--)
|
||||||
if (edit_line_is_blank (edit, i) ||
|
if (edit_line_is_blank (edit, i) ||
|
||||||
(force && bad_line_start (edit, line_start (edit, i))))
|
(force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i))))
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return edit_move_backward (edit, edit_buffer_get_current_bol (&edit->buffer), edit->buffer.curs_line - i);
|
return edit_buffer_move_backward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer),
|
||||||
|
edit->buffer.curs_line - i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -150,14 +151,14 @@ end_paragraph (WEdit * edit, gboolean force)
|
|||||||
|
|
||||||
for (i = edit->buffer.curs_line + 1; i <= edit->buffer.lines; i++)
|
for (i = edit->buffer.curs_line + 1; i <= edit->buffer.lines; i++)
|
||||||
if (edit_line_is_blank (edit, i) ||
|
if (edit_line_is_blank (edit, i) ||
|
||||||
(force && bad_line_start (edit, line_start (edit, i))))
|
(force && bad_line_start (&edit->buffer, line_start (&edit->buffer, i))))
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return edit_buffer_get_eol (&edit->buffer,
|
return edit_buffer_get_eol (&edit->buffer,
|
||||||
edit_move_forward (edit, edit_buffer_get_current_bol (&edit->buffer),
|
edit_buffer_move_forward (&edit->buffer, edit_buffer_get_current_bol (&edit->buffer),
|
||||||
i - edit->buffer.curs_line, 0));
|
i - edit->buffer.curs_line, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user