reddit / emacs

Is there any way to view each file's changes in a new window in Magit?

Joey_Green · 2022-04-15 00:29
As we all know, we can view file changes in Magit directly: [Magit changes](https://preview.redd.it/s4i15f4z4lt81.png?width=1568&format=png&auto=webp&s=95ee5773aedf229bbdb8d56df2928839a7e3267e) The problem is, all the changes are displayed in a single Emacs window, sometimes I'm not sure which change belongs to which file. I know that I can go up to get the file name, but I feel it's a little inconvenient. I'm more accustomed to the UI that other text editors / IDEs are using, in which files are displayed on the left, and changes are displayed on the right. ​ [VSCode's git changes](https://preview.redd.it/1a7t08u06lt81.png?width=2560&format=png&auto=webp&s=a2892d11234e4ac1893c18581724aa68bd411245) The point is, I want to make sure that an Emacs window only shows changes in one file. When I go to the end of the window, I arrive at the end of the changes in the **current** file, instead of continually checking the next file's changes. Can I do it in Magit?
lebensterben · 2022-04-15 00:48
I don't know the answer. but why not just to use ediff of vc-diff?
Joey_Green · 2022-04-15 01:40
Because I usually use Magit in a flow: 1. Check changes 2. Commit 3. Push to remote Using `ediff` or `vc-diff` means I have to break the flow and manually find out which file is changed, which part is changes, etc. Magit can find it out for me.
ilemming · 2022-04-15 01:46
- You can see a diff for the current buffer's file by running `magit-diff-buffer-file`. The usual way to get there is through `magit-file-dispatch` transient, it should be bound to `C-c M-g`. You basically press `C-c M-g d` and see the diff for the current file. - That's one thing, but it looks like you're having trouble navigating `magit-status-mode` buffer. And it's based on [magit-section](https://github.com/magit/magit/blob/master/lisp/magit-section.el) package. It allows you to jump between the sections, as well as collapsing and expanding sections very nicely. I suggest to find the commands like `magit-section-show-level-1`, `magit-section-show-level-2`, `magit-section-forward-sibling`, etc. You can find more in the manual https://magit.vc/manual/magit/Sections.html Learning magit-section commands is useful not only for magit, some other popular packages also use it - [Org-roam](https://www.orgroam.com/) and [Code-Review](https://github.com/wandersoncferreira/code-review) are good examples. - Finally, it seems that the theme you're using, doesn't include different faces to distinguish boundaries between the sections; you may want to try a different theme, or maybe customize the faces: `magit-section-heading`, `magit-section-highlight`, `magit-section-heading-selection`, `magit-section-secondary-heading`. The easiest way of playing around changing face attributes would be like this: `(set-face-attribute 'magit-section-heading nil :foreground "Red" :background "#2e323c")` - I recommend (at least) skimming through the [manual](https://magit.vc/manual/magit.html). Magit is a powerful tool, but it doesn't easily reveal its gems, sometimes you even need to look for them in the source.
bram85 · 2022-04-15 06:18
I think you can approach this functionality with imenu-list. Run the command when in a magit status buffer to get a side-window with all magit sections and files. https://github.com/bmag/imenu-list
dzecniv · 2022-04-15 09:24
my 2c to cope with the current UI: - toggle the visibility of all files in the magit buffer, open/close them like org headlines: use shift-tab (or 1 or 2 maybe) - you can reach a state where all files diff are closed, you only see a list of changed files. - on the file name, you can deploy it (tab, choose visibility with 1 or 2 or 3, you can even toggle each chunk) - that way, you do the review (n for next, p for previous chuck), and you won't see the diff of the next file because it's closed, not expanded.
marlgl · 2022-04-15 13:19
I am not sure about why you don't want to just fold the sections. Anyway, to answer the question, there is a way to view each file changes in a separate window: you can use the *limit-to-file* argument with "--", in `magit-diff`. So, the sequence of keys would be "`d --` (select the file you want) `RET d`" with the default keybindings. Alternatively, if that is too intricate, you might want to define a function and bind that to some key. Something like this (rename it to what you want): (defun bingo () (interactive) (let ((file (expand-file-name (magit-file-at-point)))) (magit-diff-dwim nil `(,file))))
jkdufair · 2022-04-15 14:07
Often I like a bit more context when I'm reviewing a diff. So I'll launch `ediff` from `magit-diff`. With the default keybindings, it's `e` in this mode. Then when you exit `ediff` you're right back where you were in `magit-diff`
jkdufair · 2022-04-15 14:22
I also use `ctrl-return` to navigate to the file in the worktree so I can, i.e. navigate around the codebase via `xref`, see flycheck warnings, etc. I can also use `git-gutter` to navigate between hunks there too if I am viewing a diff prior to committing changes.