Good Haskell Style
Thomas Schilling
nominolo at googlemail.com
Thu Aug 2 12:16:25 EDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 2 aug 2007, at 18.03, David Brown wrote:
> Thomas Schilling wrote:
>
>> The simplest thing I can think of, is to not remove whitespace at
>> all, but to only remove it when you're saving the file. I know that
>> some modes use such a save hook. It also wouldn't modify the actual
>> file (ie, don't remove the whitespace until you save the file for
>> the first time), as long as you edit it. The only time the spaces
>> would be removed permanently were if you save the file, close the
>> buffer, and then re-open the file.
>
> Picture mode removes trailing space when you exit it, so perhaps the
> function that does that is available to call upon saving.
>
> Dave
>
Well, this works:
(defun delete-trailing-space ()
"Deletes trailing space from all lines in buffer."
(interactive)
(or buffer-read-only
(save-excursion
(message "Deleting trailing spaces ... ")
(goto-char (point-min))
(while (< (point) (point-max))
(end-of-line nil)
(delete-horizontal-space)
(forward-line 1))
(message "Deleting trailing spaces ... done.")))
nil) ; indicates buffer-not-saved for write-file-hook
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
;; Make the hook a named function, so we can redefine it
:: without having torestart emacs.
(defun my-haskell-mode-hook ()
...
(add-hook 'write-file-hooks 'delete-trailing-space)
...
))
But it has the problem that it will delete the whitespace also in the
open buffer, so you have to re-insert the whitespace at the end of
the line. I am just looking at how to modify the editing functions,
to have this work more seamlessly.
/ Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iQEVAwUBRrIDWiuNq1ISBIDTAQKE5wf/dSuD8pAIaaUj/R4qqB022Z0hfhLjxZpc
2oLNjYCWwYKbPu7NUOuQZ5KasP6A8yJstqZndpcllxNHimKAuqJ6CSGcEEswfpVL
LX5yz9YctFvABXSF0n7zITaQACkkTSHiFPpv/7B6h6mUZYNq8aTpW+PjxGTWn1g3
r2aE5ihhMJZwH/ted+jvjWibf1tP8CtHXSQkzyJpDRGdVcpKogwoJ0HLdL/pA4Kg
+Nc0rAST/zPGPIJPXsUq4LHyH5kMQcLrgtukwN43ijqOv1sGR4Yh6hlapi82nZ0i
J0avFsi/6TibwrMgearo/WqU8gbrD4Nefl191vCmyWv5JUSAt/H6Gw==
=/gC3
-----END PGP SIGNATURE-----
More information about the Libraries
mailing list