On 13-01-11 01:47 AM, Samuel Wales wrote:
I have more on this, but if possible it would be best to make ediff do
that natively. I don't know if that's possible.
Thanks for your prompt replies. The reason I looked for this feature is
that it is available in the package git-emacs. There I can choose Git -
Add to index - Select changes in current file. Then ediff starts, and I
can modify the buffer named <index>:FILENAME at will.
After I answer 'y' to 'Quit this Ediff session?', another question comes up
'Add changes to the git index? (y or n)'. With 'y' I see the message
'Saving file /tmp/git-emacs-tmp6991oXZ...'
So I guess all it takes is saving a temporary file and adding its
content to the index. Given my lack of experience in lisp programming, I
don't know how hard it actually is to implement in magit, though. But a
quick look into the source code of git-emacs revealed this function
(defun git-add-interactively()
"A friendly replacement for git add -i, using ediff"
(interactive) ; haha
(git--require-buffer-in-git)
(git--diff
(git--if-in-status-mode
(git--status-view-select-filename)
buffer-file-name )
":" ; index
;; before ediff
(lambda()
(with-current-buffer ediff-buffer-B
(setq buffer-read-only nil)
(set-buffer-modified-p nil))
(message "Your changes to the second buffer will be added to the
index"))
;; after ediff
(lambda()
(let ((file-buf ediff-buffer-A)
(index-buf ediff-buffer-B))
(if (not (buffer-modified-p index-buf))
(message "No changes to the index")
(with-current-buffer file-buf
(let ((filename (file-relative-name buffer-file-name)))
(when (y-or-n-p "Add changes to the git index? ")
;; insert index-buf as blob object, get its hash
(let ((new-content-hash
(git--trim-string (git--exec-pipe
"hash-object"
index-buf
"-t" "blob" "-w" "--stdin")))
(fileinfo (car-safe (git--status-index filename))))
;; update index with the new object
(git--exec-string
"update-index" "--cacheinfo"
(git--fileinfo->perm fileinfo)
new-content-hash
(git--get-relative-to-top buffer-file-name))))))))
)))
I would be very happy if this became available in magit.
best regards
Fred