aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-03-10 19:06:59 +0000
committerRichard M. Stallman1994-03-10 19:06:59 +0000
commit42918ba5073f555125016edc7815c719d11272f8 (patch)
tree4921810da4200935a49fd783bc53d55b41917377 /src
parenta867a90a321479fd1a9028c6e4eef35d0abe2052 (diff)
downloademacs-42918ba5073f555125016edc7815c719d11272f8.tar.gz
emacs-42918ba5073f555125016edc7815c719d11272f8.zip
(compute_motion): Initialize prev_hpos.
(Fcompute_motion): New function.
Diffstat (limited to 'src')
-rw-r--r--src/indent.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/indent.c b/src/indent.c
index e2711c1fdee..e4ab5ff735e 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -447,7 +447,7 @@ compute_motion (from, fromvpos, fromhpos, to, tovpos, tohpos, width, hscroll, ta
447 = XTYPE (current_buffer->selective_display) == Lisp_Int 447 = XTYPE (current_buffer->selective_display) == Lisp_Int
448 ? XINT (current_buffer->selective_display) 448 ? XINT (current_buffer->selective_display)
449 : !NILP (current_buffer->selective_display) ? -1 : 0; 449 : !NILP (current_buffer->selective_display) ? -1 : 0;
450 int prev_vpos, prev_hpos; 450 int prev_vpos, prev_hpos = 0;
451 int selective_rlen 451 int selective_rlen
452 = (selective && dp && XTYPE (DISP_INVIS_VECTOR (dp)) == Lisp_Vector 452 = (selective && dp && XTYPE (DISP_INVIS_VECTOR (dp)) == Lisp_Vector
453 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size : 0); 453 ? XVECTOR (DISP_INVIS_VECTOR (dp))->size : 0);
@@ -605,6 +605,76 @@ compute_motion (from, fromvpos, fromhpos, to, tovpos, tohpos, width, hscroll, ta
605 return &val_compute_motion; 605 return &val_compute_motion;
606} 606}
607 607
608DEFUN ("compute-motion", Fcompute_motion, Scompute_motion, 6, 6, 0,
609 "Scan through the current buffer, calculating screen position.\n\
610Scan the current buffer forward from offset FROM,\n\
611assuming it is at position FROMPOS--a cons of the form (HPOS . VPOS)--\n\
612to position TO or position TOPOS--another cons of the form (HPOS . VPOS)--\n\
613and return the ending buffer position and screen location.\n\
614\n\
615There are two additional arguments:\n\
616\n\
617WIDTH is the number of columns available to display text;\n\
618this affects handling of continuation lines.\n\
619Use the value returned by `window-width' for the window of your choice.\n\
620\n\
621OFFSETS is either nil or a cons cell (HSCROLL . TAB-OFFSET).\n\
622HSCROLL is the number of columns not being displayed at the left\n\
623margin; this is usually taken from a window's hscroll member.\n\
624TAB-OFFSET is the number of columns of the first tab that aren't\n\
625being displayed, perhaps because the line was continued within it.\n\
626\n\
627The value is a list of five elements:\n\
628 (POS VPOS HPOS PREVHPOS CONTIN)\n\
629POS is the buffer position where the scan stopped.\n\
630VPOS is the vertical position where the scan stopped.\n\
631HPOS is the horizontal position where the scan stopped.\n\
632\n\
633PREVHPOS is the horizontal position one character back from POS.\n\
634CONTIN is t if a line was continued after (or within) the previous character.\n\
635\n\
636For example, to find the buffer position of column COL of line LINE\n\
637of a certain window, pass the window's starting location as FROM\n\
638and the window's upper-left coordinates as FROMPOS.\n\
639Pass the buffer's (point-max) as TO, to limit the scan to the end of the\n\
640visible section of the buffer, and pass LINE and COL as TOPOS.")
641 (from, frompos, to, topos, width, offsets)
642 Lisp_Object from, frompos, to, topos;
643 Lisp_Object width, offsets;
644{
645 Lisp_Object bufpos, hpos, vpos, prevhpos, contin;
646 struct position *pos;
647 int hscroll, tab_offset;
648
649 CHECK_CONS (frompos, 0);
650 CHECK_CONS (topos, 0);
651 if (!NILP (offsets))
652 {
653 CHECK_CONS (offsets, 0);
654 hscroll = XINT (XCONS (offsets)->car);
655 tab_offset = XINT (XCONS (offsets)->cdr);
656 }
657 else
658 hscroll = tab_offset = 0;
659
660 pos = compute_motion (XINT (from), XINT (XCONS (frompos)->cdr),
661 XINT (XCONS (frompos)->car),
662 XINT (to), XINT (XCONS (topos)->cdr),
663 XINT (XCONS (topos)->car),
664 XINT (width), hscroll, tab_offset);
665
666 XFASTINT (bufpos) = pos->bufpos;
667 XFASTINT (hpos) = pos->hpos;
668 XSET (vpos, Lisp_Int, pos->vpos);
669 XFASTINT (prevhpos) = pos->prevhpos;
670
671 return Fcons (bufpos,
672 Fcons (hpos,
673 Fcons (vpos,
674 Fcons (prevhpos,
675 Fcons (pos->contin ? Qt : Qnil, Qnil)))));
676
677}
608 678
609/* Return the column of position POS in window W's buffer, 679/* Return the column of position POS in window W's buffer,
610 rounded down to a multiple of the internal width of W. 680 rounded down to a multiple of the internal width of W.
@@ -771,4 +841,5 @@ Setting this variable automatically makes it local to the current buffer.");
771 defsubr (&Scurrent_column); 841 defsubr (&Scurrent_column);
772 defsubr (&Smove_to_column); 842 defsubr (&Smove_to_column);
773 defsubr (&Svertical_motion); 843 defsubr (&Svertical_motion);
844 defsubr (&Scompute_motion);
774} 845}