+IT_display_cursor (int on)
+{
+ if (on && cursor_cleared)
+ {
+ ScreenSetCursor (current_pos_Y, current_pos_X);
+ cursor_cleared = 0;
+ }
+ else if (!on && !cursor_cleared)
+ {
+ ScreenSetCursor (-1, -1);
+ cursor_cleared = 1;
+ }
+}
+
+/* Emacs calls cursor-movement functions a lot when it updates the
+ display (probably a legacy of old terminals where you cannot
+ update a screen line without first moving the cursor there).
+ However, cursor movement is expensive on MSDOS (it calls a slow
+ BIOS function and requires 2 mode switches), while actual screen
+ updates access the video memory directly and don't depend on
+ cursor position. To avoid slowing down the redisplay, we cheat:
+ all functions that move the cursor only set internal variables
+ which record the cursor position, whereas the cursor is only
+ moved to its final position whenever screen update is complete.
+
+ `IT_cmgoto' is called from the keyboard reading loop and when the
+ frame update is complete. This means that we are ready for user
+ input, so we update the cursor position to show where the point is,
+ and also make the mouse pointer visible.
+
+ Special treatment is required when the cursor is in the echo area,
+ to put the cursor at the end of the text displayed there. */
+
+static void
+IT_cmgoto (FRAME_PTR f)
+{
+ /* Only set the cursor to where it should be if the display is
+ already in sync with the window contents. */
+ int update_cursor_pos = MODIFF == unchanged_modified;
+ static int previous_pos_X = -1;
+
+ /* If the display is in sync, forget any previous knowledge about
+ cursor position. This is primarily for unexpected events like
+ C-g in the minibuffer. */
+ if (update_cursor_pos && previous_pos_X >= 0)
+ previous_pos_X = -1;
+ /* If we are in the echo area, put the cursor at the
+ end of the echo area message. */
+ if (!update_cursor_pos
+ && XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top) <= new_pos_Y)
+ {
+ int tem_X = current_pos_X, dummy;
+
+ if (echo_area_glyphs)
+ {
+ tem_X = echo_area_glyphs_length;
+ /* Save current cursor position, to be restored after the
+ echo area message is erased. Only remember one level
+ of previous cursor position. */
+ if (previous_pos_X == -1)
+ ScreenGetCursor (&dummy, &previous_pos_X);
+ }
+ else if (previous_pos_X >= 0)
+ {
+ /* We wind up here after the echo area message is erased.
+ Restore the cursor position we remembered above. */
+ tem_X = previous_pos_X;
+ previous_pos_X = -1;
+ }
+
+ if (current_pos_X != tem_X)
+ {
+ new_pos_X = tem_X;
+ update_cursor_pos = 1;
+ }
+ }
+
+ if (update_cursor_pos
+ && (current_pos_X != new_pos_X || current_pos_Y != new_pos_Y))
+ {
+ ScreenSetCursor (current_pos_Y = new_pos_Y, current_pos_X = new_pos_X);
+ if (termscript)
+ fprintf (termscript, "\n<CURSOR:%dx%d>", current_pos_X, current_pos_Y);
+ }
+
+ /* Maybe cursor is invisible, so make it visible. */
+ IT_display_cursor (1);
+
+ /* Mouse pointer should be always visible if we are waiting for
+ keyboard input. */
+ if (!mouse_visible)
+ mouse_on ();
+}
+
+static void
+IT_reassert_line_highlight (int new, int vpos)