From d4b74b56d7fb3fa1ac48d5049b18ac126e800d60 Mon Sep 17 00:00:00 2001 From: Zajcev Evgeny Date: Mon, 27 Jan 2020 15:49:46 +0300 Subject: [PATCH] Support for (box . WIDTH) `cursor-type' * buffer.c (cursor-type): Add commentary about (box . WIDTH) cursor-type * xdisp.c (get_specified_cursor_type): Check for `cursor-type' in form (box . WIDTH) * xdisp.c (get_window_cursor_type): Check masked image size for (box . WIDTH) cursor-type. * doc/emacs/display.texi, doc/emacs/display.texi: Add description for (box . WIDTH) `cursor-type' * etc/NEWS: Add note about (box . WIDTH) `cursor-type' --- doc/emacs/display.texi | 2 ++ doc/lispref/frames.texi | 3 +++ etc/NEWS | 5 +++++ src/buffer.c | 5 +++++ src/xdisp.c | 28 ++++++++++++++-------------- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index cb37ef4..bbfa938 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi @@ -1647,6 +1647,8 @@ Cursor Display the text shown under the cursor is drawn using the frame's background color.) To change its shape, customize the buffer-local variable @code{cursor-type}; possible values are @code{box} (the default), +@code{(box . @var{width})} (box cursor becoming a hollow box under +masked images larger than @var{width} in either dimension), @code{hollow} (a hollow box), @code{bar} (a vertical bar), @code{(bar . @var{n})} (a vertical bar @var{n} pixels wide), @code{hbar} (a horizontal bar), @code{(hbar . @var{n})} (a horizontal bar @var{n} diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index 81a3dc6..67a4998 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -2219,6 +2219,9 @@ Cursor Parameters @table @code @item box Display a filled box. (This is the default.) +@item (box . @var{width}) +Display a filled box. However, display it as a hollow box if point is +under masked image larger than @var{width} in either dimension. @item hollow Display a hollow box. @item nil diff --git a/etc/NEWS b/etc/NEWS index dd33950..9cc0b1f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -30,6 +30,11 @@ applies, and please also update docstrings as needed. * Changes in Emacs 28.1 +** Support for `(box . WIDTH)' cursor-type. By default, `box' cursor +always has a filled box shape. Unless you specify cursor-type to be +`(box . WIDTH)'. In such case, cursor becomes a hollow box if the +point is under masked image larger than `WIDTH' in any dimension. + * Editing Changes in Emacs 28.1 diff --git a/src/buffer.c b/src/buffer.c index 80eaa97..a490d5f 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -6247,6 +6247,9 @@ from (abs POSITION). If POSITION is positive, point was at the front t use the cursor specified for the frame nil don't display a cursor box display a filled box cursor + (box . WIDTH) display a filled box cursor, but make it + hollow if cursor is under masked image larger than + WIDTH pixels in either dimension. hollow display a hollow box cursor bar display a vertical bar cursor with default width (bar . WIDTH) display a vertical bar cursor with width WIDTH @@ -6255,6 +6258,8 @@ from (abs POSITION). If POSITION is positive, point was at the front ANYTHING ELSE display a hollow box cursor WIDTH and HEIGHT can't exceed the frame's canonical character size. +Except for (box . WIDTH) case, where WIDTH specifies the size of a +masked image, not the size of the cursor. When the buffer is displayed in a non-selected window, the cursor's appearance is instead controlled by the variable diff --git a/src/xdisp.c b/src/xdisp.c index 3080f89..eb2bf1c 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -30692,14 +30692,6 @@ get_specified_cursor_type (Lisp_Object arg, int *width) return BAR_CURSOR; } - if (CONSP (arg) - && EQ (XCAR (arg), Qbar) - && RANGED_FIXNUMP (0, XCDR (arg), INT_MAX)) - { - *width = XFIXNUM (XCDR (arg)); - return BAR_CURSOR; - } - if (EQ (arg, Qhbar)) { *width = 2; @@ -30707,11 +30699,16 @@ get_specified_cursor_type (Lisp_Object arg, int *width) } if (CONSP (arg) - && EQ (XCAR (arg), Qhbar) && RANGED_FIXNUMP (0, XCDR (arg), INT_MAX)) { *width = XFIXNUM (XCDR (arg)); - return HBAR_CURSOR; + + if (EQ (XCAR (arg), Qbox)) + return FILLED_BOX_CURSOR; + else if (EQ (XCAR (arg), Qbar)) + return BAR_CURSOR; + else if (EQ (XCAR (arg), Qhbar)) + return HBAR_CURSOR; } /* Treat anything unknown as "hollow box cursor". @@ -30849,12 +30846,15 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width, struct image *img = IMAGE_OPT_FROM_ID (f, glyph->u.img_id); if (img != NULL && IMAGEP (img->spec)) { - /* Arbitrarily, interpret "Large" as >32x32 and >NxN + /* Interpret "large" as >WIDTHxWIDTH and >NxN + where WIDTH is the value from cursor-type in form (box . WIDTH), where N = size of default frame font size. - This should cover most of the "tiny" icons people may use. */ + So, setting cursor-type to (box . 32) should cover most of + the "tiny" icons people may use. */ if (!img->mask - || img->width > max (32, WINDOW_FRAME_COLUMN_WIDTH (w)) - || img->height > max (32, WINDOW_FRAME_LINE_HEIGHT (w))) + || (CONSP (BVAR (b, cursor_type)) + && img->width > max (*width, WINDOW_FRAME_COLUMN_WIDTH (w)) + && img->height > max (*width, WINDOW_FRAME_LINE_HEIGHT (w)))) cursor_type = HOLLOW_BOX_CURSOR; } } -- 2.7.4