From 450fe431fcb367ff0a5bcf13ac8608a0cc873289 Mon Sep 17 00:00:00 2001 From: Pavel Tsekov Date: Thu, 26 Jan 2006 15:42:56 +0000 Subject: [PATCH] * edit.c (edit_auto_indent): Remove redundant parameters. Change the indentation strategy to copy whitespace from the previous line instead of filling up with allegedly equivalent whitespace depending on the tab setting. (edit_execute_cmd): Accomodate change of parameters to edit_auto_indent(). --- edit/ChangeLog | 9 +++++++++ edit/edit.c | 23 +++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/edit/ChangeLog b/edit/ChangeLog index 45857f032..6b59bc5b7 100644 --- a/edit/ChangeLog +++ b/edit/ChangeLog @@ -1,3 +1,12 @@ +2006-01-26 Oswald Buddenhagen + + * edit.c (edit_auto_indent): Remove redundant parameters. + Change the indentation strategy to copy whitespace + from the previous line instead of filling up with allegedly + equivalent whitespace depending on the tab setting. + (edit_execute_cmd): Accomodate change of parameters to + edit_auto_indent(). + 2005-11-22 Leonard den Ottolander * editcmd.c (edit_replace_dialog): Alt-p is in use for the diff --git a/edit/edit.c b/edit/edit.c index 8780bc502..3cc2622a7 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -1934,17 +1934,20 @@ void edit_insert_indent (WEdit * edit, int indent) } static void -edit_auto_indent (WEdit * edit, int extra, int no_advance) +edit_auto_indent (WEdit * edit) { long p; - int indent; + char c; p = edit->curs1; - while (isspace (edit_get_byte (edit, p - 1)) && p > 0) /* move back/up to a line with text */ - p--; - indent = edit_indent_width (edit, edit_bol (edit, p)); - if (edit->curs_col < indent && no_advance) - indent = edit->curs_col; - edit_insert_indent (edit, indent + (option_fake_half_tabs ? HALF_TAB_SIZE : TAB_SIZE) * space_width * extra); + /* use the previous line as a template */ + p = edit_move_backward (edit, p, 1); + /* copy the leading whitespace of the line */ + for (;;) { /* no range check - the line _is_ \n-terminated */ + c = edit_get_byte (edit, p++); + if (c != ' ' && c != '\t') + break; + edit_insert (edit, c); + } } static void edit_double_newline (WEdit * edit) @@ -2255,12 +2258,12 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) if (option_auto_para_formatting) { edit_double_newline (edit); if (option_return_does_auto_indent) - edit_auto_indent (edit, 0, 1); + edit_auto_indent (edit); format_paragraph (edit, 0); } else { edit_insert (edit, '\n'); if (option_return_does_auto_indent) { - edit_auto_indent (edit, 0, 1); + edit_auto_indent (edit); } } break;