emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding refactoring capabilities to Emacs


From: Stefan Monnier
Subject: Re: Adding refactoring capabilities to Emacs
Date: Thu, 07 Sep 2023 12:20:10 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

> 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 :-)

Going back from there to the actual source code can be a fair bit more
tricky, but Alan's symbols-with-positions should provide just what we need.

> IMO diff is the lingua franca for communicating changes to source
> code around the world, even in those pretty web interfaces that
> you and many others like.  So it makes full sense to support it
> and to support it well.

+1, tho I think the general framework should be agnostic to the specific
way a change is presented to the user.

>> - I would probably want to bind the originally proposed
>> 'diff-apply-everything' to 'C-c C-c' (e.g. "commit the change to disk"),

Agreed.

>> 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
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).

>> - '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.  ]

> But I wouldn't overthink UI details at this point in the game either.

+1


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]