Mercurial > emacs
comparison src/scroll.c @ 49600:23a1cea22d13
Trailing whitespace deleted.
| author | Juanma Barranquero <lekktu@gmail.com> |
|---|---|
| date | Tue, 04 Feb 2003 14:56:31 +0000 |
| parents | 3aa5ba8c3ef4 |
| children | 332134065648 d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
| 49599:5ade352e8d1c | 49600:23a1cea22d13 |
|---|---|
| 230 | 230 |
| 231 | 231 |
| 232 /* Perform insert-lines and delete-lines operations on CURRENT_MATRIX | 232 /* Perform insert-lines and delete-lines operations on CURRENT_MATRIX |
| 233 according to the costs in MATRIX, using the general scrolling | 233 according to the costs in MATRIX, using the general scrolling |
| 234 method that is used if the terminal does not support the setting of | 234 method that is used if the terminal does not support the setting of |
| 235 scroll windows (scroll_region_ok == 0). | 235 scroll windows (scroll_region_ok == 0). |
| 236 | 236 |
| 237 WINDOW_SIZE is the number of lines being considered for scrolling | 237 WINDOW_SIZE is the number of lines being considered for scrolling |
| 238 and UNCHANGED_AT_TOP is the vpos of the first line being | 238 and UNCHANGED_AT_TOP is the vpos of the first line being |
| 239 considered. These two arguments can specify any contiguous range | 239 considered. These two arguments can specify any contiguous range |
| 240 of lines. */ | 240 of lines. */ |
| 241 | 241 |
| 242 static void | 242 static void |
| 243 do_scrolling (current_matrix, matrix, window_size, unchanged_at_top) | 243 do_scrolling (current_matrix, matrix, window_size, unchanged_at_top) |
| 244 struct glyph_matrix *current_matrix; | 244 struct glyph_matrix *current_matrix; |
| 245 struct matrix_elt *matrix; | 245 struct matrix_elt *matrix; |
| 246 int window_size; | 246 int window_size; |
| 256 /* A queue for line insertions to be done. */ | 256 /* A queue for line insertions to be done. */ |
| 257 struct queue { int count, pos; }; | 257 struct queue { int count, pos; }; |
| 258 struct queue *queue_start | 258 struct queue *queue_start |
| 259 = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue)); | 259 = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue)); |
| 260 struct queue *queue = queue_start; | 260 struct queue *queue = queue_start; |
| 261 | 261 |
| 262 char *retained_p = (char *) alloca (window_size * sizeof (char)); | 262 char *retained_p = (char *) alloca (window_size * sizeof (char)); |
| 263 int *copy_from = (int *) alloca (window_size * sizeof (int)); | 263 int *copy_from = (int *) alloca (window_size * sizeof (int)); |
| 264 | 264 |
| 265 /* Zero means line is empty. */ | 265 /* Zero means line is empty. */ |
| 266 bzero (retained_p, window_size * sizeof (char)); | 266 bzero (retained_p, window_size * sizeof (char)); |
| 281 When i is advanced, this corresponds to inserted lines. */ | 281 When i is advanced, this corresponds to inserted lines. */ |
| 282 i = j = window_size; | 282 i = j = window_size; |
| 283 while (i > 0 || j > 0) | 283 while (i > 0 || j > 0) |
| 284 { | 284 { |
| 285 p = matrix + i * (window_size + 1) + j; | 285 p = matrix + i * (window_size + 1) + j; |
| 286 | 286 |
| 287 if (p->insertcost < p->writecost && p->insertcost < p->deletecost) | 287 if (p->insertcost < p->writecost && p->insertcost < p->deletecost) |
| 288 { | 288 { |
| 289 /* Insert should be done at vpos i-1, plus maybe some before. | 289 /* Insert should be done at vpos i-1, plus maybe some before. |
| 290 Queue the screen operation to be performed. */ | 290 Queue the screen operation to be performed. */ |
| 291 queue->count = p->insertcount; | 291 queue->count = p->insertcount; |
| 363 glyph row j. */ | 363 glyph row j. */ |
| 364 copy_from[k + j] = next; | 364 copy_from[k + j] = next; |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 while (queue > queue_start); | 367 while (queue > queue_start); |
| 368 | 368 |
| 369 } | 369 } |
| 370 | 370 |
| 371 for (k = 0; k < window_size; ++k) | 371 for (k = 0; k < window_size; ++k) |
| 372 xassert (copy_from[k] >= 0 && copy_from[k] < window_size); | 372 xassert (copy_from[k] >= 0 && copy_from[k] < window_size); |
| 373 | 373 |
| 375 mirrored_line_dance (current_matrix, unchanged_at_top, window_size, | 375 mirrored_line_dance (current_matrix, unchanged_at_top, window_size, |
| 376 copy_from, retained_p); | 376 copy_from, retained_p); |
| 377 | 377 |
| 378 /* Some sanity checks if GLYPH_DEBUG != 0. */ | 378 /* Some sanity checks if GLYPH_DEBUG != 0. */ |
| 379 CHECK_MATRIX (current_matrix); | 379 CHECK_MATRIX (current_matrix); |
| 380 | 380 |
| 381 if (terminal_window_p) | 381 if (terminal_window_p) |
| 382 set_terminal_window (0); | 382 set_terminal_window (0); |
| 383 } | 383 } |
| 384 | 384 |
| 385 | 385 |
| 560 rate of change of these two parameters. Each of these | 560 rate of change of these two parameters. Each of these |
| 561 growth rates can be determined by a simple difference. | 561 growth rates can be determined by a simple difference. |
| 562 To reduce the cumulative effects of rounding error, we | 562 To reduce the cumulative effects of rounding error, we |
| 563 vary the position at which the difference is computed. */ | 563 vary the position at which the difference is computed. */ |
| 564 cost1 += first_insert_cost[-j] - first_insert_cost[1-j] + | 564 cost1 += first_insert_cost[-j] - first_insert_cost[1-j] + |
| 565 (delta-1) * (next_insert_cost[-j] - next_insert_cost[1-j]); | 565 (delta-1) * (next_insert_cost[-j] - next_insert_cost[1-j]); |
| 566 } | 566 } |
| 567 else | 567 else |
| 568 { | 568 { |
| 569 delta = j - i; | 569 delta = j - i; |
| 570 cost += scroll_overhead + first_delete_cost[-delta] + | 570 cost += scroll_overhead + first_delete_cost[-delta] + |
| 571 (delta-1) * (next_delete_cost[-delta] + extra_cost); | 571 (delta-1) * (next_delete_cost[-delta] + extra_cost); |
| 572 cost1 += first_delete_cost[-i] - first_delete_cost[1-i] + | 572 cost1 += first_delete_cost[-i] - first_delete_cost[1-i] + |
| 573 (delta-1) * ( next_delete_cost[-i] - next_delete_cost[1-i]); | 573 (delta-1) * ( next_delete_cost[-i] - next_delete_cost[1-i]); |
| 574 } | 574 } |
| 575 if (cost1 < cost) | 575 if (cost1 < cost) |
| 576 { | 576 { |
| 577 cost = cost1; | 577 cost = cost1; |
| 578 p->writecount = p1->writecount + 1; | 578 p->writecount = p1->writecount + 1; |
| 639 | 639 |
| 640 WINDOW_SIZE is the number of lines being considered for scrolling | 640 WINDOW_SIZE is the number of lines being considered for scrolling |
| 641 and UNCHANGED_AT_TOP is the vpos of the first line being | 641 and UNCHANGED_AT_TOP is the vpos of the first line being |
| 642 considered. These two arguments can specify any contiguous range | 642 considered. These two arguments can specify any contiguous range |
| 643 of lines. | 643 of lines. |
| 644 | 644 |
| 645 In the direct scrolling method, a new scroll window is selected | 645 In the direct scrolling method, a new scroll window is selected |
| 646 before each insertion or deletion, so that groups of lines can be | 646 before each insertion or deletion, so that groups of lines can be |
| 647 scrolled directly to their final vertical positions. This method | 647 scrolled directly to their final vertical positions. This method |
| 648 is described in more detail in calculate_direct_scrolling, where | 648 is described in more detail in calculate_direct_scrolling, where |
| 649 the cost matrix for this approach is constructed. */ | 649 the cost matrix for this approach is constructed. */ |
| 699 If i is decremented without also decrementing j, this corresponds | 699 If i is decremented without also decrementing j, this corresponds |
| 700 to inserting empty lines in the result. If j is decremented | 700 to inserting empty lines in the result. If j is decremented |
| 701 without also decrementing i, this corresponds to omitting these | 701 without also decrementing i, this corresponds to omitting these |
| 702 lines in the new rows, i.e. rows are deleted. */ | 702 lines in the new rows, i.e. rows are deleted. */ |
| 703 i = j = window_size; | 703 i = j = window_size; |
| 704 | 704 |
| 705 while (i > 0 || j > 0) | 705 while (i > 0 || j > 0) |
| 706 { | 706 { |
| 707 p = cost_matrix + i * (window_size + 1) + j; | 707 p = cost_matrix + i * (window_size + 1) + j; |
| 708 | 708 |
| 709 if (p->insertcost < p->writecost | 709 if (p->insertcost < p->writecost |
| 710 && p->insertcost < p->deletecost | 710 && p->insertcost < p->deletecost |
| 711 && (write_follows_p || i < j)) | 711 && (write_follows_p || i < j)) |
| 712 { | 712 { |
| 713 /* Insert is cheaper than deleting or writing lines. Leave | 713 /* Insert is cheaper than deleting or writing lines. Leave |
| 715 empty lines when the queue is emptied. */ | 715 empty lines when the queue is emptied. */ |
| 716 queue->count = 0; | 716 queue->count = 0; |
| 717 queue->window = i; | 717 queue->window = i; |
| 718 queue->pos = i - p->insertcount; | 718 queue->pos = i - p->insertcount; |
| 719 ++queue; | 719 ++queue; |
| 720 | 720 |
| 721 i -= p->insertcount; | 721 i -= p->insertcount; |
| 722 write_follows_p = 0; | 722 write_follows_p = 0; |
| 723 } | 723 } |
| 724 else if (p->deletecost < p->writecost | 724 else if (p->deletecost < p->writecost |
| 725 && (write_follows_p || i > j)) | 725 && (write_follows_p || i > j)) |
| 734 /* One or more lines should be written. In the direct | 734 /* One or more lines should be written. In the direct |
| 735 scrolling method we do this by scrolling the lines to the | 735 scrolling method we do this by scrolling the lines to the |
| 736 place they belong. */ | 736 place they belong. */ |
| 737 int n_to_write = p->writecount; | 737 int n_to_write = p->writecount; |
| 738 write_follows_p = 1; | 738 write_follows_p = 1; |
| 739 xassert (n_to_write > 0); | 739 xassert (n_to_write > 0); |
| 740 | 740 |
| 741 if (i > j) | 741 if (i > j) |
| 742 { | 742 { |
| 743 /* Immediately insert lines */ | 743 /* Immediately insert lines */ |
| 744 set_terminal_window (i + unchanged_at_top); | 744 set_terminal_window (i + unchanged_at_top); |
| 820 | 820 |
| 821 if (scroll_region_ok) | 821 if (scroll_region_ok) |
| 822 { | 822 { |
| 823 calculate_direct_scrolling (frame, matrix, window_size, | 823 calculate_direct_scrolling (frame, matrix, window_size, |
| 824 unchanged_at_bottom, | 824 unchanged_at_bottom, |
| 825 draw_cost, old_draw_cost, | 825 draw_cost, old_draw_cost, |
| 826 old_hash, new_hash, free_at_end); | 826 old_hash, new_hash, free_at_end); |
| 827 do_direct_scrolling (frame->current_matrix, | 827 do_direct_scrolling (frame->current_matrix, |
| 828 matrix, window_size, unchanged_at_top); | 828 matrix, window_size, unchanged_at_top); |
| 829 } | 829 } |
| 830 else | 830 else |
| 1052 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | 1052 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); |
| 1053 FRAME_DELETEN_COST (frame) = | 1053 FRAME_DELETEN_COST (frame) = |
| 1054 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | 1054 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); |
| 1055 FRAME_INSERTN_COST (frame) = | 1055 FRAME_INSERTN_COST (frame) = |
| 1056 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | 1056 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); |
| 1057 FRAME_DELETE_COST (frame) = | 1057 FRAME_DELETE_COST (frame) = |
| 1058 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | 1058 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 ins_del_costs (frame, | 1061 ins_del_costs (frame, |
| 1062 ins_line_string, multi_ins_string, | 1062 ins_line_string, multi_ins_string, |
