Good Haskell Style

Thomas Schilling nominolo at
Thu Aug 2 12:16:25 EDT 2007

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."
    (or buffer-read-only
          (message "Deleting trailing spaces ... ")
          (goto-char (point-min))
          (while (< (point) (point-max))
            (end-of-line nil)
            (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
Version: GnuPG v1.4.5 (Darwin)


More information about the Libraries mailing list