Re: Indentation within block
Alan Mackenzie <[email protected]> Mon, 29 Apr 2024 18:48:03 +0000
| Newsgroups | gmane.emacs.cc-mode.general |
|---|---|
| Message-ID | <Zi_rYxovADrhTyj_@ACM> |
Hello, Ryan.
Good to hear from you again!
On Mon, Apr 29, 2024 at 10:01:53 +0000, Dixon Ryan (ETAS-VOS/XPC-Yok1) via CC-Mode-help wrote:
> Hello Alan,
> I am sure it is my fault for not reading some relevant part of
> documentation, but I have tried while at work.
;-)
> I use:
> (setq c-default-style "linux"
> c-basic-offset 4
> indent-tabs-mode nil)
> Everything works as expected until:
> ===
> If(x)
> {[]
> ===
> Two cases:
> 1. At the marker [] if I press return a new line is inserted and always
> with a tab character.
> 2. If instead at the marker [] I press the "down arrow" and press C-o
> and then press the tab character there is a tab character inserted.
> What am I doing wrong. It seems to only be a problem in the block. I
> know that linux mode uses tabs (I think) - what do I need to set to
> eradicate tabs.
setq'ing c-default-style to "linux" is fine, but c-basic-offset is a
buffer local variable, so setq'ing it will only set it in the current
buffer. Same with indent-tabs-mode.
There are several ways to fix this (alas, too many), but I would
recommend you, in your .emacs (or init.el) to have:
(setq c-default-style "linux")
(defun rd-cc-variables ()
(setq c-basic-offset 4
indent-tabs-mode nil))
(add-hook 'c-mode-common-hook #'rd-cc-variables)
(not tested). That should ensure that the the two buffer local variables
get set in each CC Mode buffer.
> Regards,
--
Alan Mackenzie (Nuremberg, Germany).