feat(emacs): Configure Ediff
- Restore window configuration on quit. - Very simple, half-broken helper for resolving Syncthing conflicts. - Doesn't automatically delete the conflict file after resolve. }:\
This commit is contained in:
@@ -94,4 +94,45 @@ If FORCE-P, delete without confirmation."
|
||||
:desc "Open current file as root. See `doom/sudo-this-file'."
|
||||
:interactive t)
|
||||
|
||||
(defun syd--make-syncthing-merge-finalise-hook (file-name conflict-file-name)
|
||||
(lambda ()
|
||||
(let ((merge-result-file (read-file-name
|
||||
(format "Write merge to (default: %s):"
|
||||
file-name)
|
||||
nil file-name))
|
||||
(delete-conflict-p (yes-or-no-p (format "Delete conflict file? (%s)"
|
||||
conflict-file-name)))))
|
||||
(when merge-result-file
|
||||
(with-current-buffer ediff-buffer-C
|
||||
(set-visited-file-name merge-result-file)
|
||||
(save-buffer))
|
||||
(kill-buffer ediff-buffer-C))
|
||||
(when delete-conflict-p
|
||||
(kill-buffer (find-buffer-visiting conflict-file-name))
|
||||
(delete-file conflict-file-name))))
|
||||
|
||||
(defun syd--read-syncthing-conflict-file (&optional directory)
|
||||
(let ((conflict-files (directory-files-recursively
|
||||
(or directory default-directory)
|
||||
(rx ".sync-conflict-"))))
|
||||
(completing-read "Conflict file: " conflict-files nil t)))
|
||||
|
||||
(defun syd--syncthing-conflict-file-base-name (conflict-file)
|
||||
(replace-regexp-in-string (rx ".sync-conflict-" (* (not ?.)))
|
||||
""
|
||||
conflict-file))
|
||||
|
||||
(defun syd-resolve-syncthing-conflict (conflict-file)
|
||||
(interactive (list (syd--read-syncthing-conflict-file)))
|
||||
(require 'ediff)
|
||||
(let* ((base-file (syd--syncthing-conflict-file-base-name conflict-file))
|
||||
(ediff-after-quit-hook-internal
|
||||
;; Override Ediff's "save and quit" hook with our own.
|
||||
(cons (syd--make-syncthing-merge-finalise-hook base-file conflict-file)
|
||||
(remq #'ediff-write-merge-buffer-and-maybe-kill
|
||||
(ensure-list ediff-quit-merge-hook)))))
|
||||
(ediff-merge-files
|
||||
base-file
|
||||
conflict-file)))
|
||||
|
||||
(provide 'syd-file)
|
||||
|
||||
Reference in New Issue
Block a user