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: Rudolf Schlatte
Subject: Re: Adding refactoring capabilities to Emacs
Date: Mon, 04 Sep 2023 14:18:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

João Távora <joaotavora@gmail.com> writes:

> On Mon, Sep 4, 2023 at 11:48 AM Rudolf Schlatte <rudi@constantly.at> wrote:
>>
>> Stefan Kangas <stefankangas@gmail.com> writes:
>>
>> > Dmitry Gutov <dmitry@gutov.dev> writes:
>> >
>> >> I previously posted a link to a screenshot from VS Code, here it is
>> >> again:
>> >> https://bobbyhadz.com/images/blog/rename-variable-vscode/refactor-preview.webp
>> >
>> > So fundamentally, it is a one-line diff along the lines of "git diff
>> > --word-diff", plus some folding, and check-boxes to select which diff
>> > chunks to apply.  Or is there more to it?
>>
>> This sounds very similar to magit's staging interface to me, which is a
>> nice emacs-y way to pick and choose from changes files or individual
>> changes within files.
>
> Can you show a screenshot of that interface or give a recipe
> to try it out?  Is it very different from regular "diff-mode"?

Sure--it's easy to try if you have a git repository checked out locally
that contains uncommitted changes.  Here's how to navigate that part of
magit:

- Open the repository in magit (`M-x magit-status`)

- Depending on the local state of the repository, you will see multiple
  sections in the resulting buffer ("Untracked files", "Stashes",
  "Recent commits", etc.)  The section we are interested in is called
  "Unstaged Changes".

- You can use Tab to fold and unfold any of magit's sections, like in
  outline-mode.  Also, M-1 .. M-4 fold or unfold all sections in the
  magit buffer to the specified level, and the keys 1 .. 4 fold/unfold
  the current subtree to the specified level; it's easier to try this
  out than to explain it succinctly :-)

- In "Unstaged chages", you will see the list of files that contain
  changes.  (Note that this list does not contain files whose buffers
  contain unsaved changes, only on-disk state; a refactoring UI might
  want to include modified unsaved buffers here.)

- You can use `magit-stage` (bound to "s") to stage ("accept") all
  changes in the file that point is on.  The file will vanish from
  "Unstaged changes" and appear in a section "Staged changes".  It can
  be moved back via `magit-unstage` (bound to "u") with point on the
  staged file.

- You can also use `magit-stage` with point on the "Unstaged changes"
  section header to stage all changes in one go.

- You can use TAB (`magit-section-toggle`) to unfold the file (or use
  the "4" key); this gives you a diff view with all unstaged changes.
  Move point to a hunk and use "s" to stage that individual hunk.  You
  can observe the file will now appear both in the "Unstaged changes"
  and "Staged changes" sections, with the entries showing the staged vs
  committed / unstaged vs staged diffs, respectively.  You can unstage
  one hunk of a diff by expanding a file in the "Staged changes" section
  and pressing "u" with point in the hunk.

- In the diff view, you can mark part of the diff and stage only that
  part (pressing "s" when the region is active stages only the region).
  The same goes for unstaging part of a diff.

  ... this last feature is where people who do not use Emacs become very
  motivated to install and learn it, since this detailed control over
  what source changes get committed is seemingly not available in other
  tools.  I believe a similar level of control would be beneficial for
  source changes proposed by a refactoring tool, which is why I brought
  up magit.

I hope that helped a bit; I'll be happy to explain more of course.




reply via email to

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