[Python-Dev] Reindenting the C code base?
Alexandre Vassalotti
alexandre at peadrop.com
Sun Dec 14 19:03:40 CET 2008
On Sun, Dec 14, 2008 at 12:57 PM, Alexandre Vassalotti
<alexandre at peadrop.com> wrote:
> On Sun, Dec 14, 2008 at 12:43 PM, Jeffrey Yasskin <jyasskin at gmail.com> wrote:
>> I've never figured out how to configure emacs to deduce whether the
>> current file uses spaces or tabs and has a 4 or 8 space indent. I
>> always try to get it right anyway, but it'd be a lot more convenient
>> if my editor did it for me. If there are such instructions, perhaps
>> they should be added to PEPs 7 and 8?
>>
>
> I know python-mode is able to detect indent configuration of python
> code automatically, but I don't know if c-mode is able to. Personally,
>
[sorry, <tab><space> in gmail made it send my unfinished email]
Personally, I use auto-mode-alist to make Emacs choose the indent
configuration to use automatically.
Here's how it looks like for me:
(defmacro def-styled-c-mode (name style &rest body)
"Define styled C modes."
`(defun ,name ()
(interactive)
(c-mode)
(c-set-style ,style)
, at body))
(def-styled-c-mode python-c-mode "python"
(setq indent-tabs-mode t
tab-width 8
c-basic-offset 8))
(def-styled-c-mode py3k-c-mode "python"
(setq indent-tabs-mode nil
tab-width 4
c-basic-offset 4))
(setq auto-mode-alist
(append '(("/python.org/python/.*\\.[ch]\\'" . python-c-mode)
("/python.org/.*/.*\\.[ch]\\'" . py3k-c-mode)) auto-mode-alist))
More information about the Python-Dev
mailing list