From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#65380: [PATCH] Add command to copy contents in a diff-mode buffer Date: Sun, 18 Aug 2024 16:20:52 +0000 Message-ID: <87bk1pztsr.fsf@posteo.net> References: <87wmxrwe6h.fsf@posteo.net> <83o7j3z4wm.fsf@gnu.org> <87pm3jwboc.fsf@posteo.net> <83lee7z3xs.fsf@gnu.org> <87jztrvxx2.fsf@posteo.net> <83r0nyyhlz.fsf@gnu.org> <86o7j2qgmc.fsf@mail.linkov.net> <83cyzhwpcj.fsf@gnu.org> <87a5ultvuy.fsf@posteo.net> <83a5ulwos6.fsf@gnu.org> <87fs4bgwuj.fsf@posteo.net> <83fs4btiw1.fsf@gnu.org> <871q2n152u.fsf@posteo.net> <87frr1zw6i.fsf@posteo.net> <864j7hzviv.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17785"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65380@debbugs.gnu.org, juri@linkov.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 18 18:21:46 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 1sfif3-0004Uv-Mx for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Aug 2024 18:21:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sfiej-0005ru-Q8; Sun, 18 Aug 2024 12:21:25 -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 1sfieg-0005r8-GE for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 12:21:22 -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 1sfieg-0003vL-7S for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 12:21:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=CJCItrC9H2MQTl7WKCQLqYWfkDQnrX1GdEpEHjFJJJc=; b=WaNSxfidHQrPyFmMYNpj2+napHyActM4sRQxBHQPec6mJCEmPBFQP1fLdtJtw7I4D4PyZydqTU1ZM6u1+jqfBH74HzebcZiCpW++PHv39r3Sl1P3hC2BNrt1J9xo5ZLTmkhPapwQqGjOWzByjgsALLJ44Qp0PyBi5utteQCruYlAqocXCnj/gQuVC15zooYVyqlXgKnZCLNS7y5fWtLusvNQzfxU1F+q/G3BIQUualOPZMhZDx/W7B2M3J9KoHLiSL0GNrfb13ATGoMuXMSPaB9lZm3Frm2EPVIt5NMQP59KqmybsyygQzzVMw8HK9auA95rJqitiLqmGshnZluejw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sfifK-0002wi-CP for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 12:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Aug 2024 16:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65380 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65380-submit@debbugs.gnu.org id=B65380.172399810511302 (code B ref 65380); Sun, 18 Aug 2024 16:22:02 +0000 Original-Received: (at 65380) by debbugs.gnu.org; 18 Aug 2024 16:21:45 +0000 Original-Received: from localhost ([127.0.0.1]:56545 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfif3-0002wE-AA for submit@debbugs.gnu.org; Sun, 18 Aug 2024 12:21:45 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:42139) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfif1-0002vo-0J for 65380@debbugs.gnu.org; Sun, 18 Aug 2024 12:21:44 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 45A86240028 for <65380@debbugs.gnu.org>; Sun, 18 Aug 2024 18:20:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1723998056; bh=eKrUVzuIGvmK5awb5ZaWJ1RA88U5hWRCY7XvORUN760=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=YnBzaVsOnvtGZhE1erJrp/nKpsus5VlR29aHZHWTquAvlOMl0f59URIvJSqJ3k6P6 Ck34XjZLTNSCqlHpTloOZ8L6uDWAQoVeRC68nizkkkoNXvmWpvcOQ/or3MTcJ29lrv Aayc3+2AosW7zLuefRS7qS63G+kT8gVkG4cqtAch1yKbloMVU+AVaCP05X4roK5oXV n+j9+5JJ6cJz3GW3maeNOlGbzFOjJHhY8QBlfFyTfJJfA84Oz2vwMttB0Z335oLVma luZ/Mr34kTYI6v5lWTlvboRvZd8zUwXs7WOmIKtDEDYzeSw004sPDhtrD9ZXyIDPxN DnKHkULpyHXdg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Wn1Dk10Ctz6tvk; Sun, 18 Aug 2024 18:20:53 +0200 (CEST) In-Reply-To: <864j7hzviv.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 18 Aug 2024 18:43:36 +0300") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=philipk@posteo.net; url="https://keys.openpgp.org/vks/v1/by-email/philipk@posteo.net"; preference=signencrypt 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:290334 Archived-At: Eli Zaretskii writes: >> From: Philip Kaludercic >> Cc: juri@linkov.net, 65380@debbugs.gnu.org >> Date: Sun, 18 Aug 2024 15:29:25 +0000 >> >> > + ;; copy the text between hunks >> > + (let (start) >> > + (save-window-excursion >> > + (save-excursion >> > + (forward-line -1) >> > + (diff-goto-source) >> > + (forward-line +1) >> > + (setq start (point)))) >> >> One issue I still have here is that the `forwarad-line' might scroll the >> window, which `save-window-excursion' doesn't restore. > > I don't understand what you are saying here. As long as a Lisp > program runs and doesn't force redisplay (via sit-for or explicit > calls to 'redisplay' or somesuch), forwarad-line cannot cause any > scroll of the window, because what scrolls the window is redisplay > when it kicks in and finds that point is outside of the window. So if > the above code takes care to restore point before it finishes, the > window won't scroll. Or what am I missing? No, you were right, and I manged to locate what was causing the issue. I had a (revert-buffer t t t) at the beginning of the function. Wrapping `save-window-start' around just that expression also prevented the displayed portion of the window from changing. Thinking about the proposal again, it might seem better to avoid calling `revert-buffer' in the first place. The problem I was concerned with was that if a .diff was outdated, jumping to the original file might not do the right thing and copy the wrong inter-hunk text. Now I realise that `revert-buffer' doesn't always help resolve this either, e.g. if copying text from an old .patch file. The proper solution would be to try and detect these kinds of inconsistencies and signal and error instead. >> To fix this I have written a general macro for subr.el to restore >> the scroll position: > > Let's first make sure we understand what happens here before we add > such a macro. (It also has some conceptual problems of its own, but > let's defer that until we actually sure it is needed.) It is not needed, but I would be interested in what the conceptual errors are. -- Philip Kaludercic on peregrine