Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multi-file edits #2359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fab4100
Copy link

@fab4100 fab4100 commented Dec 2, 2024

Git send-email by default uses multi-file edit mode
(sendemail.multiEdit) when more than one patch file requires editing an
associated email message and/or cover-letters. Multi edit mode spawns
one editor instance with multiple files in argument list. This behavior
is supported by creating multiple splits for a running vim instance when
:G send-email is called. When the user sets sendemail.multiEdit to
false in the local or global config, if multiple files need editing then
they are processed sequentially in a single split at a time.

Closes #2352

Git send-email by default uses multi-file edit mode
(sendemail.multiEdit) when more than one patch file requires editing an
associated email message and/or cover-letters.  Multi edit mode spawns
one editor instance with multiple files in argument list.  This behavior
is supported by creating multiple splits for a running vim instance when
`:G send-email` is called.  When the user sets sendemail.multiEdit to
false in the local or global config, if multiple files need editing then
they are processed sequentially in a single split at a time.

Closes tpope#2352
@fab4100
Copy link
Author

fab4100 commented Feb 15, 2025

To help push progress, I am describing the changes introduced in this PR in more detail below.

  1. Multiple file arguments are read by adding a for-loop that appends the arguments to the sentinel $FUGITIVE.edit (https://github.com/fab4100/vim-fugitive/blob/28f17e54691def71d5f0bf3aa448fe5bd68b70de/autoload/fugitive.vim#L3958)
  2. Instead of reading a single file argument, a list of arguments is read (https://github.com/fab4100/vim-fugitive/blob/28f17e54691def71d5f0bf3aa448fe5bd68b70de/autoload/fugitive.vim#L3446) which are then processed in a newly added outer loop (https://github.com/fab4100/vim-fugitive/blob/28f17e54691def71d5f0bf3aa448fe5bd68b70de/autoload/fugitive.vim#L3448), each loop iteration initializes a new buffer with focus on the first file argument given upon loop exit (hence the reverse(files) iterator). Since now multiple buffers may be created, it is no longer sufficient to indicate buffer deletion by simply removing the sentinel ($FUGITIVE.edit). Instead, the number of active buffers is stored into the sentinel to keep track of the number of active buffers when multiple files are being edited (https://github.com/fab4100/vim-fugitive/blob/28f17e54691def71d5f0bf3aa448fe5bd68b70de/autoload/fugitive.vim#L3447).
  3. Whenever a buffer is deleted, the active buffer count in the sentinel is decreased https://github.com/fab4100/vim-fugitive/blob/28f17e54691def71d5f0bf3aa448fe5bd68b70de/autoload/fugitive.vim#L3735-L3736. If the active buffer count is zero, the same code is executed as is currently the case for the single file only edit (deleting the sentinel then resume session https://github.com/fab4100/vim-fugitive/blob/28f17e54691def71d5f0bf3aa448fe5bd68b70de/autoload/fugitive.vim#L3739-L3740). If one or more buffers are active, the sentinel is updated and the session is resumed without deleting the sentinel (https://github.com/fab4100/vim-fugitive/blob/28f17e54691def71d5f0bf3aa448fe5bd68b70de/autoload/fugitive.vim#L3742-L3743).
  4. The active buffer count is appended to the resume queue whose arguments are passed down s:RunWait which checks for the newly appended active buffer count argument (see previous item). If there are 1 or more active buffers, s:RunWait returns to caller without taking any action (continuing editing session of active buffers). If the active buffer count is zero the same code is executed as is currently done for the single file only implementation (which concludes the $FUGITIVE.edit session).

Please let me know if I can implement some changes you may desire. Thanks for taking the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edit multiple files / load multiple files into buffer list for :Git <command>'s
1 participant