All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Patrick Ohly <patrick.ohly@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"David S. Miller" <davem@davemloft.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH -mm] documentation: update CodingStyle tips for Emacs users
Date: Wed, 18 Feb 2009 10:59:31 +0100	[thread overview]
Message-ID: <20090218095931.GA2054@cmpxchg.org> (raw)
In-Reply-To: <1234948770.23768.25.camel@ecld0pohly>

On Wed, Feb 18, 2009 at 10:19:30AM +0100, Patrick Ohly wrote:
> On Fri, 2008-07-04 at 19:52 +0200, Johannes Weiner wrote:
> > Describe a setup that integrates better with Emacs' cc-mode and also
> > fixes up the alignment of continuation lines to really only use tabs.
> [...]
> > +(defun c-lineup-arglist-tabs-only (ignored)
> > +  "Line up argument lists by tabs, not spaces"
> > +  (let* ((anchor (c-langelem-pos c-syntactic-element))
> > +	 (column (c-langelem-2nd-pos c-syntactic-element))
> > +	 (offset (- (1+ column) anchor))
> > +	 (steps (floor offset c-basic-offset)))
> > +    (* (max steps 1)
> > +       c-basic-offset)))
> >+
> >+(add-hook 'c-mode-hook
> > +          (lambda ()
> > +            (let ((filename (buffer-file-name)))
> > +              ;; Enable kernel mode for the appropriate files
> > +              (when (and file
> > +                         (string-match "/usr/src/linux" filename))
> > +                (setq indent-tabs-mode t)
> > +                (c-set-style "linux")
> > +                (c-set-offset 'arglist-cont-nonempty
> > +                              '(c-lineup-gcc-asm-reg
> > +                                c-lineup-arglist-tabs-only))))))
> 
> When starting writing kernel source code last year (the hardware time
> stamping patch) I used this macro to format it. I very much liked the
> possibility to only switch on Linux style when editing Linux code
> (because I work on a variety of code bases with different formatting).
> 
> But the macro above did not produce the result expected by some patch
> reviewers (John Stultz, Dave Miller). I had to redo the formatting
> manually.
> 
> The sticky point is continuation after splitting a long parameter list -
> in other words, exactly what the "arglist-cont-nonempty" setting above
> changes. The macro formats it so that the continuation is aligned at the
> tab that is closest to the initial argument in the previous line:
> 
> int a_very_long_function_name(int arg1, char *arg2,
> 			double arg3);
> 
> The expected style was tab plus spaces to align with the first argument:
> 
> int a_very_long_function_name(int arg1, char *arg2,
> 			        double arg3);
> 
> Is this a bug in the macro? I'm using emacs 22.1.1, in case that
> matters. Or are there different opinions in the Linux developer
> community about the right formatting?

Unfortunately, this seems to depend on the maintainer.  Both styles
are used all over the kernel but Documentation/CodingStyle and
scripts/checkpatch.pl prefer what the above emacs configuration does.

I doubt that people do tab tab tab space space space space space by
hand, so I strongly suspect that the tab-only zealots don't use emacs
which does this adjustment automatically.

You should probably add linux-davem to the above or something.  Or
name the coding style after the text-editor the target maintainer
uses :-)

	Hannes

  reply	other threads:[~2009-02-18  9:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-04 17:52 [PATCH -mm] documentation: update CodingStyle tips for Emacs users Johannes Weiner
2008-07-04 19:41 ` Jonathan Corbet
2008-07-05 11:36   ` Johannes Weiner
2008-07-05 14:32     ` Jonathan Corbet
2008-07-05 18:33       ` [PATCH -mm] documentation: update CodingStyle tips for Emacs users v2 Johannes Weiner
2009-02-18  9:19 ` [PATCH -mm] documentation: update CodingStyle tips for Emacs users Patrick Ohly
2009-02-18  9:59   ` Johannes Weiner [this message]
2009-02-18 10:23     ` Patrick Ohly
2009-02-18 17:28       ` Johannes Weiner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090218095931.GA2054@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrick.ohly@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.