From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: Adding refactoring capabilities to Emacs Date: Thu, 7 Sep 2023 23:41:08 +0300 Message-ID: <0af2ae2e-3486-e67b-7caa-6ff21f9a41dc@gutov.dev> References: <83fs4f36wi.fsf@gnu.org> 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="11045"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: Eli Zaretskii , "Philip K." , emacs-devel@gnu.org To: Stefan Monnier , =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 07 22:42:41 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 1qeLpn-0002e2-3L for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Sep 2023 22:42:40 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeLoW-0005f3-G4; Thu, 07 Sep 2023 16:41:20 -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 1qeLoU-0005ek-E6 for emacs-devel@gnu.org; Thu, 07 Sep 2023 16:41:18 -0400 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeLoR-0003rM-Ml; Thu, 07 Sep 2023 16:41:18 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B2DB73200F1D; Thu, 7 Sep 2023 16:41:12 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 07 Sep 2023 16:41:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1694119272; x=1694205672; bh=lsDOxARTA4kG17hjGLpkQsj2DcqArKA1/kR 0Acv0KHo=; b=h829PW1wgVxhohDRIG2q4WoJh4g6sS/9BOrqIV9pLArTpTlxdeR HCclGJdEDq2cDijTQdhEr4nqMZcxjeYiHwOXq/Is2xn0NRrmBc3WtnsMiGHcAIjd +Y/ScbkryJ4QfjVmPZDRegNAeQ+Z4Ojhok8w2ssZFc5+Nb5WIS9zfWZzmMFSufLx G8a5NtMDxkO8BBkEduAE4l/ADvKel+D8LNhWWjpEPKFbFb4vStvzciu5rqcIUoyn p5alPTD6YQfdQZNc1+o4FG56geeywmQkrNoM6iuEPuyyJhRAOZmODwZEWz4X2wS+ tVWGqDdO+uvP7rAFOLPjhaq+Otzb1ZIrylQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1694119272; x=1694205672; bh=lsDOxARTA4kG17hjGLpkQsj2DcqArKA1/kR 0Acv0KHo=; b=JLJjdQexAbBjRG3Wntl4sCsciiMdX67by7xGGfcfKQ5WLs1qLwh 5Y8YXRUpbM/5B1S4g6+4CQwBdHW1Hfmdnn+oRl0oLCtLD37JS+rrzgR6k6xfKWSs dnygsWg0D9rEhZI7IQzk4FFIC4hiiNSH4lCg+6ltk1g4MWDPS8t2bZa6gewN5+pO 4yhESgjnfFtZaSFNGnqCtjVfeSDzamAGnw5F5WPdNdHRiYxnwNWE2ELYSPcZ5Pdv tOULc93Lu2+datn1PprNVFkF6m8Z2vXyIKkPO4rSZ7ovtpZy6ismVEreGpy/7+Aq cA9lQnA4q+uYaK7EcI8QtKWw+l79WA967Ng== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudehhedgudehfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttdefjeenucfhrhhomhepffhm ihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvghvqeenucggtffrrg htthgvrhhnpeeigfetveehveevffehledtueekieeikeeufeegudfgfeeghfdulefgfeev ledvveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gumhhithhrhiesghhuthhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 7 Sep 2023 16:41:10 -0400 (EDT) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=64.147.123.20; envelope-from=dmitry@gutov.dev; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 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, NICE_REPLY_A=-1.473, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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:310283 Archived-At: On 07/09/2023 19:20, Stefan Monnier wrote: >> Also, it would be very good if we could have an early backend which is >> *not* LSP. An obvious candidate is Elisp. I'd like to know what is >> the minimal effort to write a lisp function based on the new >> macroexpanding tricks that Stefan Monnier developed that says >> precisely where a given symbol is used as a variable in a function. >> As far as I understand, these techniques are currently being used for >> accurate completion, but they could maybe be used for accurate >> refactorings. > > Hmm... the `elisp--local-variables` functionality (beside the > associated security issues and occasional errors) provides only > a (somewhat) reliable list of variables that are in-scope. So it could > potentially be extended to offer a way to jump to the declaration of > a local variable from a reference to it, but it doesn't know how to find > all (and only) the references to a given variable. > > We could extend it to a full code-walker that can distinguish between > identifiers that refer to functions vs variables and which skips "data" > and obeys scope, and thus collect reliably all the references. > But `cconv-analyze-form` is probably a better starting point :-) I think the Helpful packages used some of the approach. Though I'm not sure how precise/thorough it is, and combining the outputs of xref-find-references and elisp--local-variables is likely to be faster. As a first/initial implementation anyway. If we're only talking about 'rename', at least. >>> but that's already taken in diff-mode. > > I don't think the current `C-c C-c` binding in `diff-mode` should get in > the way. That command is available via different bindings already, and diff-apply-everything is a little destructive, though (there is no 'undo' across multiple files), so maybe a warning could help. Or make it an initially-disabled command, for example. > this is a specific use of diff-mode where `diff-apply-everything` makes > a lot of sense (as opposed to `C-x v =` where the changes are usually > already applied anyway so `diff-apply-everything` is rarely what we want). So... the binding wouldn't be used in "regular" Diff buffers, it it just would stop with a "hunk already applied" message? If it's the former, we'd need to distinguish the "refactoring diff" buffers by look somehow. >>> - 'git diff' has a less-frequently used option called '--word-diff' >>> which could reduce the length of the diff in the case I am testing (but >>> I guess diff-mode would have to be updated to support that output). And >>> another way in that direction would be to reduce the size of the diff >>> context (e.g. to 0). > > [ Side note: we could also extend diff-mode to do such "rewrite" inside > Emacs. Hiding some of the context should be fairly easy, for example. > Also I've often wished for `diff-refine-hunk` to try and interlace > the lines so as to minimize the distance between the "before" and > "after" lines. ] Interesting.