From bab56b25149d5f86ac82272a3646893dfb58c41e Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 27 Apr 2024 20:47:34 +0200 Subject: [PATCH] New window parameter 'cursor-type' * src/xdisp.c (get_window_cursor_type): Consult new window parameter 'cursor-type'. * src/window.c (Fset_window_parameter): Mark window for redisplay after 'cursor-type' parameter is set. * doc/lispref/windows.texi (Window Parameters): Document it. * doc/lispref/frames.texi (Cursor Parameters): Mention it. * etc/NEWS: Announce it. (Bug#70622) --- doc/lispref/frames.texi | 5 +++-- doc/lispref/windows.texi | 13 +++++++++++++ etc/NEWS | 6 ++++++ src/window.c | 4 ++++ src/xdisp.c | 39 +++++++++++++++++++++++++++------------ 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index cf7fc7721c5..65d7cf063c5 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -2341,8 +2341,9 @@ Display a horizontal bar @var{height} pixels high. @end table @vindex cursor-type -The @code{cursor-type} frame parameter may be overridden by the -variables @code{cursor-type} and +The @code{cursor-type} frame parameter may be overridden by the window +parameter @code{cursor-type} (@pxref{Definition of cursor-type window +parameter}), and by the variables @code{cursor-type} and @code{cursor-in-non-selected-windows}: @defopt cursor-type diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 104420235df..4dbb1072ba3 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -6691,6 +6691,19 @@ applications that use large margins to center buffer text within a window and should be used, with due care, exclusively by those applications. It might be replaced by an improved solution in future versions of Emacs. + +@item cursor-type +@vindex cursor-type@r{, a window parameter} +@anchor{Definition of cursor-type window parameter} +If this parameter is set to a cons cell, its @sc{car} specifies the +shape of the cursor in this window, using the same format as the +buffer-local variable @code{cursor-type}. @xref{Cursor Parameters}. +Use this window parameter instead of the @code{cursor-type} variable or +frame parameter when a buffer is displayed in multiple windows and you +want to change the cursor for one window without affecting the others. +This window parameter takes precedence over the @code{cursor-type} +variable when the window is selected. For non-selected windows, the +variable @code{cursor-in-non-selected-windows} takes precedence. @end table diff --git a/etc/NEWS b/etc/NEWS index 5534b3162b8..70df011269f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -319,6 +319,12 @@ and 'window-state-get'. Then later another new variable 'window-state-put' to restore positions of window points according to the context stored in a window parameter. ++++ +*** New window parameter 'cursor-type'. +If this parameter is set to a cons cell, its 'car' specifies the shape +of the window's cursor, using the same format as the buffer-local +variable 'cursor-type'. + ** Tab Bars and Tab Lines --- diff --git a/src/window.c b/src/window.c index 6c0fce4119f..7e7a33ed69e 100644 --- a/src/window.c +++ b/src/window.c @@ -2401,6 +2401,10 @@ Return VALUE. */) (w, Fcons (Fcons (parameter, value), w->window_parameters)); else Fsetcdr (old_alist_elt, value); + + if (EQ (parameter, Qcursor_type)) + mark_window_display_accurate (window, false); + return value; } diff --git a/src/xdisp.c b/src/xdisp.c index 72a217513ef..7c2aba0fe34 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -33603,7 +33603,7 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width, struct frame *f = XFRAME (w->frame); struct buffer *b = XBUFFER (w->contents); int cursor_type = DEFAULT_CURSOR; - Lisp_Object alt_cursor; + Lisp_Object alt_cursor, win_cursor; bool non_selected = false; *active_cursor = true; @@ -33615,7 +33615,13 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width, { if (w == XWINDOW (echo_area_window)) { - if (EQ (BVAR (b, cursor_type), Qt) || NILP (BVAR (b, cursor_type))) + win_cursor = window_parameter (w, Qcursor_type); + if (!NILP (win_cursor)) + return get_specified_cursor_type (EQ (win_cursor, Qnone) + ? Qnil + : win_cursor, + width); + else if (EQ (BVAR (b, cursor_type), Qt) || NILP (BVAR (b, cursor_type))) { *width = FRAME_CURSOR_WIDTH (f); return FRAME_DESIRED_CURSOR (f); @@ -33642,18 +33648,27 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width, non_selected = true; } - /* Never display a cursor in a window in which cursor-type is nil. */ - if (NILP (BVAR (b, cursor_type))) - return NO_CURSOR; - - /* Get the normal cursor type for this window. */ - if (EQ (BVAR (b, cursor_type), Qt)) + win_cursor = window_parameter (w, Qcursor_type); + if (!NILP (win_cursor)) + cursor_type = get_specified_cursor_type (EQ (win_cursor, Qnone) + ? Qnil + : win_cursor, + width); + else { - cursor_type = FRAME_DESIRED_CURSOR (f); - *width = FRAME_CURSOR_WIDTH (f); + /* Never display a cursor in a window in which cursor-type is nil. */ + if (NILP (BVAR (b, cursor_type))) + return NO_CURSOR; + + /* Get the normal cursor type for this window. */ + if (EQ (BVAR (b, cursor_type), Qt)) + { + cursor_type = FRAME_DESIRED_CURSOR (f); + *width = FRAME_CURSOR_WIDTH (f); + } + else + cursor_type = get_specified_cursor_type (BVAR (b, cursor_type), width); } - else - cursor_type = get_specified_cursor_type (BVAR (b, cursor_type), width); /* Use cursor-in-non-selected-windows instead for non-selected window or frame. */ -- 2.39.5