From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Moving point after character when clicking latter half of it Date: Wed, 12 Jul 2023 14:17:41 -0700 Message-ID: <76D3E9B6-C3BE-4E41-B228-AA252AAD4A11@gmail.com> References: <2255158.iZASKD2KPV@silef> <21946289.EfDdHjke4D@anduin> <87mt02ar4e.fsf@yahoo.com> <3242369.aeNJFYEL58@anduin> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_B09E0940-94B1-498A-883E-9988786692E0" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17304"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , Eli Zaretskii , emacs-devel@gnu.org To: Moritz Maxeiner Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 12 23:18:59 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 1qJhEf-0004I7-JN for ged-emacs-devel@m.gmane-mx.org; Wed, 12 Jul 2023 23:18:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJhDh-0002Jd-RG; Wed, 12 Jul 2023 17:17:57 -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 1qJhDg-0002IZ-Qh for emacs-devel@gnu.org; Wed, 12 Jul 2023 17:17:56 -0400 Original-Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJhDe-0005jl-VU; Wed, 12 Jul 2023 17:17:56 -0400 Original-Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-553b2979fceso58434a12.3; Wed, 12 Jul 2023 14:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689196673; x=1691788673; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=U353Rb1QwWJRaTAQ9+wAD8WNljgJKm8+wZmU7D/X6RI=; b=on9tCETRoSOI3K/w/BkV9xd5KFGiYUM+tvUVVoK58Au0wWV6m8L6C45DmKMSF5nhl1 gADDIi+uPVsFh0SmYE1QIHtaW9b/J8pJC2x4He4Nm9JGhRvGIAks6Cr5LIFVDFLEcg4Z msdfgwi6VE2Gpe9UM1R7Q66LYuSMtY2+vdUkA/Wv159y3zm/w0TsfGZMWSuQuOXUxsDo 9u8HLpIIxWeHUsOcUkWhgY3g8g2Jt/TdfVAgRgmkZ+cnmoyMO/wX5xk10gHUtyCLbJ31 1Oa7+mbQ8LNzHcryozL6418JoS2ODofBF2F6MJ1M/Si/cLT8CInhGVXTgt3pQxfif2/m 4I2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689196673; x=1691788673; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U353Rb1QwWJRaTAQ9+wAD8WNljgJKm8+wZmU7D/X6RI=; b=dmJmxLobC7Ip6lwnKZggBc7pLnZ2LbPInfgrq9v6SL/Ge9fTlnXtAm96xU6E7F8y5c /dsaqO7NG5C7ovNSWSVFFB+/4p+NGEXE/gMhpjE9WcZRVDQwHAmFrYWpeFAXDWrRnjxk Cy6wXE7E/+WEKRaZuoYJFgfQJ3QKKB6QMLQJsmkN3khsND0efF0TlwKbAeXW+ZMfJbKI N4fYPAIfqiojmUXGnaepjUdgSbCCqehpU8r1exQW/4zJwsvBdeRpQbEUOqGvGkJ0EEhw oTnv2H6EEj053b8mjrJU/wX1mpk9tGu9ByhoiaCfQ6efMTcIqLnyzIGf84wnODlcXOQj CfJw== X-Gm-Message-State: ABy/qLbtSczL71dHd2mWkCiBnN+KQeJND+33YH3dxBATTQnKKkr4JgqX PB2bf+G8JarW69JR3UmCSdk= X-Google-Smtp-Source: APBJJlHXOUhoP+U8PYIf4UaKDoSL932q08W6nkDO63s+KvGzKvkrqbXD4fK7NLEnZQKAPr4XWxysgw== X-Received: by 2002:a17:902:db06:b0:1b5:25bd:df2b with SMTP id m6-20020a170902db0600b001b525bddf2bmr19620017plx.14.1689196673153; Wed, 12 Jul 2023 14:17:53 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id bd5-20020a170902830500b001b8761c739csm4354812plb.271.2023.07.12.14.17.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2023 14:17:52 -0700 (PDT) In-Reply-To: <3242369.aeNJFYEL58@anduin> X-Mailer: Apple Mail (2.3731.600.7) Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=casouri@gmail.com; helo=mail-pg1-x535.google.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, 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:307797 Archived-At: --Apple-Mail=_B09E0940-94B1-498A-883E-9988786692E0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Jul 12, 2023, at 12:58 PM, Moritz Maxeiner wrote: >=20 > On Wednesday 12 July 2023 02:52:01 CEST Po Lu wrote: >> Moritz Maxeiner writes: >>> I'm not clear on why that would make it wrong (as in incorrect = semantics). >>> It's definitely inefficient (though I've not noticed the overhead in >>> practice), which is why I asked if there's a more elegant solution. >>=20 >> The overhead is apparent when options such as >> `mouse-drag-and-drop-region' are enabled and the connection to the X >> server is slow. >>=20 >>> Which this is, thank you very much for pointing that out. I've = changed >>> that >>> part of the patch accordingly, though this does unfortunately mean = that a >>> new function is required, due to multiple places setting the glyph >>> rectangle as it relates to dragging. >>=20 >> I find that difficult to believe. Would you please describe the = other >> callers of `remember_mouse_glyph' that make adjustments there >> impossible? >>=20 >> I asked you to make the change in `remember_mouse_glyph' because that >> would avoid the need to modify each of the *term.[cm] files >> individually. Replacing it with a different function would miss the >> point of the change. >=20 > My apologies, after rereading your previous message I realize I = misunderstood.=20 > I thought I was to put the changes after the remember_mouse_glyph call = (like I=20 > was previously asked to do for move_it_in_display_line instead of = modifying=20 > another xdisp.c function, move_it_in_display_line_to). My comment = derived from=20 > that misunderstanding as there are multiple calls to = remember_mouse_glyph that=20 > need to be affected. >=20 > I have adjusted the patch as requested (I think), added some = documentation in=20 > commands.texi, as well as a NEWS entry. I'm not sure about correct = placement /=20 > formatting of the latter two. >=20 > Btw. I'm not particularly happy about needed to add the `original_gx'=20= > variable, but since the function seems to overwrite its argument, = which I need=20 > access to at its end (once the full glyph has been determined), I = don't see=20 > another option. I'm also not super happy about the needed division, = but I also=20 > don't see a way around that. If you know a more elegant solution I'd = be happy=20 > to hear it. >=20 >>=20 >>> Assuming this version of the implementation meets muster I will work >>> on the etc/NEWS entry and can look into adding something to >>> (elisp)Accessing Mouse, as well. >>=20 >> Several other comments below: >>> +/* Function to bisect `glyph` into left and right halves, then >>> + replace it with the half in which `x` is. */ >>> + >>> +static void >>> +x_vertical_bisect_glyph(XRectangle *glyph, int x) >>> +{ >>> + int halfwidth =3D glyph->width / 2; >>> + glyph->width =3D halfwidth; >>> + >>> + int bisection =3D glyph->x + halfwidth; >>> + if (x > bisection) >>> + glyph->x =3D bisection; >>> +} >>=20 >> Please follow the GNU coding standards for both function declarators = and >> comments, by capitalizing (not quoting) arguments which appear in the >> commentary, and placing a space between the identifier name and the >> opening parentheses of the parameter type list. Also, use the active >> voice when describing the behavior of a function within its = commentary: >>=20 >> /* Replace *GLYPH, a rectangle containing the bounds of a glyph, with >> the half of the rectangle containing the position X. */ >>=20 >> static void >> x_vertical_bisect_glyph (XRectangle *glyph, int x) >> { >> /* ... */ >> } >>=20 >> In addition, we don't use Markdown style quotes for code. When = quoting >> identifier names in the future, either write: >>=20 >> /* `foo' is used to perform ... */ >>=20 >> or >>=20 >> /* 'foo' is used to perform ... */ >>=20 >>> /* Function to report a mouse movement to the mainstream Emacs code. >>>=20 >>> The input handler calls this. >>>=20 >>> @@ -14218,6 +14232,8 @@ x_note_mouse_movement (struct frame *frame, = const >>> XMotionEvent *event,>=20 >>> note_mouse_highlight (frame, event->x, event->y); >>> /* Remember which glyph we're now on. */ >>> remember_mouse_glyph (frame, event->x, event->y, r); >>>=20 >>> + if (mouse_prefer_closest_glyph) >>> + x_vertical_bisect_glyph(r, event->x); >>>=20 >>> dpyinfo->last_mouse_glyph_frame =3D frame; >>> return true; >>>=20 >>> } >>>=20 >>> @@ -14382,6 +14398,8 @@ x_fast_mouse_position (struct frame **fp, = int >>> insist, Lisp_Object *bar_window,>=20 >>> remember_mouse_glyph (f1, win_x, win_y, >>> =20 >>> &dpyinfo->last_mouse_glyph); >>> =20 >>> dpyinfo->last_mouse_glyph_frame =3D f1; >>>=20 >>> + if (mouse_prefer_closest_glyph) >>> + x_vertical_bisect_glyph(&dpyinfo->last_mouse_glyph, win_x); >>>=20 >>> *bar_window =3D Qnil; >>> *part =3D scroll_bar_nowhere; >>>=20 >>> @@ -14733,6 +14751,8 @@ XTmouse_position (struct frame **fp, int = insist, >>> Lisp_Object *bar_window,>=20 >>> dpyinfo =3D FRAME_DISPLAY_INFO (f1); >>> remember_mouse_glyph (f1, win_x, win_y, &dpyinfo- >> last_mouse_glyph); >>> dpyinfo->last_mouse_glyph_frame =3D f1; >>>=20 >>> + if (mouse_prefer_closest_glyph) >>> + x_vertical_bisect_glyph(&dpyinfo->last_mouse_glyph, win_x); >>=20 >> Please place a space between the identifier name and the opening = brace >> of each function call. >>=20 >> However, implementing this feature shouldn't need changes to xterm.c = at >> all. Please make the change in `remember_mouse_glyph', not in window >> system specific code. >=20 > Since that function (and calls to it) are now merged into=20 > `remember_mouse_glyph', I think these are solved by default. I'll take = more=20 > care next time, though, thank you for the = correction. Sorry for joining late into the discussion. But I wonder if a Elisp = solution would suffice? Someone had requested this feature to me in the = past and this is my solution at the time. Yuan --Apple-Mail=_B09E0940-94B1-498A-883E-9988786692E0 Content-Disposition: attachment; filename=delicate-click.el Content-Type: application/octet-stream; x-unix-mode=0644; name="delicate-click.el" Content-Transfer-Encoding: quoted-printable ;;;=20delicate-click.el=20---=20Delicate=20click=20position=20=20=20=20=20= =20-*-=20lexical-binding:=20t;=20-*-=0A=0A;;=20Author:=20Yuan=20Fu=20= =0A=0A;;;=20This=20file=20is=20NOT=20part=20of=20GNU=20= Emacs=0A=0A;;;=20Commentary:=0A;;=0A;;=20If=20you=20set=20= =E2=80=98cursor-type=E2=80=99=20to=20bar=20and=20clicks=20on=20the=20= right=20side=20of=20a=0A;;=20character,=20you=20would=20expect=20the=20= point=20to=20be=20set=20after=20that=0A;;=20character.=20Normally=20= that=E2=80=99s=20not=20the=20case,=20this=20package=20provides=0A;;=20= =E2=80=98delicate-click-mode=E2=80=99=20that=20makes=20Emacs=20to=20do=20= the=20right=20thing.=0A;;=0A;;=20To=20use:=0A;;=20=20=20=20=20M-x=20= delicate-click-mode=20RET=0A=0A;;;=20Code:=0A;;=0A=0A(defun=20= adjust-point-after-click=20(event=20&optional=20_)=0A=20=20"Adjust=20= point.=0AAdjust=20point=20depending=20on=20which=20portion=20of=20the=20= character=20the=0Acursor=20clicked=20on,=20if=20on=20the=20right=20half,=20= move=20point=20after.=0AEVENT=20is=20the=20mouse=20event."=0A=20=20(let*=20= ((posn=20(event-end=20event))=0A=20=20=20=20=20=20=20=20=20(x=20(car=20= (posn-object-x-y=20posn)))=0A=20=20=20=20=20=20=20=20=20(w=20(car=20= (posn-object-width-height=20posn))))=0A=20=20=20=20;;=20= =E2=80=98mouse-set-point=E2=80=99=20is=20called=20twice=20when=20you=20= click=20mouse,=20first=0A=20=20=20=20;;=20in=20=E2=80=98down-mouse-1=E2=80= =99,=20called=20by=20=E2=80=98mouse-drag-region=E2=80=99=20->=0A=20=20=20= =20;;=20=E2=80=98mouse-drag-track=E2=80=99=20to=20set=20point,=20second=20= in=20=E2=80=98mouse-1=E2=80=99,=20when=0A=20=20=20=20;;=20mouse=20= released=20and=20Emacs=20realized=20that=20this=20is=20a=20click=20= event.=0A=20=20=20=20;;=20We=20want=20to=20adjust=20point=20in=20both=20= cases.=0A=20=20=20=20(when=20(and=20(null=20(posn-object=20posn))=0A=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(>=20x=20(/=20w=202))=0A=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(not=20(eq=20(char-after)=20?\n)))=0A=20= =20=20=20=20=20(forward-char))))=0A=0A(define-minor-mode=20= delicate-click-mode=0A=20=20"Accurate=20point=20position=20on=20click.=0A= That=20is,=20if=20you=20click=20on=20the=20right=20half=20of=20a=20= character,=20the=20point=0Ais=20set=20to=20after=20it."=0A=20=20:global=20= t=0A=20=20:lighter=20""=0A=20=20(if=20delicate-click-mode=0A=20=20=20=20=20= =20(advice-add=20'mouse-set-point=20:after=20#'adjust-point-after-click)=0A= =20=20=20=20(advice-remove=20'mouse-set-point=20= #'adjust-point-after-click)))=0A=0A(provide=20'delicate-click)=0A=0A;;;=20= delicate-click.el=20ends=20here=0A= --Apple-Mail=_B09E0940-94B1-498A-883E-9988786692E0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_B09E0940-94B1-498A-883E-9988786692E0--