From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: Moving point after character when clicking latter half of it Date: Sat, 22 Jul 2023 19:31:20 +0800 Message-ID: <87mszo2nef.fsf@yahoo.com> References: <2255158.iZASKD2KPV@silef> <87a5vo4y2m.fsf@yahoo.com> <83edl0a4f2.fsf@gnu.org> <5697547.DvuYhMxLoT@anduin> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5653"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Moritz Maxeiner Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jul 22 13:32:35 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qNAqh-0001Hb-Iu for ged-emacs-devel@m.gmane-mx.org; Sat, 22 Jul 2023 13:32:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNApl-00057F-0b; Sat, 22 Jul 2023 07:31: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 1qNApi-00056v-QD for emacs-devel@gnu.org; Sat, 22 Jul 2023 07:31:35 -0400 Original-Received: from sonic306-20.consmr.mail.ne1.yahoo.com ([66.163.189.82]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNApg-0006aT-Uf for emacs-devel@gnu.org; Sat, 22 Jul 2023 07:31:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1690025490; bh=Ucv0D66INBrJvO9hJGIRaSTdYaQVB6q8+KfWAJvb/Ck=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=aEbEbwrz7CDFtb/wRtdGKBD76bitHWfrnJYihw0gt4d6YBm08LQhJ1D9EThthyBH8dhtuJIRom88in1bMzJ+t93r9IaOt62fz0QVH1QUn9byUh2CM1nlNr0d4AAsWMf1eFdTinphssCwBWGr54miNWxan4PIKDmfK8pOgw0oytGw5/FRYlMc8feypPaHztAg5oahB/oc8QoFE6ZF+6XppTGy0tgrQkVYsOxxo3N2B67ASSglU1+U2RpMVqyvaSMZP9VdVXN1P2Ov4H56GYLPzulGYJt6mOykbHpVc1w5y5clhegCeoO0QzRxgiJXHRbWhLRyeiMkGmCwt3jBer9qUg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1690025490; bh=S8GhHqxVaEbHHIMIqLAbTxFnVOArGqeGd0l4gNAOf44=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=bl82bG66A41x6gK5OPQpb+dIlSZ1S5gkv8aCZ3Cg1XkBXdir2V/MR9+kXeYWglEylg55QR0wRlEMQHfJkl4kiS5Qltp+sMZh7k2z6yRycq3Tk2oy2xXVsmu5Tir0M1EKTYJvf0pWbevKHkdI8F2Lmciq2zY+zeJ2lhedcRP5WcSI3q7JSKZDZ2ztc6aUZWj/a9hTGmTeKdjihKIsZGiGVuUh4VSW6oRtPLPDnb3XiaaVoDVUbkJom1xo2A9AOBH+vDr16B7JSwmAn/Vk0ZhIZW6tuH28y2OeAv812v8EFekHvyaGiH5GugiSO6pupMePaZWIiN9fXGaoEl5LejMgbg== X-YMail-OSG: _8EQuRIVM1koFEqRfHPUyDDv1xrpsCYdIatuACFKKb4NUul3sDjWuCprdkDQMbd S_sAFT0daRIeO_ERBvGCWSVrSVvwhS6Kxs4eEpv.8T0yIyHuVXzHqg7k4gwtzxHA5dSKxpor9p_t PBKoVrhCCke21Y4gcEjIImEPmKZ0UzSFKd8ZWMp9UEeKBV_ej0zcKvM30CYIvzxMhIw934E8ZVqb vNHVqBmma_Cf851c3w.ZD52tT2tc828blBlLeQNc8joolrRjY8.vn.yAaNsYljST0aLLoEzpAOQC WnXGNra7NuCClhBNUJKq6CCVWLhDBwpKNmUSP0VSCHW6FDpQbduwlNiuKsx7Vi4Nj6HgTguSUnCU eBp4SNhyHtgRNeiBs2Xe8NGiPspAMvBzgSHaOKRSyX2OUZZ30N1VoleSb6OTYVtS151.5eGGpTdP UhHaR3bHpfuU8zLPf9TxNO_J8AJus.klJ9.YfnMV2my8VyzmQ3A3a4YS3aTCLyoOqzk9BtL1EyNk EaFwy6NYhIWXPtnBfhO8OdWSC.ooGKnF7im7cI2xUEYBLt4835.9seBERl24BUVfr4NMAW8XsVjE MhsAZiuwcA9ALCBhAwgqV4miW0gsE3_BJZ5M2Ug1wzsmgtlowBYgaRmlNEJOB.TFUIBbtzldL95v i44MyjxytKNtRjy6cKyRdIschLZv4_txFbEjBPevTbWrhv0TiXSkMwVKSl2IMS9kxc06F3ZVsA2K JYbh9P4MD4jBuaNwBqjqXzv4wxgFEivZQl5pLyBY1utXsvJZUjMBKnK7.5Yc99UkJoH4BhQsS5yk 9BS0NQDZeMeuim59ugFuXRnbc4MziFndffMTxaomEe X-Sonic-MF: X-Sonic-ID: bb15b7db-899d-42a7-9dce-68b2b02d0582 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Sat, 22 Jul 2023 11:31:30 +0000 Original-Received: by hermes--production-sg3-9dc5f54fc-9znrz (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 1bd725280204b3624dfb620df0737269; Sat, 22 Jul 2023 11:31:26 +0000 (UTC) In-Reply-To: <5697547.DvuYhMxLoT@anduin> (Moritz Maxeiner's message of "Sat, 22 Jul 2023 12:07:27 +0200") X-Mailer: WebService/1.1.21647 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.189.82; envelope-from=luangruo@yahoo.com; helo=sonic306-20.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:308013 Archived-At: Moritz Maxeiner writes: > Done. Though I am concerned that capitalizing "x coordinate" to "X > coordinate" will lead to confusion, as capitalized X seems to usually refer to > the X window system within NEWS. In this instance, it's not supposed to be > referring to that, instead it's referring to the x of the (x,y) coordinate > pair. I think that what the X refers to is sufficiently clear from the surrounding context. If you're still concerned, however, how about ``cordinate on the X axis''? > diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi > index cd1745614eb..d1b8f9c494c 100644 > --- a/doc/lispref/commands.texi > +++ b/doc/lispref/commands.texi > @@ -2751,6 +2751,16 @@ If @var{whole} is non-@code{nil}, the @var{x} coordinate is relative > to the entire window area including scroll bars, margins and fringes. > @end defun > > +@defopt mouse-prefer-closest-glyph > +If this variable is non-@code{nil}, the @code{posn-point} of a mouse > +position list will be set to the position of the glyph whose left most > +position is closest to the mouse pointer, as opposed to the position of > +the glyph underneath the mouse pointer itself. For example, if > +@code{posn-at-x-y} is called with @var{x} set to @code{9}, which is > +contained within a character of width 10 positioned at column 0, the > +point saved within the mouse position list will be after that character. > +@end defopt > + > @node Accessing Scroll > @subsection Accessing Scroll Bar Events > @cindex scroll bar events, data in > diff --git a/etc/NEWS b/etc/NEWS > index 9e6f0c16bcd..3c127aa9bd7 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -952,6 +952,17 @@ wheel reports. Unlike 'pixel-scroll-mode', this mode scrolls the > display pixel-by-pixel, as opposed to only animating line-by-line > scrolls. > > ++++ > +** New user option 'mouse-prefer-closest-glyph'. > +When enabled, clicking or dragging with the mouse will put the point > +in front of the buffer position corresponding to the glyph with the > +closest X coordinate to the click or start of the drag. > +In other words, if the mouse pointer is in the right half of a glyph, > +point will be put after the buffer position corresponding to that glyph, > +whereas if the mouse pointer is in the left half of a glyph, point > +will be put in front the buffer position corresponding to that glyph. > +By default this is disabled. > + > ** Terminal Emacs > > --- > diff --git a/lisp/cus-start.el b/lisp/cus-start.el > index 054683d7cf6..2ed904f178f 100644 > --- a/lisp/cus-start.el > +++ b/lisp/cus-start.el > @@ -231,6 +231,7 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of > (inverse-video display boolean) > (visible-bell display boolean) > (no-redraw-on-reenter display boolean) > + (mouse-prefer-closest-glyph display boolean) > > ;; doc.c > (text-quoting-style display > diff --git a/src/dispnew.c b/src/dispnew.c > index 65d9cf9b4e1..143dda412e9 100644 > --- a/src/dispnew.c > +++ b/src/dispnew.c > @@ -5611,6 +5611,15 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p > argument is ZV to prevent move_it_in_display_line from matching > based on buffer positions. */ > move_it_in_display_line (&it, ZV, to_x, MOVE_TO_X); > + if (mouse_prefer_closest_glyph) > + { > + int next_x = it.current_x + it.pixel_width; > + int before_dx = to_x - it.current_x; > + int after_dx = next_x - to_x; > + if (before_dx > after_dx) > + move_it_in_display_line (&it, ZV, next_x, MOVE_TO_X); > + } > + > bidi_unshelve_cache (itdata, 0); > > Fset_buffer (old_current_buffer); > @@ -6788,6 +6797,15 @@ predicates which report frame's specific UI-related capabilities. */); > DEFVAR_BOOL ("cursor-in-echo-area", cursor_in_echo_area, > doc: /* Non-nil means put cursor in minibuffer, at end of any message there. */); > > + DEFVAR_BOOL ("mouse-prefer-closest-glyph", mouse_prefer_closest_glyph, > + doc: /* Non-nil means mouse position lists are reported relative > +to the glyph closest to their coordinates. > + > + When non-nil, mouse position lists will be reported with their > +`posn-point' set to the position of the glyph closest to the mouse > +pointer, instead of the glyph immediately under. */); > + mouse_prefer_closest_glyph = false; > + > DEFVAR_LISP ("glyph-table", Vglyph_table, > doc: /* Table defining how to output a glyph code to the frame. > If not nil, this is a vector indexed by glyph code to define the glyph. > diff --git a/src/xdisp.c b/src/xdisp.c > index 763af7d3bc8..1d71bb02641 100644 > --- a/src/xdisp.c > +++ b/src/xdisp.c > @@ -2723,6 +2723,7 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect) > enum window_part part; > enum glyph_row_area area; > int x, y, width, height; > + int original_gx; > > if (mouse_fine_grained_tracking) > { > @@ -2733,6 +2734,8 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect) > /* Try to determine frame pixel position and size of the glyph under > frame pixel coordinates X/Y on frame F. */ > > + original_gx = gx; > + > if (window_resize_pixelwise) > { > width = height = 1; > @@ -2948,6 +2951,15 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect) > gy += WINDOW_TOP_EDGE_Y (w); > > store_rect: > + if (mouse_prefer_closest_glyph) > + { > + int half_width = width / 2; > + width = half_width; > + > + int bisection = gx + half_width; > + if (original_gx > bisection) > + gx = bisection; > + } > STORE_NATIVE_RECT (*rect, gx, gy, width, height); > > /* Visible feedback for debugging. */ > @@ -37345,7 +37357,10 @@ may be more familiar to users. */); > DEFVAR_BOOL ("mouse-fine-grained-tracking", mouse_fine_grained_tracking, > doc: /* Non-nil for pixel-wise mouse-movement. > When nil, mouse-movement events will not be generated as long as the > -mouse stays within the extent of a single glyph (except for images). */); > +mouse stays within the extent of a single glyph (except for images). > +When nil and mouse-prefer-closest-glyph is non-nil, mouse-movement > +events will instead not be generated as long as the mouse stays within > +the extent of a single left/right half glyph (except for images). */); > mouse_fine_grained_tracking = false; > > DEFVAR_BOOL ("tab-bar--dragging-in-progress", tab_bar__dragging_in_progress, Otherwise, LGTM. Thanks.