Mercurial > emacs
comparison src/indent.c @ 526:a41500eed1c5
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sat, 01 Feb 1992 19:17:17 +0000 |
parents | 4fddd0f0fc33 |
children | 937bccff8155 |
comparison
equal
deleted
inserted
replaced
525:44213fc1fbb6 | 526:a41500eed1c5 |
---|---|
406 compute_motion (from, fromvpos, fromhpos, to, tovpos, tohpos, width, hscroll, tab_offset) | 406 compute_motion (from, fromvpos, fromhpos, to, tovpos, tohpos, width, hscroll, tab_offset) |
407 int from, fromvpos, fromhpos, to, tovpos, tohpos; | 407 int from, fromvpos, fromhpos, to, tovpos, tohpos; |
408 register int width; | 408 register int width; |
409 int hscroll, tab_offset; | 409 int hscroll, tab_offset; |
410 { | 410 { |
411 /* Note that `cpos' is CURRENT_VPOS << SHORTBITS + CURRENT_HPOS, | 411 register int hpos = fromhpos; |
412 and that CURRENT_HPOS may be negative. Use these macros | 412 register int vpos = fromvpos; |
413 to extract the hpos or the vpos from cpos or anything like it. | 413 |
414 */ | |
415 #ifndef SHORT_CAST_BUG | |
416 #define HPOS(VAR) (short) (VAR) | |
417 #else | |
418 #define HPOS(VAR) (((VAR) & (1 << (SHORTBITS - 1)) \ | |
419 ? ~((1 << SHORTBITS) - 1) : 0) \ | |
420 | (VAR) & ((1 << SHORTBITS) - 1)) | |
421 /* #define HPOS(VAR) (((VAR) & 0x8000 ? 0xffff0000 : 0) | ((VAR) & 0xffff)) */ | |
422 #endif /* SHORT_CAST_BUG */ | |
423 | |
424 #define VPOS(VAR) (((VAR) >> SHORTBITS) + (HPOS (VAR) < 0)) | |
425 | |
426 | |
427 #ifndef TAHOE_REGISTER_BUG | |
428 register | |
429 #endif /* TAHOE_REGISTER_BUG */ | |
430 int cpos = fromhpos + (fromvpos << SHORTBITS); | |
431 register int target = tohpos + (tovpos << SHORTBITS); | |
432 register int pos; | 414 register int pos; |
433 register int c; | 415 register int c; |
434 register int tab_width = XFASTINT (current_buffer->tab_width); | 416 register int tab_width = XFASTINT (current_buffer->tab_width); |
435 register int ctl_arrow = !NILP (current_buffer->ctl_arrow); | 417 register int ctl_arrow = !NILP (current_buffer->ctl_arrow); |
436 register struct Lisp_Vector *dp = buffer_display_table (); | 418 register struct Lisp_Vector *dp = buffer_display_table (); |
437 int selective | 419 int selective |
438 = XTYPE (current_buffer->selective_display) == Lisp_Int | 420 = XTYPE (current_buffer->selective_display) == Lisp_Int |
439 ? XINT (current_buffer->selective_display) | 421 ? XINT (current_buffer->selective_display) |
440 : !NILP (current_buffer->selective_display) ? -1 : 0; | 422 : !NILP (current_buffer->selective_display) ? -1 : 0; |
441 int prevpos; | 423 int prev_vpos, prev_hpos; |
442 int selective_rlen | 424 int selective_rlen |
443 = (selective && dp && XTYPE (DISP_INVIS_ROPE (dp)) == Lisp_String | 425 = (selective && dp && XTYPE (DISP_INVIS_ROPE (dp)) == Lisp_String |
444 ? XSTRING (DISP_INVIS_ROPE (dp))->size / sizeof (GLYPH) : 0); | 426 ? XSTRING (DISP_INVIS_ROPE (dp))->size / sizeof (GLYPH) : 0); |
445 | 427 |
446 if (tab_width <= 0 || tab_width > 20) tab_width = 8; | 428 if (tab_width <= 0 || tab_width > 20) tab_width = 8; |
447 for (pos = from; pos < to && cpos < target; pos++) | 429 for (pos = from; pos < to; pos++) |
448 { | 430 { |
449 prevpos = cpos; | 431 /* Stop if past the target screen position. */ |
432 if (vpos > tovpos | |
433 || (vpos == tovpos && hpos >= tohpos)) | |
434 break; | |
435 | |
436 prev_vpos = vpos; | |
437 prev_hpos = hpos; | |
438 | |
450 c = FETCH_CHAR (pos); | 439 c = FETCH_CHAR (pos); |
451 if (c >= 040 && c < 0177 | 440 if (c >= 040 && c < 0177 |
452 && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String)) | 441 && (dp == 0 || XTYPE (DISP_CHAR_ROPE (dp, c)) != Lisp_String)) |
453 cpos++; | 442 hpos++; |
454 else if (c == '\t') | 443 else if (c == '\t') |
455 { | 444 { |
456 cpos += tab_width | 445 hpos += tab_width - ((hpos + tab_offset + hscroll - (hscroll > 0) |
457 - HPOS (cpos + tab_offset + hscroll - (hscroll > 0) | 446 /* Add tab_width here to make sure positive. |
458 /* Add tab_width here to make sure positive. | 447 hpos can be negative after continuation |
459 cpos can be negative after continuation | 448 but can't be less than -tab_width. */ |
460 but can't be less than -tab_width. */ | 449 + tab_width) |
461 + tab_width) | 450 % tab_width); |
462 % tab_width; | |
463 } | 451 } |
464 else if (c == '\n') | 452 else if (c == '\n') |
465 { | 453 { |
466 if (selective > 0 && position_indentation (pos + 1) >= selective) | 454 if (selective > 0 && position_indentation (pos + 1) >= selective) |
467 { | 455 { |
468 /* Skip any number of invisible lines all at once */ | 456 /* Skip any number of invisible lines all at once */ |
469 do | 457 do |
470 { | 458 { |
471 while (++pos < to && FETCH_CHAR(pos) != '\n'); | 459 while (++pos < to && FETCH_CHAR (pos) != '\n'); |
472 } | 460 } |
473 while (selective > 0 && position_indentation (pos + 1) >= selective); | 461 while (selective > 0 && position_indentation (pos + 1) >= selective); |
474 pos--; | 462 pos--; |
475 /* Allow for the " ..." that is displayed for them. */ | 463 /* Allow for the " ..." that is displayed for them. */ |
476 if (selective_rlen) | 464 if (selective_rlen) |
477 { | 465 { |
478 cpos += selective_rlen; | 466 hpos += selective_rlen; |
479 if (HPOS (cpos) >= width) | 467 if (hpos >= width) |
480 cpos -= HPOS (cpos) - width; | 468 hpos = width; |
481 } | 469 } |
482 } | 470 } |
483 else | 471 else |
484 cpos += (1 << SHORTBITS) - HPOS (cpos); | 472 { |
485 cpos -= hscroll; | 473 /* A visible line. */ |
486 if (hscroll > 0) cpos++; /* Count the ! on column 0 */ | 474 vpos++; |
475 hpos = 0; | |
476 } | |
477 hpos -= hscroll; | |
478 if (hscroll > 0) hpos++; /* Count the ! on column 0 */ | |
487 tab_offset = 0; | 479 tab_offset = 0; |
488 } | 480 } |
489 else if (c == CR && selective < 0) | 481 else if (c == CR && selective < 0) |
490 { | 482 { |
491 /* In selective display mode, | 483 /* In selective display mode, |
492 everything from a ^M to the end of the line is invisible */ | 484 everything from a ^M to the end of the line is invisible */ |
493 while (pos < to && FETCH_CHAR(pos) != '\n') pos++; | 485 while (pos < to && FETCH_CHAR (pos) != '\n') pos++; |
486 /* Stop *before* the real newline. */ | |
494 pos--; | 487 pos--; |
495 /* Allow for the " ..." that is displayed for them. */ | 488 /* Allow for the " ..." that is displayed for them. */ |
496 if (selective_rlen) | 489 if (selective_rlen) |
497 { | 490 { |
498 cpos += selective_rlen; | 491 hpos += selective_rlen; |
499 if (HPOS (cpos) >= width) | 492 if (hpos >= width) |
500 cpos -= HPOS (cpos) - width; | 493 hpos = width; |
501 } | 494 } |
502 } | 495 } |
503 else if (dp != 0 && XTYPE (DISP_CHAR_ROPE (dp, c)) == Lisp_String) | 496 else if (dp != 0 && XTYPE (DISP_CHAR_ROPE (dp, c)) == Lisp_String) |
504 cpos += XSTRING (DISP_CHAR_ROPE (dp, c))->size / sizeof (GLYPH); | 497 hpos += XSTRING (DISP_CHAR_ROPE (dp, c))->size / sizeof (GLYPH); |
505 else | 498 else |
506 cpos += (ctl_arrow && c < 0200) ? 2 : 4; | 499 hpos += (ctl_arrow && c < 0200) ? 2 : 4; |
507 | 500 |
508 if (HPOS (cpos) >= width | 501 /* Handle right margin. */ |
509 && (HPOS (cpos) > width | 502 if (hpos >= width |
510 || (pos < (ZV - 1) | 503 && (hpos > width |
504 || (pos < ZV - 1 | |
511 && FETCH_CHAR (pos + 1) != '\n'))) | 505 && FETCH_CHAR (pos + 1) != '\n'))) |
512 { | 506 { |
513 if (cpos >= target) | 507 if (vpos > tovpos |
508 || (vpos == tovpos && hpos >= tohpos)) | |
514 break; | 509 break; |
515 if (hscroll | 510 if (hscroll |
516 || (truncate_partial_width_windows | 511 || (truncate_partial_width_windows |
517 && width + 1 < SCREEN_WIDTH (selected_screen)) | 512 && width + 1 < SCREEN_WIDTH (selected_screen)) |
518 || !NILP (current_buffer->truncate_lines)) | 513 || !NILP (current_buffer->truncate_lines)) |
519 { | 514 { |
520 while (pos < to && FETCH_CHAR(pos) != '\n') pos++; | 515 /* Truncating: skip to newline. */ |
516 while (pos < to && FETCH_CHAR (pos) != '\n') pos++; | |
521 pos--; | 517 pos--; |
522 } | 518 } |
523 else | 519 else |
524 { | 520 { |
525 cpos += (1 << SHORTBITS) - width; | 521 /* Continuing. */ |
522 vpos++; | |
523 hpos -= width; | |
526 tab_offset += width; | 524 tab_offset += width; |
527 } | 525 } |
528 | 526 |
529 } | 527 } |
530 } | 528 } |
531 | 529 |
532 val_compute_motion.bufpos = pos; | 530 val_compute_motion.bufpos = pos; |
533 val_compute_motion.hpos = HPOS (cpos); | 531 val_compute_motion.hpos = hpos; |
534 val_compute_motion.vpos = VPOS (cpos); | 532 val_compute_motion.vpos = vpos; |
535 val_compute_motion.prevhpos = HPOS (prevpos); | 533 val_compute_motion.prevhpos = prev_hpos; |
536 | 534 |
537 /* Nonzero if have just continued a line */ | 535 /* Nonzero if have just continued a line */ |
538 val_compute_motion.contin | 536 val_compute_motion.contin |
539 = pos != from | 537 = (pos != from |
540 && (val_compute_motion.vpos != VPOS (prevpos)) | 538 && (val_compute_motion.vpos != prev_vpos) |
541 && c != '\n'; | 539 && c != '\n'); |
542 | 540 |
543 return &val_compute_motion; | 541 return &val_compute_motion; |
544 } | 542 } |
545 #undef HPOS | |
546 #undef VPOS | |
547 | 543 |
548 | 544 |
549 /* Return the column of position POS in window W's buffer, | 545 /* Return the column of position POS in window W's buffer, |
550 rounded down to a multiple of the internal width of W. | 546 rounded down to a multiple of the internal width of W. |
551 This is the amount of indentation of position POS | 547 This is the amount of indentation of position POS |
606 && prevline > BEGV | 602 && prevline > BEGV |
607 && position_indentation (prevline) >= selective) | 603 && position_indentation (prevline) >= selective) |
608 prevline = find_next_newline (prevline - 1, -1); | 604 prevline = find_next_newline (prevline - 1, -1); |
609 pos = *compute_motion (prevline, 0, | 605 pos = *compute_motion (prevline, 0, |
610 lmargin + (prevline == 1 ? start_hpos : 0), | 606 lmargin + (prevline == 1 ? start_hpos : 0), |
611 from, 10000, 10000, | 607 from, 1 << (INTBITS - 2), 0, |
612 width, hscroll, 0); | 608 width, hscroll, 0); |
613 } | 609 } |
614 else | 610 else |
615 { | 611 { |
616 pos.hpos = lmargin + (from == 1 ? start_hpos : 0); | 612 pos.hpos = lmargin + (from == 1 ? start_hpos : 0); |
617 pos.vpos = 0; | 613 pos.vpos = 0; |
618 } | 614 } |
619 return compute_motion (from, vpos, pos.hpos, | 615 return compute_motion (from, vpos, pos.hpos, |
620 ZV, vtarget, - (1 << (SHORTBITS - 1)), | 616 ZV, vtarget, - (1 << (INTBITS - 2)), |
621 width, hscroll, pos.vpos * width); | 617 width, hscroll, pos.vpos * width); |
622 } | 618 } |
623 | 619 |
624 /* To move upward, go a line at a time until | 620 /* To move upward, go a line at a time until |
625 we have gone at least far enough */ | 621 we have gone at least far enough */ |
637 || position_indentation (prevline) < selective) | 633 || position_indentation (prevline) < selective) |
638 break; | 634 break; |
639 } | 635 } |
640 pos = *compute_motion (prevline, 0, | 636 pos = *compute_motion (prevline, 0, |
641 lmargin + (prevline == 1 ? start_hpos : 0), | 637 lmargin + (prevline == 1 ? start_hpos : 0), |
642 from, 10000, 10000, | 638 from, 1 << (INTBITS - 2), 0, |
643 width, hscroll, 0); | 639 width, hscroll, 0); |
644 vpos -= pos.vpos; | 640 vpos -= pos.vpos; |
645 first = 0; | 641 first = 0; |
646 from = prevline; | 642 from = prevline; |
647 } | 643 } |