all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* C style alist question?
@ 2019-04-06  3:26 Ergus
  2019-04-06  4:10 ` Óscar Fuentes
  2019-04-06  6:48 ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Ergus @ 2019-04-06  3:26 UTC (permalink / raw)
  To: help-gnu-emacs

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
style.

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
style.

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)
       c-basic-offset)))

(add-hook 'c-mode-common-hook
          (lambda ()
            ;; Add kernel style
            (c-add-style
             "linux-tabs-only"
             '("linux" (c-offsets-alist
                        (arglist-cont-nonempty
                         c-lineup-gcc-asm-reg
                         c-lineup-arglist-tabs-only))))))

(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")
                                       filename))
                (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
configure.

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
Ergus.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-04-11 15:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-06  3:26 C style alist question? Ergus
2019-04-06  4:10 ` Óscar Fuentes
2019-04-06  6:48 ` Eli Zaretskii
2019-04-11  1:16   ` Ergus
2019-04-11  8:28     ` Alan Mackenzie
2019-04-11 14:22     ` Eli Zaretskii
2019-04-11 15:00       ` Ergus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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.