|
From: | Vinicius Jose Latorre |
Subject: | Re: Proposal: diff-remove-trailing-blanks |
Date: | Wed, 30 Apr 2008 21:34:37 -0300 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/20080313 SeaMonkey/1.1.9 |
(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.
Ok, but the search in diff buffer is only for modified lines with trailing blanks,
so there is less finds/replacements in the source file.
(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 bufferMy CVS Emacs is a few weeks old, son I can't test this, but it looks good to me :-)
Ok.
(add-hook 'diff-mode-hook 'diff-show-trailing-blanks)Of course this is left for the .emacs file of each own.
Of course, this line is there only as an usage example.
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?
Well, can I install diff-kill-trailing-whitespace and diff-show-trailing-whitespace into diff-mode?
[Prev in Thread] | Current Thread | [Next in Thread] |