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 17:15:38 +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 ...))) ;; (> )

[snip]

>      (if modified-buffers
>          (let ((whitespace-style '(trailing))
>                (whitespace-trailing-regexp "^[+!>] .*?\\([\t ]+\\)$"))

Likewise.

>            (whitespace-mode 1)        ; display trailing blanks in diff buffer

Seeing that the diff introduces trailing whitespace is most interesting
before removing it too. Actually, you want to highlight trailing
withespace on the diff for knowing that you should invoke
`diff-remove-trailing-blanks'. (A nice thing would be to automatically
test the diff and put something on the buffer's modeline indicating that
the diff introduces trailing whitespace. `diff-mode-hook' is handy for
this).

[snip]

-- 
Oscar




reply via email to

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