Subject: #22873 (multiple fake cursors); and, #17684 (crosshairs).

From: Keith David Bershatsky <[email-masked]>
Date: Sun, 02 Jun 2019 00:29:09 -0700

VERSION:  021.000 [06/01/2019]

CHANGELOG:

-  Added a new feature to visually distinguish with user-defined colors when a
   fake cursor is on a screen line containing _only_ ZV, or subsequent to a
   screen line containing _only_ ZV, or all screen lines prior to a line
   containing _only_ ZV (if such a line exists), which includes a screen line
   that has characters and ends at ZV (i.e., no final new line).

   SCREENSHOT -- DARK BACKGROUND:

   https://lawlist.com/images/22873_17684__2019_06_01_dark_bg.png

   SCREENSHOT -- LIGHT BACKGROUND:

   https://lawlist.com/images/22873_17684__2019_06_01_light_bg.png

-  `free_window_matrices':  Added a call to free the fake cursor cache matrices.

-  Tweaked how colors are assigned for the MC_FRAMED_BOX when at region begin,
   region end, and in between region begin/end.

-  Fixed a crash caused by NULL glyph when attempting to cache coordinates for
   a right fringe bitmap when cursor is exactly at the right fringe.  When
   coordinates for the real cursor do not correlate to an actual glyph, we use
   the last glyph of the current row instead.

-  Fixed a crash caused by using the built-in region begin/end function, which
   failed when Fmarker_position returned a NULL Lisp_Object -- leading to one of
   those hard to debug bugs; i.e., when garbage collection chokes due to a NULL
   Lisp_Object.  `mc_region_limit' is now used instead.

-  Fixed a bug caused by a failure to have a `fill_column_trump_p` test at the
   tail end of `mc_update_text_area' which is used to suppress the vertical
   crosshairs ruler when the fill column indicator trumps at that exact X.

-  NS port:  Fixed a bug relating to `mc_ns_draw_overwritten' drawing fake
   cursors outside of the clipped area when dealing with STRETCH_GLYPH.

-  NS port:  Created a workaround to deal with the `row->clip' inhibiting the
   drawing of glyphs on the box family of fake cursors in certain circumstances.
   [More work needs to be done, but will likely require help from Emacs Devel.]

SETUP:

Step 1:  git clone -b master git://git.sv.gnu.org/emacs.git

Step 2:  In the new emacs folder, go back to an Emacs version from 04/08/2019:

git reset --hard a038df77de7b1aa2d73a6478493b8838b59e4982

Step 3:  From within the new emacs folder created in Step 1, apply the patch:

git apply /path/to/the/patch.diff

Step 4:  ./autogen.sh

Step 5:  ./configure ... [your custom options]

Step 6:  make

Step 7:  make install

USAGE:

- For a minimal working example of built-in fake cursors, type:  M-x mc-test

  ;;; TURN ON FAKE CURSORS (buffer position, cursor-type, cursor color):

  (setq mc-conf '((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])
                  (7 "framed" "OrangeRed"))))

  ;;; TURN OFF FAKE CURSORS:

  (setq mc-conf nil)

- To try out the crosshairs feature, type:  M-x +-mode

- To try out built-in fake cursors with Magnar Sveen's multiple-cursors package,
  install that package first.  [If the multiple-cursors package is installed, an
  eval-after-load "multiple-cursors-core" statement within `crosshairs.el` will
  redefine a couple of functions and set up a few keyboard shortcuts.]  If the
  multiple-cursors package by Magnar Sveen is not already installed, then here
  are two easy ways to install that package:

  Type:  M-x mc-install

  OR, evaluate the following snippet:

  (progn
    (require 'package)
    (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
    (package-initialize)
    (package-refresh-contents)
    (package-install 'multiple-cursors))

TODO:

- `ns_draw_window_cursor' calls `ns_clip_to_rect', which does _not_ take
  `row->clip` into consideration when drawing cursors with `NSRectFill'.  When
  it comes time to draw glyphs on top of the box/hollow family of cursors,
  `row->clip` is taken into consideration by `get_glyph_string_clip'.  Fake
  cursors can be drawn even though the glyphs cannot, resulting in hollow/box
  family of cursors without text.  The issue can be reproduced with M-x mc-test.
  [A temporary workaround is to disable `row->clip` while drawing the glyphs.]
  https://lists.gnu.org/archive/html/emacs-devel/2019-04/msg00009.html

- Add additional support for `ch_inactive_windows' and `fc_inactive_windows'
  when the variables have a `nil` value.  In such a case, the inactive windows
  should not display the crosshairs and/or visible fill column indicator.  At the
  present time, fake cursors are drawn in active/inactive windows alike.

- Deal with left/right overwritten glyphs in the w32 and X ports of Emacs.

- Is there any additional meaningful optimization that can be added to the
  three calls of `mc_pre_scroll_clean'?

- NOTE:  As to `mc_scrolling_window', it would appear that there is no tangible
  benefit to rotating the current/prospective cache of fake cursors to compare
  the data before removing the fake cursors.  When scrolling the display, only
  _some_ lines are copied to new locations.  Areas that are not overwritten may
  have fake cursors and those may not necessarily be removed if desired/current
  matrix glyphs are equal.  The test for `GLYPH_EQUAL_P' does not take into
  consideration the existence of a fake cursor, and the glyph (with a fake
  cursor) may not be updated as a result thereof.  As to lines that are not
  copied, portions may be updated and fake cursors would be removed thereby.

- When an idle-timer fires and point is at the end of a horizontally scrolled
  line in a narrow window, the temporary horizontal scroll is canceled.  Create
  an minimal working example and file a bug report.

- There is a bug affecting an older version of Emacs for the NS port that causes
  partial line flickering when the same characters are grouped together (;;;;;;)
  and MC_GLYPHLESS cursors are above or below -- having the same background color
  as the frame; e.g., black on black (used to erase a glyphless cursor).  The
  partial flickering is only noticeable with rapid fire; e.g., holding down the
  right/left arrow key.  When changing the color of the glyphless cursor, the
  issue is not present.  [@lawlist has verified that the X and HPOS coordinates
  are accurate.]

- There is a bug affecting the recorded `w->mc.lnum_pixel_width` that is
  observable when not running under gdb, but disappears when running under gdb.
  While viewing a folded org-mode buffer, the non-gdb instance had a visible
  line number pixel-width of 44, but Emacs treated it as fluctuating between
  44 and 55 as the cursor was moved to the end of line.  In the gdb instance,
  the visible line number pixel width was 55 with no fluctuation under the same
  conditions as the non-gdb instance.  This appears to be a different bug than
  bug#32177 (current line number shifts one column to the left) because the line
  number of the current line does not shift left, and changing the bidi settings
  did not correct the issue.

- The current test for `auto_hscroll_mode_p' only looks for `current_line` and
  all five related tests are based upon that assumption, which may not be true.

- Multiple Cursors:  If point is in the middle of a composite character, then
  select a fully composed character so that the fake cursor is visible.

- Implement functionality similar to the Lisp multiple-cursors by Magnar Sveen.

- 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.