I'd like to use wdiff to compare the contents of the current buffer to a previous version of the file the buffer is visiting. So, this would be a word-level live diff of the current buffer against a given git commit. The shell version of this would look like this:

 wdiff -w "[[delete:" -x "]]" -y "[[insert:"  -z "]]" <(git show "9409c06d816b7c677a4b07b80b76a54d65014257:FILENAME") FILENAME

I'd like to replace the second "FILENAME" with something that pipes the contents of hte current buffer to a shell. Is this possible? The code I am currently stealing from (John Kitchin's scimax package) uses shell-command-to-string but that chokes on the buffer string when it contains quotes & special characters.

  • 1
    Why not just save the buffer contents to a file and pass the file to wdiff? – izkon Oct 26 '18 at 1:53
  • I was trying to avoid that step so I could use live updating without adding an I/O bottleneck. But yes, maybe it's the most sensible solution? – Matt Oct 26 '18 at 15:12
  • Does magit-diff-refine-hunk help? Setting it to 'all will show word-granularity differences – Felipe Lema Oct 26 '18 at 17:39
  • Is I/O really going to be a bottleneck here? I'd suggest testing out the simplest solution first to see if works for you. If it's too slow, then explore more creative options. – izkon Oct 27 '18 at 5:48

It looks like you can use echo and argument quoting with the subshell method:

 (format "wdiff -w \"[[delete:\" -x \"]]\" -y \"[[insert:\"  -z \"]]\" <(git show efc4752:2018-10-27.org) <(echo \"%s\")"
         (find-file-noselect "2018-10-27.org")
        (buffer-substring-no-properties (point-min) (point-max))))))

This worked for me on a buffer containing quotes and & in it.

  • ah, great, thanks John. and now... looks like it'sstill all your code! – Matt Oct 29 '18 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.