2

The documentation for the 'cursor overlay property does not discuss methods for altering the type of cursor that is used when point is on a particular overlay: https://www.gnu.org/software/emacs/manual/html_node/elisp/Special-Properties.html The default overlay cursor type is hollow.

Is there a way for a user to select the type of cursor that is displayed when point is on a particular overlay? E.g., box; bar; (bar . [WIDTH]); hbar; (hbar . [WIDTH])

The following example creates an overlay using an xpm image at the end of the current line, which requires an Emacs version that supports xpm images. The test was performed with a default Emacs installation -- i.e., a white buffer background and a black cursor color -- the hollow cursor outline can be easily seen in this example.

(let ((xpm--pilcrow
       (propertize " " 'cursor t 'display
         `(image :type xpm :mask nil :ascent center :data
         "/* XPM */
         static char * pilcrow_plain_xpm[] = {
         \"11 20 2 1\",
         \". c white\",
         \"+ c cyan\",
         \"...........\",
         \"...........\",
         \"...........\",
         \"...........\",
         \"...++++++..\",
         \"..++++.+...\",
         \"..++++.+...\",
         \"..++++.+...\",
         \"...+++.+...\",
         \".....+.+...\",
         \".....+.+...\",
         \".....+.+...\",
         \".....+.+...\",
         \".....+.+...\",
         \"...........\",
         \"...........\",
         \"...........\",
         \"...........\",
         \"...........\",
         \"...........\"};"))))
  (overlay-put (make-overlay (point-at-eol) (point-at-eol)) 'after-string xpm--pilcrow))
1
  • I don't believe the cursor property alters that at all since the manual is speaking of completely different behaviour compared to the docstring of cursor-type.
    – wasamasa
    Commented Mar 8, 2015 at 7:58

1 Answer 1

0

The following is a partial workaround to prevent the hollow outline around the primary xpm; and, it serves to create the visual appearance of a cursor-type 'bar. It is achieved by creating an xpm image that is one (1) pixel in width and whatever the chosen height happens to be (in this example 20 pixels high). The color of the one-pixel wide image should match the buffer background -- this effectively creates a very thin xpm image that is invisible because it blends in with the buffer's background. The result is a visual vertical bar when the cursor touches it and it works with a blinking cursor. The concatenated xpm does not get a hollow cursor. This example reduces the concatenated image by one (1) pixel in width to compensate for the new xpm that is added to the left.

(let* (
    (xpm--cursor-vbar
      (propertize " " 'cursor t 'display
        `(image :type xpm :mask nil :ascent center :data
        "/* XPM */
        static char * cursor_vbar_xpm[] = {
        \"1 20 1 1\",
        \"+ c white\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\",
        \"+\"};")))
    (xpm--pilcrow
      (propertize " " 'cursor t 'display
        `(image :type xpm :mask nil :ascent center :data
        "/* XPM */
        static char * pilcrow_plain_xpm[] = {
        \"10 20 2 1\",
        \". c white\",
        \"+ c cyan\",
        \"..........\",
        \"..........\",
        \"..........\",
        \"..........\",
        \"..++++++..\",
        \".++++.+...\",
        \".++++.+...\",
        \".++++.+...\",
        \"..+++.+...\",
        \"....+.+...\",
        \"....+.+...\",
        \"....+.+...\",
        \"....+.+...\",
        \"....+.+...\",
        \"..........\",
        \"..........\",
        \"..........\",
        \"..........\",
        \"..........\",
        \"..........\"};"))) )
  (overlay-put (make-overlay (point-at-eol) (point-at-eol)) 'after-string
    (concat xpm--cursor-vbar xpm--pilcrow)) )
5
  • Couldn't you just declare the overlay as intangible?
    – wasamasa
    Commented Mar 8, 2015 at 16:47
  • @wasamasa -- the property intangible seems to come in handy when the goal is to skip over a particular overlay; however, I was not able to get it to simulate a cursor-type 'bar that is one pixel in width. In the context of the custom minor-mode that I am using, I place a particular color/shape xpm at the end of the line when point is at that location. My preference is to use the cursor-type (bar . 1) and I was experiencing a visual shock when the hollow outline appeared. The above example creates the visual appearance of cursor-type (bar . 1) to the immediate left of the xpm.
    – lawlist
    Commented Mar 8, 2015 at 17:26
  • I don't believe it's a hollow cursor either and just the selected character.
    – wasamasa
    Commented Mar 8, 2015 at 18:03
  • @wasamasa -- I have no experience reading c-source-code, but I believe the file xdisp.c has some discussion regarding using a hollow cursor for images: Display current only supports BOX and HOLLOW cursors for images. So for now, unconditionally use a HOLLOW cursor when cursor is not a solid box cursor. There are a few other references in that particular c-source-code file that look like the Emacs team has made certain decisions regarding what type of cursor to use with images.
    – lawlist
    Commented Mar 8, 2015 at 18:59
  • Hmm, you're right, apparently this is a baked in feature.
    – wasamasa
    Commented Mar 8, 2015 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.