diff --git a/lisp/faces.el b/lisp/faces.el
index 18b821a..614205b 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -2502,6 +2502,33 @@ unwanted effects."
   :group 'basic-faces
   :group 'display-line-numbers)
 
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Multiple Cursors
+
+(defface +-vertical-bar-face
+  '((t (:foreground "cyan")))
+  "Face for `+-vertical-bar-face'.  Used in `xdisp.c'."
+  :group '+-mode)
+
+(defface +-even-numbered-column-face
+  '((t (:foreground "yellow")))
+  "Face for `+-even-numbered-column-face'.  Used in `xdisp.c'."
+  :group '+-mode)
+
+(defface +-odd-numbered-column-face
+  '((t (:foreground "red")))
+  "Face for `+-odd-numbered-column-face'.  Used in `xdisp.c'."
+  :group '+-mode)
+
+(defface +-beyond-fill-column-face
+  '((t (:foreground "green")))
+  "Face for `+-beyond-fill-column-face'.  Used in `xdisp.c'."
+  :group '+-mode)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
 (defface escape-glyph
   '((((background dark)) :foreground "cyan")
     ;; See the comment in minibuffer-prompt for
diff --git a/src/buffer.c b/src/buffer.c
index 244c185..17cfcb0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5119,6 +5119,20 @@ init_buffer_once (void)
   bset_last_selected_window (&buffer_local_flags, make_number (0));
 
   idx = 1;
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  XSETFASTINT (BVAR (&buffer_local_flags, mc_glyph_list), idx); ++idx;
+  XSETFASTINT (BVAR (&buffer_local_flags, crosshairs), idx); ++idx;
+  XSETFASTINT (BVAR (&buffer_local_flags, crosshairs_horizontal_ruler), idx); ++idx;
+  XSETFASTINT (BVAR (&buffer_local_flags, crosshairs_vertical_ruler), idx); ++idx;
+  XSETFASTINT (BVAR (&buffer_local_flags, mc_stderr), idx); ++idx;
+
+/* *************************************************************************** */
+
+
   XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx;
   XSETFASTINT (BVAR (&buffer_local_flags, abbrev_mode), idx); ++idx;
   XSETFASTINT (BVAR (&buffer_local_flags, overwrite_mode), idx); ++idx;
@@ -5200,6 +5214,20 @@ init_buffer_once (void)
   /* Must do these before making the first buffer! */
 
   /* real setup is done in bindings.el */
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  bset_blv_mc_glyph_list (&buffer_defaults, Qnil);
+  bset_blv_crosshairs (&buffer_defaults, Qnil);
+  bset_blv_crosshairs_horizontal_ruler (&buffer_defaults, Qt);
+  bset_blv_crosshairs_vertical_ruler (&buffer_defaults, Qt);
+  bset_blv_mc_stderr (&buffer_defaults, Qnil);
+
+/* *************************************************************************** */
+
+
   bset_mode_line_format (&buffer_defaults, build_pure_c_string ("%-"));
   bset_header_line_format (&buffer_defaults, Qnil);
   bset_abbrev_mode (&buffer_defaults, Qnil);
@@ -5448,6 +5476,19 @@ syms_of_buffer (void)
   staticpro (&QSFundamental);
   staticpro (&Vbuffer_alist);
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  DEFSYM (Qmc_glyph_list, "mc-glyph-list");
+  DEFSYM (Qcrosshairs, "crosshairs");
+  DEFSYM (Qcrosshairs_horizontal_ruler, "crosshairs-horizontal-ruler");
+  DEFSYM (Qcrosshairs_vertical_ruler, "crosshairs-vertical-ruler");
+  DEFSYM (Qmc_stderr, "mc-stderr");
+
+/* *************************************************************************** */
+
+
   DEFSYM (Qchoice, "choice");
   DEFSYM (Qleft, "left");
   DEFSYM (Qright, "right");
@@ -5485,6 +5526,29 @@ syms_of_buffer (void)
   Fput (Qprotected_field, Qerror_message,
 	build_pure_c_string ("Attempt to modify a protected field"));
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  DEFVAR_PER_BUFFER ("mc-glyph-list", &BVAR (current_buffer, mc_glyph_list), Qnil,
+    doc: /* A bufer-local variable to store the value of the multiple cursors to be displayed
+during the next redisplay. */);
+
+  DEFVAR_PER_BUFFER ("crosshairs", &BVAR (current_buffer, crosshairs), Qnil,
+    doc: /* A bufer-local variable to activate/deactivate crosshairs. */);
+
+  DEFVAR_PER_BUFFER ("crosshairs-horizontal-ruler", &BVAR (current_buffer, crosshairs_horizontal_ruler), Qnil,
+    doc: /* A bufer-local variable to activate/deactivate the crosshairs horizontal ruler. */);
+
+  DEFVAR_PER_BUFFER ("crosshairs-vertical-ruler", &BVAR (current_buffer, crosshairs_vertical_ruler), Qnil,
+    doc: /* A bufer-local variable to activate/deactivate the crosshairs vertical ruler. */);
+
+  DEFVAR_PER_BUFFER ("mc-stderr", &BVAR (current_buffer, mc_stderr), Qnil,
+    doc: /* A bufer-local variable to activate/deactivate debugging messages to stderr. */);
+
+/* *************************************************************************** */
+
+
   DEFVAR_PER_BUFFER ("header-line-format",
 		     &BVAR (current_buffer, header_line_format),
 		     Qnil,
diff --git a/src/buffer.h b/src/buffer.h
index 85b5631..7e03be4 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -658,6 +658,28 @@ struct buffer
      cache are enabled.  See search.c, indent.c and bidi.c for details.  */
   Lisp_Object cache_long_scans_;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  /* The name of list used by multiple cursors for next redisplay. */
+  Lisp_Object mc_glyph_list_;
+
+  /* The name of list. */
+  Lisp_Object crosshairs_;
+
+  /* The name of the crosshairs horizontal ruler. */
+  Lisp_Object crosshairs_horizontal_ruler_;
+
+  /* The name of the crosshairs vertical ruler. */
+  Lisp_Object crosshairs_vertical_ruler_;
+
+  /* Used in conjunction with generating stderr debugging message. */
+  Lisp_Object mc_stderr_;
+
+/* *************************************************************************** */
+
+
   /* If the width run cache is enabled, this table contains the
      character widths width_run_cache (see above) assumes.  When we
      do a thorough redisplay, we compare this against the buffer's
@@ -918,6 +940,44 @@ XBUFFER (Lisp_Object a)
 /* Most code should use these functions to set Lisp fields in struct
    buffer.  (Some setters that are private to a single .c file are
    defined as static in those files.)  */
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+INLINE void
+bset_blv_mc_glyph_list (struct buffer *b, Lisp_Object val)
+{
+  b->mc_glyph_list_ = val;
+}
+
+INLINE void
+bset_blv_crosshairs (struct buffer *b, Lisp_Object val)
+{
+  b->crosshairs_ = val;
+}
+
+INLINE void
+bset_blv_crosshairs_horizontal_ruler (struct buffer *b, Lisp_Object val)
+{
+  b->crosshairs_horizontal_ruler_ = val;
+}
+
+INLINE void
+bset_blv_crosshairs_vertical_ruler (struct buffer *b, Lisp_Object val)
+{
+  b->crosshairs_vertical_ruler_ = val;
+}
+
+INLINE void
+bset_blv_mc_stderr (struct buffer *b, Lisp_Object val)
+{
+  b->mc_stderr_ = val;
+}
+
+/* *************************************************************************** */
+
+
 INLINE void
 bset_bidi_paragraph_direction (struct buffer *b, Lisp_Object val)
 {
diff --git a/src/dispextern.h b/src/dispextern.h
index 2180c9a..f0b10c5 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3284,6 +3284,30 @@ extern void get_font_ascent_descent (struct font *, int *, int *);
 
 #ifdef HAVE_WINDOW_SYSTEM
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+enum mc_glyph_flavor
+{
+  NO_FLAVOR,
+  MC_GLYPH,
+  MC_GLYPHLESS,
+  MC_GLYPH_TAB,
+  OVERLAY_ARROW_BITMAP,
+  MC_PILCROW,
+  MC_HOLLOW_RECTANGLE_RIGHT_ANGLE,
+  MC_HOLLOW_RECTANGLE,
+  MC_VERTICAL_BAR_RIGHT_ANGLE,
+  MC_VERTICAL_BAR,
+  MC_VERTICAL_BAR_BACKSLASH
+};
+
+void mc_portal (struct window *, bool);
+
+/* *************************************************************************** */
+
+
 #ifdef GLYPH_DEBUG
 extern void dump_glyph_string (struct glyph_string *) EXTERNALLY_VISIBLE;
 #endif
diff --git a/src/fringe.c b/src/fringe.c
index 6069184..66d0187 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -433,6 +433,231 @@ static unsigned short empty_line_bits[] = {
   0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
 
 
+/* *************************************************************************** */
+/* begin MULTIPLE CURSORS */
+
+/*  ;; AUTHOR:  Nikolaj Schumacher -- https://github.com/nschum/fringe-helper.el
+    (defun +-fringe-helper-hexadecimal (&rest strings)
+    "Convert STRINGS into a vector usable for `define-fringe-bitmap'.
+    Each string in STRINGS represents a line of the fringe bitmap.
+    Periods (.) are background-colored pixel; Xs are foreground-colored. The
+    fringe bitmap always is aligned to the right. If the fringe has half
+    width, only the left 4 pixels of an 8 pixel bitmap will be shown.
+    For example, the following code defines a diagonal line.
+    \(+-fringe-helper-hexadecimal
+    \"XX......\"
+    \"..XX....\"
+    \"....XX..\"
+    \"......XX\"\)"
+      (unless (cdr strings)
+        (setq strings (split-string (car strings) "\n")))
+      (apply 'vector
+        (mapcar
+          (lambda (str)
+            (let ((num 0))
+              (dolist (c (string-to-list str))
+                (setq num (+ (* num 2) (if (eq c ?.) 0 1))))
+              (format "%#-x" num)))
+          strings)))
+*/
+
+/* 24
+    (+-fringe-helper-hexadecimal
+      "x......."
+      "x......."
+      "x......."
+      "x..xx..."
+      "x...xx.."
+      "x....xx."
+      "x.xxxxxx"
+      "x.xxxxxx"
+      "x....xx."
+      "x...xx.."
+      "x..xx..."
+      "x......."
+      "x......."
+      "x.......")
+*/
+static unsigned short mc_vertical_bar_right_angle_bits[] ={
+  0x80, 0x80, 0x80, 0x98, 0x8c, 0x86, 0xbf,
+  0xbf, 0x86, 0x8c, 0x98, 0x80, 0x80, 0x80};
+
+/* 25
+    (+-fringe-helper-hexadecimal
+      "xxxxxxxx"
+      "x......x"
+      "x......x"
+      "x..xx..x"
+      "x...xx.x"
+      "x....xxx"
+      "x.xxxxxx"
+      "x.xxxxxx"
+      "x....xxx"
+      "x...xx.x"
+      "x..xx..x"
+      "x......x"
+      "x......x"
+      "xxxxxxxx")
+*/
+static unsigned short mc_hollow_rectangle_right_angle_bits[] ={
+  0xff, 0x81, 0x81, 0x99, 0x8d, 0x87, 0xbf,
+  0xbf, 0x87, 0x8d, 0x99, 0x81, 0x81, 0xff};
+
+/* 26
+    (+-fringe-helper-hexadecimal
+      "xxxxxxxx"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "x......x"
+      "xxxxxxxx")
+*/
+static unsigned short mc_hollow_rectangle_bits[] ={
+  0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+  0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff};
+
+/* 27
+    (+-fringe-helper-hexadecimal
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x......."
+      "x.......")
+*/
+static unsigned short mc_vertical_bar_bits[] ={
+  0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+  0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};
+
+/* 28
+    (+-fringe-helper-hexadecimal
+      "xx......"
+      ".xx....."
+      "..xx...."
+      "...xx..."
+      "....xx.."
+      ".....xx."
+      "......xx"
+      ".....xx."
+      "....xx.."
+      "...xx..."
+      "..xx...."
+      ".xx....."
+      "xx......")
+*/
+static unsigned short mc_right_angle_bits[] ={
+  0xc0, 0x60, 0x30, 0x18, 0xc, 0x6, 0x3, 0x6, 0xc, 0x18, 0x30, 0x60, 0xc0};
+
+/* 29
+    (+-fringe-helper-hexadecimal
+      "xx......"
+      "xx......"
+      " xx....."
+      ".xx....."
+      "..xx...."
+      "..xx...."
+      "...xx..."
+      "...xx..."
+      "....xx.."
+      "....xx.."
+      ".....xx."
+      ".....xx."
+      "......xx"
+      "......xx")
+*/
+static unsigned short mc_backslash_bits[] ={
+  0xc0, 0xc0, 0xe0, 0x60, 0x30, 0x30, 0x18, 0x18, 0xc, 0xc, 0x6, 0x6, 0x3, 0x3};
+
+/* 30
+    (+-fringe-helper-hexadecimal
+      "xx......"
+      "xx......"
+      "xxx....."
+      "xxx....."
+      "x.xx...."
+      "x.xx...."
+      "x..xx..."
+      "x..xx..."
+      "x...xx.."
+      "x...xx.."
+      "x....xx."
+      "x....xx."
+      "x.....xx"
+      "x.....xx")
+*/
+static unsigned short mc_vertical_bar_backslash_bits[] ={
+  0xc0, 0xc0, 0xe0, 0xe0, 0xb0, 0xb0, 0x98,
+  0x98, 0x8c, 0x8c, 0x86, 0x86, 0x83, 0x83};
+
+/* 31
+    (+-fringe-helper-hexadecimal
+      ".xxxxxx."
+      "xxxx.x.."
+      "xxxx.x.."
+      "xxxx.x.."
+      ".xxx.x.."
+      "...x.x.."
+      "...x.x.."
+      "...x.x.."
+      "...x.x.."
+      "...x.x.."
+      "...x.x..")
+*/
+static unsigned short mc_pilcrow_bits[] ={
+  0x7e, 0xf4, 0xf4, 0xf4, 0x74, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14};
+
+/* 32
+    (+-fringe-helper-hexadecimal
+      "xx.xx..."
+      ".xx.xx.."
+      "..xx.xx."
+      "...xx.xx"
+      "..xx.xx."
+      ".xx.xx.."
+      "xx.xx...")
+*/
+static unsigned short mc_right_double_angle_bits[] ={
+  0xd8, 0x6c, 0x36, 0x1b, 0x36, 0x6c, 0xd8};
+
+/* 33
+    (+-fringe-helper-hexadecimal
+      "..xxxx.."
+      ".xxxxxx."
+      "x..xx..x"
+      "x..xx..x"
+      "xxxxxxxx"
+      "xx....xx"
+      "xxx..xxx"
+      ".xxxxxx."
+      "..xxxx..")
+*/
+static unsigned short mc_smiley_face_bits[] ={
+  0x3c, 0x7e, 0x99, 0x99, 0xff, 0xc3, 0xe7, 0x7e, 0x3c};
+
+/* Add the following bitmaps:
+  (define-fringe-bitmap 'breakpoint "\x3c\x7e\xff\xff\xff\xff\x7e\x3c")
+  (define-fringe-bitmap 'hollow-right-triangle "\xe0\x90\x88\x84\x84\x88\x90\xe0") */
+
+/* end MULTIPLE CURSORS */
+/* *************************************************************************** */
+
+
 #define BYTES_PER_BITMAP_ROW  (sizeof (unsigned short))
 #define STANDARD_BITMAP_HEIGHT(bits) (sizeof (bits)/BYTES_PER_BITMAP_ROW)
 #define FRBITS(bits)  bits, STANDARD_BITMAP_HEIGHT (bits)
@@ -466,6 +691,35 @@ static struct fringe_bitmap standard_bitmaps[] =
   { FRBITS (vertical_bar_bits),       8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (horizontal_bar_bits),     8, 0, ALIGN_BITMAP_BOTTOM, 0 },
   { FRBITS (empty_line_bits),         8, 3, ALIGN_BITMAP_TOP,    0 },
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  /* 24 */
+  { FRBITS (mc_vertical_bar_right_angle_bits),     8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 25 */
+  { FRBITS (mc_hollow_rectangle_right_angle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 26 */
+  { FRBITS (mc_hollow_rectangle_bits),             8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 27 */
+  { FRBITS (mc_vertical_bar_bits),                 8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 28 */
+  { FRBITS (mc_right_angle_bits),                  8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 29 */
+  { FRBITS (mc_backslash_bits),                    8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 30 */
+  { FRBITS (mc_vertical_bar_backslash_bits),       8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 31 */
+  { FRBITS (mc_pilcrow_bits),                      8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 32 */
+  { FRBITS (mc_right_double_angle_bits),           8, 0, ALIGN_BITMAP_CENTER, 0 },
+  /* 33 */
+  { FRBITS (mc_smiley_face_bits),                  8, 0, ALIGN_BITMAP_CENTER, 0 },
+
+/* *************************************************************************** */
+
+
 };
 
 #define NO_FRINGE_BITMAP 0
@@ -1715,6 +1969,77 @@ If nil, also continue lines which are exactly as wide as the window.  */);
   DEFVAR_LISP ("fringe-bitmaps", Vfringe_bitmaps,
     doc: /* List of fringe bitmap symbols.  */);
   Vfringe_bitmaps = Qnil;
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  /* (get 'empty-line 'fringe) => 23 => the last standard-bitmap before this one.
+  See `fringe.el`. */
+
+  /* 24 */
+  DEFSYM (Qmc_vertical_bar_right_angle, "+-vertical-bar-right-angle");
+  Vfringe_bitmaps = Fcons (Qmc_vertical_bar_right_angle, Vfringe_bitmaps);
+  Fput (Qmc_vertical_bar_right_angle, Qfringe, make_number (24));
+  /* (get '+-vertical-bar-right-angle 'fringe) => 24 */
+
+  /* 25 */
+  DEFSYM (Qmc_hollow_rectangle_right_angle, "+-hollow-rectangle-right-angle");
+  Vfringe_bitmaps = Fcons (Qmc_hollow_rectangle_right_angle, Vfringe_bitmaps);
+  Fput (Qmc_hollow_rectangle_right_angle, Qfringe, make_number (25));
+  /* (get '+-hollow-rectangle-right-angle 'fringe) => 25 */
+
+  /* 26 */
+  DEFSYM (Qmc_hollow_rectangle, "+-hollow-rectangle");
+  Vfringe_bitmaps = Fcons (Qmc_hollow_rectangle, Vfringe_bitmaps);
+  Fput (Qmc_hollow_rectangle, Qfringe, make_number (26));
+  /* (get '+-hollow-rectangle 'fringe) => 26 */
+
+  /* 27 */
+  DEFSYM (Qmc_vertical_bar, "+-vertical-bar");
+  Vfringe_bitmaps = Fcons (Qmc_vertical_bar, Vfringe_bitmaps);
+  Fput (Qmc_vertical_bar, Qfringe, make_number (27));
+  /* (get '+-vertical-bar 'fringe) => 27 */
+
+  /* 28 */
+  DEFSYM (Qmc_right_angle, "+-right-angle");
+  Vfringe_bitmaps = Fcons (Qmc_right_angle, Vfringe_bitmaps);
+  Fput (Qmc_right_angle, Qfringe, make_number (28));
+  /* (get '+-right-angle 'fringe) => 28 */
+
+  /* 29 */
+  DEFSYM (Qmc_backslash, "+-backslash");
+  Vfringe_bitmaps = Fcons (Qmc_backslash, Vfringe_bitmaps);
+  Fput (Qmc_backslash, Qfringe, make_number (29));
+  /* (get '+-backslash 'fringe) => 29 */
+
+  /* 30 */
+  DEFSYM (Qmc_vertical_bar_backslash, "+-vertical-bar-backslash");
+  Vfringe_bitmaps = Fcons (Qmc_vertical_bar_backslash, Vfringe_bitmaps);
+  Fput (Qmc_vertical_bar_backslash, Qfringe, make_number (30));
+  /* (get '+-vertical-bar-backslash 'fringe) => 30 */
+
+  /* 31 */
+  DEFSYM (Qmc_pilcrow, "+-pilcrow");
+  Vfringe_bitmaps = Fcons (Qmc_pilcrow, Vfringe_bitmaps);
+  Fput (Qmc_pilcrow, Qfringe, make_number (31));
+  /* (get '+-pilcrow 'fringe) => 31 */
+
+  /* 32 */
+  DEFSYM (Qmc_right_double_angle, "+-right-double-angle");
+  Vfringe_bitmaps = Fcons (Qmc_right_double_angle, Vfringe_bitmaps);
+  Fput (Qmc_right_double_angle, Qfringe, make_number (32));
+  /* (get '+-right-double-angle 'fringe) => 32 */
+
+  /* 33 */
+  DEFSYM (Qmc_smiley_face, "+-smiley-face");
+  Vfringe_bitmaps = Fcons (Qmc_smiley_face, Vfringe_bitmaps);
+  Fput (Qmc_smiley_face, Qfringe, make_number (33));
+  /* (get '+-smiley-face 'fringe) => 33 */
+
+/* *************************************************************************** */
+
+
 }
 
 /* Garbage collection hook */
diff --git a/src/keyboard.c b/src/keyboard.c
index aa58e26..8fd3ac8 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1224,6 +1224,29 @@ static int read_key_sequence (Lisp_Object *, Lisp_Object,
                               bool, bool, bool, bool);
 static void adjust_point_for_property (ptrdiff_t, bool);
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+static void
+kbd_mc_activate_cursors (void)
+{
+  struct window *w = decode_live_window (selected_window);
+  w->mc.draw_glyph_cursor = true;
+  w->mc.erase_glyph_cursor = true;
+}
+
+static void
+kbd_mc_activate_crosshairs (void)
+{
+  struct window *w = decode_live_window (selected_window);
+  w->mc.draw_crosshairs = true;
+  w->mc.erase_crosshairs = true;
+}
+
+/* *************************************************************************** */
+
+
 Lisp_Object
 command_loop_1 (void)
 {
@@ -1419,6 +1442,15 @@ command_loop_1 (void)
       Vreal_this_command = cmd;
       safe_run_hooks (Qpre_command_hook);
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      kbd_mc_activate_cursors ();
+
+/* *************************************************************************** */
+
+
       already_adjusted = 0;
 
       if (NILP (Vthis_command))
diff --git a/src/nsterm.m b/src/nsterm.m
index a15684d..2602920 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1188,10 +1188,14 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
     {
       block_input ();
 
-      if (cursor_on_p)
-	display_and_set_cursor (w, 1,
-				w->output_cursor.hpos, w->output_cursor.vpos,
-				w->output_cursor.x, w->output_cursor.y);
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      mc_portal (w, cursor_on_p);
+
+/* *************************************************************************** */
+
 
       if (draw_window_fringes (w, 1))
 	{
@@ -3206,8 +3210,29 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
 
   if ((phys_cursor_glyph = get_phys_cursor_glyph (w)) == NULL)
     {
-      if (glyph_row->exact_window_width_line_p
-          && w->phys_cursor.hpos >= glyph_row->used[TEXT_AREA])
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      /* This modification enables placement of the cursor-in-fringe bitmap when
+      the window-width is slightly less than `glyph_row->exact_window_width_line_p`.
+      This modification also prevents drawing the real cursor on the fringe (instead
+      of using the cursor-in-fringe bitmap) in the above-mentioned circumstance.
+      See the following related patches:
+      -  July 19, 2016:  bf5ddded70c11edaf3514b25da27fc71cfb8e965
+      -  May 21, 2016:  e5015c5d9632a0bf685c093249ae4a7d3e825b13
+      See the following bug reports:  #16856 and #29233. */
+      int frame_char_width = FRAME_COLUMN_WIDTH (f);
+      int text_area_width = window_box_width (w, TEXT_AREA);
+      bool cursor_in_fringe_p = w->phys_cursor.x + frame_char_width >= text_area_width;
+      if ((glyph_row->exact_window_width_line_p
+            && w->phys_cursor.hpos >= glyph_row->used[TEXT_AREA])
+          || cursor_in_fringe_p)
+
+/* *************************************************************************** */
+
+
         {
           glyph_row->cursor_in_fringe_p = 1;
           draw_fringe_bitmap (w, glyph_row, 0);
@@ -3243,17 +3268,68 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
       h = cursor_height;
     }
 
-  r.origin.x = fx, r.origin.y = fy;
-  r.size.height = h;
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  r.origin.x = (w->mc.fx > 0)
+               ? w->mc.fx
+               : fx;
+  r.origin.y = (w->mc.fy > 0)
+               ? w->mc.fy
+               : fy;
+  r.size.height = (w->mc.h > 0)
+                  ? w->mc.h
+                  : h;
   r.size.width = w->phys_cursor_width;
 
+/* *************************************************************************** */
+
+
   /* Prevent the cursor from being drawn outside the text area.  */
   ns_clip_to_row (w, glyph_row, TEXT_AREA, NO); /* do ns_focus(f, &r, 1); if remove */
 
 
   face = FACE_FROM_ID_OR_NULL (f, phys_cursor_glyph->face_id);
-  if (face && NS_FACE_BACKGROUND (face)
-      == ns_index_color (FRAME_CURSOR_COLOR (f), f))
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* EXAMPLE OF HOW TO LOOK-UP A COLOR:
+  enum face_id face_id = lookup_named_face (f, intern ("+-vertical-bar-face"), true);
+  struct face *face = FACE_FROM_ID (f, face_id);
+  NSColor *color = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), f);
+*/
+
+  if (w->mc.glyph_flavor == MC_GLYPH
+      || w->mc.glyph_flavor == MC_GLYPHLESS
+      || w->mc.glyph_flavor == MC_GLYPH_TAB)
+    {
+      Lisp_Object buf = w->contents;
+      CHECK_BUFFER (buf);
+      struct buffer *b = XBUFFER (buf);
+      bool region_active_p = (!NILP (Vtransient_mark_mode)
+                              && !NILP (BVAR (b, mark_active)));
+      ptrdiff_t region_beginning = (region_active_p) ? XINT (Fregion_beginning ()) : -1;
+      ptrdiff_t region_end = (region_active_p) ? XINT (Fregion_end ()) : -1;
+      bool region_p = (region_active_p
+                       && PT >= region_beginning
+                       && PT < region_end);
+      [[NSColor colorWithCalibratedRed: w->mc.red green: w->mc.green blue: w->mc.blue alpha: 1.0] set];
+      if (region_p)
+        hollow_color = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
+        else if (face && NS_FACE_BACKGROUND (face) == ns_index_color (FRAME_CURSOR_COLOR (f), f))
+          hollow_color = FRAME_CURSOR_COLOR (f);
+      /* FIXME:  Add a condition for `hollow_color` if the region foreground is the
+      same as the default background and choose an appropriate color if so. */
+    }
+  else if (face && NS_FACE_BACKGROUND (face)
+           == ns_index_color (FRAME_CURSOR_COLOR (f), f))
+
+/* *************************************************************************** */
+
+
     {
       [ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), f) set];
       hollow_color = FRAME_CURSOR_COLOR (f);
@@ -3300,10 +3376,19 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
     }
   ns_unfocus (f);
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
   /* draw the character under the cursor */
-  if (cursor_type != NO_CURSOR)
+  if (cursor_type != NO_CURSOR
+      && w->mc.glyph_flavor != MC_GLYPHLESS
+      && w->mc.glyph_flavor != MC_GLYPH_TAB)
     draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
 
+/* *************************************************************************** */
+
+
 #ifdef NS_IMPL_COCOA
   NSEnableScreenUpdates ();
 #endif
diff --git a/src/w32term.c b/src/w32term.c
index ff0d2bf..8400426 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -705,10 +705,14 @@ x_update_window_end (struct window *w, bool cursor_on_p,
     {
       block_input ();
 
-      if (cursor_on_p)
-	display_and_set_cursor (w, true,
-				w->output_cursor.hpos, w->output_cursor.vpos,
-				w->output_cursor.x, w->output_cursor.y);
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      mc_portal (w, cursor_on_p);
+
+/* *************************************************************************** */
+
 
       if (draw_window_fringes (w, true))
 	{
@@ -973,7 +977,13 @@ static void w32_draw_box_rect (struct glyph_string *, int, int, int, int,
 static void
 x_set_cursor_gc (struct glyph_string *s)
 {
-  if (s->font == FRAME_FONT (s->f)
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  struct window *w = decode_live_window (selected_window);
+  if ((s->font == FRAME_FONT (s->f)
       && s->face->background == FRAME_BACKGROUND_PIXEL (s->f)
       && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f)
       /* Sometimes we are not called for each change in the default
@@ -981,6 +991,11 @@ x_set_cursor_gc (struct glyph_string *s)
 	 test in the next line gives us a chance to resync.  */
       && s->f->output_data.w32->cursor_gc->foreground == s->face->background
       && !s->cmp)
+      || w->mc.cursor_gc_default)
+
+/* *************************************************************************** */
+
+
     s->gc = s->f->output_data.w32->cursor_gc;
   else
     {
@@ -5690,6 +5705,26 @@ x_draw_hollow_cursor (struct window *w, struct glyph_row *row)
 
   /* Compute frame-relative coordinates for phys cursor.  */
   get_phys_cursor_geometry (w, row, cursor_glyph, &left, &top, &h);
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* LEGEND:
+
+-  top y == WINDOW_TO_FRAME_PIXEL_Y (w, row->y)
+
+-  bottom y == WINDOW_TO_FRAME_PIXEL_Y (w, row->y) - row->height
+
+-  h of HOLLOW_BOX_CURSOR == row->height
+   [This avoids a visible gap above/below.] */
+
+  if (w->mc.h > 0)
+    h = row->height;
+
+/* *************************************************************************** */
+
+
   rect.left = left;
   /* When on R2L character, show cursor at the right edge of the
      glyph, unless the cursor box is as wide as the glyph or wider
@@ -5753,7 +5788,17 @@ x_draw_bar_cursor (struct window *w, struct glyph_row *row,
 	 invisible.  Use the glyph's foreground color instead in this
 	 case, on the assumption that the glyph's colors are chosen so
 	 that the glyph is legible.  */
-      if (face->background == cursor_color)
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      if (face->background == cursor_color
+          && !w->mc.cursor_gc_invisible_okay)
+
+/* *************************************************************************** */
+
+
 	cursor_color = face->foreground;
 
       x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
@@ -5774,6 +5819,17 @@ x_draw_bar_cursor (struct window *w, struct glyph_row *row,
 	  if ((cursor_glyph->resolved_level & 1) != 0)
 	    x += cursor_glyph->pixel_width - width;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+    /* Align all fake BAR_CURSOR of the VERTICAL_RULER with `opoint_x'. */
+    if (w->mc.fx > 0)
+      x = w->mc.fx;
+
+/* *************************************************************************** */
+
+
 	  w32_fill_area (f, hdc, cursor_color, x,
 			 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y),
 			 width, row->height);
@@ -5895,31 +5951,108 @@ w32_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
 	  return;
 	}
 
-      switch (cursor_type)
-	{
-	case HOLLOW_BOX_CURSOR:
-	  x_draw_hollow_cursor (w, glyph_row);
-	  break;
 
-	case FILLED_BOX_CURSOR:
-	  draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
-	  break;
+/* *************************************************************************** */
+/* begin MULTIPLE CURSORS */
 
-	case BAR_CURSOR:
-	  x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
-	  break;
+  struct frame *f = XFRAME (WINDOW_FRAME (w));
+  COLORREF original_cursor_pixel = f->output_data.w32->cursor_pixel;
+  double base = 255.0;
+  double term_red = base * w->mc.red;
+  double term_green = base * w->mc.green;
+  double term_blue = base * w->mc.blue;
+  int int_red = XINT (Ftruncate (make_float (term_red), Qnil));
+  int int_green = XINT (Ftruncate (make_float (term_green), Qnil));;
+  int int_blue = XINT (Ftruncate (make_float (term_blue), Qnil));;
+  COLORREF color_pixel = PALETTERGB (int_red, int_green, int_blue);
+  switch (cursor_type)
+  {
+    case HOLLOW_BOX_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        {
+          /* Temporarily hijack `f->output_data.w32->cursor_pixel'.  */
+          f->output_data.w32->cursor_pixel = color_pixel;
+          x_draw_hollow_cursor (w, glyph_row);
+          f->output_data.w32->cursor_pixel = original_cursor_pixel;
+        }
+        else
+          x_draw_hollow_cursor (w, glyph_row);
+      break;
+    }
+    case FILLED_BOX_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        {
+          /* Temporarily hijack `f->output_data.w32->cursor_gc' by borrowing the
+          functionality of `x_make_gc' in w32fns.c.  */
+          block_input ();
+          struct window *w = decode_live_window (selected_window);
+          XGCValues gc_values;
+          unsigned long mask = GCFont | GCForeground | GCBackground;
+          COLORREF frame_bg_pixel = FRAME_BACKGROUND_PIXEL (f);
+          gc_values.font = FRAME_FONT (f);
+          gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
+          gc_values.background = color_pixel;
+          f->output_data.w32->cursor_gc
+            = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &gc_values);
+          /* When `w->mc.cursor_gc_default = true', force `x_set_cursor_gc' to
+          use `s->f->output_data.w32->cursor_gc'.  */
+          w->mc.cursor_gc_default = true;
+          draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
+          w->mc.cursor_gc_default = false;
+          gc_values.font = FRAME_FONT (f);
+          gc_values.foreground = frame_bg_pixel;
+          gc_values.background = original_cursor_pixel;
+          f->output_data.w32->cursor_gc
+            = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &gc_values);
+          unblock_input ();
+        }
+        else
+          draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
+      break;
+    }
+    case BAR_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        {
+          /* Temporarily hijack `f->output_data.w32->cursor_pixel'.  */
+          f->output_data.w32->cursor_pixel = color_pixel;
+          w->mc.cursor_gc_invisible_okay = true;
+          x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
+          w->mc.cursor_gc_invisible_okay = false;
+          f->output_data.w32->cursor_pixel = original_cursor_pixel;
+        }
+        else
+          x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
+      break;
+    }
+    case HBAR_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        {
+          /* Temporarily hijack `f->output_data.w32->cursor_pixel'.  */
+          f->output_data.w32->cursor_pixel = color_pixel;
+          w->mc.cursor_gc_invisible_okay = true;
+          x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
+          w->mc.cursor_gc_invisible_okay = false;
+          f->output_data.w32->cursor_pixel = original_cursor_pixel;
+        }
+        else
+          x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
+      break;
+    }
+    case NO_CURSOR:
+      w->phys_cursor_width = 0;
+      break;
+    default:
+      emacs_abort ();
+  }
 
-	case HBAR_CURSOR:
-	  x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
-	  break;
+/* end MULTIPLE CURSORS */
+/* *************************************************************************** */
 
-	case NO_CURSOR:
-	  w->phys_cursor_width = 0;
-	  break;
 
-	default:
-	  emacs_abort ();
-	}
     }
 }
 
diff --git a/src/window.c b/src/window.c
index 422b06a..6f3e59d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -6810,6 +6810,29 @@ get_phys_cursor_glyph (struct window *w)
   struct glyph *glyph;
   int hpos = w->phys_cursor.hpos;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* This modification enables placement of the cursor-in-fringe bitmap when
+the window-width is slightly less than `glyph_row->exact_window_width_line_p`.
+This modification also prevents drawing the real cursor on the fringe (instead
+of using the cursor-in-fringe bitmap) in the above-mentioned circumstance.
+See the following related patches:
+-  July 19, 2016:  bf5ddded70c11edaf3514b25da27fc71cfb8e965
+-  May 21, 2016:  e5015c5d9632a0bf685c093249ae4a7d3e825b13
+See the following bug reports:  #16856 and #29233. */
+
+  struct frame *f = XFRAME (w->frame);
+  int frame_char_width = FRAME_COLUMN_WIDTH (f);
+  int text_area_width = window_box_width (w, TEXT_AREA);
+  bool cursor_in_fringe_p = w->phys_cursor.x + frame_char_width >= text_area_width;
+  if (cursor_in_fringe_p)
+    return NULL;
+
+/* *************************************************************************** */
+
+
   if (!(w->phys_cursor.vpos >= 0
 	&& w->phys_cursor.vpos < w->current_matrix->nrows))
     return NULL;
diff --git a/src/window.h b/src/window.h
index 013083e..958ecef 100644
--- a/src/window.h
+++ b/src/window.h
@@ -76,6 +76,50 @@ one and the same, so its prev and next members are nil.
 
 A dead window has its contents field set to nil.  */
 
+
+/* *************************************************************************** */
+/* begin MULTIPLE CURSORS */
+
+/* Suffixes for the `mc` window pointer prefix. */
+struct multiple_cursors
+{
+  /* Values for previous and current `window-start' and `window-end'. */
+  EMACS_INT current_start, current_end, previous_start, previous_end, current_x, previous_x;
+
+  /* True means to force `x_set_cursor_gc' to use `s->f->output_data.w32->cursor_gc'
+  in w32term.c or `s->f->output_data.x->cursor_gc' in xterm.c. */
+  bool_bf cursor_gc_default : 1;
+
+  /* True means `x_set_cursor_gc' should permit the foreground and background
+  colors to be the same.  The default behavior disallows an invisible result. */
+  bool_bf cursor_gc_invisible_okay : 1;
+
+  /* True means `mc_calc' has not run yet drawn glyph fake cursors. */
+  bool_bf draw_glyph_cursor : 1;
+
+  /* True means `mc_calc' has not run yet erased glyph fake cursors. */
+  bool_bf erase_glyph_cursor : 1;
+
+  /* True means crosshairs have not yet been drawn. */
+  bool_bf draw_crosshairs : 1;
+
+  /* True means crosshairs have not yet been erased. */
+  bool_bf erase_crosshairs : 1;
+
+  /* The flavor of the glyph used by `draw_window_cursor'. */
+  int glyph_flavor;
+
+  /* L.S.L. colors. */
+  double red, green, blue;
+
+  /* Pixel position (window relative) of horizontal/vertical rulers. */
+  int fx, fy, h;
+};
+
+/* end MULTIPLE CURSORS */
+/* *************************************************************************** */
+
+
 struct cursor_pos
 {
   /* Pixel position.  These are always window relative.  */
@@ -181,6 +225,22 @@ struct window
     /* The help echo text for this window.  Qnil if there's none.  */
     Lisp_Object mode_line_help_echo;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+    /* The cache for multiple glyph cursors.  For an example of the structure of
+    the list, see the comments at the beginning of `mc_calc' in xdisp.c.  */
+    Lisp_Object multiple_cursors_cache;
+
+    /* The cache for multiple glyph/glyphless cursors that form crosshairs.  For an
+    example of the structure of the list, see the comments at the beginning of
+    `mc_crosshairs' in xdisp.c.  */
+    Lisp_Object crosshairs_cache;
+
+/* *************************************************************************** */
+
+
     /* No Lisp data may follow below this point without changing
        mark_object in alloc.c.  The member current_matrix must be the
        first non-Lisp member.  */
@@ -283,6 +343,16 @@ struct window
 
 #ifdef HAVE_WINDOW_SYSTEM
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+    /* The prefix for window pointers relating to multiple cursors.  */
+    struct multiple_cursors mc;
+
+/* *************************************************************************** */
+
+
     /* Cursor type of last cursor drawn on the window.  */
     enum text_cursor_kinds phys_cursor_type;
 
@@ -421,6 +491,25 @@ XWINDOW (Lisp_Object a)
   return XUNTAG (a, Lisp_Vectorlike, struct window);
 }
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+INLINE void
+wset_multiple_cursors_cache (struct window *w, Lisp_Object val)
+{
+  w->multiple_cursors_cache = val;
+}
+
+INLINE void
+wset_crosshairs_cache (struct window *w, Lisp_Object val)
+{
+  w->crosshairs_cache = val;
+}
+
+/* *************************************************************************** */
+
+
 /* Most code should use these functions to set Lisp fields in struct
    window.  */
 INLINE void
diff --git a/src/xdisp.c b/src/xdisp.c
index 9b4febd..e4422f6 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -921,6 +921,2673 @@ static void show_mouse_face (Mouse_HLInfo *, enum draw_glyphs_face);
 static bool coords_in_mouse_face_p (struct window *, int, int);
 
 
+/* *************************************************************************** */
+/* begin MULTIPLE CURSORS */
+
+/* MULTIPLE CURSORS:  Emacs Bug #22873 (feature request)
+
+   CROSSHAIRS:  Emacs Bug #17684 (feature request)
+
+PATCH VERSION:  014
+Apply patch to master branch:  Sat Jul 7 09:59:53 2018 -0700
+git reset --hard 98463bed07ecc9057094928ffdc2321eaaf3ab52
+
+Last Commit : Sat Jul 7 09:59:53 2018 -0700
+            : Glenn Morris <rgm@gnu.org>
+            : 98463bed07ecc9057094928ffdc2321eaaf3ab52
+            : * lisp/imenu.el: Require cl-lib, not internal components of same.
+
+EXAMPLE #1:  (setq mc-glyph-list '((1 "hbar" "magenta")
+                             (2 "bar" "purple")
+                             (3 "box" "#00FF00")
+                             (4 "hollow" "#0000FF")
+                             (5 ("hbar" 3) [1.0 0.0 1.0])
+                             (6 ("bar" 3) [0.0 1.0 1.0])))
+
+EXAMPLE #2:  (setq mc-glyph-list nil)
+
+TODO:
+
+-  Keep an eye out for a potential bug (not seen recently) wherein a fake
+   cursor does not get erased.
+
+-  Follow up with the Emacs team re bug#32177; i.e.,
+   (Current line number shifts one column to the left.)
+
+-  Follow up with the Emacs team re bug#32060; i.e.,
+   (Horizontal Scrolling (Current Line):  Wrong line gets h-scrolled.)
+
+-  Determine if bug #28936 needs to be fixed and help the Emacs team re same.
+
+-  When choosing multiple lines from the browse-kill-ring selection, the proposed
+   insertion (in the form of overlays in the target buffer) creates multiple
+   green smiley faces in the fringe.
+
+-  When the vertical ruler intersects a tab STRETCH on the last line in the
+   buffer, the background color used to erase the fake cursor is incorrect.
+
+-  When the vertical ruler intersects a highlighted region on the last line in
+   the buffer, the background color used to erase the fake cursor is incorrect.
+
+-  Set up a user option similar to `cursor-in-non-selected-windows'.
+
+-  Explore the idea of whether we need additional code to handle removing/
+   redrawing fake cursors when windows change sizes / layouts.
+
+-  Fake cursors are being redrawn too often when non-selected visible windows
+   have an ongoing process that require frequent redisplay updates (e.g.,
+   an eshell buffer.  @lawlist may have already corrected the frequent redisplay
+   issue as to mouse-overs, but will need to check this once again to be sure.
+
+-  Implement a way to properly calculate X, Y, HPOS, VPOS when dealing with
+   overlays, text properties, folded text, composition characters, unrecognized
+   characters; e.g., a rectangle looking like a Borg cube on OSX or an A on X11.
+
+-  Implement a test for crosshairs to see if the buffer uses monospace versus
+   proportional fonts, and suppress crosshairs when the latter.
+
+-  Deal with characters that have a font->space_width different than all the rest.
+
+-  Implement functionality similar to the multiple cursors library by Magnar Sveen.
+
+-  Create a comprehensive list of features to always test, and setup a test file.
+
+TESTING:  Situations that always need to be tested when working on these features.
+
+-  Multiple Fake Cursors:  Line endings.
+
+-  Crosshairs:  Line endings.
+
+-  it->line_wrap == TRUNCATE
+
+-  it->line_wrap == WORD_WRAP
+
+-  it->line_wrap == WINDOW_WRAP
+
+-  Horizontal Scrolling -- Temporary:  (scroll-left 1)
+
+   (setq-local auto-hscroll-mode 'current-line)
+
+-  Horizontal Scrolling -- Permanent:  (scroll-left 1 t)
+
+   (setq-local auto-hscroll-mode 'current-line)
+
+-  (fundamental-mode)
+   (setq display-line-numbers t)
+   (setq buffer-display-table (make-display-table))
+   (aset buffer-display-table
+         ?\t
+         (vector (make-glyph-code ?\u00BB 'font-lock-warning-face)
+                 (make-glyph-code ?\t 'highlight)))
+   (aset buffer-display-table
+         ?\n
+         (vector (make-glyph-code ?\u00B6 'font-lock-comment-face)
+                 ?\n))
+   (setq tab-width 8)
+   (setq-local auto-hscroll-mode 'current-line)
+
+-  No Line Numbers
+
+LEGEND
+
+fprintf (stderr, "My lisp object:  %s\n", SSDATA (Fchar_to_string (make_number (101))));
+
+fprintf (stderr, "string: %s | int: %d\n", SSDATA (build_string ("foo")), 69);
+
+if (BUFFERP (w->contents) && STRINGP (BVAR (XBUFFER (w->contents), name)))
+  fprintf (stderr, "ns_update_window_end:  %s\n", SSDATA (BVAR (XBUFFER (w->contents), name)));
+
+AUTO_STRING (my_string_one, "This is the value of `my_object_one':  %s");
+Lisp_Object my_object_one = make_float (0.1);
+CALLN (Fmessage, my_string_one, my_object_one);
+
+AUTO_STRING (my_string_two, "This is the value of `my_object_two':  %s");
+Lisp_Object my_object_two = make_number (777);
+CALLN (Fmessage, my_string_two, my_object_two);
+
+WINDOW:  w->contents
+
+BUFFER:  XBUFFER (w->contents)
+
+BUFFER LOCAL VARIABLE:  BVAR (XBUFFER (w->contents), variable_name)
+
+NO NARROWING:
+
+BEG == Beginning of Buffer (window displays current buffer)
+
+ZV == End of Buffer (window displays current buffer)
+
+BEG_BYTE == Beginning Byte of Buffer
+
+Z_BYTE == Ending Byte of Buffer
+
+NARROWED -- "V":
+
+BEGV == Beginning of NARROWED Buffer (window displays current buffer)
+
+ZV == End of NARROWED Buffer (window displays current buffer)
+
+BEGV_BYTE == Beginning Byte of NARROWED Buffer
+
+ZV_BYTE == Ending Byte of NARROWED buffer
+
+WINDOW DOES NOT NECESSARILY DISPLAY BUFFER:
+
+bob_disregard_narrow = BUF_BEG (buffer)
+eob_disregard_narrow = BUF_Z (buffer)
+
+bob_respect_narrow = BUF_BEGV (buffer)
+eob_respect_narrow = BUF_ZV (buffer)
+
+window_start = marker_position (w->start)
+window_end = eob_disregard_narrow - w->window_end_pos
+
+buffer_size = eob_disregard_narrow - bob_disregard_narrow
+
+buffer_narrowed_p = (eob_respect_narrow - bob_respect_narrow != buffer_size)
+
+window_contents_visible_p = (bob_respect_narrow == window_start
+                             && eob_respect_narrow == window_end)
+
+This is the C [ternary operator][1] (Objective-C is a superset of C):
+
+    label.frame = (inPseudoEditMode) ? kLabelIndentedRect : kLabelRect;
+
+is semantically equivalent to
+
+    if(inPseudoEditMode) {
+     label.frame = kLabelIndentedRect;
+    } else {
+     label.frame = kLabelRect;
+    }
+
+The ternary with no first element (e.g. `variable ?: anotherVariable`) means the same as `(valOrVar != 0) ? valOrVar : anotherValOrVar`
+
+EASSERT:
+
+  eassert (BUF_BEG (b) <= charpos && charpos <= BUF_Z (b));
+  bool barf_crash = (BUF_BEG (b) <= ZV && ZV <= BUF_Z (b)) ? false : true; */
+
+#include <time.h>
+#include <ftoastr.h>
+
+#define NO_FRINGE_BITMAP 0
+
+/* Text cursor types.  */
+
+enum type_of_action
+{
+  MULTIPLE_CURSORS,
+  HORIZONTAL_RULER,
+  VERTICAL_RULER
+};
+
+/* Function prototypes.  */
+
+static void debug_method_add (struct window *, char const *, ...);
+
+static int window_hscroll_limited (struct window *w, struct frame *f);
+
+void dump_glyph_row (struct glyph_row *, int, int) EXTERNALLY_VISIBLE;
+
+/* This is meant to be used when target is visible and when code is sandwiched:
+     update_begin (f);
+     block_input ();
+     mc_erase_glyph_cursor (w, x, y, hpos, vpos, cursor_type);
+     unblock_input ();
+     update_end (f); */
+
+static void
+mc_erase_glyph_cursor (struct window *w, ptrdiff_t x, ptrdiff_t y, ptrdiff_t hpos,
+                       ptrdiff_t vpos, enum text_cursor_kinds cursor_type)
+{
+  /* `matrix_row' in `dispnew.c` contains the following tests,
+  eassert (matrix && matrix->rows);
+  eassert (row >= 0 && row < matrix->nrows); */
+  bool barf_crash_one = (w->current_matrix && w->current_matrix->rows) ? false : true;
+  if (barf_crash_one)
+    return;
+  bool barf_crash_two = (vpos >= 0 && vpos < w->current_matrix->nrows) ? false : true;
+  if (barf_crash_two)
+    return;
+  if (x < 0
+      || y < 0
+      || hpos < 0
+      || vpos < 0)
+    return;
+  /* Record some of the current values for the cursor and glyph_row. */
+  struct glyph_row *glyph_row = MATRIX_ROW (w->current_matrix, vpos);
+  bool original_cursor_in_fringe_p = glyph_row->cursor_in_fringe_p;
+  bool original_reversed_p = glyph_row->reversed_p;
+  ptrdiff_t original_x = w->phys_cursor.x;
+  ptrdiff_t original_y = w->phys_cursor.y;
+  ptrdiff_t original_hpos = w->phys_cursor.hpos;
+  ptrdiff_t original_vpos = w->phys_cursor.vpos;
+  ptrdiff_t original_ascent = w->phys_cursor_ascent;
+  ptrdiff_t original_height = w->phys_cursor_height;
+  ptrdiff_t original_width = w->phys_cursor_width;
+  enum text_cursor_kinds original_cursor_type = w->phys_cursor_type;
+  /* Hijack w->phys_cursor. */
+  w->phys_cursor.x = x;
+  w->phys_cursor.y = y;
+  w->phys_cursor.hpos = hpos;
+  w->phys_cursor.vpos = vpos;
+  w->phys_cursor_type = cursor_type;
+  w->phys_cursor_ascent = glyph_row->ascent;
+  w->phys_cursor_height = glyph_row->height;
+  erase_phys_cursor (w);
+  /* Restore the previous values for w->phys_cursor and glyph_row. */
+  w->phys_cursor.x = original_x;
+  w->phys_cursor.y = original_y;
+  w->phys_cursor.hpos = original_hpos;
+  w->phys_cursor.vpos = original_vpos;
+  w->phys_cursor_type = original_cursor_type;
+  glyph_row->cursor_in_fringe_p = original_cursor_in_fringe_p;
+  glyph_row->reversed_p = original_reversed_p;
+  w->phys_cursor_ascent = original_ascent;
+  w->phys_cursor_height = original_height;
+  w->phys_cursor_width = original_width;
+}
+
+/* This is meant to be used when target is visible and when code is sandwiched:
+     update_begin (f);
+     block_input ();
+     mc_draw_erase_hybrid (...);
+     unblock_input ();
+     update_end (f);
+We call this a draw/erase hybrid because it does all of the following:
+-  Draw all glyph cursors, but erase with `mc_erase_glyph_cursor'.
+-  Draw/erase all fringe bitmaps relating to crosshairs.
+-  Draw/erase all glyphless cursors. */
+
+static void
+mc_draw_erase_hybrid (struct window *w, int x, int fx, int y, int fy, int hpos, int vpos,
+                      int h, enum text_cursor_kinds cursor_type, int cursor_width,
+                      Lisp_Object color_vector, int flavor)
+{
+  /* `matrix_row' in `dispnew.c` contains the following tests,
+  eassert (matrix && matrix->rows);
+  eassert (row >= 0 && row < matrix->nrows); */
+  bool barf_crash_one = (w->current_matrix && w->current_matrix->rows) ? false : true;
+  if (barf_crash_one)
+    return;
+  bool barf_crash_two = (vpos >= 0 && vpos < w->current_matrix->nrows) ? false : true;
+  if (barf_crash_two)
+    return;
+  if (x < 0
+      || y < 0
+      || hpos < 0
+      || vpos < 0)
+    return;
+  struct frame *f = XFRAME (w->frame);
+  /* Record some of the current values for the cursor and glyph_row. */
+  struct glyph_row *glyph_row = MATRIX_ROW (w->current_matrix, vpos);
+  bool original_cursor_in_fringe_p = glyph_row->cursor_in_fringe_p;
+  bool original_reversed_p = glyph_row->reversed_p;
+  ptrdiff_t original_x = w->phys_cursor.x;
+  ptrdiff_t original_y = w->phys_cursor.y;
+  ptrdiff_t original_hpos = w->phys_cursor.hpos;
+  ptrdiff_t original_vpos = w->phys_cursor.vpos;
+  ptrdiff_t original_ascent = w->phys_cursor_ascent;
+  ptrdiff_t original_height = w->phys_cursor_height;
+  ptrdiff_t original_width = w->phys_cursor_width;
+  enum text_cursor_kinds original_cursor_type = w->phys_cursor_type;
+  /* Hijack w->phys_cursor. */
+  w->phys_cursor.x = x;
+  w->phys_cursor.y = glyph_row->y;
+  w->phys_cursor.hpos = hpos;
+  w->phys_cursor.vpos = vpos;
+  w->phys_cursor_type = cursor_type;
+  w->phys_cursor_ascent = glyph_row->ascent;
+  w->phys_cursor_height = glyph_row->height;
+  /* (get '+-left-fringe-overlay-position 'overlay-arrow-bitmap)
+     => '+-overlay-arrow-bitmap
+     => Qmc_smiley_face */
+  /* Lisp_Object val = Fget (intern ("+-left-fringe-overlay-position"), Qoverlay_arrow_bitmap); */
+  Lisp_Object marker = find_symbol_value (intern ("overlay-arrow-position"));
+  int fringe_bitmap = NO_FRINGE_BITMAP;
+  int face_id = DEFAULT_FACE_ID;
+  if (flavor == OVERLAY_ARROW_BITMAP)
+    {
+      Lisp_Object vlist;
+      for (vlist = Voverlay_arrow_variable_list;
+           CONSP (vlist);
+           vlist = XCDR (vlist))
+        {
+          Lisp_Object var = XCAR (vlist);
+          Lisp_Object val;
+          if (!SYMBOLP (var))
+            continue;
+          val = find_symbol_value (var);
+          if (val = Fget (var, Qoverlay_arrow_bitmap), SYMBOLP (val))
+            fringe_bitmap = lookup_fringe_bitmap (val);
+        }
+      glyph_row->overlay_arrow_bitmap = (cursor_type != NO_CURSOR)
+                                        ? fringe_bitmap /* lookup_fringe_bitmap (flavor) */
+                                        : NO_FRINGE_BITMAP;
+      draw_fringe_bitmap (w, glyph_row, true);
+      /* optimization 3:  DRAW the `overlay-arrow-bitmap' if there is a marker. */
+      if (MARKERP (marker)
+          && XMARKER (marker)->buffer
+          && BUFFER_LIVE_P (XMARKER (marker)->buffer))
+        {
+          glyph_row->overlay_arrow_bitmap = fringe_bitmap;
+          draw_fringe_bitmap (w, glyph_row, true);
+        }
+    }
+    else if (flavor == MC_HOLLOW_RECTANGLE_RIGHT_ANGLE
+             || flavor == MC_HOLLOW_RECTANGLE
+             || flavor == MC_VERTICAL_BAR_RIGHT_ANGLE
+             || flavor == MC_VERTICAL_BAR
+             || flavor == MC_VERTICAL_BAR_BACKSLASH)
+      {
+        Lisp_Object bitmap_flavor = (flavor == MC_HOLLOW_RECTANGLE_RIGHT_ANGLE)
+                                    ? Qmc_hollow_rectangle_right_angle
+                                    : (flavor == MC_HOLLOW_RECTANGLE)
+                                      ? Qmc_hollow_rectangle
+                                    : (flavor == MC_VERTICAL_BAR_RIGHT_ANGLE)
+                                      ? Qmc_vertical_bar_right_angle
+                                    : (flavor == MC_VERTICAL_BAR)
+                                      ? Qmc_vertical_bar
+                                    : (flavor == MC_VERTICAL_BAR_BACKSLASH)
+                                      ? Qmc_vertical_bar_backslash
+                                    : Qnil;
+        fringe_bitmap = (cursor_type != NO_CURSOR)
+                        ? lookup_fringe_bitmap (bitmap_flavor)
+                        : NO_FRINGE_BITMAP;
+        face_id = (cursor_type != NO_CURSOR)
+                  ? lookup_named_face (w, f, intern ("+-vertical-bar-face"), true)
+                  : DEFAULT_FACE_ID;
+        glyph_row->cursor_in_fringe_p = false;
+        glyph_row->fringe_bitmap_periodic_p = 0;
+        glyph_row->right_fringe_bitmap = fringe_bitmap;
+        glyph_row->right_fringe_face_id = face_id;
+        glyph_row->right_fringe_offset = 0;
+        draw_fringe_bitmap (w, glyph_row, false);
+      }
+      else if (flavor == MC_GLYPH
+               || flavor == MC_GLYPHLESS
+               || flavor == MC_GLYPH_TAB)
+        {
+          w->mc.h = h;
+          w->mc.fx = fx;
+          w->mc.fy = fy;
+          w->mc.glyph_flavor = flavor;
+          w->mc.red = XFLOAT_DATA (AREF (color_vector, 0));
+          w->mc.green = XFLOAT_DATA (AREF (color_vector, 1));
+          w->mc.blue = XFLOAT_DATA (AREF (color_vector, 2));
+          /* Some of these values come through as 1.003906, which causes a breakage
+          of the colors in that multiplication by the base will exceed the base. */
+          if (w->mc.red > 1.0)
+            w->mc.red = 1.0;
+          if (w->mc.green > 1.0)
+            w->mc.green = 1.0;
+          if (w->mc.blue > 1.0)
+            w->mc.blue = 1.0;
+          FRAME_RIF (f)->draw_window_cursor (w, glyph_row, x, y, cursor_type,
+                                             cursor_width, true, false);
+        }
+  /* Restore the previous values for w->phys_cursor and glyph_row. */
+  w->phys_cursor.x = original_x;
+  w->phys_cursor.y = original_y;
+  w->phys_cursor.hpos = original_hpos;
+  w->phys_cursor.vpos = original_vpos;
+  w->phys_cursor_type = original_cursor_type;
+  glyph_row->cursor_in_fringe_p = original_cursor_in_fringe_p;
+  glyph_row->reversed_p = original_reversed_p;
+  w->phys_cursor_ascent = original_ascent;
+  w->phys_cursor_height = original_height;
+  w->phys_cursor_width = original_width;
+}
+
+static int
+mc_lisp_to_cursor_type (Lisp_Object arg)
+{
+  char *str;
+  if (XTYPE (arg) == Lisp_String)
+    str = SSDATA (arg);
+  else if (XTYPE (arg) == Lisp_Symbol)
+    str = SSDATA (SYMBOL_NAME (arg));
+  else return -1;
+  if (!strcmp (str, "box"))
+    return FILLED_BOX_CURSOR;
+  if (!strcmp (str, "hollow"))
+    return HOLLOW_BOX_CURSOR;
+  if (!strcmp (str, "hbar"))
+    return HBAR_CURSOR;
+  if (!strcmp (str, "bar"))
+    return BAR_CURSOR;
+  if (!strcmp (str, "no"))
+    return NO_CURSOR;
+  return -1;
+}
+
+static Lisp_Object
+mc_cursor_type_to_lisp (int arg)
+{
+  switch (arg)
+    {
+    case FILLED_BOX_CURSOR: return Qbox;
+    case HOLLOW_BOX_CURSOR: return Qhollow;
+    case HBAR_CURSOR: return Qhbar;
+    case BAR_CURSOR: return Qbar;
+    case NO_CURSOR:
+    default: return intern ("no");
+    }
+}
+
+static Lisp_Object
+mc_color_vector_calc (struct window *w, Lisp_Object color)
+{
+  CHECK_STRING (color);
+  Lisp_Object target_frame = w->frame;
+  Lisp_Object color_values;
+  double valmax = XINT (XCAR (Fxw_color_values (build_string ("#ffffff"), target_frame)));
+  Lisp_Object vlist;
+  ptrdiff_t x;
+  int i = 0;
+  Lisp_Object temp = Qnil;
+  Lisp_Object vector = (Fmake_vector (make_number (3), Qnil));
+  if (!NILP (Fmemq ((Fframep (target_frame)), listn (CONSTYPE_HEAP, 3, intern ("x"), intern ("w32"), intern ("ns")))))
+    {
+      color_values = (Fxw_color_values (color, target_frame));
+      for (vlist = color_values;
+           CONSP (vlist);
+           vlist = XCDR (vlist))
+        {
+          x = XINT (XCAR (vlist));
+          temp = make_float (x / valmax);
+          ASET (vector, i, temp);
+          i = i + 1;
+        }
+    }
+  return vector;
+}
+
+/* You only need to call lookup_basic_face if it.face_id is a basic face
+AND face-remapping-alist is non-nil.  If it.face_id is not a basic
+face, lookup_basic_face will abort, and you should call lookup_face
+instead.  For a remapped non-basic face you will have to look up
+face-remapping-alist manually and then use lookup_named_face. */
+
+static Lisp_Object
+mc_bg_lsl (struct window *w, enum face_id face_id)
+{
+  struct frame *f = XFRAME (w->frame);
+  struct face *face;
+  Lisp_Object color, color_vector;
+  if (!NILP (Vface_remapping_alist)
+      && (face_id == DEFAULT_FACE_ID /* Qdefault */
+          || face_id == MODE_LINE_FACE_ID /* Qmode_line */
+          || face_id == MODE_LINE_INACTIVE_FACE_ID /* Qmode_line_inactive */
+          || face_id == HEADER_LINE_FACE_ID /* Qheader_line */
+          || face_id == TOOL_BAR_FACE_ID /* Qtool_bar */
+          || face_id == FRINGE_FACE_ID /* Qfringe */
+          || face_id == SCROLL_BAR_FACE_ID /* Qscroll_bar */
+          || face_id == BORDER_FACE_ID /* Qborder */
+          || face_id == CURSOR_FACE_ID /* Qcursor */
+          || face_id == MOUSE_FACE_ID /* Qmouse */
+          || face_id == MENU_FACE_ID /* Qmenu */
+          || face_id == WINDOW_DIVIDER_FACE_ID /* Qwindow_divider */
+          || face_id == WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID /* Qwindow_divider_first_pixel */
+          || face_id == WINDOW_DIVIDER_LAST_PIXEL_FACE_ID /* Qwindow_divider_last_pixel */
+          || face_id == VERTICAL_BORDER_FACE_ID /* Qvertical_border */
+          || face_id == INTERNAL_BORDER_FACE_ID)) /* Qinternal_border */
+    face = FACE_FROM_ID (f, lookup_basic_face (w, f, face_id));
+    else
+      face = FACE_FROM_ID (f, face_id);
+  color = face->lface[LFACE_BACKGROUND_INDEX];
+  CHECK_STRING (color);
+  color_vector = mc_color_vector_calc (w, color);
+  return color_vector;
+}
+
+/* You only need to call lookup_basic_face if it.face_id is a basic face
+AND face-remapping-alist is non-nil.  If it.face_id is not a basic
+face, lookup_basic_face will abort, and you should call lookup_face
+instead.  For a remapped non-basic face you will have to look up
+face-remapping-alist manually and then use lookup_named_face. */
+
+static Lisp_Object
+mc_bg_face (struct window *w, enum face_id face_id)
+{
+  struct frame *f = XFRAME (w->frame);
+  struct face *face;
+  if (!NILP (Vface_remapping_alist)
+      && (face_id == DEFAULT_FACE_ID /* Qdefault */
+          || face_id == MODE_LINE_FACE_ID /* Qmode_line */
+          || face_id == MODE_LINE_INACTIVE_FACE_ID /* Qmode_line_inactive */
+          || face_id == HEADER_LINE_FACE_ID /* Qheader_line */
+          || face_id == TOOL_BAR_FACE_ID /* Qtool_bar */
+          || face_id == FRINGE_FACE_ID /* Qfringe */
+          || face_id == SCROLL_BAR_FACE_ID /* Qscroll_bar */
+          || face_id == BORDER_FACE_ID /* Qborder */
+          || face_id == CURSOR_FACE_ID /* Qcursor */
+          || face_id == MOUSE_FACE_ID /* Qmouse */
+          || face_id == MENU_FACE_ID /* Qmenu */
+          || face_id == WINDOW_DIVIDER_FACE_ID /* Qwindow_divider */
+          || face_id == WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID /* Qwindow_divider_first_pixel */
+          || face_id == WINDOW_DIVIDER_LAST_PIXEL_FACE_ID /* Qwindow_divider_last_pixel */
+          || face_id == VERTICAL_BORDER_FACE_ID /* Qvertical_border */
+          || face_id == INTERNAL_BORDER_FACE_ID)) /* Qinternal_border */
+    face = FACE_FROM_ID (f, lookup_basic_face (w, f, face_id));
+    else
+      face = FACE_FROM_ID (f, face_id);
+  return face->lface[LFACE_BACKGROUND_INDEX];
+}
+
+struct face *
+mc_lookup_face (struct it *it)
+{
+  if (!NILP (Vface_remapping_alist)
+      && (it->face_id == DEFAULT_FACE_ID /* Qdefault */
+          || it->face_id == MODE_LINE_FACE_ID /* Qmode_line */
+          || it->face_id == MODE_LINE_INACTIVE_FACE_ID /* Qmode_line_inactive */
+          || it->face_id == HEADER_LINE_FACE_ID /* Qheader_line */
+          || it->face_id == TOOL_BAR_FACE_ID /* Qtool_bar */
+          || it->face_id == FRINGE_FACE_ID /* Qfringe */
+          || it->face_id == SCROLL_BAR_FACE_ID /* Qscroll_bar */
+          || it->face_id == BORDER_FACE_ID /* Qborder */
+          || it->face_id == CURSOR_FACE_ID /* Qcursor */
+          || it->face_id == MOUSE_FACE_ID /* Qmouse */
+          || it->face_id == MENU_FACE_ID /* Qmenu */
+          || it->face_id == WINDOW_DIVIDER_FACE_ID /* Qwindow_divider */
+          || it->face_id == WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID /* Qwindow_divider_first_pixel */
+          || it->face_id == WINDOW_DIVIDER_LAST_PIXEL_FACE_ID /* Qwindow_divider_last_pixel */
+          || it->face_id == VERTICAL_BORDER_FACE_ID /* Qvertical_border */
+          || it->face_id == INTERNAL_BORDER_FACE_ID)) /* Qinternal_border */
+    return FACE_FROM_ID (it->f, lookup_basic_face (it->w, it->f, it->face_id));
+      else
+        return FACE_FROM_ID (it->f, it->face_id);
+}
+
+static void
+mc_stderr (struct it *it, int count, int new_x, int relative_x,
+           int previous_character,int previous_hpos, bool issue_31716_p,
+           bool final_loop_p, bool lpw_reached_p, bool green_light_p,
+           bool advance_hpos_p, bool ghost_christmas_future_p,
+           bool hscl_temporary, bool hscl_permanent,
+           enum move_it_result rc, enum type_of_action action_type)
+{
+  int w_hscroll = it->w->hscroll;
+  int w_min_hscroll = it->w->min_hscroll;
+  int it_charpos = IT_CHARPOS (*it);
+  struct face *face = mc_lookup_face (it);
+  struct font *font = face->font;
+  Lisp_Object foreground_face = face->lface[LFACE_FOREGROUND_INDEX];
+  Lisp_Object background_face = face->lface[LFACE_BACKGROUND_INDEX];
+  fprintf (stderr, "\n%d.  %s%s -- (%s)\n\
+    it->c (%d)\n\
+    fetch_byte (%d)\n\
+    character (%s)\n\
+    IT_CHARPOS (%d)\n\
+    w->hscroll (%d)\n\
+    w->min_hscroll (%d)\n\
+    hscl_temporary (%s)\n\
+    hscl_permanent (%s)\n\
+    it->hpos (%d)\n\
+    it->vpos (%d)\n\
+    it->current_x (%d)\n\
+    new_x (%d)\n\
+    font->space_width (%d)\n\
+    it->lnum_pixel_width (%d)\n\
+    it->lnum_width (%d)\n\
+    it->pixel_width (%d)\n\
+    it->first_visible_x (%d)\n\
+    it->last_visible_x (%d)\n\
+    relative_x (%d)\n\
+    it->face_id (%d)\n\
+    foreground_face (%s)\n\
+    background_face (%s)\n\
+    previous character (%s)\n\
+    previous_hpos (%d)\n\
+    issue_31716_p (%s)\n\
+    final_loop_p (%s)\n\
+    lpw_reached_p (%s)\n\
+    green_light_p (%s)\n\
+    advance_hpos_p (%s)\n\
+    ghost_christmas_future_p (%s)\n\
+    rc (%s)\n",
+      count,
+      (it->c == 0
+        ? "NOTHING"
+        : it->c == 187
+          ? "TAB CHARACTER"
+        : it->c == '\t'
+          ? "TAB STRETCH"
+        : "TEXT"),
+      (relative_x == it->lnum_pixel_width
+        ? " -- THE FUN STARTS HERE"
+        : ""),
+      (action_type == MULTIPLE_CURSORS
+       ? "MULTIPLE_CURSORS"
+       : action_type == HORIZONTAL_RULER
+         ? "HORIZONTAL_RULER"
+       : action_type == VERTICAL_RULER
+         ? "VERTICAL_RULER"
+       : "OOPS"),
+      it->c,
+      FETCH_BYTE (IT_BYTEPOS (*it)),
+      (!NILP (Fchar_to_string (make_number (it->c)))
+        ? SSDATA (Fchar_to_string (make_number (it->c)))
+        : "NILP -- it->c as a string"),
+      it_charpos,
+      /* When `it->w->hscroll` is set to an `int`, gdb reports the value
+      as being:  <variable optimized away by compiler> */
+      w_hscroll,
+      w_min_hscroll,
+      (hscl_temporary ? "true" : "false"),
+      (hscl_permanent ? "true" : "false"),
+      it->hpos,
+      it->vpos,
+      it->current_x,
+      new_x,
+      /* Cannot access memory at address 0xa0.  This came about by using
+      `?\U0001D4D5` to create a fancy form feed character that was not
+      recognized by the font chosen on X11. */
+      (font == NULL
+       ? 0
+       : font->space_width),
+      it->lnum_pixel_width,
+      it->lnum_width,
+      it->pixel_width,
+      it->first_visible_x,
+      it->last_visible_x,
+      relative_x,
+      it->face_id,
+      (!NILP (foreground_face)
+        ? SSDATA (foreground_face)
+        : "NILP foreground_face"),
+      (!NILP (background_face)
+        ? SSDATA (background_face)
+        : "NILP background_face"),
+      (!NILP (Fchar_to_string (make_number (previous_character)))
+        ? SSDATA (Fchar_to_string (make_number (previous_character)))
+        : "NILP -- previous_character as a string"),
+      previous_hpos,
+      (issue_31716_p ? "true" : "false"),
+      (final_loop_p ? "true" : "false"),
+      (lpw_reached_p ? "true" : "false"),
+      (green_light_p ? "true" : "false"),
+      (advance_hpos_p ? "true" : "false"),
+      (ghost_christmas_future_p ? "true" : "false"),
+      (rc == MOVE_UNDEFINED
+        ? "MOVE_UNDEFINED"
+        : rc == MOVE_POS_MATCH_OR_ZV
+          ? "MOVE_POS_MATCH_OR_ZV"
+        : rc == MOVE_X_REACHED
+          ? "MOVE_X_REACHED"
+        : rc == MOVE_LINE_CONTINUED
+          ? "MOVE_LINE_CONTINUED"
+        : rc == MOVE_LINE_TRUNCATED
+          ? "MOVE_LINE_TRUNCATED"
+        : rc == MOVE_NEWLINE_OR_CR
+          ? "MOVE_NEWLINE_OR_CR"
+        : "OOPS"));
+}
+
+static void
+mc_crosshairs_helper (struct window *w, int x, int fx, int y, int fy, int hpos,
+                      int vpos, int h, enum text_cursor_kinds type, int width,
+                      Lisp_Object foreground, Lisp_Object background,
+                      int flavor, ptrdiff_t pos, Lisp_Object *result)
+{
+  Lisp_Object thirteen_elements;
+  mc_draw_erase_hybrid (w, x, fx, y, fy, hpos, vpos, h, type, width, foreground, flavor);
+  thirteen_elements = listn (CONSTYPE_HEAP, 13,
+                           make_number (x),
+                           make_number (fx),
+                           make_number (y),
+                           make_number (fy),
+                           make_number (hpos),
+                           make_number (vpos),
+                           make_number (h),
+                           mc_cursor_type_to_lisp (type),
+                           make_number (width),
+                           foreground,
+                           background,
+                           make_number (flavor),
+                           make_number (pos));
+  *result = Fcons (thirteen_elements, *result);
+}
+
+static void
+mc_calc_helper (struct window *w, int x, int fx, int y, int fy, int hpos,
+                int vpos, int h, enum text_cursor_kinds type, int width,
+                Lisp_Object foreground, Lisp_Object background, int flavor,
+                ptrdiff_t pos, Lisp_Object specs, Lisp_Object *result)
+{
+  Lisp_Object thirteen_elements;
+  Lisp_Object temp;
+  mc_draw_erase_hybrid (w, x, fx, y, fy, hpos, vpos, h, type, width, foreground, flavor);
+  thirteen_elements = listn (CONSTYPE_HEAP, 13,
+                           make_number (x),
+                           make_number (fx),
+                           make_number (y),
+                           make_number (fy),
+                           make_number (hpos),
+                           make_number (vpos),
+                           make_number (h),
+                           mc_cursor_type_to_lisp (type),
+                           make_number (width),
+                           foreground,
+                           background,
+                           make_number (flavor),
+                           make_number (pos));
+  temp = Fcons (specs, Fcons (thirteen_elements, Qnil));
+  *result = Fcons (temp, *result);
+}
+
+static void
+mc_get_phys_cursor_geometry (struct window *w, struct glyph_row *glyph_row,
+                             int x, int *fx, int y, int *fy, int hpos,
+                             int vpos, int *h, enum text_cursor_kinds type,
+                             int cursor_width)
+{
+  int cursor_height;
+  bool original_cursor_in_fringe_p = glyph_row->cursor_in_fringe_p;
+  bool original_reversed_p = glyph_row->reversed_p;
+  ptrdiff_t original_x = w->phys_cursor.x;
+  ptrdiff_t original_y = w->phys_cursor.y;
+  ptrdiff_t original_hpos = w->phys_cursor.hpos;
+  ptrdiff_t original_vpos = w->phys_cursor.vpos;
+  ptrdiff_t original_ascent = w->phys_cursor_ascent;
+  ptrdiff_t original_height = w->phys_cursor_height;
+  ptrdiff_t original_width = w->phys_cursor_width;
+  enum text_cursor_kinds original_cursor_type = w->phys_cursor_type;
+  /* Hijack w->phys_cursor. */
+  w->phys_cursor.x = x;
+  w->phys_cursor.y = y;
+  w->phys_cursor.hpos = hpos;
+  w->phys_cursor.vpos = vpos;
+  w->phys_cursor_type = type;
+  w->phys_cursor_ascent = glyph_row->ascent;
+  w->phys_cursor_height = glyph_row->height;
+  struct glyph *fake_phys_cursor_glyph = get_phys_cursor_glyph (w);
+  if (fake_phys_cursor_glyph != NULL)
+    {
+/*
+      get_phys_cursor_geometry (w, glyph_row, fake_phys_cursor_glyph, fx, fy, h);
+      cursor_height = (cursor_width < 1) ? lrint (0.25 * *h) : cursor_width;
+      if (cursor_height > glyph_row->height)
+        cursor_height = glyph_row->height;
+      if (*h > cursor_height)
+        *fy += *h - cursor_height;
+      *h = cursor_height;
+*/
+      get_phys_cursor_geometry (w, glyph_row, scratch_glyphs, fx, fy, h);
+      if (type == HBAR_CURSOR)
+        {
+          cursor_height = (cursor_width < 1) ? lrint (0.25 * *h) : cursor_width;
+          if (cursor_height > glyph_row->height)
+            cursor_height = glyph_row->height;
+          if (*h > cursor_height)
+            *fy += *h - cursor_height;
+          *h = cursor_height;
+        }
+    }
+  /* Restore the previous values for w->phys_cursor and glyph_row. */
+  w->phys_cursor.x = original_x;
+  w->phys_cursor.y = original_y;
+  w->phys_cursor.hpos = original_hpos;
+  w->phys_cursor.vpos = original_vpos;
+  w->phys_cursor_type = original_cursor_type;
+  glyph_row->cursor_in_fringe_p = original_cursor_in_fringe_p;
+  glyph_row->reversed_p = original_reversed_p;
+  w->phys_cursor_ascent = original_ascent;
+  w->phys_cursor_height = original_height;
+  w->phys_cursor_width = original_width;
+}
+
+/* Return the start or end position of the region.
+   BEGINNINGP means return the start.
+   If there is no region active, signal an error.
+   EXAMPLE (region-beginning):  region_limit (1)
+   EXAMPLE (region-end):  region_limit (0) */
+
+static Lisp_Object
+mc_region_limit (bool beginningp)
+{
+  Lisp_Object m;
+  if (!NILP (Vtransient_mark_mode)
+      && NILP (Vmark_even_if_inactive)
+      && NILP (BVAR (current_buffer, mark_active)))
+    return Qnil;
+  m = Fmarker_position (BVAR (current_buffer, mark));
+  if (NILP (m))
+    return Qnil;
+  /* See `region-active-p' and `redisplay--update-region-highlight'. */
+  if (!NILP (Vtransient_mark_mode)
+      && !NILP (BVAR (current_buffer, mark_active))
+      && !NILP (m))
+    return make_number ((PT < XFASTINT (m)) == beginningp
+                        ? PT
+                        : clip_to_bounds (BEGV, XFASTINT (m), ZV));
+      else
+        return Qnil;
+}
+
+/* SPECS will be an LSL color vector if coming from `mc_draw_crosshairs'.
+SPECS will be a consp list if coming from `mc_calc'. */
+
+static void
+mc_move_it (struct it *it, enum type_of_action action_type, Lisp_Object specs, Lisp_Object *result)
+{
+  ptrdiff_t posint = (VECTORP (specs))
+                     ? -1
+                     : XINT (Fnth (make_number (0), specs));
+  Lisp_Object lisp_type = (VECTORP (specs))
+                          ? Qnil
+                          : Fnth (make_number (1), specs);
+  enum text_cursor_kinds cursor_type = (VECTORP (specs)
+                                        && action_type == HORIZONTAL_RULER)
+                                       ? HBAR_CURSOR
+                                       :  (VECTORP (specs)
+                                           && action_type == VERTICAL_RULER)
+                                         ? BAR_CURSOR
+                                       : (CONSP (lisp_type))
+                                          ? mc_lisp_to_cursor_type (XCAR (lisp_type))
+                                       : mc_lisp_to_cursor_type (lisp_type);
+  int cursor_width = (VECTORP (specs))
+                     ? 1
+                     : (CONSP (lisp_type))
+                        ? XINT (XCAR (XCDR (lisp_type)))
+                     : 1;
+  Lisp_Object foreground = (VECTORP (specs))
+                           ? specs
+                           : Fnth (make_number (2), specs);
+  if (STRINGP (foreground))
+    foreground = mc_color_vector_calc (it->w, foreground);
+  int opoint_x = it->w->output_cursor.x;
+  int opoint_y = it->w->output_cursor.y;
+  int opoint_hpos = it->w->output_cursor.hpos;
+  int opoint_vpos = it->w->output_cursor.vpos;
+  int relative_x = 0;
+  int prior_previous_hpos = -1;
+  int previous_hpos = -1;
+  enum move_it_result rc = MOVE_X_REACHED;
+  Lisp_Object buf = it->w->contents;
+  int frame_char_width = FRAME_COLUMN_WIDTH (it->f);
+  int text_area_width = window_box_width (it->w, TEXT_AREA);
+  bool cursor_in_fringe_p = opoint_x + frame_char_width >= text_area_width;
+  int hscl_first_hpos = window_hscroll_limited (it->w, it->f);
+  int header_line_height = WINDOW_HEADER_LINE_HEIGHT (it->w);
+  int count = 0;
+  int vpos = 0;
+  int new_x = 0;
+  int saved_relative_x_for_tab = 0;
+  int saved_current_x = 0;
+  ptrdiff_t previous_pt = 0;
+  int fetch_byte_previous_character = 0;
+  int prior_previous_character = 0;
+  int previous_character = 0;
+  int prior_previous_relative_x = 0;
+  int previous_relative_x = 0;
+  enum face_id previous_face_id = DEFAULT_FACE_ID;
+  bool ghost_christmas_future_p = false;
+  int ghost_christmas_future_relative_x = 0;
+  int ghost_christmas_future_hpos = 0;
+  int ghost_christmas_future_face_id = 0;
+  Lisp_Object region_limit_true = mc_region_limit (true);
+  ptrdiff_t region_beginning = (!NILP (region_limit_true))
+                               ? XINT (region_limit_true)
+                               : 0;
+  Lisp_Object region_limit_false = mc_region_limit (false);
+  ptrdiff_t region_end = (!NILP (region_limit_false))
+                         ? XINT (region_limit_false)
+                         : 0;
+  struct glyph *real_phys_cursor_glyph = get_phys_cursor_glyph (it->w);
+  bool region_active_p = (region_beginning != region_end);
+  while (true)
+    {
+      count += 1;
+      struct face *face = mc_lookup_face (it);
+      struct font *font = face->font;
+      int font_space_width = (font == NULL
+                              ? frame_char_width
+                              : font->space_width);
+      if (header_line_height > 0)
+        vpos = it->vpos + 1;
+        else
+          vpos = it->vpos;
+      bool hscl_temporary = (!it->w->suspend_auto_hscroll
+                             && EQ (Fbuffer_local_value (Qauto_hscroll_mode, buf), Qcurrent_line)
+                             && it->w->hscroll > 0
+                             && it->w->min_hscroll == 0
+                             && opoint_y == it->current_y
+                             && opoint_vpos == vpos);
+      bool hscl_permanent = (!it->w->suspend_auto_hscroll
+                             && EQ (Fbuffer_local_value (Qauto_hscroll_mode, buf), Qcurrent_line)
+                             && it->w->hscroll > 0
+                             && it->w->min_hscroll > 0
+                             && it->w->min_hscroll != it->w->hscroll
+                             && opoint_y == it->current_y
+                             && opoint_vpos == vpos);
+      /* Temporary horizontal scrolling of _only_ the current line.
+      This was difficult to get right, so be careful if ever changing it.
+      The reason it is difficult to get right is because in a vertical
+      ruler situation, we stop when `relative_x` equals `opoint_x` and the
+      latter is of course always correct, but the HPOS will sometimes be
+      wrong if `relative_x` and `opoint_x` are out of sync. */
+      if (new_x > 0
+          && (hscl_permanent
+              || hscl_temporary))
+        relative_x = new_x - (hscl_first_hpos * frame_char_width);
+        else if (new_x > 0)
+          relative_x = new_x - it->first_visible_x;
+          else
+            relative_x = 0;
+      /* See the explanation by Eli Z. as to issue #31716.  Horizontal scrolling
+      (of all lines) is active.  The beginning of the TAB STRETCH lies before
+      it->first_visible_x + it->lnum_pixel_width; and, the next display element is
+      subsequent thereto.
+      -------------------------------
+      7.  TAB STRETCH
+          it->c (9)
+          char (	)
+          it->w->hscroll (4)
+          hscl_temporary (false)
+          it->hpos (0)
+          it->current_x (11)
+          new_x (77)
+          font_space_width (11)
+          it->lnum_pixel_width (44)
+          relative_x (33)
+          rc (MOVE_X_REACHED)
+      -------------------------------
+      8.  TEXT -- THE FUN STARTS HERE
+          it->c (72)
+          char (H)
+          it->w->hscroll (4)
+          hscl_temporary (false)
+          it->hpos (5)
+          it->current_x (132)
+          new_x (88)
+          font_space_width (11)
+          it->lnum_pixel_width (44)
+          relative_x (44)
+          rc (MOVE_X_REACHED)
+      ===============================
+      7.  TAB STRETCH
+          it->c (9)
+          char (	)
+          it->w->hscroll (2)
+          hscl_temporary (false)
+          it->hpos (0)
+          it->current_x (11)
+          new_x (77)
+          font_space_width (11)
+          it->lnum_pixel_width (44)
+          relative_x (55)
+          rc (MOVE_X_REACHED)
+      -------------------------------
+      8.  TEXT
+          it->c (72)
+          char (H)
+          it->w->hscroll (2)
+          hscl_temporary (false)
+          it->hpos (5)
+          it->current_x (132)
+          new_x (88)
+          font_space_width (11)
+          it->lnum_pixel_width (44)
+          relative_x (66)
+          rc (MOVE_X_REACHED) */
+      bool issue_31716_p = (!hscl_temporary
+                            && !hscl_permanent
+                            && it->w->hscroll > 0
+                            && prior_previous_hpos == -1
+                            && previous_character == '\t'
+                            && it->hpos > it->lnum_pixel_width / font_space_width);
+      int hscl_x = (hscl_temporary
+                    || hscl_permanent)
+                    ? it->current_x - (hscl_first_hpos * frame_char_width)
+                    : it->current_x - it->first_visible_x;
+      bool final_loop_p = (!hscl_temporary
+                           && !hscl_permanent)
+                          ? ((FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'
+                              && it->c != 0
+                              /* We keep going until `relative_x` catches up with
+                              `it->current_x` for a situation such as a line
+                              containing only a tab folled by a new line; e.g.,
+                              issue_31716_p followed by a Ghost of Christmas future.
+                              We use >= because there is no guarantee that all of
+                              characters will be exactly `font_char_width'. */
+                              && (relative_x >= it->current_x - it->first_visible_x
+                                  /* Permanently h-scrolled and only a new line. */
+                                  || it->current_x == 0))
+                             /* || ITERATOR_AT_END_OF_LINE_P (it) */
+                             || rc == MOVE_POS_MATCH_OR_ZV
+                             || rc == MOVE_LINE_CONTINUED
+                             || hscl_x + frame_char_width >= text_area_width)
+                            : true
+                          ? (hscl_temporary
+                             || hscl_permanent)
+                            ? ((FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'
+                                && it->c != 0
+                                /* We keep going until `relative_x` catches up with
+                                `it->current_x` for a situation such as a line
+                                containing only a tab folled by a new line; e.g.,
+                                issue_31716_p followed by a Ghost of Christmas future.
+                                We use >= because there is no guarantee that all of
+                                characters will be exactly `font_char_width'. */
+                                && relative_x >= it->current_x - (hscl_first_hpos * frame_char_width))
+                               /* || ITERATOR_AT_END_OF_LINE_P (it) */
+                               || rc == MOVE_POS_MATCH_OR_ZV
+                               || rc == MOVE_LINE_CONTINUED
+                               || hscl_x + frame_char_width >= text_area_width)
+                              : true
+                          : false;
+      bool lpw_reached_p = (previous_relative_x >= it->lnum_pixel_width
+                            || issue_31716_p);
+      bool green_light_p = (it->current_x > saved_current_x) ? true : false;
+      bool advance_hpos_p = (green_light_p
+                             && lpw_reached_p);
+      if (advance_hpos_p)
+        previous_hpos += (previous_hpos == -1
+                           && !NILP (Vdisplay_line_numbers)
+                           && !EQ (Vdisplay_line_numbers, Qvisual))
+                          ? (it->lnum_pixel_width / font_space_width) + 1
+                          : (relative_x > 0)
+                            ? 1
+                            : 0;
+        else if (final_loop_p
+                 && previous_hpos == -1)
+          previous_hpos = 0;
+      /* it->c == '\t' when IT is at a tab-width spacer following a
+      `buffer-display-table' glyph such as ». */
+      bool tab_invisible_p = previous_character == '\t';
+      bool tab_visible_p = (previous_character != '\t'
+                            && fetch_byte_previous_character == '\t');
+      bool real_fake_cursor_p = (action_type == VERTICAL_RULER)
+                                ? (opoint_y == it->current_y
+                                   && opoint_vpos == vpos)
+                                : (opoint_x == previous_relative_x
+                                   && opoint_y == it->current_y
+                                   && opoint_hpos == previous_hpos
+                                   && opoint_vpos == vpos);
+      if (!NILP (BVAR (current_buffer, mc_stderr)))
+        mc_stderr (it, count, new_x, relative_x, previous_character,
+                   previous_hpos, issue_31716_p, final_loop_p, lpw_reached_p,
+                   green_light_p, advance_hpos_p, ghost_christmas_future_p,
+                   hscl_temporary, hscl_permanent, rc, action_type);
+  switch (action_type)
+  {
+/* --------------------------------------------------------------------------- */
+/*                                MULTIPLE CURSORS                             */
+/* --------------------------------------------------------------------------- */
+    case MULTIPLE_CURSORS:
+    {
+      if ((green_light_p
+          /* WORD_WRAP:  When posint is on the space character at the end of a
+          WORD_WRAP line, `green_light_p' and `advance_hpos_p' are both `false`.
+          In case we need to add more conditions, `rc` =is MOVE_LINE_CONTINUED. */
+          || final_loop_p)
+          && (previous_pt == posint
+              || FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'))
+        {
+          enum face_id temp_face_id = previous_face_id;
+          int temp_x = relative_x;
+          int temp_hpos = previous_hpos;
+          /* As to `mc_calc', we are interested in the current HPOS and the current
+          `relative_x`.  The incoming argument for previous_hpos is actually hpos,
+          which gets modified accordingly here (even though a different name). */
+          if (previous_pt == posint)
+            /* We could, but are not modifying the global previous_relative_x. */
+            temp_x = previous_relative_x;
+            /* We are at the end of the line. */
+            else if (IT_CHARPOS (*it) == posint
+                     && (ITERATOR_AT_END_OF_LINE_P (it)
+                         || FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'))
+              /* `relative_x` is already correct. */
+              temp_hpos = previous_hpos + 1;
+          if (rc == MOVE_LINE_CONTINUED)
+            temp_hpos = previous_hpos + 1;
+          int flavor;
+          if (IT_CHARPOS (*it) == posint
+              && (ITERATOR_AT_END_OF_LINE_P (it)
+                  || FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'))
+            {
+              flavor = MC_GLYPHLESS;
+              temp_face_id = it->face_id;
+            }
+              else
+                flavor = MC_GLYPH;
+          mc_calc_helper (it->w, temp_x, -1, it->current_y, -1, temp_hpos,
+                          vpos, -1, cursor_type, cursor_width, foreground,
+                          mc_bg_lsl (it->w, temp_face_id), flavor, posint,
+                          specs, result);
+          return;
+        }
+      break;
+    }
+/* --------------------------------------------------------------------------- */
+/*                             HORIZONTAL RULER                                */
+/* --------------------------------------------------------------------------- */
+    case HORIZONTAL_RULER:
+    {
+/* --------------------------------------------------------------------------- */
+/*                                   MC_GLYPH                                  */
+/* --------------------------------------------------------------------------- */
+      if ((green_light_p
+           /* Place an MC_GLYPH on the last space of a wrapped line. */
+           || rc == MOVE_LINE_CONTINUED)
+          && !real_fake_cursor_p
+          && lpw_reached_p
+          && !tab_invisible_p)
+        {
+          enum face_id temp_face_id = (rc == MOVE_LINE_CONTINUED)
+                                      ? it->face_id
+                                      : previous_face_id;
+          int temp_x = previous_relative_x;
+          ptrdiff_t it_charpos = (rc == MOVE_LINE_CONTINUED)
+                                  ? IT_CHARPOS (*it)
+                                  : IT_CHARPOS (*it) - 1;
+          int temp_hpos = (rc == MOVE_LINE_CONTINUED)
+                          ? previous_hpos + 1
+                          : previous_hpos;
+          /* Record some of the current values for the cursor and glyph_row. */
+          struct glyph_row *glyph_row =  MATRIX_ROW (it->w->current_matrix, vpos);
+          int fx, fy, h;
+          mc_get_phys_cursor_geometry (it->w, glyph_row, temp_x, &fx,
+                                       glyph_row->y, &fy, temp_hpos, vpos,
+                                       &h, cursor_type, cursor_width);
+          mc_crosshairs_helper (it->w, temp_x, -1, it->current_y, fy,
+                                temp_hpos, vpos, -1, cursor_type, cursor_width,
+                                foreground, mc_bg_lsl (it->w, temp_face_id),
+                                MC_GLYPH, it_charpos, result);
+        }
+/* --------------------------------------------------------------------------- */
+/*                                MC_GLYPH_TAB                                 */
+/* --------------------------------------------------------------------------- */
+      /* FIXME:  Drawing a MC_GLYPH HBAR_CURSOR on certain letters (A, m, M, w, W)
+      located to the immediate right of a tab spacer, cause the MC_GLYPHLESS
+      HBAR_CURSOR to the immediate left to be erased.  This is probably an
+      overhang situation.  An obvious workaround would be to record the
+      coordinates for the MC_GLYPHLESS cursors and then draw them all AFTER the
+      MC_GLYPH cursors have been laid.  How about pushing all the coordinates
+      to the cache, and then executing a variation of `mc_redraw_crosshairs'
+      [with said version being rewritten] to loop twice over the list, first
+      for MC_GLYPH, and then for MC_GLYPHLESS? */
+      if (green_light_p
+          && !real_fake_cursor_p
+          && lpw_reached_p
+          && tab_invisible_p)
+        {
+          int i;
+          int temp_x = (saved_relative_x_for_tab < it->lnum_pixel_width)
+                        ? it->lnum_pixel_width
+                        : saved_relative_x_for_tab;
+          int count = (relative_x - temp_x) / font_space_width;
+          for (i = 0; i < count; i++)
+            {
+              mc_crosshairs_helper (it->w, temp_x, -1, it->current_y, -1, previous_hpos,
+                                    vpos, -1, cursor_type, cursor_width, foreground,
+                                    mc_bg_lsl (it->w, previous_face_id),
+                                    MC_GLYPH_TAB, IT_CHARPOS (*it) - 1, result);
+              temp_x += font_space_width;
+            }
+        }
+/* --------------------------------------------------------------------------- */
+/*                   Ghost of Christmas Future -- MC_GLYPH_TAB                 */
+/* --------------------------------------------------------------------------- */
+      if (green_light_p
+          && ghost_christmas_future_p
+          && lpw_reached_p)
+        {
+          int i;
+          int temp_x = (ghost_christmas_future_relative_x < it->lnum_pixel_width)
+                        ? it->lnum_pixel_width
+                        : ghost_christmas_future_relative_x;
+          int count = (previous_relative_x - temp_x) / font_space_width;
+          for (i = 0; i < count; i++)
+            {
+              mc_crosshairs_helper (it->w, temp_x, -1, it->current_y, -1,
+                                    ghost_christmas_future_hpos, vpos, -1,
+                                    cursor_type, cursor_width, foreground,
+                                    mc_bg_lsl (it->w, ghost_christmas_future_face_id),
+                                    MC_GLYPH_TAB, IT_CHARPOS (*it) - 2, result);
+              temp_x += font_space_width;
+            }
+        }
+/* --------------------------------------------------------------------------- */
+/*                                 MC_GLYPHLESS                                */
+/* --------------------------------------------------------------------------- */
+      if (final_loop_p)
+        {
+          /* We want to start drawing the floating horizontal line from IT
+          (line feed; ZV; or space-word_wrap) until the right fringe.
+          If the line is empty or hidden by horizontal scrolling, then `it.current_x`
+          may be somewhere before `lnum_pixel_width`.  The real cursor will be to the
+          left of `lnum_pixel_width` if we are horizontal scrolling and point is
+          hidden somewhere to the left thereof. */
+          enum face_id temp_face_id = (real_phys_cursor_glyph == NULL)
+                                       ? DEFAULT_FACE_ID
+                                       : (IT_CHARPOS (*it) >= region_end
+                                          || region_beginning == region_end)
+                                         ? DEFAULT_FACE_ID
+                                         : real_phys_cursor_glyph->face_id;
+          /* An empty new line -- loop in previous section broke immediately. */
+          int temp_hpos = (relative_x == it->lnum_pixel_width)
+                           ? it->lnum_pixel_width / frame_char_width
+                           /* No need to readjust because it was done above. */
+                           : rc == MOVE_LINE_CONTINUED
+                             ? previous_hpos
+                           : previous_hpos + 1;
+          /* An empty new line -- loop in previous section broke immediately. */
+          int temp_x = (relative_x < it->lnum_pixel_width)
+                       ? it->lnum_pixel_width
+                       : relative_x;
+          while (temp_x + frame_char_width < text_area_width)
+            {
+              mc_crosshairs_helper (it->w, temp_x, -1, it->current_y, -1,
+                                    temp_hpos, vpos, -1, cursor_type, cursor_width,
+                                    foreground, mc_bg_lsl (it->w, temp_face_id),
+                                    MC_GLYPHLESS, IT_CHARPOS (*it), result);
+              temp_x = temp_x + frame_char_width;
+            }
+          return;
+        }
+      break;
+    }
+/* --------------------------------------------------------------------------- */
+/*                              VERTICAL RULER                                 */
+/* --------------------------------------------------------------------------- */
+    case VERTICAL_RULER:
+    {
+      if ((!final_loop_p
+           /* When the current line contains special characters like Japanese,
+           then opoint_x and previous_relative_x may not necessarily be the same.
+           We want to stop on the character _containing_ `opoint_x`. */
+           && previous_relative_x >= opoint_x)
+          || final_loop_p)
+        {
+          struct glyph_row *glyph_row =  MATRIX_ROW (it->w->current_matrix, vpos);
+          int flavor;
+          enum face_id temp_bg_face_id = previous_face_id;
+          int temp_x;
+          int temp_hpos = previous_hpos;
+          /* Skip this line. */
+          if (real_fake_cursor_p)
+            return;
+          /* If point is to the left of the line numbers when scrolling
+          horizontally, then we want the vertical line to align with right edge
+          of the line numbers. */
+          if (it->w->hscroll > 0
+              && previous_relative_x == opoint_x
+              && opoint_x < it->lnum_pixel_width
+              && previous_hpos == -1)
+            temp_hpos = (it->lnum_pixel_width / font_space_width) - 1;
+            else if (final_loop_p
+                     && previous_hpos != 0
+                     && rc == MOVE_LINE_CONTINUED)
+              temp_hpos = previous_hpos + 1;
+          if ((it->w->hscroll > 0
+               && previous_relative_x == opoint_x
+               && opoint_x < it->lnum_pixel_width)
+              || IT_CHARPOS (*it) == ZV)
+            {
+              flavor = MC_GLYPHLESS;
+              temp_bg_face_id = DEFAULT_FACE_ID;
+            }
+            else if (ghost_christmas_future_p
+                     && previous_relative_x == opoint_x)
+              {
+                flavor = MC_GLYPH_TAB;
+                temp_bg_face_id = ghost_christmas_future_face_id;
+              }
+              else if (cursor_in_fringe_p
+                       && glyph_row->truncated_on_right_p)
+                flavor = MC_VERTICAL_BAR_RIGHT_ANGLE;
+                else if (cursor_in_fringe_p
+                         && glyph_row->continued_p)
+                  flavor = MC_VERTICAL_BAR_BACKSLASH;
+                  else if (cursor_in_fringe_p
+                           && !glyph_row->truncated_on_right_p
+                           && !glyph_row->continued_p)
+                    flavor = MC_VERTICAL_BAR;
+                    /* When IT is at the end of a line, use `MC_GLYPHLESS'.
+                    However, it is okay to use MC_GLYPH for a word-wrapped line. */
+                    else if (!ITERATOR_AT_END_OF_LINE_P (it)
+                             && FETCH_BYTE (IT_BYTEPOS (*it)) != '\n'
+                             && FETCH_BYTE (IT_BYTEPOS (*it)) != '\f'
+                             /* it->c == '\t' when IT is at a tab-width spacer following a
+                             `buffer-display-table' glyph such as ». */
+                             && previous_character != '\t'
+                             && rc != MOVE_POS_MATCH_OR_ZV
+                             && rc != MOVE_LINE_CONTINUED
+                             && relative_x >= it->lnum_pixel_width)
+                      flavor = MC_GLYPH;
+                      /* It is okay to use MC_GLYPH for a word-wrapped line. */
+                      else if (rc == MOVE_LINE_CONTINUED
+                               && FETCH_BYTE (IT_BYTEPOS (*it)) == ' '
+                               && previous_relative_x == opoint_x)
+                        flavor = MC_GLYPH;
+                        else if (previous_character == '\t'
+                                 && previous_relative_x == opoint_x)
+                          {
+                            flavor = MC_GLYPH_TAB;
+                            temp_bg_face_id = previous_face_id;
+                          }
+                          else if (final_loop_p
+                                   && (previous_relative_x >= opoint_x
+                                       || opoint_x < relative_x))
+                            flavor = MC_GLYPH;
+                            else
+                              {
+                                flavor = MC_GLYPHLESS;
+                                temp_bg_face_id = DEFAULT_FACE_ID;
+                              }
+          /* CORNER CASES:
+          -  When the vertical line is to the left of the text and just to the
+             right of the line numbers, we want the default face.
+          -  When there is an imaginary empty line at the end of the buffer with
+             nothing other than ZV, we want to use the frame default face if ZV
+             is at the end of an active region. */
+          if (region_active_p)
+            {
+              /* Subsequent to `region_end` and at the end of a line. */
+              if (IT_CHARPOS (*it) >= region_end
+                  && (ITERATOR_AT_END_OF_LINE_P (it)
+                      || FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'))
+                temp_bg_face_id = DEFAULT_FACE_ID;
+                /* Prior to `region_beginning` and at the end of a line. */
+                else if (IT_CHARPOS (*it) < region_beginning
+                         && (ITERATOR_AT_END_OF_LINE_P (it)
+                             || FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'))
+                  temp_bg_face_id = DEFAULT_FACE_ID;
+                  /* -  Within the region.
+                     -  `real_phys_cursor_glyph` is NULL. */
+                  else if (IT_CHARPOS (*it) >= region_beginning
+                           && IT_CHARPOS (*it) < region_end
+                           && real_phys_cursor_glyph == NULL)
+                    temp_bg_face_id = previous_face_id;
+                    /* -  Within the region.
+                       -  `real_phys_cursor_glyph` is non-NULL.
+                       -  At the end of the line.
+                       -  PT is at `region_beginning`. */
+                    else if (IT_CHARPOS (*it) >= region_beginning
+                             && IT_CHARPOS (*it) < region_end
+                             && (ITERATOR_AT_END_OF_LINE_P (it)
+                                 || FETCH_BYTE (IT_BYTEPOS (*it)) == '\n')
+                             && real_phys_cursor_glyph != NULL
+                             && PT == region_beginning)
+                      temp_bg_face_id = real_phys_cursor_glyph->face_id;
+                      /* -  Within the region.
+                         -  `real_phys_cursor_glyph` is non-NULL.
+                         -  At the end of the line.
+                         -  PT is at `region_region_end`. */
+                      else if (IT_CHARPOS (*it) >= region_beginning
+                               && IT_CHARPOS (*it) < region_end
+                               && (ITERATOR_AT_END_OF_LINE_P (it)
+                                   || FETCH_BYTE (IT_BYTEPOS (*it)) == '\n')
+                               && real_phys_cursor_glyph != NULL
+                               && PT == region_end)
+                        /* temp_bg_face_id = real_phys_cursor_glyph->face_id; */
+                        /* temp_bg_face_id = lookup_named_face (it->f, intern ("region"), true); */
+                        temp_bg_face_id = it->face_id;
+                        /* -  Within the region.
+                           -  `real_phys_cursor_glyph` is non-NULL.
+                           -  Not at the end of the line. */
+                        else if (IT_CHARPOS (*it) >= region_beginning
+                                 && IT_CHARPOS (*it) < region_end
+                                 && (!ITERATOR_AT_END_OF_LINE_P (it)
+                                     || FETCH_BYTE (IT_BYTEPOS (*it)) != '\n')
+                                 && real_phys_cursor_glyph != NULL)
+                          temp_bg_face_id = previous_face_id;
+            }
+  double red = XFLOAT_DATA (AREF (foreground, 0));
+  double green = XFLOAT_DATA (AREF (foreground, 1));
+  double blue = XFLOAT_DATA (AREF (foreground, 2));
+  /* Some of these values come through as 1.003906, which causes a breakage
+  of the colors in that multiplication by the base will exceed the base. */
+  if (red > 1.0)
+    red = 1.0;
+  if (green > 1.0)
+    green = 1.0;
+  if (blue > 1.0)
+    blue = 1.0;
+  if (!NILP (BVAR (current_buffer, mc_stderr)))
+    fprintf (stderr, "\n\
+    VERTICAL RULER -- SPECS:\n\
+    x/opoint_x (%d)\n\
+    y (%d)\n\
+    hpos (%d)\n\
+    vpos (%d)\n\
+    foreground:  R (%f) | G (%f) | B (%f)\n\
+    background (%s)\n\
+    flavor (%s)\n",
+    opoint_x,
+    it->current_y,
+    temp_hpos,
+    vpos,
+    red, green, blue,
+    SSDATA (mc_bg_face (it->w, temp_bg_face_id)),
+    (flavor == MC_GLYPH
+      ? "MC_GLYPH"
+      : flavor == MC_GLYPH_TAB
+        ? "MC_GLYPH_TAB"
+      : flavor == MC_GLYPHLESS
+        ? "MC_GLYPHLESS"
+      : flavor == MC_VERTICAL_BAR_RIGHT_ANGLE
+        ? "MC_VERTICAL_BAR_RIGHT_ANGLE"
+      : flavor == MC_VERTICAL_BAR_BACKSLASH
+        ? "MC_VERTICAL_BAR_BACKSLASH"
+      : flavor == MC_VERTICAL_BAR
+        ? "MC_VERTICAL_BAR"
+      : "OOPS"));
+          if (flavor == MC_GLYPH
+              && previous_relative_x > opoint_x)
+            {
+              temp_x = prior_previous_relative_x;
+              temp_hpos = prior_previous_hpos;
+            }
+            else if (flavor == MC_GLYPH
+                     && final_loop_p
+                     && rc != MOVE_LINE_CONTINUED
+                     && opoint_x < relative_x)
+              {
+                temp_x = previous_relative_x;
+                temp_hpos = previous_hpos;
+              }
+              else
+                temp_x = opoint_x;
+          int fx, fy, h;
+          mc_get_phys_cursor_geometry (it->w, glyph_row, temp_x, &fx,
+                                       glyph_row->y, &fy, temp_hpos, vpos,
+                                       &h, cursor_type, cursor_width);
+          fx = WINDOW_TEXT_TO_FRAME_PIXEL_X (it->w, opoint_x);
+          mc_crosshairs_helper (it->w, temp_x, fx, it->current_y, -1, temp_hpos,
+                                vpos, h, cursor_type, cursor_width, foreground,
+                                mc_bg_lsl (it->w, temp_bg_face_id),
+                                flavor, IT_CHARPOS (*it) -1, result);
+          return;
+          /* Do NOT remove this `break` under any circumstances!!!  Without this
+          `break`, the loop continues until `final_loop_p` and places an
+          erroneous second fake cursor over the first one.  That error is visible
+          when dealing with `MC_GLYPH_TAB` because the wrong face_id is used.
+          The error is difficult to debug because `opoint_x` is correct. */
+        }
+      break;
+    }
+  }
+/* --------------------------------------------------------------------------- */
+/*                          Store Values for Next Loop                         */
+/* --------------------------------------------------------------------------- */
+      if (green_light_p
+          && issue_31716_p)
+        {
+          ghost_christmas_future_p = true;
+          /* Use `relative_x' because this is where the previous mc_glyph_tab ends. */
+          ghost_christmas_future_relative_x = relative_x;
+          ghost_christmas_future_hpos = it->lnum_pixel_width / font_space_width;
+          ghost_christmas_future_face_id = previous_face_id;
+        }
+        else if (green_light_p
+                 && ghost_christmas_future_p)
+          ghost_christmas_future_p = false;
+      /* @lawlist previously encountered a crash that was probably caused by
+      FETCH_BYTE (IT_BYTEPOS (*it) - 1) not finding anything at this location. */
+      fetch_byte_previous_character = (it->c > 0)
+                                      ? FETCH_BYTE (IT_BYTEPOS (*it))
+                                      : 0;
+      prior_previous_character = previous_character;
+      previous_character = it->c;
+      previous_pt = IT_CHARPOS (*it);
+      previous_face_id = it->face_id;
+      prior_previous_relative_x = previous_relative_x;
+      previous_relative_x = relative_x;
+      if (green_light_p)
+        {
+          saved_current_x = it->current_x;
+          saved_relative_x_for_tab = relative_x;
+        }
+      prior_previous_hpos = previous_hpos;
+      /* Some characters, e.g., a `buffer-display-table' character of 𝓕 have a
+      `font->space_width` that is less than the `frame_char_width`.
+      -  #30226.  Bottom line: to get accurate values of pixel width, you need
+      to subtract it->current_x value at some position from current_x at the
+      next glyph position.  This is the only reliable way to obtain accurate
+      pixel width values when using the move_it_* functions. */
+      int increment = (it->pixel_width > 0
+                       && it->c != '\t'
+                       && it->c != 0)
+                      ? it->pixel_width
+                      : (font_space_width != frame_char_width)
+                        ? frame_char_width
+                        : font_space_width;
+      new_x += increment;
+/* --------------------------------------------------------------------------- */
+/*                                 Move to X                                   */
+/* --------------------------------------------------------------------------- */
+      rc = (IT_CHARPOS (*it) == ZV)
+             ? MOVE_POS_MATCH_OR_ZV
+             : MOVE_X_REACHED;
+      /* When `auto-hscroll-mode' is set to `current-line` and we are horizontal scrolling
+      a long line that approaches or exceeds an `it.current.x` of approximately 1000, `rc`
+      will erroneously return early with a MOVE_LINE_TRUNCATED indicator  without pushing
+      forwards until IT reaches the new_x.  As a workaround, ignore MOVE_LINE_TRUNCATED. */
+      if (IT_CHARPOS (*it) != ZV
+          /* `ITERATOR_AT_END_OF_LINE_P` may be `true` when IT is at the beginning of a line. */
+          /* && !ITERATOR_AT_END_OF_LINE_P (it) */
+          && (FETCH_BYTE (IT_BYTEPOS (*it)) != '\n'
+              || (FETCH_BYTE (IT_BYTEPOS (*it)) == '\n'
+                  && it->c == 0))
+          && it->current_x + font_space_width <= new_x
+          && (rc == MOVE_X_REACHED
+              || rc == MOVE_LINE_TRUNCATED
+              || (it->line_wrap == WORD_WRAP
+                  && rc == MOVE_POS_MATCH_OR_ZV)))
+        {
+          struct it saved_it;
+          void *saved_itdata = bidi_shelve_cache ();
+          int prev_x;
+          SAVE_IT (saved_it, *it, saved_itdata);
+          rc = move_it_in_display_line_to (it, ZV, new_x, MOVE_TO_POS | MOVE_TO_X);
+          /* When word-wrap is on, TO_X may lie past the end of a wrapped line.
+          Then it->current is the character on the next line, so backtrack to the
+          space before the wrap point.  */
+          if (it->line_wrap == WORD_WRAP
+              && rc == MOVE_LINE_CONTINUED)
+            {
+              prev_x = max (it->current_x - 1, 0);
+              RESTORE_IT (it, &saved_it, saved_itdata);
+              move_it_in_display_line_to (it, -1, prev_x, MOVE_TO_X);
+            }
+          /* Workaround for bug #28936 -- correct the erroneous MOVE_POS_MATCH_OR_ZV.
+          #28936:  `move_it_in_display_line_to' returns MOVE_POS_MATCH_OR_ZV
+          before reaching ZV when the latter is at the end of the line AND `word-wrap'
+          is non-nil:  abcdefg[ZV].  The workaround is to add an extra check using
+          IT_CHARPOS and comparing it to ZV. */
+          if (it->current_x == new_x
+              && rc == MOVE_POS_MATCH_OR_ZV
+              && IT_CHARPOS (*it) != ZV)
+            rc = MOVE_X_REACHED;
+          bidi_unshelve_cache (saved_itdata, true);
+        }
+    }
+}
+
+/* MC_GLYPH_CACHE:
+-  The first element is compared to the `mc-glyph-list' to determine whether we need to
+   recalculate coordinates.  [We also check whether window-start/window-end changed.]
+-  The second element contains all previously calculated coordinates.
+-  The third element is the buffer where the `w->multiple_cursors_cache' was set.  Because the
+   `w->multiple_cursors_cache' is window-local, we need to check both the window and the buffer.
+     (((3 hbar [1.0 0.0 0.0])
+       (4 bar [0.0 1.0 0.0])
+       (5 box [0.0 0.0 1.0])
+       (6 hollow [0.8 0.4 0.2])
+       (7 (hbar 3) [1.0 0.0 1.0])
+       (8 (bar 3) [0.0 1.0 1.0]))
+      (((3 hbar [1.0 0.0 0.0]) (22 20 2 0 cursor_type cursor_width foreground background flavor posint))
+       ((4 bar [0.0 1.0 0.0]) (33 20 3 0 cursor_type cursor_width foreground background flavor posint))
+       ((5 box [0.0 0.0 1.0]) (44 20 4 0 cursor_type cursor_width foreground background flavor posint))
+       ((6 hollow [0.8 0.4 0.2]) (55 20 5 0 cursor_type cursor_width foreground background flavor posint))
+       ((7 (hbar 3) [1.0 0.0 1.0]) (66 20 6 0 cursor_type cursor_width foreground background flavor posint))
+       ((8 (bar 3) [0.0 1.0 1.0]) (77 20 7 0 cursor_type cursor_width foreground background flavor posint)))
+      (BUFFER where `w->multiple_cursors_cache' was set.)) */
+/* If REMOVE is 0, then draw fake cursors.  If REMOVE is 1, then erase fake cursors. */
+
+void
+mc_calc (struct window *w, bool remove)
+{
+  /* `start_display' calls `init_iterator' which crashes Emacs if:
+  eassert (charpos < 0 || (charpos >= BUF_BEG (current_buffer) && charpos <= ZV))
+  eassert (charpos == BYTE_TO_CHAR (bytepos))
+  This happens when multiple cursors are active and the user types:  M-x .... */
+  ptrdiff_t charpos = marker_position (w->start);
+  bool barf_crash_one = (charpos < 0 || (charpos >= BUF_BEG (current_buffer) && charpos <= ZV)) ? false : true;
+  if (barf_crash_one)
+    return;
+  struct text_pos start_text_position;
+  SET_TEXT_POS_FROM_MARKER (start_text_position, w->start);
+  ptrdiff_t bytepos = BYTEPOS (start_text_position);
+  bool barf_crash_two = (charpos == BYTE_TO_CHAR (bytepos)) ? false : true;
+  if (barf_crash_two)
+    return;
+  struct frame *f = XFRAME (w->frame);
+  struct window *sw = XWINDOW (f->selected_window);
+  Lisp_Object buf = w->contents;
+  CHECK_BUFFER (buf);
+  struct buffer *b = XBUFFER (buf);
+  struct it it;
+  void *itdata = bidi_shelve_cache ();
+  struct it saved_it_for_window_start;
+  void *saved_itdata_for_window_start = NULL;
+  ptrdiff_t it_start;
+  int first_x, last_x;
+  int lnum_width = 0;
+  int lnum_pixel_width = 0;
+  int new_x = 0;
+  ptrdiff_t posint = -1;
+  int x, fx, y, fy, hpos, vpos, h;
+  enum text_cursor_kinds cursor_type;
+  int cursor_width = 1;
+  Lisp_Object specs, lisp_type, foreground, vlist, thirteen_elements;
+  int flavor;
+  Lisp_Object background = Qnil;
+  Lisp_Object temp = Qnil;
+  Lisp_Object result = Qnil;
+  /* An idle timer situation at the outset may not necessarily invoke `redisplay_window',
+  which is where certain multiple cursor values are set at the tail end thereof. */
+  if (!w->mc.current_start)
+    w->mc.current_start = marker_position (w->start);
+  start_display (&it, w, start_text_position);
+  first_x = it.first_visible_x;
+  last_x = it.last_visible_x;
+  it_start = IT_CHARPOS (it);
+  SAVE_IT (saved_it_for_window_start, it, saved_itdata_for_window_start);
+  /* Finish priming the IT for potential line numbers. */
+  if (!NILP (Vdisplay_line_numbers)
+      && !EQ (Vdisplay_line_numbers, Qvisual))
+    {
+      it.first_visible_x = 0;
+      move_it_by_lines (&it, 1);
+      lnum_width = it.lnum_width;
+      lnum_pixel_width = it.lnum_pixel_width;
+      RESTORE_IT (&it, &saved_it_for_window_start, saved_itdata_for_window_start);
+      it.first_visible_x = first_x;
+      it.last_visible_x = last_x;
+      it.lnum_width = lnum_width;
+      it.lnum_pixel_width = lnum_pixel_width;
+      SAVE_IT (saved_it_for_window_start, it, saved_itdata_for_window_start);
+    }
+/* ******************************************************************************
+                              REMOVE GLYPH CURSORS
+****************************************************************************** */
+  /* Remove the cursors using the cache if the conditions are satisfied. */
+  if ((remove && !NILP (w->multiple_cursors_cache) && NILP (BVAR (b, mc_glyph_list)))
+      || (!NILP (w->multiple_cursors_cache) && !NILP (BVAR (b, mc_glyph_list)) && (remove || w != sw)))
+    {
+      /* Erase the real cursor so that the whole vertical line gets removed, not just the fake cursors. */
+      mc_erase_glyph_cursor (w, w->phys_cursor.x, w->phys_cursor.y, w->phys_cursor.hpos,
+                             w->phys_cursor.vpos, w->phys_cursor_type);
+      /* Process the MC_GLYPH_CACHE. */
+      if (!NILP (w->multiple_cursors_cache))
+        {
+          for (vlist = XCAR (XCDR (w->multiple_cursors_cache));
+               CONSP (vlist);
+               vlist = XCDR (vlist))
+            {
+              thirteen_elements = XCAR (XCDR (XCAR (vlist)));
+              x = XINT (Fnth (make_number (0), thirteen_elements));
+              fx = XINT (Fnth (make_number (1), thirteen_elements));
+              y = XINT (Fnth (make_number (2), thirteen_elements));
+              fy = XINT (Fnth (make_number (3), thirteen_elements));
+              hpos = XINT (Fnth (make_number (4), thirteen_elements));
+              vpos = XINT (Fnth (make_number (5), thirteen_elements));
+              h = XINT (Fnth (make_number (6), thirteen_elements));
+              cursor_type = mc_lisp_to_cursor_type (Fnth (make_number (7), thirteen_elements));
+              cursor_width = XINT (Fnth (make_number (8), thirteen_elements));
+              foreground = Fnth (make_number (9), thirteen_elements);
+              background = Fnth (make_number (10), thirteen_elements);
+              flavor = XINT (Fnth (make_number (11), thirteen_elements));
+              posint = XINT (Fnth (make_number (12), thirteen_elements));
+              if (flavor == MC_GLYPHLESS)
+                mc_draw_erase_hybrid (w, x, fx, y, fy, hpos, vpos, h, cursor_type, cursor_width, background, flavor);
+                else
+                  mc_erase_glyph_cursor (w, x, y, hpos, vpos, cursor_type);
+            }
+          if (NILP (BVAR (b, mc_glyph_list)))
+            wset_multiple_cursors_cache (w, Qnil);
+        }
+      w->mc.erase_glyph_cursor = false;
+    }
+/* ******************************************************************************
+                              REDRAW GLYPH CURSORS
+****************************************************************************** */
+  /* If the first element of w->multiple_cursors_cache is the same as the local variable mc_glyph_list,
+     and the previous/current window-start/window-end are the same (e.g., no scrolling),
+     then redraw the cursors using the cache.  This avoids recalculating coordinates. */
+  if (!remove
+      && w == sw
+      && w->mc.current_start
+      && w->mc.current_end
+      && w->mc.previous_start
+      && w->mc.previous_end
+      && w->mc.current_start == w->mc.previous_start
+      && w->mc.current_end == w->mc.previous_end
+      && !NILP (BVAR (b, mc_glyph_list))
+      && !NILP (w->multiple_cursors_cache)
+      && !NILP (Fequal (Fnth (make_number (0), w->multiple_cursors_cache), BVAR (b, mc_glyph_list))))
+    {
+      for (vlist = XCAR (XCDR (w->multiple_cursors_cache));
+           CONSP (vlist);
+           vlist = XCDR (vlist))
+        {
+          thirteen_elements = XCAR (XCDR (XCAR (vlist)));
+          x = XINT (Fnth (make_number (0), thirteen_elements));
+          fx = XINT (Fnth (make_number (1), thirteen_elements));
+          y = XINT (Fnth (make_number (2), thirteen_elements));
+          fy = XINT (Fnth (make_number (3), thirteen_elements));
+          hpos = XINT (Fnth (make_number (4), thirteen_elements));
+          vpos = XINT (Fnth (make_number (5), thirteen_elements));
+          h = XINT (Fnth (make_number (6), thirteen_elements));
+          cursor_type = mc_lisp_to_cursor_type (Fnth (make_number (7), thirteen_elements));
+          cursor_width = XINT (Fnth (make_number (8), thirteen_elements));
+          foreground = Fnth (make_number (9), thirteen_elements);
+          background = Fnth (make_number (10), thirteen_elements);
+          flavor = XINT (Fnth (make_number (11), thirteen_elements));
+          posint = XINT (Fnth (make_number (12), thirteen_elements));
+          mc_draw_erase_hybrid (w, x, fx, y, fy, hpos, vpos, h, cursor_type, cursor_width, foreground, MC_GLYPH);
+        }
+      w->mc.draw_glyph_cursor = false;
+    }
+/* ******************************************************************************
+                             DRAW GLYPH CURSORS ANEW
+****************************************************************************** */
+    /* Draw the cursors anew because something has changed, e.g., the first element of
+       w->multiple_cursors_cache is NOT the same as the local variable mc_glyph_list; and/or, the previous/
+       current window-start/window-end are NOT the same (e.g., scrolling has occurred).
+       Semi-expensive calculation of coordinates is required. */
+    else if (!remove
+             && w == sw
+             && w->mc.current_start
+             && !NILP (BVAR (b, mc_glyph_list)))
+      {
+        for (vlist = BVAR (b, mc_glyph_list);
+             CONSP (vlist);
+             vlist = XCDR (vlist))
+          {
+            specs = XCAR (vlist);
+            posint = XINT (Fnth (make_number (0), specs));
+            lisp_type = Fnth (make_number (1), specs);
+            if (CONSP (lisp_type))
+              cursor_type = mc_lisp_to_cursor_type (XCAR (lisp_type));
+              else
+                cursor_type = mc_lisp_to_cursor_type (lisp_type);
+            if (CONSP (lisp_type))
+              cursor_width = XINT (XCAR (XCDR (lisp_type)));
+              else
+                cursor_width = 1;
+            foreground = Fnth (make_number (2), specs);
+            if (STRINGP (foreground))
+              foreground = mc_color_vector_calc (w, foreground);
+            if (posint >= w->mc.current_start
+                && posint <= w->mc.current_end)
+              {
+                RESTORE_IT (&it, &saved_it_for_window_start, saved_itdata_for_window_start);
+                move_it_to (&it, posint, it.last_visible_x, it.last_visible_y - 1, -1,
+                            MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
+              }
+            if (IT_CHARPOS (it) == posint)
+              {
+                int voffset = it.vpos;
+                RESTORE_IT (&it, &saved_it_for_window_start, saved_itdata_for_window_start);
+                move_it_by_lines (&it, voffset);
+                mc_move_it (&it, MULTIPLE_CURSORS, specs, &result);
+              }
+              else
+                {
+                  x = -1;
+                  fx = -1;
+                  y = -1;
+                  fy = -1;
+                  hpos = -1;
+                  vpos = -1;
+                  h = -1;
+                  background = mc_bg_lsl (it.w, DEFAULT_FACE_ID);
+                  flavor = MC_GLYPH;
+                  thirteen_elements = listn (CONSTYPE_HEAP, 13,
+                                           make_number (x),
+                                           make_number (fx),
+                                           make_number (y),
+                                           make_number (fy),
+                                           make_number (hpos),
+                                           make_number (vpos),
+                                           make_number (h),
+                                           mc_cursor_type_to_lisp (cursor_type),
+                                           make_number (cursor_width),
+                                           foreground,
+                                           background,
+                                           make_number (flavor),
+                                           make_number (posint));
+                  temp = Fcons (specs, Fcons (thirteen_elements, Qnil));
+                  result = Fcons (temp, result);
+                }
+          }
+/* `w->multiple_cursors_cache' is set for the window, not buffer+window -- i.e., all buffers appearing
+in the same window via `switch-to-buffer' will have `w->multiple_cursors_cache'.  This behavior
+is consistent with functions such as `set-window-display-table'.  We deal with this in
+`nsterm.m' / `w32term.c' / `xterm.c' by comparing `w->contents' to the value of the `buf'
+stored in `w->multiple_cursors_cache':  (EQ (w->contents, XCAR (Fnth (make_number (2), w->multiple_cursors_cache)))) */
+        if (!NILP (result))
+          wset_multiple_cursors_cache (w, listn (CONSTYPE_HEAP, 3,
+                                       BVAR (b, mc_glyph_list),
+                                       Freverse (result),
+                                       Fcons (buf, Qnil)));
+        w->mc.draw_glyph_cursor = false;
+      }
+  bidi_unshelve_cache (itdata, false);
+}
+
+void
+mc_draw_crosshairs (struct window *w)
+{
+  /* Eli Z.:  This doesn't feel relevant.  You can always redisplay a window that is
+  not the selected window, provided that you take care to switch to its buffer
+  (redisplay does that already). */
+  if (w != XWINDOW (selected_window))
+    return;
+  /* Eli Z.:  How did you get into this situation?  It shouldn't happen during redisplay. */
+  if (!WINDOW_VALID_P (selected_window))
+    return;
+  struct frame *f = XFRAME (w->frame);
+  Lisp_Object buf = w->contents;
+  CHECK_BUFFER (buf);
+  struct buffer *b = XBUFFER (buf);
+/* eassert (CHARPOS (pos) >= BEGV && CHARPOS (pos) <= ZV);
+   eassert (charpos == BYTE_TO_CHAR (bytepos));
+   eassert (BUF_BEG_BYTE (b) <= bytepos && bytepos <= BUF_Z_BYTE (b)); */
+  ptrdiff_t charpos = marker_position (w->start);
+  ptrdiff_t bytepos = marker_byte_position (w->start);
+  /* Eli Z.:  If window's start point is invalid, it means the window needs to be
+  redisplayed.  Again, I'm not sure I understand how do you get into this situation
+  in the middle of redisplay. */
+  bool barf_crash_one = (charpos >= BEGV && charpos <= ZV) ? false : true;
+  if (barf_crash_one)
+    return;
+  /* Eli Z.:  Likewise.  Markers are updated when a buffer is modified, so this
+  should never happen. */
+  bool barf_crash_two = (charpos == BYTE_TO_CHAR (bytepos)) ? false : true;
+  if (barf_crash_two)
+    return;
+  if (!BUFFERP (buf))
+    return;
+  if (NILP (BVAR (b, crosshairs)))
+    return;
+  if (NILP (BVAR (b, crosshairs_horizontal_ruler))
+      && NILP (BVAR (b, crosshairs_vertical_ruler)))
+    return;
+/* ******************************************************************************
+                              START THE TIMER
+****************************************************************************** */
+/*
+#ifdef GLYPH_DEBUG
+  clock_t start, end;
+  double cpu_time_used;
+  char buf_time[DBL_BUFSIZE_BOUND];
+  start = clock();
+#endif
+*/
+/* ******************************************************************************
+                              BEGIN JOURNEY ...
+****************************************************************************** */
+  struct it it;
+  void *itdata = bidi_shelve_cache ();
+  struct it saved_it_for_window_start;
+  void *saved_itdata_for_window_start = NULL;
+  struct it saved_it_for_horizontal_ruler;
+  void *saved_itdata_for_horizontal_ruler = NULL;
+  struct text_pos start_text_position;
+  ptrdiff_t it_start;
+  int first_x, last_x;
+  int lnum_width = 0;
+  int lnum_pixel_width = 0;
+  int frame_char_width = FRAME_COLUMN_WIDTH (f);
+  int text_area_width = window_box_width (w, TEXT_AREA);
+  bool cursor_in_fringe_p = w->output_cursor.x + frame_char_width >= text_area_width;
+  struct glyph_row *glyph_row;
+  int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w);
+  int cursor_width = 1;
+  ptrdiff_t opoint_pt = PT;
+  int relative_x = 0;
+  int previous_hpos = -1;
+  int opoint_x = w->output_cursor.x;
+  int opoint_y = w->output_cursor.y;
+  int opoint_hpos = w->output_cursor.hpos;
+  int opoint_vpos = w->output_cursor.vpos;
+  ptrdiff_t current_col = current_column ();
+  bool fill_column_p = !NILP (BVAR (b, fill_column));
+  ptrdiff_t fill_col = XINT (BVAR (b, fill_column));
+  Lisp_Object result = Qnil;
+  int flavor;
+  /* Values for the current column of the vertical line. */
+  Lisp_Object foreground = Fmake_vector (make_number (3), Qnil);
+  enum face_id face_id;
+  struct glyph *phys_cursor_glyph;
+/* ******************************************************************************
+                             COLOR OF CROSSHAIRS
+****************************************************************************** */
+  enum face_id even_face_id =
+    lookup_named_face (w, f, intern ("+-even-numbered-column-face"), true);
+  struct face *even_face = FACE_FROM_ID (f, even_face_id);
+  Lisp_Object even_color = even_face->lface[LFACE_FOREGROUND_INDEX];
+  CHECK_STRING (even_color);
+  Lisp_Object even_color_vector = mc_color_vector_calc (w, even_color);
+  enum face_id odd_face_id =
+    lookup_named_face (w, f, intern ("+-odd-numbered-column-face"), true);
+  struct face *odd_face = FACE_FROM_ID (f, odd_face_id);
+  Lisp_Object odd_color = odd_face->lface[LFACE_FOREGROUND_INDEX];
+  CHECK_STRING (odd_color);
+  Lisp_Object odd_color_vector = mc_color_vector_calc (w, odd_color);
+  enum face_id fill_face_id =
+    lookup_named_face (w, f, intern ("+-beyond-fill-column-face"), true);
+  struct face *fill_face = FACE_FROM_ID (f, fill_face_id);
+  Lisp_Object fill_color = fill_face->lface[LFACE_FOREGROUND_INDEX];
+  CHECK_STRING (fill_color);
+  Lisp_Object fill_color_vector = mc_color_vector_calc (w, fill_color);
+  /* red */
+  if (current_col % 2 != 0
+      && !fill_column_p)
+    foreground = odd_color_vector;
+  /* yellow */
+  if (current_col % 2 == 0
+      && !fill_column_p)
+    foreground = even_color_vector;
+  /* red */
+  if (current_col % 2 != 0
+      && fill_column_p
+      && current_col <= fill_col)
+    foreground = odd_color_vector;
+  /* yellow */
+  if (current_col % 2 == 0
+      && fill_column_p
+      && current_col <= fill_col)
+    foreground = even_color_vector;
+  /* green */
+  if (fill_column_p
+      && current_col > fill_col)
+    foreground = fill_color_vector;
+/* ******************************************************************************
+                      START DISPLAY AND PRIME IT
+****************************************************************************** */
+  /* Begin the journey at w->start. */
+  SET_TEXT_POS_FROM_MARKER (start_text_position, w->start);
+  start_display (&it, w, start_text_position);
+  first_x = it.first_visible_x;
+  last_x = it.last_visible_x;
+  it_start = IT_CHARPOS (it);
+  SAVE_IT (saved_it_for_window_start, it, saved_itdata_for_window_start);
+  /* Finish priming the IT for potential line numbers. */
+  if (!NILP (Vdisplay_line_numbers)
+      && !EQ (Vdisplay_line_numbers, Qvisual))
+    {
+      it.first_visible_x = 0;
+      move_it_by_lines (&it, 1);
+      lnum_width = it.lnum_width;
+      lnum_pixel_width = it.lnum_pixel_width;
+      RESTORE_IT (&it, &saved_it_for_window_start, saved_itdata_for_window_start);
+      it.first_visible_x = first_x;
+      it.last_visible_x = last_x;
+      it.lnum_width = lnum_width;
+      it.lnum_pixel_width = lnum_pixel_width;
+      SAVE_IT (saved_it_for_window_start, it, saved_itdata_for_window_start);
+    }
+  /* This might happen on OSX 10.11 when restoring desktop at the beginning
+  of a new session? */
+  if (it_start > opoint_pt)
+    return;
+/* ******************************************************************************
+                           ERASE THE REAL CURSOR
+****************************************************************************** */
+/* `w->phys_cursor.x/y/hpos/vpos` are incorrect after evaluating (scroll-left 1)
+a couple of times.  Redisplay erases the real cursor almost immediately after
+`mc_draw_crosshairs' runs its course -- almost too quickly to see it happening.
+The character where Emacs thinks the real cursor is located gets redrawn, albiet
+without the real cursor.  Emacs thinks the real cursor is one character to the
+right of where it should be -- this is most likely due to an incorrect HPOS.
+This phenomena does not occur when (scroll-left 1) is called interactively; e.g.,
+horizontal scroll wheel.  Inasmuch as `erase_phys_cursor' updates more than
+merely the aforementioned coordinates, resetting those coordinates after the fact
+is insufficient to fix the problem.  We use `w->output_cursor.x/y/hpos/vpos`
+because those coordinates are correct.  We fix `w->phys_cursor.x/y/hpos/vpos`
+BEFORE calling `erase_phys_cursor' so that other goodies are updated. */
+  w->phys_cursor.x = opoint_x;
+  w->phys_cursor.y = opoint_y;
+  w->phys_cursor.hpos = opoint_hpos;
+  w->phys_cursor.vpos = opoint_vpos;
+  erase_phys_cursor (w);
+/* ******************************************************************************
+                          REPLACE THE REAL CURSOR
+****************************************************************************** */
+  glyph_row = MATRIX_ROW (w->current_matrix, opoint_vpos);
+  if (!cursor_in_fringe_p)
+    flavor = MC_GLYPH;
+    /* This condition probably does not exist for the real fake cursor. */
+    else if (cursor_in_fringe_p
+             && glyph_row->continued_p)
+      flavor = MC_PILCROW;
+      else if (cursor_in_fringe_p
+               && glyph_row->truncated_on_right_p)
+        flavor = MC_HOLLOW_RECTANGLE_RIGHT_ANGLE;
+        else if (cursor_in_fringe_p
+                 && !glyph_row->continued_p
+                 && !glyph_row->truncated_on_right_p)
+          flavor = MC_HOLLOW_RECTANGLE;
+  face_id = ((phys_cursor_glyph = get_phys_cursor_glyph (w)) == NULL)
+              ? DEFAULT_FACE_ID
+              : phys_cursor_glyph->face_id;
+  int opoint_fx = -1;
+  int opoint_fy = -1;
+  int opoint_h = -1;
+  if (flavor == MC_GLYPH)
+    mc_get_phys_cursor_geometry (w, glyph_row, opoint_x, &opoint_fx,
+                                 opoint_y, &opoint_fy, opoint_hpos, opoint_vpos,
+                                 &opoint_h, HOLLOW_BOX_CURSOR, cursor_width);
+  mc_crosshairs_helper (w, opoint_x, opoint_fx, opoint_y, opoint_fy,
+                        opoint_hpos, opoint_vpos, opoint_h,
+                        HOLLOW_BOX_CURSOR, cursor_width,
+                        foreground, mc_bg_lsl (w, face_id),
+                        flavor, opoint_pt, &result);
+  mc_crosshairs_helper (w, opoint_x, opoint_fx, opoint_y, opoint_fy,
+                        opoint_hpos, opoint_vpos, opoint_h,
+                        HOLLOW_BOX_CURSOR, cursor_width,
+                        foreground, mc_bg_lsl (w, face_id),
+                        OVERLAY_ARROW_BITMAP, opoint_pt, &result);
+  if (NILP (BVAR (b, crosshairs_horizontal_ruler)))
+    goto vertical_ruler;
+/* ******************************************************************************
+                HORIZONTAL RULER:  FIRST X => EOL
+                                and
+       HORIZONTAL RULER:  DRAW FLOATING GLYPHLESS LINE (EOL TO FRINGE)
+****************************************************************************** */
+  /* Place the IT on the current line containing PT. */
+  int voffset = (header_line_height > 0
+                 && opoint_vpos > 0)
+                  ? opoint_vpos - 1
+                  : opoint_vpos;
+  if (voffset > 0)
+    move_it_by_lines (&it, voffset);
+  mc_move_it (&it, HORIZONTAL_RULER, foreground, &result);
+/* ******************************************************************************
+           VERTICAL RULER:  COMBINATION OF GLYPH & GLYPHLESS CURSORS
+****************************************************************************** */
+  vertical_ruler:
+  if (NILP (BVAR (b, crosshairs_vertical_ruler)))
+    goto crosshairs_finish;
+  RESTORE_IT (&it, &saved_it_for_window_start, saved_itdata_for_window_start);
+  while (true)
+    {
+      mc_move_it (&it, VERTICAL_RULER, foreground, &result);
+      /* This combination of a ZV check before `move_it_by_lines' followed by a
+      Y check subsequent thereto gives us the FEATURE of having a vertical line
+      following a line terminating with ZV.  Whereas `display-line-numbers-mode'
+      has a FEATURE of suppressing the line numbers in this situation, we draw
+      crosshairs in that situation.  `mc_move_it' has been
+      equipped with a condition to test for ZV at the outset and return if true,
+      which prevents Emacs from crashing. */
+      if (IT_CHARPOS (it) == ZV)
+        break;
+      move_it_by_lines (&it, 1);
+      if (it.current_y >= it.last_visible_y)
+        break;
+    }
+/* ******************************************************************************
+                                SET THE CACHE
+****************************************************************************** */
+  crosshairs_finish:
+  if (!NILP (result))
+    wset_crosshairs_cache (w, listn (CONSTYPE_HEAP, 3,
+                                     Freverse (result),
+                                     Fcons (selected_window, Qnil),
+                                     Fcons (buf, Qnil)));
+  w->mc.draw_crosshairs = false;
+  bidi_unshelve_cache (itdata, false);
+/* ******************************************************************************
+                                STOP THE TIMER
+****************************************************************************** */
+/*
+#ifdef GLYPH_DEBUG
+  end = clock();
+  cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
+  dtoastr (buf_time, sizeof buf_time, 0, 0, cpu_time_used);
+  debug_method_add (w, "mc_draw_crosshairs:  TIME (%s)", buf_time);
+#endif
+*/
+}void
+
+mc_redraw_crosshairs (struct window *w)
+{
+/*
+#ifdef GLYPH_DEBUG
+  clock_t start, end;
+  double cpu_time_used;
+  char buf_time[DBL_BUFSIZE_BOUND];
+  start = clock();
+#endif
+*/
+  Lisp_Object vlist = Qnil;
+  Lisp_Object thirteen_elements = Qnil;
+  int x, fx, y, fy, hpos, vpos, h;
+  enum text_cursor_kinds cursor_type;
+  int cursor_width;
+  Lisp_Object foreground = Qnil;
+  Lisp_Object background = Qnil;
+  int flavor;
+  ptrdiff_t pos;
+  for (vlist = XCAR (w->crosshairs_cache);
+       CONSP (vlist);
+       vlist = XCDR (vlist))
+    {
+      thirteen_elements = XCAR (vlist);
+      x = XINT (Fnth (make_number (0), thirteen_elements));
+      fx = XINT (Fnth (make_number (1), thirteen_elements));
+      y = XINT (Fnth (make_number (2), thirteen_elements));
+      fy = XINT (Fnth (make_number (3), thirteen_elements));
+      hpos = XINT (Fnth (make_number (4), thirteen_elements));
+      vpos = XINT (Fnth (make_number (5), thirteen_elements));
+      h = XINT (Fnth (make_number (6), thirteen_elements));
+      cursor_type = mc_lisp_to_cursor_type (Fnth (make_number (7), thirteen_elements));
+      cursor_width = XINT (Fnth (make_number (8), thirteen_elements));
+      foreground = Fnth (make_number (9), thirteen_elements);
+      background = Fnth (make_number (10), thirteen_elements);
+      flavor = XINT (Fnth (make_number (11), thirteen_elements));
+      pos = XINT (Fnth (make_number (12), thirteen_elements));
+      mc_draw_erase_hybrid (w, x, fx, y, fy, hpos, vpos, h, cursor_type, cursor_width, foreground, flavor);
+    }
+/*
+#ifdef GLYPH_DEBUG
+  end = clock();
+  cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
+  dtoastr (buf_time, sizeof buf_time, 0, 0, cpu_time_used);
+  debug_method_add (w, "mc_redraw_crosshairs:  TIME (%s)", buf_time);
+#endif
+*/
+}
+
+void
+mc_erase_crosshairs (struct window *w, bool delete_cache)
+{
+/*
+#ifdef GLYPH_DEBUG
+  clock_t start, end;
+  double cpu_time_used;
+  char buf_time[DBL_BUFSIZE_BOUND];
+  start = clock();
+#endif
+*/
+  Lisp_Object vlist = Qnil;
+  Lisp_Object thirteen_elements = Qnil;
+  int x, fx, y, fy, hpos, vpos, h;
+  enum text_cursor_kinds cursor_type;
+  int cursor_width;
+  Lisp_Object foreground = Qnil;
+  Lisp_Object background = Qnil;
+  int flavor;
+  ptrdiff_t pos;
+  /* Depending upon the direction of movement and distance from the real cursor the current command
+  takes us, the previous real cursor will be left behind.  I tried restoring point after draw/erase,
+  but that didn't fix the issue.  So for now, we just erase the real cursor. */
+  mc_erase_glyph_cursor (w, w->phys_cursor.x, w->phys_cursor.y, w->phys_cursor.hpos,
+                         w->phys_cursor.vpos, w->phys_cursor_type);
+  for (vlist = XCAR (w->crosshairs_cache);
+       CONSP (vlist);
+       vlist = XCDR (vlist))
+    {
+      thirteen_elements = XCAR (vlist);
+      x = XINT (Fnth (make_number (0), thirteen_elements));
+      fx = XINT (Fnth (make_number (1), thirteen_elements));
+      y = XINT (Fnth (make_number (2), thirteen_elements));
+      fy = XINT (Fnth (make_number (3), thirteen_elements));
+      hpos = XINT (Fnth (make_number (4), thirteen_elements));
+      vpos = XINT (Fnth (make_number (5), thirteen_elements));
+      h = XINT (Fnth (make_number (6), thirteen_elements));
+      cursor_type = mc_lisp_to_cursor_type (Fnth (make_number (7), thirteen_elements));
+      cursor_width = XINT (Fnth (make_number (8), thirteen_elements));
+      foreground = Fnth (make_number (9), thirteen_elements);
+      background = Fnth (make_number (10), thirteen_elements);
+      flavor = XINT (Fnth (make_number (11), thirteen_elements));
+      pos = XINT (Fnth (make_number (12), thirteen_elements));
+      if (flavor == MC_GLYPH)
+        mc_erase_glyph_cursor (w, x, y, hpos, vpos, cursor_type);
+          else
+            {
+              if (flavor == OVERLAY_ARROW_BITMAP
+                  || flavor == MC_HOLLOW_RECTANGLE_RIGHT_ANGLE
+                  || flavor == MC_HOLLOW_RECTANGLE
+                  || flavor == MC_VERTICAL_BAR_RIGHT_ANGLE
+                  || flavor == MC_VERTICAL_BAR
+                  || flavor == MC_VERTICAL_BAR_BACKSLASH)
+                cursor_type = NO_CURSOR;
+              mc_draw_erase_hybrid (w, x, fx, y, fy, hpos, vpos, h, cursor_type, cursor_width, background, flavor);
+            }
+    }
+  if (delete_cache)
+    wset_crosshairs_cache (w, Qnil);
+  w->mc.erase_crosshairs = false;
+/*
+#ifdef GLYPH_DEBUG
+  end = clock();
+  cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
+  dtoastr (buf_time, sizeof buf_time, 0, 0, cpu_time_used);
+  debug_method_add (w, "mc_erase_crosshairs:  TIME (%s)", buf_time);
+#endif
+*/
+}
+
+void
+mc_portal (struct window *w, bool cursor_on_p)
+{
+/* ******************************************************************************
+                              MULTIPLE CURSORS
+****************************************************************************** */
+  if (!MINI_WINDOW_P (w)
+      && w->mc.erase_glyph_cursor
+      && !NILP (w->multiple_cursors_cache)
+      && EQ (w->contents, XCAR (Fnth (make_number (2), w->multiple_cursors_cache))))
+    mc_calc (w, 1);
+  if (w == XWINDOW (selected_window)
+      && WINDOW_VALID_P (selected_window)
+      && !MINI_WINDOW_P (w)
+      && w->mc.draw_glyph_cursor
+      && !NILP (BVAR (XBUFFER (w->contents), mc_glyph_list)))
+    /* Draw fake cursors */
+    mc_calc (w, 0);
+    /* First attempt at dealing with a `redisplay_preserve_echo_area' situation. */
+    else if (!MINI_WINDOW_P (w)
+             && !w->mc.draw_glyph_cursor
+             && !NILP (BVAR (XBUFFER (w->contents), mc_glyph_list))
+             && !NILP (w->multiple_cursors_cache)
+             && EQ (w->contents, XCAR (Fnth (make_number (2), w->multiple_cursors_cache))))
+      {
+        /* Remove fake cursors. */
+        mc_calc (w, 1);
+        /* Draw fake cursors */
+        mc_calc (w, 0);
+      }
+/* ******************************************************************************
+                              CROSSHAIRS
+****************************************************************************** */
+  /* Remove crosshairs and delete the cache, but ONLY if we plan on redrawing them.
+  In a timer situation, we want to erase and redraw -- we go from `checkpoint_2'
+  in `redisplay_internal' and force our way over to `update_frame' 2 of 3.
+  Emacs refreshes the selected window after about 1 to 2 minutes of no activity
+  even though there is nothing attached to the `time_list'/`idle_timer_list'.
+  In that refresh no-timer situation, we want to erase/draw using the cache. */
+  if (!MINI_WINDOW_P (w)
+      && w->mc.erase_crosshairs
+      && w->mc.draw_crosshairs
+      && !NILP (w->crosshairs_cache)
+      && w == XWINDOW (XCAR (Fnth (make_number (1), w->crosshairs_cache)))
+      && EQ (w->contents, XCAR (Fnth (make_number (2), w->crosshairs_cache))))
+    mc_erase_crosshairs (w, true);
+  if (w == XWINDOW (selected_window)
+      && WINDOW_VALID_P (selected_window)
+      && !MINI_WINDOW_P (w)
+      && (!NILP (BVAR (XBUFFER (w->contents), crosshairs))
+          /* A rare circumstance where crosshairs mode is non-nil, but the
+          user has unwittingly set both `crosshairs-horizontal-ruler' to nil and also
+          set `crosshairs-vertical-ruler' to nil -- i.e., there is nothing to do. */
+          && (!NILP (BVAR (XBUFFER (w->contents), crosshairs_horizontal_ruler))
+              || !NILP (BVAR (XBUFFER (w->contents), crosshairs_vertical_ruler))))
+      && w->mc.draw_crosshairs)
+    /* Draw crosshairs. */
+    mc_draw_crosshairs (w);
+    /* A situation that occurs with `redisplay_preserve_echo_area'. */
+    else if (!MINI_WINDOW_P (w)
+             && !w->mc.draw_crosshairs
+             && !NILP (w->crosshairs_cache)
+             && !NILP (BVAR (XBUFFER (w->contents), crosshairs))
+             && w == XWINDOW (XCAR (Fnth (make_number (1), w->crosshairs_cache)))
+             && EQ (w->contents, XCAR (Fnth (make_number (2), w->crosshairs_cache))))
+      {
+        /* Remove crosshairs, but do NOT delete the cache. */
+        mc_erase_crosshairs (w, false);
+        /* Redraw the crosshairs using the cache. */
+        mc_redraw_crosshairs (w);
+      }
+      /* CATCHALL:  DRAW THE REAL CURSOR (maybe)! */
+      else if (cursor_on_p)
+        display_and_set_cursor (w, true, w->output_cursor.hpos,
+                                         w->output_cursor.vpos,
+                                         w->output_cursor.x,
+                                         w->output_cursor.y);
+}
+
+void
+mc_record_window_bounds (struct window *w)
+{
+  /* Record prior values for cursor X, window-start and window-end.
+  The goal here is to facilitate `mc_calc' redraw multiple fake
+  cursors using the cache if nothing has changed. */
+  if (!MINI_WINDOW_P (w)
+      && w->mc.draw_glyph_cursor
+      && (!NILP (BVAR (XBUFFER (w->contents), mc_glyph_list))
+          || !NILP (w->multiple_cursors_cache)))
+    {
+      if (w->mc.current_start)
+        w->mc.previous_start = w->mc.current_start;
+        else
+          w->mc.previous_start = -1;
+      if (w->mc.current_end)
+        w->mc.previous_end = w->mc.current_end;
+        else
+          w->mc.previous_end = -1;
+      w->mc.current_start = marker_position (w->start);
+      w->mc.current_end = BUF_Z (XBUFFER (w->contents)) - w->window_end_pos;
+      /* The assumption is that `w->output_cursor.x` is updated AFTER `redisplay_window'.
+      This is only relevant when using glyphless multiple fake cursors because it is
+      possible that the buffer points remain the same, but the X may have changed.
+      Crosshairs do not use `w->mc.previous_x`.  If it turns out that `w->output_cursor.x`
+      is updated DURING `redisplay_window', then it will be necessary to change this
+      to use `it.current_x' and perhaps run `start_display' to get that value. */
+      if (w->output_cursor.x)
+        w->mc.previous_x = w->output_cursor.x;
+          else
+            w->mc.previous_x = -1;
+    }
+}
+
+void
+mc_remove_everything (struct window *w)
+{
+  /* Remove fake cursors.  If we rely upon `update_frame' to remove fake cursors,
+  then it would be too late to remove fake cursors from all areas of the visible
+  window when cutting/pasting text and perhaps a few other situations. */
+  bool remove_cursors = false;
+  bool remove_crosshairs = false;
+  if (!w->pseudo_window_p
+      && w == XWINDOW (selected_window)
+      && !MINI_WINDOW_P (w)
+      && !NILP (w->multiple_cursors_cache)
+      && EQ (w->contents, XCAR (Fnth (make_number (2), w->multiple_cursors_cache))))
+    remove_cursors = true;
+  if (!w->pseudo_window_p
+      /* The crosshairs interfere with the browse-kill-ring library. */
+      /* && w == XWINDOW (selected_window) */
+      && !MINI_WINDOW_P (w)
+      && !NILP (w->crosshairs_cache)
+      && w == XWINDOW (XCAR (Fnth (make_number (1), w->crosshairs_cache)))
+      && EQ (w->contents, XCAR (Fnth (make_number (2), w->crosshairs_cache))))
+    remove_crosshairs = true;
+  if (remove_cursors
+      || remove_crosshairs)
+    {
+      struct frame *f = XFRAME (w->frame);
+      update_begin (f);
+      block_input ();
+      if (remove_cursors)
+        mc_calc (w, 1);
+      /* Remove crosshairs and delete the cache. */
+      if (remove_crosshairs)
+        mc_erase_crosshairs (w, true);
+      unblock_input ();
+      update_end (f);
+    }
+}
+
+int
+mc_crosshairs_p (struct window *w)
+{
+/* Moving the mouse triggers `update_window_cursor' which calls
+`display_and_set_cursor' that would otherwise remove a portion of the horizontal
+ruler at point and/or from point at end of visual line to window edge. */
+  if (!MINI_WINDOW_P (w)
+      && !w->mc.draw_crosshairs
+      && !NILP (w->crosshairs_cache)
+      && !NILP (BVAR (XBUFFER (w->contents), crosshairs))
+      && w == XWINDOW (XCAR (Fnth (make_number (1), w->crosshairs_cache)))
+      && EQ (w->contents, XCAR (Fnth (make_number (2), w->crosshairs_cache))))
+    return true;
+    else
+      return false;
+}
+
+int
+mc_without_update_frame (struct window *w)
+{
+/* `timer-list' / `timer-idle-list':  The boolean switches are not automatically
+turned on when a function attached to a timer is called.  We have switches that are
+set in `keyboard.c` for multiple fake cursors (e.g., a keyboard press).  We set
+the switches manually for both multiple cursors and crosshairs in conjunction with
+timer functions.  `update_frame' may not be called if there are no changes to the
+window/buffer.  To test this theory, throw the switches for crosshairs from an idle
+timer without drawing/erasing any overlays in the buffer.  `kbd_mc_activate_cursors'
+sets the multiple cursors boolean switches to `true` whenever there is a keyboard
+triggered command.  However, that does not necessarily mean that we need to draw
+multiple cursors.  Inasmuch as the multiple cursors boolean switches might have
+been set through a timer function, it is better to check the buffer local variables
+and the window caches.  In the case of crosshairs, the corresponding boolean
+switches are only set when we really want to draw the crosshairs.
+-  We also use this function as part of `update_window_cursor' when mousing over
+something that would ordinarily cause the real cursor to be redrawn. */
+      if (!NILP (w->multiple_cursors_cache)
+          || !NILP (BVAR (XBUFFER (w->contents), mc_glyph_list))
+          || w->mc.draw_crosshairs
+          || mc_crosshairs_p (w))
+        {
+          /* We are bypassing `update_frame' and going straight to `mc_portal'. */
+          struct frame *f = XFRAME (w->frame);
+          update_begin (f);
+          block_input ();
+          mc_portal (w, true);
+          unblock_input ();
+          update_end (f);
+          return true;
+        }
+        else
+          return false;
+}
+
+DEFUN ("mc-activate-crosshairs", Fmc_activate_crosshairs, Smc_activate_crosshairs, 1, 1, 0,
+       doc: /* Doc-string. */)
+  (Lisp_Object window)
+{
+  struct window *w = decode_live_window (window);
+  w->mc.draw_crosshairs = true;
+  w->mc.erase_crosshairs = true;
+  return Qnil;
+}
+
+DEFUN ("mc-activate-cursors", Fmc_activate_cursors, Smc_activate_cursors, 1, 1, 0,
+       doc: /* When using a timer, `kbd_mc_activate_cursors' in `keyboard.c' is not called.
+There are also some other circumstances where `mc-activate-cursors' is helpful. */)
+  (Lisp_Object window)
+{
+  struct window *w = decode_live_window (window);
+  w->mc.draw_glyph_cursor = true;
+  w->mc.erase_glyph_cursor = true;
+  return Qnil;
+}
+
+DEFUN ("mc-stderr", Fmc_stderr, Smc_stderr, 0, 1, "P",
+       doc: /* Toggle tracing of multiple fake cursors.
+With ARG, turn tracing on if and only if ARG is positive. */)
+  (Lisp_Object arg)
+{
+  struct buffer *b = current_buffer;
+  bool mc_stderr_p = (!NILP (BVAR (current_buffer, mc_stderr)))
+                   ? true
+                   : false;
+  if (NILP (arg))
+    mc_stderr_p = !mc_stderr_p;
+  else
+    {
+      arg = Fprefix_numeric_value (arg);
+      mc_stderr_p = XINT (arg) > 0;
+    }
+  if (mc_stderr_p)
+    bset_blv_mc_stderr (b, Qt);
+    else
+      bset_blv_mc_stderr (b, Qnil);
+  return Qnil;
+}
+
+/*  (fundamental-mode)
+    (setq display-line-numbers t)
+    (setq buffer-display-table (make-display-table))
+    (aset buffer-display-table
+          ?\t
+          (vector (make-glyph-code ?\u00BB 'font-lock-warning-face)
+                  (make-glyph-code ?\t 'highlight)))
+    (aset buffer-display-table
+          ?\n
+          (vector (make-glyph-code ?\u00B6 'font-lock-comment-face)
+                  ?\n))
+    (setq tab-width 8)
+    (setq-local auto-hscroll-mode 'current-line) */
+
+DEFUN ("debugging", Fdebugging, Sdebugging, 0, 0, 0,
+       doc: /* This function used for debugging. */)
+  (void)
+{
+/* ******************************************************************************
+                      PRELIMINARY STUFF
+****************************************************************************** */
+  struct window *w = decode_live_window (selected_window);
+  struct frame *f = XFRAME (w->frame);
+  struct it it;
+  void *itdata = bidi_shelve_cache ();
+  enum move_it_result rc = MOVE_X_REACHED;
+  struct text_pos start_text_position;
+  int count = 0;
+  int new_x = 0;
+  int relative_x = 0;
+/* ******************************************************************************
+                      START DISPLAY -- w->start
+****************************************************************************** */
+  /* Begin the journey at w->start. */
+  SET_TEXT_POS_FROM_MARKER (start_text_position, w->start);
+  start_display (&it, w, start_text_position);
+/* ******************************************************************************
+                GO TO THE BEGINNING OF THE CURRENT LINE.
+****************************************************************************** */
+  /* Place the IT on the current line containing PT. */
+  int voffset = (WINDOW_HEADER_LINE_HEIGHT (w) > 0
+                 && w->output_cursor.vpos > 0)
+                  ? w->output_cursor.vpos - 1
+                  : w->output_cursor.vpos;
+  if (voffset > 0)
+    move_it_by_lines (&it, voffset);
+/* ******************************************************************************
+             MOVE IT OVER EACH CHARACTER ON THE CURRENT LINE.
+****************************************************************************** */
+  while (true)
+    {
+      count += 1;
+      if (new_x > 0)
+        relative_x = new_x - it.first_visible_x;
+/* ******************************************************************************
+                       DUMP RELEVANT GLYPH INFORMATION
+****************************************************************************** */
+  int w_hscroll = it.w->hscroll;
+  int w_min_hscroll = it.w->min_hscroll;
+  int it_charpos = IT_CHARPOS (it);
+  int frame_char_width = FRAME_COLUMN_WIDTH (f);
+  struct face *face = mc_lookup_face (&it);
+  struct font *font = face->font;
+  int font_space_width = (font == NULL
+                          ? frame_char_width
+                          : font->space_width);
+  Lisp_Object foreground_face = face->lface[LFACE_FOREGROUND_INDEX];
+  Lisp_Object background_face = face->lface[LFACE_BACKGROUND_INDEX];
+  Lisp_Object buf = it.w->contents;
+  bool hscl = (!it.w->suspend_auto_hscroll
+               && EQ (Fbuffer_local_value (Qauto_hscroll_mode, buf), Qcurrent_line)
+               && it.w->hscroll > 0);
+  fprintf (stderr, "\n%d.  %s%s\n\
+    it.c (%d)\n\
+    fetch_byte (%d)\n\
+    character (%s)\n\
+    IT_CHARPOS (%d)\n\
+    w->hscroll (%d)\n\
+    hscl (%s)\n\
+    w->min_hscroll (%d)\n\
+    it.hpos (%d)\n\
+    it.vpos (%d)\n\
+    it.current_x (%d)\n\
+    new_x (%d)\n\
+    font->space_width (%d)\n\
+    it.lnum_pixel_width (%d)\n\
+    it.lnum_width (%d)\n\
+    it.first_visible_x (%d)\n\
+    relative_x (%d)\n\
+    it.face_id (%d)\n\
+    foreground_face (%s)\n\
+    background_face (%s)\n\
+    rc (%s)\n",
+      count,
+      (it.c == 0
+        ? "NOTHING"
+        : it.c == 187
+          ? "TAB CHARACTER"
+        : it.c == '\t'
+          ? "TAB STRETCH"
+        : "TEXT"),
+      (relative_x == it.lnum_pixel_width
+        ? " -- THE FUN STARTS HERE"
+        : ""),
+      it.c,
+      FETCH_BYTE (IT_BYTEPOS (it)),
+      (!NILP (Fchar_to_string (make_number (it.c)))
+        ? SSDATA (Fchar_to_string (make_number (it.c)))
+        : "NILP -- it.c as a string"),
+      it_charpos,
+      /* When `it.w->hscroll` is set to an `int`, gdb reports the value
+      as being:  <variable optimized away by compiler> */
+      w_hscroll,
+      (hscl ? "true" : "false"),
+      w_min_hscroll,
+      it.hpos,
+      it.vpos,
+      it.current_x,
+      new_x,
+      /* Cannot access memory at address 0xa0.  This came about by using
+      `?\U0001D4D5` to create a fancy form feed character that was not
+      recognized by the font chosen on X11. */
+      (font == NULL
+       ? 0
+       : font->space_width),
+      it.lnum_pixel_width,
+      it.lnum_width,
+      it.first_visible_x,
+      relative_x,
+      it.face_id,
+      (!NILP (foreground_face)
+        ? SSDATA (foreground_face)
+        : "NILP foreground_face"),
+      (!NILP (background_face)
+        ? SSDATA (background_face)
+        : "NILP background_face"),
+      (rc == MOVE_UNDEFINED
+        ? "MOVE_UNDEFINED"
+        : rc == MOVE_POS_MATCH_OR_ZV
+          ? "MOVE_POS_MATCH_OR_ZV"
+        : rc == MOVE_X_REACHED
+          ? "MOVE_X_REACHED"
+        : rc == MOVE_LINE_CONTINUED
+          ? "MOVE_LINE_CONTINUED"
+        : rc == MOVE_LINE_TRUNCATED
+          ? "MOVE_LINE_TRUNCATED"
+        : rc == MOVE_NEWLINE_OR_CR
+          ? "MOVE_NEWLINE_OR_CR"
+        : "OOPS"));
+/* ******************************************************************************
+                       MOVE IT:  INCREMENT == FONT.SPACE_WIDTH
+****************************************************************************** */
+      if ((FETCH_BYTE (IT_BYTEPOS (it)) == '\n'
+           && it.c != 0)
+          /* || ITERATOR_AT_END_OF_LINE_P (&it) */
+          || rc == MOVE_POS_MATCH_OR_ZV)
+        break;
+      new_x += font_space_width;
+      rc = move_it_in_display_line_to (&it, ZV, new_x, MOVE_TO_POS | MOVE_TO_X);
+      if (rc == MOVE_LINE_CONTINUED)
+        break;
+      if (it.current_x - it.first_visible_x + font_space_width >=
+          window_box_width (w, TEXT_AREA))
+        break;
+    }
+/* ******************************************************************************
+                         REDISPLAY AND DUMP_GLPYH_ROW
+****************************************************************************** */
+  redisplay_internal ();
+  int vpos = (WINDOW_HEADER_LINE_HEIGHT (it.w) > 0)
+             ? it.vpos + 1
+             : it.vpos;
+  struct glyph_row *glyph_row = MATRIX_ROW (w->current_matrix, vpos);
+  fprintf (stderr, "\n");
+  dump_glyph_row (glyph_row, vpos, 2);
+  bidi_unshelve_cache (itdata, false);
+  return Qnil;
+}
+
+/* end MULTIPLE CURSORS */
+/* *************************************************************************** */
+
+
 
 /***********************************************************************
 		      Window display dimensions
@@ -13366,9 +16033,23 @@ hscroll_window_tree (Lisp_Object window)
 	      else
 		pt = clip_to_bounds (BEGV, marker_position (w->pointm), ZV);
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  struct display_pos *pos = &cursor_row->start;
+  ptrdiff_t charpos = CHARPOS (pos->pos);
+  bool barf_crash = (charpos < 0 || (charpos >= BUF_BEG (current_buffer) && charpos <= ZV)) ? false : true;
+  if (barf_crash)
+    return hscrolled_p;
+    else
 	      /* Move iterator to pt starting at cursor_row->start in
 		 a line with infinite width.  */
 	      init_to_row_start (&it, w, cursor_row);
+
+/* *************************************************************************** */
+
+
 	      if (hscl)
 		it.first_visible_x = window_hscroll_limited (w, it.f)
 				     * FRAME_COLUMN_WIDTH (it.f);
@@ -13677,20 +16358,36 @@ overlay_arrows_changed_p (bool set_redisplay)
 		Fget (var, Qlast_arrow_position))
 	  || ! (pstr = overlay_arrow_string_or_property (var),
 		EQ (pstr, Fget (var, Qlast_arrow_string))))
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* @lawlist added checks for a valid marker and a live buffer to avoid crashing;
+and, he opted to bypass `redisplay_other_windows' when the buffer is displayed
+in more than one window.  Otherwise, using this feature is unbearably slow. */
 	{
 	  struct buffer *buf = XMARKER (val)->buffer;
-
-	  if (set_redisplay)
-            {
-              if (buf)
-	        bset_redisplay (buf);
-              changed = true;
-            }
+	  if (set_redisplay
+        /* To avoid crashing due to: #<marker in no buffer> */
+        && buf
+        && MARKERP (val)
+        && BUFFER_LIVE_P (buf))
+      /* bset_redisplay (buf); */
+      /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
+      so that if we later set windows_or_buffers_changed, this buffer will
+      not be omitted.  */
+      buf->text->redisplay = true;
 	  else
 	    return true;
 	}
+
     }
   return changed;
+
+/* *************************************************************************** */
+
+
 }
 
 /* Mark overlay arrows to be updated on next redisplay.  */
@@ -14281,6 +16978,21 @@ redisplay_internal (void)
 #ifdef HAVE_WINDOW_SYSTEM
 	      update_window_fringes (w, false);
 #endif
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* NOTE:  An idle-timer function may not necessarily trigger `redisplay_window'.
+`optimization 1` (which includes left/right cursor movement on the first screen
+line), and `optimization 3` (which includes left/right cursor movement on screen
+lines subsequent to the first screen line), bypass `redisplay_window'. */
+
+      mc_remove_everything (w);
+
+/* *************************************************************************** */
+
+
 	      goto update;
 	    }
 	  else
@@ -14303,6 +17015,16 @@ redisplay_internal (void)
 		  && (w = XWINDOW (selected_window)) != sw)
 		goto retry;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+       if (mc_without_update_frame (w))
+         goto end_of_redisplay;
+
+/* *************************************************************************** */
+
+
 	      /* We used to always goto end_of_redisplay here, but this
 		 isn't enough if we have a blinking cursor.  */
 	      if (w->cursor_off_p == w->last_cursor_off_p)
@@ -14344,6 +17066,21 @@ redisplay_internal (void)
 		  *w->desired_matrix->method = 0;
 		  debug_method_add (w, "optimization 3");
 #endif
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* NOTE:  An idle-timer function may not necessarily trigger `redisplay_window'.
+`optimization 1` (which includes left/right cursor movement on the first screen
+line), and `optimization 3` (which includes left/right cursor movement on screen
+lines subsequent to the first screen line), bypass `redisplay_window'. */
+
+      mc_remove_everything (w);
+
+/* *************************************************************************** */
+
+
 		  goto update;
 		}
 	      else
@@ -14477,6 +17214,20 @@ redisplay_internal (void)
 		    unrequest_sigio ();
 		  STOP_POLLING;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+    /* On Emacs for Windows, crosshairs will not draw at the beginning of the buffer
+    without this condition when the idle-timer switches are toggled.  This may have
+    been due to the parentheses overlays that were removed and did not need to be
+    redrawn since opening parentheses at the beginning of the buffer are not highlighted. */
+    if (w->mc.draw_crosshairs)
+      w->must_be_updated_p = true;
+
+/* *************************************************************************** */
+
+
 		  pending |= update_frame (f, false, false);
 		  f->cursor_type_changed = false;
 		  f->updated_p = true;
@@ -17689,6 +20490,22 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
   else
     TEMP_SET_PT_BOTH (CHARPOS (opoint), BYTEPOS (opoint));
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* NOTE:  An idle-timer function may not necessarily trigger `redisplay_window'.
+`optimization 1` (which includes left/right cursor movement on the first screen
+line), and `optimization 3` (which includes left/right cursor movement on screen
+lines subsequent to the first screen line), bypass `redisplay_window'. */
+
+  mc_record_window_bounds (w);
+
+  mc_remove_everything (w);
+
+/* *************************************************************************** */
+
+
   set_buffer_internal_1 (old);
   /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
      shorter.  This can be caused by log truncation in *Messages*.  */
@@ -21041,6 +23858,30 @@ display_count_lines_visually (struct it *it)
 static void
 maybe_produce_line_number (struct it *it)
 {
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  bool barf_crash = (it->glyph_row == NULL
+                     || it->glyph_row->used[TEXT_AREA] == 0)
+                    ? false
+                    : true;
+  if (barf_crash)
+   return;
+
+  /* This code will be replaced with:
+  commit fe06fcc5955731b1373aa74a586da04f5c2c11f7
+  Author: Eli Zaretskii <eliz@gnu.org>
+  Date:   Tue Aug 28 14:11:12 2018 +0300 */
+  int text_area_width = window_box_width (it->w, TEXT_AREA);
+  if (!NILP (Vdisplay_line_numbers)
+      && text_area_width < it->lnum_pixel_width)
+    return;
+
+/* *************************************************************************** */
+
+
   ptrdiff_t last_line = it->lnum;
   ptrdiff_t start_from, bytepos;
   ptrdiff_t this_line;
@@ -29692,9 +32554,24 @@ display_and_set_cursor (struct window *w, bool on,
       w->phys_cursor.vpos = vpos;
     }
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  w->mc.h = -1;
+  w->mc.fx = -1;
+  w->mc.fy = -1;
+  w->mc.glyph_flavor = NO_FLAVOR;
+  w->mc.red = -1.0;
+  w->mc.green = -1.0;
+  w->mc.blue = -1.0;
   FRAME_RIF (f)->draw_window_cursor (w, glyph_row, x, y,
                                      new_cursor_type, new_cursor_width,
                                      on, active_cursor);
+
+/* *************************************************************************** */
+
+
 }
 
 
@@ -29726,10 +32603,30 @@ update_window_cursor (struct window *w, bool on)
       if (row->reversed_p && hpos >= row->used[TEXT_AREA])
 	hpos = row->used[TEXT_AREA] - 1;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      /* Moving the mouse triggers `update_window_cursor' which calls
+      `display_and_set_cursor' that would otherwise remove a portion of the
+      horizontal ruler from point at end of visual line to window edge. */
+      bool crosshairs_p = (!MINI_WINDOW_P (w)
+                           && !w->mc.draw_crosshairs
+                           && !NILP (w->crosshairs_cache)
+                           && !NILP (BVAR (XBUFFER (w->contents), crosshairs))
+                           && w == XWINDOW (XCAR (Fnth (make_number (1), w->crosshairs_cache)))
+                           && EQ (w->contents, XCAR (Fnth (make_number (2), w->crosshairs_cache))));
+      if (!crosshairs_p)
+        {
       block_input ();
       display_and_set_cursor (w, on, hpos, vpos,
 			      w->phys_cursor.x, w->phys_cursor.y);
       unblock_input ();
+        }
+
+/* *************************************************************************** */
+
+
     }
 }
 
@@ -32436,6 +35333,22 @@ x_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
 void
 syms_of_xdisp (void)
 {
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  defsubr (&Smc_activate_cursors);
+
+  defsubr (&Smc_activate_crosshairs);
+
+  defsubr (&Smc_stderr);
+
+  defsubr (&Sdebugging);
+
+/* *************************************************************************** */
+
+
   Vwith_echo_area_save_vector = Qnil;
   staticpro (&Vwith_echo_area_save_vector);
 
diff --git a/src/xterm.c b/src/xterm.c
index af28dab..d3f5e9a 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1151,10 +1151,14 @@ x_update_window_end (struct window *w, bool cursor_on_p,
     {
       block_input ();
 
-      if (cursor_on_p)
-	display_and_set_cursor (w, true,
-				w->output_cursor.hpos, w->output_cursor.vpos,
-				w->output_cursor.x, w->output_cursor.y);
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      mc_portal (w, cursor_on_p);
+
+/* *************************************************************************** */
+
 
       if (draw_window_fringes (w, true))
 	{
@@ -1530,10 +1534,21 @@ static void x_check_font (struct frame *, struct font *);
 static void
 x_set_cursor_gc (struct glyph_string *s)
 {
-  if (s->font == FRAME_FONT (s->f)
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+  struct window *w = decode_live_window (selected_window);
+  if ((s->font == FRAME_FONT (s->f)
       && s->face->background == FRAME_BACKGROUND_PIXEL (s->f)
       && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f)
       && !s->cmp)
+      || w->mc.cursor_gc_default)
+
+/* *************************************************************************** */
+
+
     s->gc = s->f->output_data.x->cursor_gc;
   else
     {
@@ -9252,6 +9267,26 @@ x_draw_hollow_cursor (struct window *w, struct glyph_row *row)
 
   /* Compute frame-relative coordinates for phys cursor.  */
   get_phys_cursor_geometry (w, row, cursor_glyph, &x, &y, &h);
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+/* LEGEND:
+
+-  top y == WINDOW_TO_FRAME_PIXEL_Y (w, row->y)
+
+-  bottom y == WINDOW_TO_FRAME_PIXEL_Y (w, row->y) - row->height
+
+-  h of HOLLOW_BOX_CURSOR == row->height
+   [This avoids a visible gap above/below.] */
+
+  if (w->mc.h > 0)
+    h = row->height;
+
+/* *************************************************************************** */
+
+
   wd = w->phys_cursor_width - 1;
 
   /* The foreground of cursor_gc is typically the same as the normal
@@ -9328,7 +9363,18 @@ x_draw_bar_cursor (struct window *w, struct glyph_row *row, int width, enum text
 	 invisible.  Use the glyph's foreground color instead in this
 	 case, on the assumption that the glyph's colors are chosen so
 	 that the glyph is legible.  */
-      if (face->background == f->output_data.x->cursor_pixel)
+
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+      if (face->background == f->output_data.x->cursor_pixel
+          && !w->mc.cursor_gc_invisible_okay)
+
+
+/* *************************************************************************** */
+
+
 	xgcv.background = xgcv.foreground = face->foreground;
       else
 	xgcv.background = xgcv.foreground = f->output_data.x->cursor_pixel;
@@ -9359,6 +9405,17 @@ x_draw_bar_cursor (struct window *w, struct glyph_row *row, int width, enum text
 	  if ((cursor_glyph->resolved_level & 1) != 0)
 	    x += cursor_glyph->pixel_width - width;
 
+
+/* *************************************************************************** */
+/* MULTIPLE CURSORS */
+
+    /* Align all fake BAR_CURSOR of the VERTICAL_RULER with `opoint_x'. */
+    if (w->mc.fx > 0)
+      x = w->mc.fx;
+
+/* *************************************************************************** */
+
+
 	  x_fill_rectangle (f, gc, x,
 			  WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y),
 			  width, row->height);
@@ -9435,31 +9492,116 @@ x_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x,
 	}
       else
 	{
-	  switch (cursor_type)
-	    {
-	    case HOLLOW_BOX_CURSOR:
-	      x_draw_hollow_cursor (w, glyph_row);
-	      break;
 
-	    case FILLED_BOX_CURSOR:
-	      draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
-	      break;
 
-	    case BAR_CURSOR:
-	      x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
-	      break;
+/* *************************************************************************** */
+/* begin MULTIPLE CURSORS */
 
-	    case HBAR_CURSOR:
-	      x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
-	      break;
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
+  Colormap cmap = FRAME_X_COLORMAP (f);
+  unsigned long original_cursor_pixel = f->output_data.x->cursor_pixel;
+  double base = 65535.0;
+  double term_red = base * w->mc.red;
+  double term_green = base * w->mc.green;
+  double term_blue = base * w->mc.blue;
+  int int_red = XINT (Ftruncate (make_float (term_red), Qnil));
+  int int_green = XINT (Ftruncate (make_float (term_green), Qnil));;
+  int int_blue = XINT (Ftruncate (make_float (term_blue), Qnil));;
+  XColor color;
+  color.red = int_red;
+  color.green = int_green;
+  color.blue = int_blue;
+  /* `x_alloc_nearest_color' sets the `color.pixel`. */
+  x_alloc_nearest_color (f, cmap, &color);
+  switch (cursor_type)
+  {
+    case HOLLOW_BOX_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        {
+          /* Temporarily hijack `f->output_data.x->cursor_pixel'.  */
+          f->output_data.x->cursor_pixel = color.pixel;
+          x_draw_hollow_cursor (w, glyph_row);
+          f->output_data.x->cursor_pixel = original_cursor_pixel;
+        }
+        else
+          x_draw_hollow_cursor (w, glyph_row);
+      break;
+    }
+    case FILLED_BOX_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        /* Temporarily hijack `f->output_data.x->cursor_gc' by borrowing the
+        functionality of `x_make_gc' in xfns.c.  */
+        {
+          block_input ();
+          struct window *w = decode_live_window (selected_window);
+          XGCValues gc_values;
+          unsigned long mask = GCForeground | GCBackground | GCFillStyle | GCLineWidth;
+          unsigned long frame_bg_pixel = FRAME_BACKGROUND_PIXEL (f);
+          gc_values.line_width = 0;  /* Means 1 using fast algorithm.  */
+          gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
+          gc_values.background = x_make_truecolor_pixel (dpyinfo, int_red, int_green, int_blue);
+          gc_values.fill_style = FillOpaqueStippled;
+          f->output_data.x->cursor_gc
+            = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), mask, &gc_values);
+          /* Force `x_set_cursor_gc' to use `s->f->output_data.x->cursor_gc'.  */
+          w->mc.cursor_gc_default = true;
+          draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
+          w->mc.cursor_gc_default = false;
+          gc_values.line_width = 0;  /* Means 1 using fast algorithm.  */
+          gc_values.foreground = frame_bg_pixel;
+          gc_values.background = original_cursor_pixel;
+          gc_values.fill_style = FillOpaqueStippled;
+          f->output_data.x->cursor_gc
+            = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), mask, &gc_values);
+          unblock_input ();
+        }
+        else
+          draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
+      break;
+    }
+    case BAR_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        {
+          /* Temporarily hijack `f->output_data.x->cursor_pixel'.  */
+          f->output_data.x->cursor_pixel = color.pixel;
+          w->mc.cursor_gc_invisible_okay = true;
+          x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
+          w->mc.cursor_gc_invisible_okay = false;
+          f->output_data.x->cursor_pixel = original_cursor_pixel;
+        }
+        else
+          x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
+      break;
+    }
+    case HBAR_CURSOR:
+    {
+      if (w->mc.red >= 0 && w->mc.blue >= 0 && w->mc.green >= 0)
+        {
+          /* Temporarily hijack `f->output_data.x->cursor_pixel'.  */
+          f->output_data.x->cursor_pixel = color.pixel;
+          w->mc.cursor_gc_invisible_okay = true;
+          x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
+          w->mc.cursor_gc_invisible_okay = false;
+          f->output_data.x->cursor_pixel = original_cursor_pixel;
+        }
+        else
+          x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
+      break;
+    }
+    case NO_CURSOR:
+      w->phys_cursor_width = 0;
+      break;
+    default:
+      emacs_abort ();
+  }
+
+/* end MULTIPLE CURSORS */
+/* *************************************************************************** */
 
-	    case NO_CURSOR:
-	      w->phys_cursor_width = 0;
-	      break;
 
-	    default:
-	      emacs_abort ();
-	    }
 	}
 
 #ifdef HAVE_X_I18N
