From e00a3d0cfa9800168125a58b1c950ef5d043d077 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Mon, 15 Aug 2022 14:33:30 +0200 Subject: [PATCH] Improve command consistency - use `n` instead of `dir` or `delta` when passing premultiplied argval - describe-xxx commands take `argval` to avoid repetition - move paragraph functions to extras.c - bumped version to 5.3.1k --- extras.c | 259 ++++++++++++++++++++++++++++++++++++++++++++++-- modes/dired.c | 29 ++++++ modes/fractal.c | 96 +++++++++--------- modes/hex.c | 15 ++- qe.c | 245 ++------------------------------------------- qe.h | 6 +- qeconfig.h | 20 +--- 7 files changed, 351 insertions(+), 319 deletions(-) diff --git a/extras.c b/extras.c index 2f4dc2a..e9f6ec9 100644 --- a/extras.c +++ b/extras.c @@ -959,7 +959,7 @@ static void print_bindings(EditBuffer *b, ModeDef *mode) } } -void do_describe_bindings(EditState *s) +void do_describe_bindings(EditState *s, int argval) { EditBuffer *b; @@ -1809,6 +1809,8 @@ static void do_sort_buffer(EditState *s, int flags, int argval) { do_sort_span(s, 0, s->b->total_size, flags, argval); } +/*---------------- tag handling ----------------*/ + static void tag_buffer(EditState *s) { unsigned int buf[COLORED_MAX_LINE_SIZE]; QETermStyle sbuf[COLORED_MAX_LINE_SIZE]; @@ -1904,7 +1906,7 @@ static void do_goto_tag(EditState *s) { /* XXX: should have next-tag and previous-tag */ -static void do_list_tags(EditState *s) { +static void do_list_tags(EditState *s, int argval) { char buf[256]; EditBuffer *b; QEProperty *p; @@ -1938,6 +1940,237 @@ static CompletionDef tag_completion = { "tag", tag_complete, tag_print_entry, tag_get_entry }; +/*---------------- paragraph handling ----------------*/ + +int eb_next_paragraph(EditBuffer *b, int offset) { + /* find end of paragraph around or after point: + skip blank lines, if any, then skip non blank lines + and return start of blank line before text. + */ + int text_found = 0; + offset = eb_goto_bol(b, offset); + while (offset < b->total_size) { + if (eb_is_blank_line(b, offset, NULL)) { + if (text_found) + break; + } else { + text_found = 1; + } + offset = eb_next_line(b, offset); + } + return offset; +} + +void do_mark_paragraph(EditState *s, int n) { + /* mark-paragraph (bound to M-h): + + mark_paragraph(n = arg_val) + + Put point at beginning of this paragraph, mark at end. + The paragraph marked is the one that contains point or follows point. + + With argument ARG, puts mark at end of a following paragraph, so that + the number of paragraphs marked equals ARG. + + If ARG is negative, point is put at end of this paragraph, mark is put + at beginning of this or a previous paragraph. + The paragraph marked is the one that contains point or precedes point. + + Interactively if the current region is highlighted, it marks + the next ARG paragraphs after the ones already marked. + */ + int start = s->offset; + int end = s->region_style ? s->b->mark : s->offset; + if (n < 0) { + end = eb_prev_paragraph(s->b, end); + if (!s->region_style) + start = eb_next_paragraph(s->b, end); + while (++n < 0 && end > 0) { + end = eb_prev_paragraph(s->b, end); + } + } else + if (n > 0) { + end = eb_next_paragraph(s->b, end); + if (!s->region_style) + start = eb_prev_paragraph(s->b, end); + while (--n > 0 && end < s->b->total_size) { + end = eb_next_paragraph(s->b, end); + } + } + do_mark_region(s, end, start); +} + +int eb_prev_paragraph(EditBuffer *b, int offset) { + /* find start of paragraph around or before point: + skip blank lines, if any, then skip non blank lines + and return start of blank line after end of text. + */ + int text_found = 0; + offset = eb_goto_bol(b, offset); + while (offset > 0) { + if (eb_is_blank_line(b, offset, NULL)) { + if (text_found) + break; + } else { + text_found = 1; + } + offset = eb_prev_line(b, offset); + } + return offset; +} + +void do_forward_paragraph(EditState *s, int n) { + for (; n < 0 && s->offset > 0; n++) { + s->offset = eb_prev_paragraph(s->b, s->offset); + } + for (; n > 0 && s->offset < s->b->total_size; n--) { + s->offset = eb_next_paragraph(s->b, s->offset); + } +} + +void do_kill_paragraph(EditState *s, int n) { + /* + kill_paragraph(n = ARG) + + Kill forward to end of paragraph. + With arg N, kill forward to Nth end of paragraph; + negative arg -N means kill backward to Nth start of paragraph. + */ + if (n != 0) { + int start = s->offset; + do_forward_paragraph(s, n); + do_kill(s, start, s->offset, n, 0); + } +} + +/* replace the contents between p1 and p2 with a specified number + of newlines and spaces */ +static int eb_respace(EditBuffer *b, int p1, int p2, int newlines, int spaces) { + int adjust = 0, nb, offset1, c; + while (newlines > 0 && p1 < p2) { + c = eb_nextc(b, p1, &offset1); + if (c != '\n') + break; + p1 = offset1; + newlines--; + } + if (newlines > 0) { + nb = eb_insert_uchars(b, p1, '\n', newlines); + adjust += nb; + p1 += nb; + p2 += nb; + } + while (spaces > 0 && p1 < p2) { + c = eb_nextc(b, p1, &offset1); + if (c == ' ') { + p1 = offset1; + spaces--; + } else { + nb = eb_delete(b, p1, offset1 - p1); + adjust -= nb; + p2 -= nb; + } + } + if (p1 < p2) { + nb = eb_delete(b, p1, p2 - p1); + adjust -= nb; + p2 -= nb; + } + if (spaces) { + nb = eb_insert_uchars(b, p1, ' ', spaces); + adjust += nb; + p1 += nb; + p2 += nb; + } + return adjust; +} + +static int get_indent_size(EditState *s, int p1, int p2) { + int indent_size = 0; + while (p1 < p2) { + int c = eb_nextc(s->b, p1, &p1); + if (!qe_isblank(c)) + break; + if (c == '\t') { + int tw = s->b->tab_width > 0 ? s->b->tab_width : DEFAULT_TAB_WIDTH; + indent_size += tw - indent_size % tw; + } else { + indent_size++; + } + } + return indent_size; +} + +void do_fill_paragraph(EditState *s) +{ + /* buffer offsets, byte counts */ + int par_start, par_end, offset, offset1, chunk_start, word_start; + /* number of characters / screen positions */ + int col, indent0_size, indent_size, word_size; + + /* find start & end of paragraph */ + par_end = eb_next_paragraph(s->b, s->offset); + par_start = eb_prev_paragraph(s->b, par_end); + /* skip the blank line if any */ + eb_is_blank_line(s->b, par_start, &par_start); + + /* compute indent sizes for first and second lines */ + indent0_size = get_indent_size(s, par_start, par_end); + offset = eb_next_line(s->b, par_start); + indent_size = get_indent_size(s, offset, par_end); + + /* reflow words to fill lines */ + col = 0; + offset = par_start; + while (offset < par_end) { + /* skip spaces */ + chunk_start = offset; + while (offset < par_end) { + int c = eb_nextc(s->b, offset, &offset1); + if (!qe_isspace(c)) + break; + offset = offset1; + } + /* skip word */ + word_start = offset; + word_size = 0; + while (offset < par_end) { + int c = eb_nextc(s->b, offset, &offset1); + if (qe_isspace(c)) + break; + offset = offset1; + /* handle variable width and combining glyphs */ + word_size += unicode_tty_glyph_width(c); + } + + if (chunk_start == par_start) { + /* preserve spaces at paragraph start */ + col += indent0_size + word_size; + } else { + if (word_start == offset) { + /* space at end of paragraph: append a newline */ + eb_respace(s->b, chunk_start, word_start, 1, 0); + break; + } + if (col + 1 + word_size > s->b->fill_column) { + /* insert newline and indentation */ + int nb = eb_respace(s->b, chunk_start, word_start, 1, indent_size); + offset += nb; + par_end += nb; + col = indent_size + word_size; + } else { + /* single space the word */ + int nb = eb_respace(s->b, chunk_start, word_start, 0, 1); + offset += nb; + par_end += nb; + col += 1 + word_size; + } + } + } +} + +/*---------------- command and binding definitions ----------------*/ + static CmdDef extra_commands[] = { CMD2( KEY_META('='), KEY_NONE, "compare-windows", do_compare_windows, ESi, "p" , "") @@ -2002,8 +2235,8 @@ static CmdDef extra_commands[] = { CMD2( KEY_CTRLH('a'), KEY_CTRLH(KEY_CTRL('A')), "apropos", do_apropos, ESs, "s{Apropos: }[symbol]|apropos|", "") - CMD0( KEY_CTRLH('b'), KEY_NONE, - "describe-bindings", do_describe_bindings, "") + CMD2( KEY_CTRLH('b'), KEY_NONE, + "describe-bindings", do_describe_bindings, ESi, "p", "") CMD2( KEY_CTRLH('B'), KEY_NONE, "show-bindings", do_show_bindings, ESs, "s{Show bindings of command: }[command]|command|", "") @@ -2040,14 +2273,28 @@ static CmdDef extra_commands[] = { CMD3( KEY_NONE, KEY_NONE, "reverse-sort-region", do_sort_region, ESii, SF_REVERSE, "*vp", "") - CMD0( KEY_NONE, KEY_NONE, - "list-tags", do_list_tags, "") + CMD2( KEY_NONE, KEY_NONE, + "list-tags", do_list_tags, ESi, "p", "") CMD0( KEY_CTRLX(','), KEY_META(KEY_F1), "goto-tag", do_goto_tag, "") CMD2( KEY_CTRLX('.'), KEY_NONE, "find-tag", do_find_tag, ESs, "s{Find tag: }[tag]|tag|", "") + /*---------------- Paragraph handling ----------------*/ + + CMD3( KEY_META('h'), KEY_NONE, + "mark-paragraph", do_mark_paragraph, ESi, +1, "P", "") + CMD3( KEY_META('{'), KEY_CTRL_UP, + "backward-paragraph", do_forward_paragraph, ESi, -1, "P", "") + CMD3( KEY_META('}'), KEY_CTRL_DOWN, + "forward-paragraph", do_forward_paragraph, ESi, +1, "P", "") + CMD2( KEY_META('q'), KEY_NONE, + "fill-paragraph", do_fill_paragraph, ES, "*", "") + /* should have fill-region */ + CMD3( KEY_NONE, KEY_NONE, + "kill-paragraph", do_kill_paragraph, ESi, 1, "P", "") + CMD_DEF_END, }; diff --git a/modes/dired.c b/modes/dired.c index 0c97052..fd633fe 100644 --- a/modes/dired.c +++ b/modes/dired.c @@ -1372,6 +1372,34 @@ static CmdDef dired_global_commands[] = { CMD_DEF_END, }; +#if 0 +static int dired_buffer_load(EditBuffer *b, FILE *f) +{ + /* XXX: launch subprocess to list dired contents */ + return -1; +} + +static int dired_buffer_save(EditBuffer *b, int start, int end, + const char *filename) +{ + /* XXX: prevent saving parsed contents to dired file */ + return -1; +} + +static void dired_buffer_close(EditBuffer *b) +{ + /* XXX: free dired structures? */ +} + +static EditBufferDataType dired_data_type = { + "dired", + dired_buffer_load, + dired_buffer_save, + dired_buffer_close, + NULL, /* next */ +}; +#endif + static int filelist_init(void); static int dired_init(void) @@ -1388,6 +1416,7 @@ static int dired_init(void) dired_mode.display_hook = dired_display_hook; dired_mode.get_default_path = dired_get_default_path; + //eb_register_data_type(&dired_data_type); qe_register_mode(&dired_mode, /* MODEF_DATATYPE | */ MODEF_MAJOR | MODEF_VIEW); qe_register_variables(dired_variables, countof(dired_variables)); qe_register_cmd_table(dired_commands, &dired_mode); diff --git a/modes/fractal.c b/modes/fractal.c index 4eae30b..1a00166 100644 --- a/modes/fractal.c +++ b/modes/fractal.c @@ -927,32 +927,32 @@ static void do_fractal_move(EditState *s, int deltax, int deltay) { } } -static void do_fractal_move_x(EditState *s, int delta) { - do_fractal_move(s, delta, 0); +static void do_fractal_move_x(EditState *s, int n) { + do_fractal_move(s, n, 0); } -static void do_fractal_move_y(EditState *s, int delta) { - do_fractal_move(s, 0, delta); +static void do_fractal_move_y(EditState *s, int n) { + do_fractal_move(s, 0, n); } -static void do_fractal_zoom(EditState *s, int delta) { +static void do_fractal_zoom(EditState *s, int n) { FractalState *ms = fractal_get_state(s, 1); if (ms) { - fractal_set_zoom(ms, ms->zoom + delta); + fractal_set_zoom(ms, ms->zoom + n); } } -static void do_fractal_rotate(EditState *s, int delta) { +static void do_fractal_rotate(EditState *s, int n) { FractalState *ms = fractal_get_state(s, 1); if (ms) { - fractal_set_rotation(ms, delta ? ms->rot + delta : 0); + fractal_set_rotation(ms, n ? ms->rot + n : 0); } } -static void do_fractal_shift_colors(EditState *s, int delta) { +static void do_fractal_shift_colors(EditState *s, int n) { FractalState *ms = fractal_get_state(s, 1); if (ms) { - ms->shift += delta; + ms->shift += n; #if USE_BITMAP_API fractal_invalidate(ms); #else @@ -979,18 +979,18 @@ static void do_fractal_set_colors(EditState *s, int type) { } } -static void do_fractal_iter(EditState *s, int delta) { +static void do_fractal_iter(EditState *s, int n) { FractalState *ms = fractal_get_state(s, 1); if (ms) { - ms->maxiter += delta; + ms->maxiter += n; fractal_invalidate(ms); } } -static void do_fractal_bailout(EditState *s, int delta) { +static void do_fractal_bailout(EditState *s, int n) { FractalState *ms = fractal_get_state(s, 1); if (ms) { - ms->bailout += delta; + ms->bailout += n; fractal_invalidate(ms); } } @@ -1084,40 +1084,40 @@ static void fractal_display_hook(EditState *s) { } static CmdDef fractal_commands[] = { - CMD1( KEY_LEFT, KEY_NONE, - "fractal-left", do_fractal_move_x, -1, "") - CMD1( KEY_RIGHT, KEY_NONE, - "fractal-right", do_fractal_move_x, +1, "") - CMD1( KEY_UP, KEY_NONE, - "fractal-up", do_fractal_move_y, -1, "") - CMD1( KEY_DOWN, KEY_NONE, - "fractal-down", do_fractal_move_y, +1, "") - CMD1( '+', ' ', - "fractal-zoom-in", do_fractal_zoom, +1, "") - CMD1( '-', '_', - "fractal-zoom-out", do_fractal_zoom, -1, "") - CMD1( '\\', '.', - "fractal-rotate-left", do_fractal_rotate, +1, "") - CMD1( '/', KEY_NONE, - "fractal-rotate-right", do_fractal_rotate, -1, "") - CMD1( '|', KEY_NONE, - "fractal-rotate-none", do_fractal_rotate, 0, "") - CMD1( 'c', KEY_NONE, - "fractal-set-colors-default", do_fractal_set_colors, 0, "") - CMD1( 'g', KEY_NONE, - "fractal-set-colors-gray", do_fractal_set_colors, 1, "") - CMD1( '[', KEY_NONE, - "fractal-shift-colors-left", do_fractal_shift_colors, -1, "") - CMD1( ']', KEY_NONE, - "fractal-shift-colors-right", do_fractal_shift_colors, +1, "") - CMD1( '{', KEY_NONE, - "fractal-iter-less", do_fractal_iter, -1, "") - CMD1( '}', KEY_NONE, - "fractal-iter-more", do_fractal_iter, +1, "") - CMD1( '<', KEY_NONE, - "fractal-bailout-less", do_fractal_bailout, -1, "") - CMD1( '>', KEY_NONE, - "fractal-bailout-more", do_fractal_bailout, +1, "") + CMD3( KEY_LEFT, KEY_NONE, + "fractal-left", do_fractal_move_x, ESi, -1, "P", "") + CMD3( KEY_RIGHT, KEY_NONE, + "fractal-right", do_fractal_move_x, ESi, +1, "P", "") + CMD3( KEY_UP, KEY_NONE, + "fractal-up", do_fractal_move_y, ESi, -1, "P", "") + CMD3( KEY_DOWN, KEY_NONE, + "fractal-down", do_fractal_move_y, ESi, +1, "P", "") + CMD3( '+', ' ', + "fractal-zoom-in", do_fractal_zoom, ESi, +1, "P", "") + CMD3( '-', '_', + "fractal-zoom-out", do_fractal_zoom, ESi, -1, "P", "") + CMD3( '\\', '.', + "fractal-rotate-left", do_fractal_rotate, ESi, +1, "P", "") + CMD3( '/', KEY_NONE, + "fractal-rotate-right", do_fractal_rotate, ESi, -1, "P", "") + CMD3( '|', KEY_NONE, + "fractal-rotate-none", do_fractal_rotate, ESi, 0, "v", "") + CMD3( 'c', KEY_NONE, + "fractal-set-colors-default", do_fractal_set_colors, ESi, 0, "v", "") + CMD3( 'g', KEY_NONE, + "fractal-set-colors-gray", do_fractal_set_colors, ESi, 1, "v", "") + CMD3( '[', KEY_NONE, + "fractal-shift-colors-left", do_fractal_shift_colors, ESi, -1, "P", "") + CMD3( ']', KEY_NONE, + "fractal-shift-colors-right", do_fractal_shift_colors, ESi, +1, "P", "") + CMD3( '{', KEY_NONE, + "fractal-iter-less", do_fractal_iter, ESi, -1, "P", "") + CMD3( '}', KEY_NONE, + "fractal-iter-more", do_fractal_iter, ESi, +1, "P", "") + CMD3( '<', KEY_NONE, + "fractal-bailout-less", do_fractal_bailout, ESi, -1, "P", "") + CMD3( '>', KEY_NONE, + "fractal-bailout-more", do_fractal_bailout, ESi, +1, "P", "") CMD2( '1', '2', "fractal-set-type", do_fractal_set_type, ESi, "k", "") CMD2( '=', KEY_NONE, diff --git a/modes/hex.c b/modes/hex.c index 5a44971..36bff31 100644 --- a/modes/hex.c +++ b/modes/hex.c @@ -124,12 +124,9 @@ static void do_set_width(EditState *s, int w) } } -static void do_increase_width(EditState *s, int incr) +static void do_increase_width(EditState *s, int n) { - int w; - w = s->dump_width + incr; - if (w >= 1) - do_set_width(s, w); + do_set_width(s, s->dump_width + n); } static void do_toggle_hex(EditState *s) @@ -139,10 +136,10 @@ static void do_toggle_hex(EditState *s) /* common binary and hex commands */ static CmdDef binary_commands[] = { - CMD1( KEY_CTRL_LEFT, KEY_NONE, - "decrease-width", do_increase_width, -1, "") - CMD1( KEY_CTRL_RIGHT, KEY_NONE, - "increase-width", do_increase_width, 1, "") + CMD3( KEY_CTRL_LEFT, KEY_NONE, + "decrease-width", do_increase_width, ESi, -1, "P", "") + CMD3( KEY_CTRL_RIGHT, KEY_NONE, + "increase-width", do_increase_width, ESi, +1, "P", "") CMD2( KEY_NONE, KEY_NONE, "set-width", do_set_width, ESi, "p{Width: }", "") diff --git a/qe.c b/qe.c index 63b672a..de00089 100644 --- a/qe.c +++ b/qe.c @@ -735,234 +735,7 @@ void do_mark_region(EditState *s, int mark, int offset) s->region_style = QE_STYLE_REGION_HILITE; } -/* paragraph handling */ - -int eb_next_paragraph(EditBuffer *b, int offset) { - /* find end of paragraph around or after point: - skip blank lines, if any, then skip non blank lines - and return start of blank line before text. - */ - int text_found = 0; - offset = eb_goto_bol(b, offset); - while (offset < b->total_size) { - if (eb_is_blank_line(b, offset, NULL)) { - if (text_found) - break; - } else { - text_found = 1; - } - offset = eb_next_line(b, offset); - } - return offset; -} - -void do_mark_paragraph(EditState *s, int n) { - /* mark-paragraph (bound to M-h): - - mark_paragraph(n = arg_val) - - Put point at beginning of this paragraph, mark at end. - The paragraph marked is the one that contains point or follows point. - - With argument ARG, puts mark at end of a following paragraph, so that - the number of paragraphs marked equals ARG. - - If ARG is negative, point is put at end of this paragraph, mark is put - at beginning of this or a previous paragraph. - The paragraph marked is the one that contains point or precedes point. - - Interactively if the current region is highlighted, it marks - the next ARG paragraphs after the ones already marked. - */ - int start = s->offset; - int end = s->region_style ? s->b->mark : s->offset; - if (n < 0) { - end = eb_prev_paragraph(s->b, end); - if (!s->region_style) - start = eb_next_paragraph(s->b, end); - while (++n < 0 && end > 0) { - end = eb_prev_paragraph(s->b, end); - } - } else - if (n > 0) { - end = eb_next_paragraph(s->b, end); - if (!s->region_style) - start = eb_prev_paragraph(s->b, end); - while (--n > 0 && end < s->b->total_size) { - end = eb_next_paragraph(s->b, end); - } - } - do_mark_region(s, end, start); -} - -int eb_prev_paragraph(EditBuffer *b, int offset) { - /* find start of paragraph around or before point: - skip blank lines, if any, then skip non blank lines - and return start of blank line after end of text. - */ - int text_found = 0; - offset = eb_goto_bol(b, offset); - while (offset > 0) { - if (eb_is_blank_line(b, offset, NULL)) { - if (text_found) - break; - } else { - text_found = 1; - } - offset = eb_prev_line(b, offset); - } - return offset; -} - -void do_forward_paragraph(EditState *s, int n) { - for (; n < 0 && s->offset > 0; n++) { - s->offset = eb_prev_paragraph(s->b, s->offset); - } - for (; n > 0 && s->offset < s->b->total_size; n--) { - s->offset = eb_next_paragraph(s->b, s->offset); - } -} - -void do_kill_paragraph(EditState *s, int n) { - /* - kill_paragraph(n = ARG) - - Kill forward to end of paragraph. - With arg N, kill forward to Nth end of paragraph; - negative arg -N means kill backward to Nth start of paragraph. - */ - if (n != 0) { - int start = s->offset; - do_forward_paragraph(s, n); - do_kill(s, start, s->offset, n, 0); - } -} - -/* replace the contents between p1 and p2 with a specified number - of newlines and spaces */ -static int eb_respace(EditBuffer *b, int p1, int p2, int newlines, int spaces) { - int adjust = 0, nb, offset1, c; - while (newlines > 0 && p1 < p2) { - c = eb_nextc(b, p1, &offset1); - if (c != '\n') - break; - p1 = offset1; - newlines--; - } - if (newlines > 0) { - nb = eb_insert_uchars(b, p1, '\n', newlines); - adjust += nb; - p1 += nb; - p2 += nb; - } - while (spaces > 0 && p1 < p2) { - c = eb_nextc(b, p1, &offset1); - if (c == ' ') { - p1 = offset1; - spaces--; - } else { - nb = eb_delete(b, p1, offset1 - p1); - adjust -= nb; - p2 -= nb; - } - } - if (p1 < p2) { - nb = eb_delete(b, p1, p2 - p1); - adjust -= nb; - p2 -= nb; - } - if (spaces) { - nb = eb_insert_uchars(b, p1, ' ', spaces); - adjust += nb; - p1 += nb; - p2 += nb; - } - return adjust; -} - -static int get_indent_size(EditState *s, int p1, int p2) { - int indent_size = 0; - while (p1 < p2) { - int c = eb_nextc(s->b, p1, &p1); - if (!qe_isblank(c)) - break; - if (c == '\t') { - int tw = s->b->tab_width > 0 ? s->b->tab_width : DEFAULT_TAB_WIDTH; - indent_size += tw - indent_size % tw; - } else { - indent_size++; - } - } - return indent_size; -} - -void do_fill_paragraph(EditState *s) -{ - /* buffer offsets, byte counts */ - int par_start, par_end, offset, offset1, chunk_start, word_start; - /* number of characters / screen positions */ - int col, indent0_size, indent_size, word_size; - - /* find start & end of paragraph */ - par_end = eb_next_paragraph(s->b, s->offset); - par_start = eb_prev_paragraph(s->b, par_end); - /* skip the blank line if any */ - eb_is_blank_line(s->b, par_start, &par_start); - - /* compute indent sizes for first and second lines */ - indent0_size = get_indent_size(s, par_start, par_end); - offset = eb_next_line(s->b, par_start); - indent_size = get_indent_size(s, offset, par_end); - - /* reflow words to fill lines */ - col = 0; - offset = par_start; - while (offset < par_end) { - /* skip spaces */ - chunk_start = offset; - while (offset < par_end) { - int c = eb_nextc(s->b, offset, &offset1); - if (!qe_isspace(c)) - break; - offset = offset1; - } - /* skip word */ - word_start = offset; - word_size = 0; - while (offset < par_end) { - int c = eb_nextc(s->b, offset, &offset1); - if (qe_isspace(c)) - break; - offset = offset1; - /* handle variable width and combining glyphs */ - word_size += unicode_tty_glyph_width(c); - } - - if (chunk_start == par_start) { - /* preserve spaces at paragraph start */ - col += indent0_size + word_size; - } else { - if (word_start == offset) { - /* space at end of paragraph: append a newline */ - eb_respace(s->b, chunk_start, word_start, 1, 0); - break; - } - if (col + 1 + word_size > s->b->fill_column) { - /* insert newline and indentation */ - int nb = eb_respace(s->b, chunk_start, word_start, 1, indent_size); - offset += nb; - par_end += nb; - col = indent_size + word_size; - } else { - /* single space the word */ - int nb = eb_respace(s->b, chunk_start, word_start, 0, 1); - offset += nb; - par_end += nb; - col += 1 + word_size; - } - } - } -} +/*---------------- Case handling ----------------*/ /* Upper / lower / capital case functions. Update offset, return isword */ /* arg: -1=lower-case, +1=upper-case, +2=capital-case */ @@ -7370,21 +7143,21 @@ EditState *qe_find_target_window(EditState *s, int activate) { } /* Select appropriate mode for buffer: - * iff dir == 0, select best mode - * iff dir > 0, select next mode - * iff dir < 0, select previous mode + * if n == 0, select best mode + * if n > 0, select n-th next mode + * if n < 0, select n-th previous mode */ -void do_set_next_mode(EditState *s, int dir) +void do_set_next_mode(EditState *s, int n) { if (s->flags & (WF_POPUP | WF_MINIBUF)) return; /* next-mode from the dired window applies to the target window */ s = qe_find_target_window(s, 0); - qe_set_next_mode(s, dir, 1); + qe_set_next_mode(s, n, 1); } -void qe_set_next_mode(EditState *s, int dir, int status) +void qe_set_next_mode(EditState *s, int n, int status) { u8 buf[4097]; int size; @@ -7414,10 +7187,10 @@ void qe_set_next_mode(EditState *s, int dir, int status) b->filename, 0, b->st_mode, b->total_size, buf, size, b->charset, b->eol_type); found = 0; - if (dir && nb > 0) { + if (n && nb > 0) { for (i = 0; i < nb; i++) { if (s->mode == modes[i]) { - found = (i + dir) % nb; + found = (i + n) % nb; if (found < 0) found += nb; break; diff --git a/qe.h b/qe.h index 7ad779a..b91f5ce 100644 --- a/qe.h +++ b/qe.h @@ -2141,8 +2141,8 @@ void edit_display(QEmacsState *qs); void edit_invalidate(EditState *s, int all); void display_mode_line(EditState *s); int edit_set_mode(EditState *s, ModeDef *m); -void qe_set_next_mode(EditState *s, int dir, int status); -void do_set_next_mode(EditState *s, int dir); +void qe_set_next_mode(EditState *s, int n, int status); +void do_set_next_mode(EditState *s, int n); /* loading files */ void do_exit_qemacs(EditState *s, int argval); @@ -2337,7 +2337,7 @@ void do_describe_key_briefly(EditState *s); void do_show_bindings(EditState *s, const char *cmd_name); void do_apropos(EditState *s, const char *str); EditBuffer *new_help_buffer(void); -void do_describe_bindings(EditState *s); +void do_describe_bindings(EditState *s, int argval); void do_help_for_help(EditState *s); void qe_event_init(void); void window_get_min_size(EditState *s, int *w_ptr, int *h_ptr); diff --git a/qeconfig.h b/qeconfig.h index dfd8203..0668f45 100644 --- a/qeconfig.h +++ b/qeconfig.h @@ -182,20 +182,6 @@ static CmdDef basic_commands[] = { "s{Set visited file name: }[file]|file|" "s{Rename file? }|newname|", "") - /*---------------- Paragraph handling ----------------*/ - - CMD3( KEY_META('h'), KEY_NONE, - "mark-paragraph", do_mark_paragraph, ESi, +1, "P", "") - CMD3( KEY_META('{'), KEY_CTRL_UP, - "backward-paragraph", do_forward_paragraph, ESi, -1, "P", "") - CMD3( KEY_META('}'), KEY_CTRL_DOWN, - "forward-paragraph", do_forward_paragraph, ESi, +1, "P", "") - CMD2( KEY_META('q'), KEY_NONE, - "fill-paragraph", do_fill_paragraph, ES, "*", "") - /* should have fill-region */ - CMD3( KEY_NONE, KEY_NONE, - "kill-paragraph", do_kill_paragraph, ESi, 1, "P", "") - /*---------------- Case handling ----------------*/ CMD3( KEY_META('c'), KEY_NONE, @@ -250,11 +236,11 @@ static CmdDef basic_commands[] = { /* should merge these functions */ CMD0( KEY_CTRLX('o'), KEY_NONE, - "other-window", do_other_window, "") /* "p"? */ + "other-window", do_other_window, "") CMD0( KEY_CTRLX('n'), KEY_NONE, - "next-window", do_other_window, "") /* "P"? */ + "next-window", do_other_window, "") CMD0( KEY_CTRLX('p'), KEY_NONE, - "previous-window", do_previous_window, "") /* "P"? */ + "previous-window", do_previous_window, "") #ifndef CONFIG_TINY CMD1( KEY_META(KEY_CTRL('l')), KEY_NONE, "center-cursor", do_center_cursor, 1, "")