[Nut-upsdev] coding style
Charles Lepple
clepple at gmail.com
Fri Feb 9 02:37:04 CET 2007
On 2/8/07, Peter Selinger <selinger at mathstat.dal.ca> wrote:
> bbCharles Lepple wrote:
> >
> > On 2/8/07, Peter Selinger <selinger at mathstat.dal.ca> wrote:
> > > +If you are using emacs, you can automatically adjust the tab-width
> > > +setting to (say) 3 spaces for all NUT sources by putting something
> > > +like this into your .emacs:
> > > +
> > > + ;; NUT style
> > > + (defun nut-c-mode ()
> > > + "C mode with adjusted defaults for use with the NUT sources."
> > > + (interactive)
> > > + (c-mode)
> > > + (c-set-style "K&R")
> > > + (setq c-basic-offset 3)
> > > + (setq tab-width 3))
> >
> > c-basic-offset of 3 is OK with me, but a tab-width of 3?
>
> This does not affect the source code. It affects how your editor
> *displays* the source code. To quote from Russell's guidelines:
>
> > Another thing to notice is that the indenting happens with tabs
> > instead of spaces. This lets everyone have their personal tab-width
> > setting without inflicting much pain on other developers. If you
> > use a space, then you've fixed the spacing in stone and have really
> > annoyed half of the people out there.
>
> So in the sources, all indentation is done by "tab". I like my editor
> to display these as 3 spaces (actually, perhaps I prefer 2 spaces, but
> that's a matter of taste).
>
> If you don't set the c-basic-offset equal to the tab-width, then your
> indentations will not be saved as one tab per indentation level.
>
> I hope this clarifies it. The above code snippet is just an example.
Ah, OK. I thought there was a third variable that controlled whether
or not a string of spaces equal in width to a tab would be collapsed
into an actual tab, but I guess that's set by default.
This does throw off tables made with tabs, but I suppose that's not a
big concern if we use HTML, or if we make sure that tabs are 8 spaces
in *.txt documentation files.
--
- Charles Lepple
More information about the Nut-upsdev
mailing list