emacs-devel
[Top][All Lists]
Advanced

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

Re: Proposal: diff-remove-trailing-blanks


From: Óscar Fuentes
Subject: Re: Proposal: diff-remove-trailing-blanks
Date: Sun, 27 Apr 2008 22:05:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (windows-nt)

Vinicius Jose Latorre <address@hidden> writes:

>>>      (while (re-search-forward "^[+!>] .*?[ \t]+$" (point-max) t)
>>
>> In unified diffs, there is no white space after `+'. In other diff
>> types, its seems that there is:
>>
>> +foo (changed or added line, unified diff)
>>> foo (changed or added line, normal diff)
>> ! foo (changed line, context diff)
>> + foo (added line, context diff)
>>
>> The solution is to test the format type and adapt the regexp for it:
>>
>> (diff-beginning-of-hunk 'try-harder)
>> (setq (diff-hunk-style))
>> (case style
>>     (unified (setq re ...)) ;; (+)
>>     (context (setq re ...)) ;; (+! )
>>     (t (setq re ...))) ;; (> )
>>
>
> Ok, so, maybe the functions below fix all of this.
[snip]
>      (while (re-search-forward "^[+!>].*?[ \t]+$" (point-max) t)

As every change indicator is followed by a white space in non-unified
format, this regexp matches every change on normal and context
formats. This is not bad, as the trailing whitespace condition is tested
again below for the source file, which is what matters. But then, you
could use a simpler regexp above ("^[+!>]", for instance), for behaving
the same with diff formats.

[snip]

> (defun diff-show-trailing-blanks ()
>  "Show trailing blanks in modified lines for diff-mode."
>  (interactive)
>  (let ((whitespace-style '(trailing))
>        (whitespace-trailing-regexp "^[+!>].*?\\([\t ]+\\)$"))
>    (whitespace-mode 1)))     ; display trailing blanks in diff buffer

My CVS Emacs is a few weeks old, son I can't test this, but it looks
good to me :-)

> (add-hook 'diff-mode-hook 'diff-show-trailing-blanks)

Of course this is left for the .emacs file of each own.

However, I suggest adding a key sequence to diff-mode that executes
diff-remove-trailing-blanks. I use C-c C-k. And perhaps a more adequate
name is diff-kill-trailing-whitespace.

Do you intend to install it on CVS soon?

-- 
Oscar





reply via email to

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