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 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
participants (2)
-
Brent Yorgey
-
Valery V. Vorotyntsev