emacs haskellers: r-stripping files becomes popular

Add the following lines to your ~/.emacs: ------- BEGIN OF ELISP CODE ------- ;(global-set-key (kbd "<f9> s") 'delete-trailing-whitespace) (defun delete-trailing-whitespace-if-confirmed () "Delete all the trailing whitespace across the current buffer, asking user for confirmation." (if (and (save-excursion (goto-char (point-min)) (re-search-forward "[[:space:]]$" nil t)) (y-or-n-p "Delete trailing whitespace? ")) (delete-trailing-whitespace))) (add-hook 'before-save-hook 'delete-trailing-whitespace-if-confirmed) ------- END OF ELISP CODE ------- Have fun! -- vvv

On Nov 16, 2007 11:14 AM, Valery V. Vorotyntsev
Add the following lines to your ~/.emacs:
------- BEGIN OF ELISP CODE ------- ;(global-set-key (kbd "<f9> s") 'delete-trailing-whitespace)
(defun delete-trailing-whitespace-if-confirmed () "Delete all the trailing whitespace across the current buffer, asking user for confirmation." (if (and (save-excursion (goto-char (point-min)) (re-search-forward "[[:space:]]$" nil t)) (y-or-n-p "Delete trailing whitespace? ")) (delete-trailing-whitespace)))
(add-hook 'before-save-hook 'delete-trailing-whitespace-if-confirmed) ------- END OF ELISP CODE -------
Nice! Is there a way to have this only run if the current buffer is in haskell-mode? I'd add it myself but I've not yet taken the plunge to being an elisp hacker. -Brent

On 11/16/07, Brent Yorgey
Nice! Is there a way to have this only run if the current buffer is in haskell-mode? I'd add it myself but I've not yet taken the plunge to being an elisp hacker.
Try adding ``(eq major-mode 'haskell-mode)'' after the `and' .. .. but why would you tolerate whitespace in other modes? -- vvv

On Nov 16, 2007 12:05 PM, Valery V. Vorotyntsev
On 11/16/07, Brent Yorgey
wrote: Nice! Is there a way to have this only run if the current buffer is in haskell-mode? I'd add it myself but I've not yet taken the plunge to being an elisp hacker.
Try adding ``(eq major-mode 'haskell-mode)'' after the `and' .. .. but why would you tolerate whitespace in other modes?
For one thing, if you happen to write code shared with other people who do not use this hook, then you may end up causing *huge* numbers of spurious differences in diff(1) output. There may be an easy way to deal with this, but, it is a problem. -- Denis

On 11/16/07, Denis Bueno
For one thing, if you happen to write code shared with other people who do not use this hook, then you may end up causing *huge* numbers of spurious differences in diff(1) output. There may be an easy way to deal with this, but, it is a problem.
Yes, you are right. That's why user is being asked for confirmation. And `diff -w' removes the noise, but still, yes, that can be a "problem". :) -- vvv

On 11/16/07, Valery V. Vorotyntsev
Add the following lines to your ~/.emacs:
Adding buffer name to confirmation message: ------- BEGIN ------- (defun delete-trailing-whitespace-if-confirmed () "Delete all the trailing whitespace across the current buffer, asking user for confirmation." (if (and (save-excursion (goto-char (point-min)) (re-search-forward "[[:space:]]$" nil t)) (y-or-n-p (format "Delete trailing whitespace from %s? " (buffer-name)))) (delete-trailing-whitespace))) ------- END -------
(add-hook 'before-save-hook 'delete-trailing-whitespace-if-confirmed)
-- vvv

Additionally, I find this to be helpful for keeping out trailing whitespace: ;; Highlight trailing whitespace in haskell files (add-hook 'haskell-mode-hook '(lambda () (setq show-trailing-whitespace t))) Cheers, -Greg Heartsfield On Fri, Nov 16, 2007 at 06:14:57PM +0200, Valery V. Vorotyntsev wrote:
Add the following lines to your ~/.emacs:
------- BEGIN OF ELISP CODE ------- ;(global-set-key (kbd "<f9> s") 'delete-trailing-whitespace)
(defun delete-trailing-whitespace-if-confirmed () "Delete all the trailing whitespace across the current buffer, asking user for confirmation." (if (and (save-excursion (goto-char (point-min)) (re-search-forward "[[:space:]]$" nil t)) (y-or-n-p "Delete trailing whitespace? ")) (delete-trailing-whitespace)))
(add-hook 'before-save-hook 'delete-trailing-whitespace-if-confirmed) ------- END OF ELISP CODE -------
Have fun!
-- vvv

why care about trailing whitespace?
On Nov 16, 2007 8:14 AM, Valery V. Vorotyntsev
Add the following lines to your ~/.emacs:
------- BEGIN OF ELISP CODE ------- ;(global-set-key (kbd "<f9> s") 'delete-trailing-whitespace)
(defun delete-trailing-whitespace-if-confirmed () "Delete all the trailing whitespace across the current buffer, asking user for confirmation." (if (and (save-excursion (goto-char (point-min)) (re-search-forward "[[:space:]]$" nil t)) (y-or-n-p "Delete trailing whitespace? ")) (delete-trailing-whitespace)))
(add-hook 'before-save-hook 'delete-trailing-whitespace-if-confirmed) ------- END OF ELISP CODE -------
Have fun!
-- vvv _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 24 Nov 2007, at 9:09 PM, Brent Yorgey wrote:
On Nov 24, 2007 10:55 PM, Conal Elliott
wrote: why care about trailing whitespace? Probably because it looks bad in darcs patch summaries (trailing whitespace --> little red dollar signs). Unless there's another reason I don't know about.
It breaks C-e. (Irreparably, of course). jcc
participants (6)
-
Brent Yorgey
-
Conal Elliott
-
Denis Bueno
-
Greg Heartsfield
-
Jonathan Cast
-
Valery V. Vorotyntsev