* 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
* Re: C style alist question?
2019-04-06 3:26 C style alist question? Ergus
@ 2019-04-06 4:10 ` Óscar Fuentes
2019-04-06 6:48 ` Eli Zaretskii
1 sibling, 0 replies; 7+ messages in thread
From: Óscar Fuentes @ 2019-04-06 4:10 UTC (permalink / raw)
To: help-gnu-emacs
Ergus <spacibba@aol.com> writes:
> For example: c-lineup-gcc-asm-reg, c-lineup-close-parenm,
> c-lineup-arglist-intro-after-paren... what are those, where are them?
Are you asking for their documentation? They are described on the
CC Mode manual:
https://www.gnu.org/software/emacs/manual/html_node/ccmode/Misc-Line_002dUp.html
> But also: what's the point with bringing a linux style that needs to be
> fixed by all the users that needs it?
Probably nobody cared about fixing the Emacs sources? Although this is
strange, because there are kernel developers with commit access to
Emacs.
> Could anyone help me to fix this, or fix the defaults in Emacs to follow
> the specifications?
Just discuss it with Alan Mackenzie, the maintainer of CC Mode. He is in
the emacs-devel mailing list.
> 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.
C styles are buffer local. If you set the correct style in your c-mode
hook, you should be ok.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C style alist question?
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
1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2019-04-06 6:48 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sat, 6 Apr 2019 05:26:38 +0200
> From: Ergus <spacibba@aol.com>
>
> 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.
Sorry, I don't understand what are "style alists" and the "official
styles". Please elaborate on that.
> 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.
Our style is defined by the .dir-locals.el file you see in the
repository. indent-tabs-mode is t only in Emacs Lisp mode.
> So, is it possible to fix this in order to bring a better and easier
> user initial experience with the right default values?
Fix how? Change our style? I think that'd be a hard change to sell,
because the current defaults were discussed several times and are a
kind of compromise between different preferences, but you need to
raise this on emacs-devel, not here.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C style alist question?
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
0 siblings, 2 replies; 7+ messages in thread
From: Ergus @ 2019-04-11 1:16 UTC (permalink / raw)
To: emacs-devel; +Cc: help-gnu-emacs
(I send to both mailing lists because it is related with a previous
thread, but the right destination for this mail is the devels mailing
list)
Hi guys:
The issue I was facing with indentations was related actually with the
fact that once an offset is set (for example in the init file) it is
ignored in some cases by c-set-style because it is not "from style"
anymore.
Does it makes sense (or is not too difficult) to provide an option (or a
parameter in c-set-style) that allows the user to overwrite all the
previous offsets with the values from the new style, in spite of if it
is not "from style"? Maybe it already exist?
Another question:
Actually emacs C indentation with tabs follows the following policy:
It add as many tabs as possible and then align with spaces until the
desired column is reached.
====================
-------> is a tab
. is a space
====================
```
int function(int var1,
------->.....double b,
------->.....double c)
{
------->for (int i = 0; i < 10; ++i)
------->------->myprintf ("%d\n",
------->------->------->..i);
}
```
But other common policies around are:
1) add only tabs (and ignore the small mismatch in some cases)
int function(int var1,
------->double b,
------->double c)
{
------->for (int i = 0; i < 10; ++i)
------->------->myprintf ("%d\n",
------->------->------->i);
}
2) Use tabs (but only for indentation) and spaces to align
int function(int var1,
.............double b)
{
------->for (int i = 0; i < 10; ++i)
------->------->myprintf ("%d\n",
------->------->..........i);
}
The last one is specially useful in C++ where templates and long type
names usually forces to break functions and expressions (and templated
types inside functions declarations) on multiple lines; because they
keep the alignment in different editors (or different emacs with
different tab-width).
Is it some variable/policy or method to produce 1 or 2 with what is
already there??
Thanks in advance,
Ergus.
On Sat, Apr 06, 2019 at 09:48:19AM +0300, Eli Zaretskii wrote:
>> Date: Sat, 6 Apr 2019 05:26:38 +0200
>> From: Ergus <spacibba@aol.com>
>>
>> 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.
>
>Sorry, I don't understand what are "style alists" and the "official
>styles". Please elaborate on that.
>
>> 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.
>
>Our style is defined by the .dir-locals.el file you see in the
>repository. indent-tabs-mode is t only in Emacs Lisp mode.
>
>> So, is it possible to fix this in order to bring a better and easier
>> user initial experience with the right default values?
>
>Fix how? Change our style? I think that'd be a hard change to sell,
>because the current defaults were discussed several times and are a
>kind of compromise between different preferences, but you need to
>raise this on emacs-devel, not here.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C style alist question?
2019-04-11 1:16 ` Ergus
@ 2019-04-11 8:28 ` Alan Mackenzie
2019-04-11 14:22 ` Eli Zaretskii
1 sibling, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-04-11 8:28 UTC (permalink / raw)
To: Ergus; +Cc: help-gnu-emacs, emacs-devel
Hello, Ergus.
On Thu, Apr 11, 2019 at 03:16:59 +0200, Ergus wrote:
> (I send to both mailing lists because it is related with a previous
> thread, but the right destination for this mail is the devels mailing
> list)
> Hi guys:
> The issue I was facing with indentations was related actually with the
> fact that once an offset is set (for example in the init file) it is
> ignored in some cases by c-set-style because it is not "from style"
> anymore.
The answer here is Read The Fantastic Manual. :-) In particular, the
CC Mode manual, page "Config Basics", explains how settings made in
different ways get resolved, and which one "wins".
> Does it makes sense (or is not too difficult) to provide an option (or a
> parameter in c-set-style) that allows the user to overwrite all the
> previous offsets with the values from the new style, in spite of if it
> is not "from style"? Maybe it already exist?
The thinking is that users, mostly, will be using the style system, or
possibly setting buffer local values in hooks (e.g. c-mode-common-hook).
And that anybody setting the global value of a style variable Really
Means It.
To supply the option you're suggesting would be quite difficult, yes,
since it would mean rethinking the entire way CC Mode handles the style
variables. To the five ways of setting style variables listed on that
manual page, could (should) be added the directory local settings. The
interaction between them all is quite involved.
I would ask you to read that manual page thoroughly, and see if it
provides you with a way to configure CC Mode adequate to your needs. If
not, then maybe we could come back to the question.
> Another question:
[ For another reply :-]
> Thanks in advance,
> Ergus.
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C style alist question?
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
1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2019-04-11 14:22 UTC (permalink / raw)
To: Ergus; +Cc: emacs-devel
> Date: Thu, 11 Apr 2019 03:16:59 +0200
> From: Ergus <spacibba@aol.com>
> Cc: help-gnu-emacs@gnu.org
>
> But other common policies around are:
>
> 1) add only tabs (and ignore the small mismatch in some cases)
>
> int function(int var1,
> ------->double b,
> ------->double c)
> {
> ------->for (int i = 0; i < 10; ++i)
> ------->------->myprintf ("%d\n",
> ------->------->------->i);
> }
AFAIU, this is the 'linux' style in CC Mode.
> 2) Use tabs (but only for indentation) and spaces to align
>
> int function(int var1,
> .............double b)
> {
> ------->for (int i = 0; i < 10; ++i)
> ------->------->myprintf ("%d\n",
> ------->------->..........i);
> }
And this is the 'bsd' style.
Can you use these built-in styles to get what you want? Or did I
misunderstand what you are looking for?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C style alist question?
2019-04-11 14:22 ` Eli Zaretskii
@ 2019-04-11 15:00 ` Ergus
0 siblings, 0 replies; 7+ messages in thread
From: Ergus @ 2019-04-11 15:00 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
On Thu, Apr 11, 2019 at 05:22:10PM +0300, Eli Zaretskii wrote:
>> Date: Thu, 11 Apr 2019 03:16:59 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> But other common policies around are:
>>
>> 1) add only tabs (and ignore the small mismatch in some cases)
>>
>> int function(int var1,
>> ------->double b,
>> ------->double c)
>> {
>> ------->for (int i = 0; i < 10; ++i)
>> ------->------->myprintf ("%d\n",
>> ------->------->------->i);
>> }
>
>AFAIU, this is the 'linux' style in CC Mode.
No, the linux style is the first example I inserted in my mail. With
some spaces to align. Like this (or at least this is what I get)
int function(int var1,
------->.....double b,
------->.....double c)
{
------->for (int i = 0; i < 10; ++i)
------->------->myprintf ("%d\n",
------->------->------->..i);
}
The indent-tabs-mode inserts "as many tabs as possible" and then aligns
with spaces.
>
>> 2) Use tabs (but only for indentation) and spaces to align
>>
>> int function(int var1,
>> .............double b)
>> {
>> ------->for (int i = 0; i < 10; ++i)
>> ------->------->myprintf ("%d\n",
>> ------->------->..........i);
>> }
>
>And this is the 'bsd' style.
>
bsd style defines 4 spaces after tabulator align for continuation lines,
not alineation with spaces.
>Can you use these built-in styles to get what you want? Or did I
>misunderstand what you are looking for?
According with Alan's mail the policy is not included and it needs a
workaround he sent in his email as an answer to a mail from 2008.
^ 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.