Subject: bug#22873: Can we support multiple Cursors?

From: Keith David Bershatsky <[email-masked]>
Date: Mon, 14 Mar 2016 15:38:55 -0700

Thank you, Eli, for resolving the issue with the `mc_cache` being GC'ed behind my back.  As per your suggestion, I moved the Lisp_Object definition of `mc_cache` in `window.h` to above the section beginning with the comment "No Lisp data may follow below this point . . . ."  I also moved the other mc-realted `int` and `bool_bf` definitions into the section beginning with "#ifdef HAVE_WINDOW_SYSTEM".

The enclosed `multiple_cursors_004.diff` applies to Emacs master branch from last night (March 13, 2016) bearing commit "181e92c4e060a7ce4740b561375f9ec9f473f144".

Multiple fake cursors now have preliminary support on all three (3) window systems -- i.e., X (--with-x --with-x-toolkit=no), Windows (XP SP-3) and OSX (10.6.8).

I will need to track down why (on Emacs for Windows) a fake cursor appearing as FILLED_BOX_CURSOR sometimes takes on the background color of the real active cursor.  This seems to depend upon whether I start with Emacs -Q versus a full configuration, so perhaps it won't be that difficult to track down.

I haven't done any calculations regarding the time needed to run `mc_x_y_hpos_vpos` on each position for fake cursors, so I don't really know how advantageous a cache is and whether more effort should be made to perfect a caching mechanism.

I'm assuming that just multiplying the LSL color vector elements by 255 for Windows and by 65535 for X is sufficient to obtain the exact color, but it certainly appears to look okay to my untrained eyes.

(defun mc-test (&optional list)
"Draw fake cursors at all POS defined in the `mc-list'.  Multiple fake cursors
are supported by GUI versions of Emacs built for X, Windows and OSX.
Color vector is LSL (The Linden Scripting Language), rather than standard RGB.
`nsterm.m' uses `NSColor', which works well with LSL.  `w32term.c' uses
`PALETTERGB' or `RGB', and the conversion from LSL is done internally by
multiplying each element of the LSL color vector by 255.  `xterm.c' uses
`x_make_truecolor_pixel', which uses 16-bit RGB -- the conversion from LSL
happens internally by multiplying each element of the LSL color vector by 65535."
(interactive)
  (setq mc-list (if list list '(
    (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])))))

(global-set-key [f1] 'mc-test)