[Emacs-ada-mode] Cleaning buffer before saving
Stephen Leake
stephen_leake at stephe-leake.org
Sat Feb 6 11:19:47 PST 2010
Simon Wright <simon at pushface.org> writes:
> In 4.01, ada-clean-buffer-before-saving is marked as obsolete, with a
> recommendation to use the write-file-functions in Emacs 23.2. I'm
> using Carbon Emacs, which doesn't appear to have write-file-functions
> or anything apropos,
According to http://homepage.mac.com/zenitani/emacs-e.html, "Carbon
Emacs Package is a Mac-friendly distribution of the GNU Emacs text
editor".
However, the history page there says the latest Carbon Emacs is based
on Gnu Emacs 22.
What do you get when you do M-x version?
My policy is to fully support the latest version of Gnu Emacs, and the
version before that if it's not too hard.
There are other similar hooks: write-contents-functions,
before-save-hook. They are in emacs 22 and 23.
> but in any case this is the only place I can see in ada-mode that
> actually references write-file-functions; so it looks as though
> ada-clean-buffer-before-saving has no effect (on Ada source).
Correct.
> I don't see why this option should be made obsolete, even if the way
> it's implemented has to change!
Because there's a better way; same reason Appendix J exists :).
The general rule here is "don't duplicate functionality". There's a
perfectly good way for people to set a customization that cleans a
buffer before saving; no need for ada-mode to get involved.
This is what ada-clean-buffer-before-saving used to do:
(if ada-clean-buffer-before-saving
(progn
;; remove all spaces at the end of lines in the whole buffer.
(add-hook 'local-write-file-hooks 'delete-trailing-whitespace)
;; convert all tabs to the correct number of spaces.
(add-hook 'local-write-file-hooks
(lambda () (untabify (point-min) (point-max))))))
The approved emacs 22 compatible replacement is to put this in your
.emacs:
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(setq-default indent-tabs-mode nil)
This then applies to all modes, which is better than each mode
providing a switch for the same thing.
Note that this does not call untabify; that's dangerous in a global
hook, because some languages (like Gnu make) require tabs.
'indent-tabs-mode nil' means you will never insert tabs except in
modes that override it, as makefile-mode does, so don't need to clean
them.
But if you want to clean tabs in ada-mode, you can use:
(add-hook 'ada-mode-hook
(lambda ()
(make-variable-buffer-local 'before-save-hook)
(add-hook 'before-save-hook
(lambda () (untabify (point-min) (point-max))))))
> The old way of doing things is still present in gpr-mode.el, by the
> way.
Thanks for the pointer; I'll fix that. gpr-mode.el isn't in Gnu Emacs
yet; I'll try to remember to get it added after this release.
--
-- Stephe
More information about the Emacs-ada-mode
mailing list