help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Diff could also show the changes within lines


From: Sebastien Vauban
Subject: Re: Diff could also show the changes within lines
Date: Wed, 14 Nov 2012 15:31:51 +0100
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2.50 (windows-nt)

Hi Tom,

Tom wrote:
> Sebastien Vauban <address@hidden> writes:
>> I'd like to get that feature as well. However, the above code causes me
>> 2 problems:
>> 
>> - only the last hunk is getting refined, both in VC dir's buffer, or when
>>   reading (with Gnus) an email with a patch file in it;
>
> Currently I use this code added to the diff mode hook:
>
> (defun my-refine-all-diff-hunks ()
>   (interactive)
>   (condition-case nil      
>       (save-excursion
>         (goto-char (point-min))
>         (while (not (eobp))
>           (diff-hunk-next)))
>     (error nil)))
>
> It works well for me, it highlights the changes in all hunks automatically.
> I use it only for diffing before checkin.
>
> But. It works only because the VC mercurial implementation calls the backend
> synchronously. In case of DVC it doesn't work for me, because DVC calls the
> backend asynchronously, so when the diff hook is run the output is not there
> yet and I did not find a hook which is called when the async diff command is
> finished
>
> You may want to check how the diff output is produced in your use cases. If
> it is done asynchronously then the diff hook is not a suitable place to call
> the highlighting code from.

I'm not sure how to check for that, but I could reduce all my `.emacs' file to
an example file which shows the problem on the current development snapshot of
the future Emacs 24.3 (from 2012-10-22):

--8<---------------cut here---------------start------------->8---
;;; emacs-minimal.el

(setenv "LC_ALL" "C")

;; enable Diff Auto Refine mode (highlight the changes with better
;; granularity)
(defun my/diff-refine-all-hunks ()
  (interactive)
  (condition-case nil
      (save-excursion
        (goto-char (point-min))
        (while (not (eobp))
          (diff-hunk-next)))
    (error nil)))

(add-hook 'diff-mode-hook
          'my/diff-refine-all-hunks)

(message "%s" (emacs-version))
(sit-for 1)
--8<---------------cut here---------------end--------------->8---

You can see, in the screencast on http://screencast.com/t/JOlsyWHh, that:

- the cursor goes to the end of the diff

- only the last diff is refined (see the string " for Diff" which should be
  highlighted in the first hunk)

Best regards,
  Seb

-- 
Sebastien Vauban


reply via email to

[Prev in Thread] Current Thread [Next in Thread]