[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C style alist question?

From: Ergus
Subject: C style alist question?
Date: Sat, 6 Apr 2019 05:26:38 +0200
User-agent: NeoMutt/20180716

Hi all:

I usually edit code in two styles; the linux kernel style and now the
emacs style. But I have seen that there are some mismatches between the
style alists and the "official" styles. Which is very uncomfortable when
I need to switch constantly or I have open different styled files at the
same time because I set some variables that then are not taken from the

In the emacs wiki (I know is not official, but is the first we use
because there are more examples to copy-paste-test) they set some of the
variables outside the style, so when the user switches he gets a wrong

For example:

When I open an emacs' C source code I see details like the fill-column
is 70 instead of 78. In the kernel style the indent-tabs-mode is not set to t.
So, is it possible to fix this in order to bring a better and easier
user initial experience with the right default values?

In fact in the linux kernel coding style page there is a fix for the
default style that has been there for years:

(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)

(add-hook 'c-mode-common-hook
         (lambda ()
           ;; Add kernel style
            '("linux" (c-offsets-alist

(add-hook 'c-mode-hook
         (lambda ()
           (let ((filename (buffer-file-name)))
             ;; Enable kernel mode for the appropriate files
             (when (and filename
                        (string-match (expand-file-name "~/src/linux-trees")
               (setq indent-tabs-mode t)
               (setq show-trailing-whitespace t)
               (c-set-style "linux-tabs-only")))))

I know all this can be customized by the user, (now I know more or less
how). But in the beginning it was a bit difficult to start, and still
there are some details that takes a lot of time to know how to

For example: c-lineup-gcc-asm-reg, c-lineup-close-parenm,
c-lineup-arglist-intro-after-paren... what are those, where are them?

But also: what's the point with bringing a linux style that needs to be
fixed by all the users that needs it?

Could anyone help me to fix this, or fix the defaults in Emacs to follow
the specifications?

What's the recommended configuration when we need to switch constantly?
Because now as I set the tabwidth and the indent-style outside a style,
when I switch I only get a mixed useless style.
Thanks in advance

reply via email to

[Prev in Thread] Current Thread [Next in Thread]