emacs-conflict
emacs-conflict copied to clipboard
Implement renaming to/from conflict.
Intro
I had made my own repo for fixing syncthing conflicts with ediff. I like your approach much better, but there is one bit of functionality I wanted to carry over, that being converting the current buffer to a conflict.
Explanation
To explain why I need this, let me describe a use-case I have. I use Orgzly for managing my org files on my phone with Syncthing to move my org files back and forth. Orgzly keeps an internal database for its org state which it syncs to the files on the phone every so often. When it detects that a change has been made in between its database syncs, it gives a warning. The best way I've found to resolve this is to change the name of the associated file on my desktop, allow Syncthing to push that change to my phone, and Orgzly will now think that a new org file has been made and no longer thinks it is out of sync since the old file looks like it was deleted, and creates a new org file of the same name as the original. Finally syncthing will push the new file from my phone to my computer where I can diff it with the renamed version.
From looking around the web, this Orgzly, Syncthing, Emacs setup is pretty common and Orgzly's sync conflicts are annoying to others as well, so maybe this will be helpful to others.
Changes
The following changes have been made to allow for this:
- The main new user-exposed function is
emacs-conflict-rename-current-buffer-file-to-sync-conflictwhich renames the current file to a conflict of the seleced type (syncthing, nextcloud, etc). The type can be selected viacompleting-reador with a default provided byemacs-conflict-default-conflict-type. - A function analogous to
emacs-conflict--get-normal-filenamecalledemacs-conflict--get-conflict-filenamewhich converts a filename to a sync-conflict of the provided type. - A test for
emacs-conflict--get-conflict-filename. It fails for now for the "pacman" and "next cloud" cases since I have only provided conversion rules for "syncthing". - A breaking change for the config variable
emacs-conflict-find-regexes. The conversion rules have been added here since it already was delimited by sync type. For the conversion, there is a regexp to find where in the filename the conflict identifying text should go and a function for how to but it there. I've converted it to an alist of alists since there are so many things in this list. There are two other implementations we could do if you don't like that this is a breaking change.- Have the values of
emacs-conflict-find-regexesbe a list of length 4. This would be less clear but keeps it all together. - Split it into a new variable like
emacs-conflict-convert-regexes.
- Have the values of
Other considerations
- To make sure the renaming process doesn't mess with other commonly used packages (
projectileandrecentf), there's some checks that reference functions that aren't always defined which produces compilation warnings.
Thank you for this. I remember stumbling into that issue when using Orgzly too. I’ll be reviewing this shortly. I already glanced over it and it looked good.