From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70622: [PATCH] New window parameter 'cursor-type' Date: Thu, 09 May 2024 12:56:54 +0200 Message-ID: References: <864jbmuf39.fsf@gnu.org> <8634r5tsit.fsf@gnu.org> <86y18wsmqy.fsf@gnu.org> <86cyq8sfif.fsf@gnu.org> <0519d8d8-2a3d-411a-a5bb-b556e0fb86db@gmx.at> <868r0ws9u1.fsf@gnu.org> <867cgfqcbn.fsf@gnu.org> <86jzk377kx.fsf@gnu.org> Reply-To: Eshel Yaron Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40599"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: rudalics@gmx.at, 70622@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 09 12:57:48 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s51T8-000AJt-Dy for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 May 2024 12:57:46 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s51Sz-0006SK-Iz; Thu, 09 May 2024 06:57:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s51Sy-0006Qr-Gg for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 06:57:36 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s51Sy-0007wO-88 for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 06:57:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s51TN-0006aw-SH for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 06:58:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eshel Yaron Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 May 2024 10:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70622 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70622-submit@debbugs.gnu.org id=B70622.171525224925331 (code B ref 70622); Thu, 09 May 2024 10:58:01 +0000 Original-Received: (at 70622) by debbugs.gnu.org; 9 May 2024 10:57:29 +0000 Original-Received: from localhost ([127.0.0.1]:54621 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s51Sq-0006aV-S7 for submit@debbugs.gnu.org; Thu, 09 May 2024 06:57:29 -0400 Original-Received: from mail.eshelyaron.com ([107.175.124.16]:48284 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s51Sl-0006aI-In for 70622@debbugs.gnu.org; Thu, 09 May 2024 06:57:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1715252217; bh=edzh2wddOlxULJVZt2tGl3r0ajCEvPihjksiwo2bDho=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=wBXTP45IUiT1RyopxLgZiBZjT2e7w8dB0ZRdVCuhr+V5IoBhKsoNRmJYRlg3VgvVI vAZsDUSzi37/P8Pn+6A+4w/982e90Nr0TIYxA8HR3KFybrN/+amRF/WkByorjgspn9 m4U1elzgU0HRAFPyAx1oxnnrCtsxMFs88uaODUNzXCczbHGKrAnfWSXbn3rs4YST8z LNkDXH4klKDoSJMWG2Q76qB7UMDFj4pY+FOJ4F9YMv9BW1bMNUXmtG/O2oGYrNe8Ha DLNYZ7bAWkFK/ViZHKWv68TxYyHeYCWt+AO4xaGsmsUZrHSh48KdQUSKBMBVvWrIZi n/UTL4U8Kr5lA== In-Reply-To: <86jzk377kx.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 09 May 2024 10:44:30 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:284751 Archived-At: --=-=-= Content-Type: text/plain Hi, Eli Zaretskii writes: >> Cc: me@eshelyaron.com, 70622@debbugs.gnu.org >> Date: Tue, 30 Apr 2024 15:12:12 +0300 >> From: Eli Zaretskii >> >> > Date: Tue, 30 Apr 2024 11:03:44 +0200 >> > Cc: me@eshelyaron.com, 70622@debbugs.gnu.org >> > From: martin rudalics >> > >> > > So that cursor-type is no longer a window-parameter? >> > >> > Yes. IIUC it would mean that we have to initialize the cursor_type slot >> > of a new window to t. With the window parameter solution one would have >> > to add a new 'cursor-type' parameter with a value of t whenever making a >> > new window. This would break with the convention that non-nil window >> > parameters are used for handling "special" behaviors only. >> >> I'm fine with this approach, thanks. It will also solve nicely the >> problem of redisplaying the affected window ASAP. > > Eshel, could you please update your patch along these lines? Yes, how does the attached patch look? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v3-0001-New-functions-set-window-cursor-type.patch >From 418170a9860d368eb268b01f7b3d00f5c4d9e169 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 27 Apr 2024 20:47:34 +0200 Subject: [PATCH v3] New functions '(set-)window-cursor-type' * src/window.h (struct window): Add 'cursor_type' slot. (wset_cursor_type): New inline function. * src/xdisp.c (get_window_cursor_type): Consult 'cursor_type'. * src/window.c (make_window): Initialize 'cursor_type' to t. (Fset_window_cursor_type, Fwindow_cursor_type): New functions. (syms_of_window): List their symbols. * doc/lispref/windows.texi (Window Point): Document them. * doc/lispref/frames.texi (Cursor Parameters): Mention new 'set-window-cursor-type'. * etc/NEWS: Announce new functions. (Bug#70622) --- doc/lispref/frames.texi | 6 +++--- doc/lispref/windows.texi | 12 ++++++++++++ etc/NEWS | 5 +++++ src/window.c | 30 ++++++++++++++++++++++++++++++ src/window.h | 9 +++++++++ src/xdisp.c | 29 ++++++++++++++++++----------- 6 files changed, 77 insertions(+), 14 deletions(-) diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index cae93acae9f..df6a94ed0f7 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -2341,9 +2341,9 @@ Cursor Parameters @end table @vindex cursor-type -The @code{cursor-type} frame parameter may be overridden by the -variables @code{cursor-type} and -@code{cursor-in-non-selected-windows}: +The @code{cursor-type} frame parameter may be overridden by +@code{set-window-cursor-type}, and by the variables @code{cursor-type} +and @code{cursor-in-non-selected-windows}: @defopt cursor-type This buffer-local variable controls how the cursor looks in a selected diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 104420235df..745dca49f9a 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -5142,6 +5142,18 @@ Window Point so @code{window-point} will stay behind text inserted there. @end defvar +@defun set-window-cursor-type window type +This function sets the cursor shape for @var{window}. This setting +takes precedence over the @code{cursor-type} variable, and @var{type} +has the same format as the value of that variable. If @var{window} is +@code{nil}, it means to set the cursor type for the selected window. +@end defun + +@defun window-cursor-type &optional window +This function returns the cursor type of @var{window}, defaulting to the +selected window. +@end defun + @node Window Start and End @section The Window Start and End Positions @cindex window start position diff --git a/etc/NEWS b/etc/NEWS index 9c356e64bde..3cf97b605e7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -340,6 +340,11 @@ 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 functions 'set-window-cursor-type' and 'window-cursor-type'. +'set-window-cursor-type' sets a per-window cursor type, and +'window-cursor-type' queries this setting for a given window. + ** Tab Bars and Tab Lines --- diff --git a/src/window.c b/src/window.c index cf12841bd51..e71f1b152a6 100644 --- a/src/window.c +++ b/src/window.c @@ -4425,6 +4425,7 @@ make_window (void) wset_old_pointm (w, Fmake_marker ()); wset_vertical_scroll_bar_type (w, Qt); wset_horizontal_scroll_bar_type (w, Qt); + wset_cursor_type (w, Qt); /* These Lisp fields are marked specially so they're not set to nil by allocate_window. */ wset_prev_buffers (w, Qnil); @@ -8050,6 +8051,33 @@ DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes, w->fringes_persistent ? Qt : Qnil); } +DEFUN ("set-window-cursor-type", Fset_window_cursor_type, + Sset_window_cursor_type, 2, 2, 0, + doc: /* Set the `cursor-type' of WINDOW to TYPE. + +This setting takes precedence over the variable `cursor-type', and TYPE +has the same format as the value of that variable. WINDOW nil means use +the selected window. */) + (Lisp_Object window, Lisp_Object type) +{ + struct window *w = decode_live_window (window); + + wset_cursor_type (w, type); + + /* Redisplay with updated cursor type. */ + wset_redisplay (w); + + return type; +} + +DEFUN ("window-cursor-type", Fwindow_cursor_type, Swindow_cursor_type, + 0, 1, 0, + doc: /* Return the `cursor-type' of WINDOW. +WINDOW must be a live window and defaults to the selected one. */) + (Lisp_Object window) +{ + return decode_live_window (window)->cursor_type; +} /*********************************************************************** @@ -8976,4 +9004,6 @@ syms_of_window (void) defsubr (&Swindow_parameters); defsubr (&Swindow_parameter); defsubr (&Sset_window_parameter); + defsubr (&Swindow_cursor_type); + defsubr (&Sset_window_cursor_type); } diff --git a/src/window.h b/src/window.h index 19283725931..297f3c66044 100644 --- a/src/window.h +++ b/src/window.h @@ -323,6 +323,9 @@ #define WINDOW_H_INCLUDED as the normal may yield a matrix which is too small. */ int nrows_scale_factor, ncols_scale_factor; + /* `cursor-type' to use in this window. */ + Lisp_Object cursor_type; + /* Intended cursor position. This is a position within the glyph matrix. */ struct cursor_pos cursor; @@ -542,6 +545,12 @@ wset_horizontal_scroll_bar_type (struct window *w, Lisp_Object val) w->horizontal_scroll_bar_type = val; } +INLINE void +wset_cursor_type (struct window *w, Lisp_Object val) +{ + w->cursor_type = val; +} + INLINE void wset_prev_buffers (struct window *w, Lisp_Object val) { diff --git a/src/xdisp.c b/src/xdisp.c index 85802ec5083..24d0c090326 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -33617,7 +33617,9 @@ 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))) + if (!EQ (Qt, w->cursor_type)) + return get_specified_cursor_type (w->cursor_type, width); + else if (EQ (BVAR (b, cursor_type), Qt) || NILP (BVAR (b, cursor_type))) { *width = FRAME_CURSOR_WIDTH (f); return FRAME_DESIRED_CURSOR (f); @@ -33644,18 +33646,23 @@ 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)) + if (!EQ (Qt, w->cursor_type)) + cursor_type = get_specified_cursor_type (w->cursor_type, 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.45.0 --=-=-=--