From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Platon Pronko Newsgroups: gmane.emacs.help Subject: Re: Moving point around empty overlays with 'after-text Date: Mon, 10 Apr 2023 11:31:53 +0800 Message-ID: <934164d0-555e-f018-adc5-0c072d79df91@gmail.com> References: <9b1654ec-1ac6-4936-860b-2d77dcc4dac7@app.fastmail.com> <28954f0d-205d-b322-4a43-cf4481d1266e@gmail.com> <3a1bb709-d00f-49b8-a2c5-d0ac5b6a82c4@app.fastmail.com> <22b315db-39eb-80b6-1a7c-127f5e703dc1@gmail.com> <2314d321-040a-4466-afdb-4317df7e6584@app.fastmail.com> <01206f38-741a-b75b-4efe-ecf7c70c6d61@gmail.com> <66d58398-8eb5-4d89-8e7c-4400f180448f@app.fastmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13855"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 To: Ash , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 10 05:32:43 2023 Return-path: Envelope-to: geh-help-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 1pliGp-0003UB-Ii for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 10 Apr 2023 05:32:43 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pliGB-0002jd-Nb; Sun, 09 Apr 2023 23:32:03 -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 1pliGA-0002jO-BP for help-gnu-emacs@gnu.org; Sun, 09 Apr 2023 23:32:02 -0400 Original-Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pliG7-0004yM-Mr for help-gnu-emacs@gnu.org; Sun, 09 Apr 2023 23:32:02 -0400 Original-Received: by mail-pj1-x102d.google.com with SMTP id j8so1432442pjy.4 for ; Sun, 09 Apr 2023 20:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681097518; x=1683689518; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=6Cw8bBFRQjbkiPq0mdHN34sFqLcWzJohTzTmiIYXqQI=; b=c69MtVeFlxbfbc1G28Kx+/4w8VbjtLJ5oKkUSWsYzMwnUkC+/64ugRHOLoTOzd/yMk cddFbnXmL3kJJZdlauHqhJb4+/Msjojtb7pGO3eKBWKATKxNCtXVWxbg3OJIhjUIOWB0 1Q+HN52pgMhdpuXa6Xttz1W8htaYHYlNQmhsvaOkysIMcBjh5ErteAiez6SYDgETSOLn pcYb+yFEQz2v3x2f4d6GBx6BnSyhLP2uuAilmRWs5sDXqZnlGVhxK5IE8eArcICZv1Mo mk9udB6XrSkrCP4MhAPDt1rJifXWR9kugD7DToMy+Kc3/VmyMDrJhTtgI8mPbdjai1c+ sujA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681097518; x=1683689518; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6Cw8bBFRQjbkiPq0mdHN34sFqLcWzJohTzTmiIYXqQI=; b=0eFqBT2JTIH+B1u3dRI9FJYXZR02WLg5E5O5YaIMuj70aKaePHJuIAlj1qGDoXUeLD EgoPPF9XRIxTnosXroRo93lR06faO5qdVpQ82/xFrYMPU7ps7mnkqZ7dWKdzbpS139cE hh+M6x5YrX+mG67jRBEO9lnOofHQFtag8tKmIeAy+w7DA23qNsT9GdP4PzZwZFAAkvuf A2n2fJEYgTYFuiJCAo4ljl+3ErUGAdd9T7TE+aZ5RbLU9YxNK9hqMZOGk+8N12X1eR9x 4vM76pBw3ogrYp5BBeOa66wfgJ9+GF/89mo4cYHm9ZW8rYsf8DaTvToPxn4j/1J4JsgK 0qVQ== X-Gm-Message-State: AAQBX9e+HyxxL0dnRojbw0YHjbgUp5HxMMDNC/k5W56X5egUlJnau7ix EETP4M86beI+ZYmxY14geBIzg+5v6Ki8Xw== X-Google-Smtp-Source: AKy350Y1KFn05xBvY62hvWyau8bMIzgO1RudNV0QaefR79kWCd9Ph/HgihIVUblKx7rOKNtl2zW1LQ== X-Received: by 2002:a05:6a20:e0a:b0:db:1119:bb48 with SMTP id ej10-20020a056a200e0a00b000db1119bb48mr7743542pzb.59.1681097517922; Sun, 09 Apr 2023 20:31:57 -0700 (PDT) Original-Received: from [192.170.1.133] ([103.24.106.35]) by smtp.gmail.com with ESMTPSA id d2-20020aa78e42000000b00627f054a3cdsm3015020pfr.31.2023.04.09.20.31.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Apr 2023 20:31:57 -0700 (PDT) Content-Language: en-US In-Reply-To: <66d58398-8eb5-4d89-8e7c-4400f180448f@app.fastmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=platon7pronko@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 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, NICE_REPLY_A=-2.888, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143239 Archived-At: On 2023-04-10 11:21, Ash wrote: > > > On Sun, Apr 9, 2023, at 7:00 PM, Platon Pronko wrote: >> On 2023-04-10 04:44, Ash wrote: >>> Yeah, I think doing this "right" might require adding a new property to overlays/strings (or giving an existing property a new value) to enable this behavior and modifying C code. Not sure how viable that is or if it's something the devs would want. >> >> I think it's even worse than adding a property to the overlay. You need common point manipulation functions to account for possibility of inlays, i.e. (point) for position before and after inlay will be returning different values, (forward-char) will correctly advance the point from the left side to the right side of the inlay, etc. >> >> (on second thought, making (point) return different values for positions around overlays sounds horrifying, because this will break about half of all Elisp code written) >> >> But inlay hints seem to be a common functionality for any modern IDE nowdays, so it might make sense to support them natively, without making major-mode developers resort to horrible hacks like described before. >> >> -- >> Best regards, >> Platon Pronko >> PGP 2A62D77A7A2CB94E >> > > You could make it so only these special overlays (I'm going to call them inlay-type overlays or just inlays) have weird behavior with (point), but that'd still make things very complicated and I wouldn't do it. A sketch for what I would do is something like this: > > When point is on a position with an inlay, the new variable point-is-after-inlay (name subject to bikeshedding) controls where point renders (before if nil, after if t). When inserting text, the inlay moves forward if point-is-after-inlay is nil, and doesn't move if it's t; this means characters appear where you'd expect. > > We add a new (forward-char-respecting-inlay) function that sets point-is-after-inlay to t if point is at the start of an inlay *and* point-is-after-inlay is nil, or increments point if not (and the same for backwards). Possibly add an 'always-respect-inlay' mode that makes forward-char act like this, with the caveat that things might break in strange ways. > > Each inlay has a 'bias' of 'before or 'after that indicates what point-is-before-inlay should be set to when navigating to it 'from afar' or other cases where there's no good heuristic for where to put it; in general, this should correspond to where the text is the inlay is semantically annotating. > > There's probably all kinds of edge cases I haven't thought about, of course. Conversely, an even more general approach that would support multiple inlays in a row would be to have point-is-after-inlay be an *index* (and rename it 'point-inlay-index' or some such). Not sure what a concrete use case for that would be. I like this approach. Seems to be mostly backward-compatible. -- Best regards, Platon Pronko PGP 2A62D77A7A2CB94E