[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Examples of the inconsitency in PenguinPlay



On Thu, 15 Jul 1999, Peter Burns wrote:

>Does any one know how to stop emacs from putting tabs into the code? I've
>been trying to get it to put spaces instead but I haven't been to
>successful.

You can 'untabify' the file before saving it. You could try something
like:

(defun better-save ()
  (untabify (point-min) (point-max)))

(add-hook 'write-file-hooks 'better-save)


This is tested once, and works ok. It should work for saving multiple
buffers too (C-x s), as well as the normal C-x C-c and C-x C-s. Note that
the function is executed for _all_ buffers, no matter what type, so it
would probably be better to create a small hook that is run upon turning
on c++-mode:

;; our nice function again
(defun better-save ()
  (untabify (point-min) (point-max)))

;; hook run when c++-mode is started
(defun autountabify ()
  (add-hook 'write-file-hooks 'better-save))

;; make sure we add our own function to c++-mode's hooks
(add-hook 'c++-mode-hook 'autountabify)

;; later use this to remove the hook. It can be done automatically too,
;; but I can't remember how, elisp is not my primary environmen....
(remove-hook 'c++-mode-hook 'autountabify)


This thing makes it nice in that it doesn't matter what Emacs uses
to show the text on the screen; when it's saved it'll always be
untabified. If you intend to print from within Emacs (not print the saved
file), you must manually untabify first.

---------------------+------------------------------------------------------
 Jan 'Chakie' Ekholm |    CS at Åbo Akademi University, Turku, Finland
    Linux Inside     | I'm the blue screen of death, no-one hears you scream