Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to avoid SPACE TAB in a file?

1 view
Skip to first unread message

Ulrich Neumerkel

unread,
Nov 25, 2009, 2:25:43 PM11/25/09
to
It occurs to me occasionally that I happen to write SPACE TAB in a buffer
saved into a file. This is mostly when I edit files with different
tabbing conventions.

Is there are general clean minor-mode or other way to avoid writing
this combination in general?

Colin S. Miller

unread,
Nov 25, 2009, 3:04:11 PM11/25/09
to

Hi Ulrich,
If you want emacs to always insert spaces instead of tabs then you can put
(setq indent-tabs-mode nil)
in your .emacs.

This needs to be set for each buffer, so it should be put in a hook like
(add-hook 'c-mode-hook '(lambda ()
(setq indent-tabs-mode nil)))


You'll need to replace 'c-mode-hook with the correct hook for the
editing mode you use. Most of them are named after the mode's main
function.


HTH,
Colin S. Miller
--
Replace the obvious in my email address with the first three letters of the hostname to reply.

Drew Adams

unread,
Nov 25, 2009, 4:21:26 PM11/25/09
to Colin S. Miller, help-gn...@gnu.org
> If you want emacs to always insert spaces instead of tabs
> then you can put (setq indent-tabs-mode nil) in your .emacs.
> This needs to be set for each buffer, so it should be put in
> a hook like
> (add-hook 'c-mode-hook '(lambda () (setq indent-tabs-mode nil)))


(setq-default indent-tabs-mode t)

Ulrich Neumerkel

unread,
Nov 25, 2009, 6:11:48 PM11/25/09
to
"Colin S. Miller" <no-spam-...@csmiller.demon.co.uk> writes:
>Ulrich Neumerkel wrote:
>> It occurs to me occasionally that I happen to write SPACE TAB in a buffer
>> saved into a file. This is mostly when I edit files with different
>> tabbing conventions.
>>
>> Is there are general clean minor-mode or other way to avoid writing
>> this combination in general?
>
>Hi Ulrich,
>If you want emacs to always insert spaces instead of tabs then you can put
>(setq indent-tabs-mode nil)
>in your .emacs.
>
>This needs to be set for each buffer, so it should be put in a hook like
>(add-hook 'c-mode-hook '(lambda ()
> (setq indent-tabs-mode nil)))
>
>You'll need to replace 'c-mode-hook with the correct hook for the
>editing mode you use. Most of them are named after the mode's main
>function.

The files/tabbing conventions are not mine, I just edit (tiny) parts of
the files. That's how those extra spaces actually appear.
I am considering rolling it on my own with after-save-hook.

Ulrich Neumerkel

unread,
Nov 26, 2009, 9:46:27 AM11/26/09
to
Thanks again for your responses. Currently I put in my .emacs.el

(defun no-space-tab ()
(interactive)
(let
((point (point)))
(save-match-data
(goto-char (point-min))
(cond
((search-forward " \t" nil t)
(backward-char 1)
(error "SPACE found prior to TAB! Press Backspace"))
(t (goto-char point))))))

(add-hook 'after-save-hook 'no-space-tab)

Drew Adams

unread,
Nov 27, 2009, 10:11:23 AM11/27/09
to Ulrich Neumerkel, help-gn...@gnu.org

`C-h f untabify'

0 new messages