Documentation: update CodingStyle tips for Emacs users
PATCH 1/1 Documentation: update CodingStyle tips for Emacs users
With the previous Emacs tips example the kernel style was made available for files in the kernel-tree only. This patch updates the tip to add separate cc-mode indent style; it makes the kernel style easily available for any filetype mode that is managed by the Emacs cc-mode.
We also fix the filename regexp in the example: Elisp function buffer-file-name returns full pathname, not a path relative to user's home directory. Hence a tilde (~) can't be used to refer to home directory (as the previous code did).
--- Documentation/CodingStyle | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)
Documentation/CodingStyle +13 -6
@@ -483,20 +483,27 @@ values. To do the latter, you can stick the following in your .emacs file: (* (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 "~/src/linux-trees" filename)) + (string-match "src/linux-trees" 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)))))) + (c-set-style "linux-tabs-only"))))) This will make emacs go better with the kernel coding style for C -files below ~/src/linux-trees. +files which pathname matches src/linux-trees. But even if you fail in getting emacs to do sane formatting, not everything is lost: use "indent".
Signature · 1 line
1.6.1.156.gb648d
Quoted 10 lines · Teemu Likonen (2009-01-18 19:18 +0200) wrote:
With the previous Emacs tips example the kernel style was made available for files in the kernel-tree only. This patch updates the tip to add separate cc-mode indent style; it makes the kernel style easily available for any filetype mode that is managed by the Emacs cc-mode.
We also fix the filename regexp in the example: Elisp function buffer-file-name returns full pathname, not a path relative to user's home directory. Hence a tilde (~) can't be used to refer to home directory (as the previous code did).
Quoted 4 lines
Signed-off-by Teemu Likonen <[email protected]>--- Documentation/CodingStyle | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)
Exactly what I expected: nobody pays any attention. :-) Well, it's not a problem, I'm not even a kernel coder. I just happen to think that this patch introduces the right way to configure Emacs for kernel coding style. Adding a custom style like this ("linux-tabs-only") makes it much easier to switch between different indent styles and also to use the kernel style elsewhere.
So, I'll just ping the lists and maintainers this one more time to see if someone is interested. Here's my original message:
http://article.gmane.org/gmane.linux.documentation/442
Quoted 40 lines
Documentation/CodingStyle +13
-6@@ -483,20 +483,27 @@ values. To do the latter, you can stick the following in your .emacs file: (* (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 "~/src/linux-trees" filename)) + (string-match "src/linux-trees" 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)))))) + (c-set-style "linux-tabs-only"))))) This will make emacs go better with the kernel coding style for C -files below ~/src/linux-trees. +files which pathname matches src/linux-trees. But even if you fail in getting emacs to do sane formatting, not everything is lost: use "indent".Signature · 1 line
1.6.1.156.gb648d
Quoted 25 lines · Teemu Likonen
Quoted 10 lines · Teemu Likonen (2009-01-18 19:18 +0200) wrote:
With the previous Emacs tips example the kernel style was made available for files in the kernel-tree only. This patch updates the tip to add separate cc-mode indent style; it makes the kernel style easily available for any filetype mode that is managed by the Emacs cc-mode.
We also fix the filename regexp in the example: Elisp function buffer-file-name returns full pathname, not a path relative to user's home directory. Hence a tilde (~) can't be used to refer to home directory (as the previous code did).
Quoted 4 lines
Signed-off-by Teemu Likonen <[email protected]>--- Documentation/CodingStyle | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)Exactly what I expected: nobody pays any attention. :-) Well, it's not a problem, I'm not even a kernel coder. I just happen to think that this patch introduces the right way to configure Emacs for kernel coding style. Adding a custom style like this ("linux-tabs-only") makes it much easier to switch between different indent styles and also to use the kernel style elsewhere.
Quoted 5 lines
So, I'll just ping the lists and maintainers this one more time to see if someone is interested. Here's my original message:
OK, I see it. I'm not an emacs user and I have no idea how correct the patch is.
There is another emacs CodingStyle patch from Dan Carpenter that expands the "~" part of the filename to the user directory:
see http://lkml.org/lkml/2009/1/21/62
so I would be tempted to merge/apply both patches.
Any other comments on these patches?
Quoted 33 lines
Quoted 33 lines
Documentation/CodingStyle +12
-5@@ -483,20 +483,27 @@ values. To do the latter, you can stick the following in your .emacs file: (* (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 "~/src/linux-trees" filename)) + (string-match "src/linux-trees" 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)))))) + (c-set-style "linux-tabs-only")))))
Quoted 7 lines
Documentation/CodingStyle values. To do the latter, you can stick the following in your .emacs file: · line 509
Quoted 7 lines
Documentation/CodingStyle +1
-1This will make emacs go better with the kernel coding style for C -files below ~/src/linux-trees. +files which pathname matches src/linux-trees. But even if you fail in getting emacs to do sane formatting, not everything is lost: use "indent".
Thanks.
Signature · 1 line
~Randy
Teemu Likonen
Acked-byQuoted 6 lines · Randy Dunlap (2009-01-26 08:38 -0800) wrote:
Quoted 1 line · Teemu Likonen
OK, I see it. I'm not an emacs user and I have no idea how correct the patch is.
Quoted 7 lines
There is another emacs CodingStyle patch from Dan Carpenter that expands the "~" part of the filename to the user directory:
see http://lkml.org/lkml/2009/1/21/62so I would be tempted to merge/apply both patches.
Any other comments on these patches?
Ah, I definitely agree with Dan's change, so
for that.
When it's applied my patch will be simpler. I'll resubmit to make your life easier.
PATCH v2 1/1 Documentation: update CodingStyle tips for Emacs users
With the previous Emacs tips example the kernel style was made available for files in the kernel-tree only. This patch updates the tip to add a separate cc-mode indent style ("linux-tabs-only"). This makes it easy to switch between different indent styles and also makes the kernel style easily available for any filetype mode (c++, awk, ...) that is managed by the Emacs cc-mode.
--- Documentation/CodingStyle | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-)
Documentation/CodingStyle +11 -4
@@ -483,6 +483,16 @@ values. To do the latter, you can stick the following in your .emacs file: (* (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)))
@@ -490,10 +500,7 @@ values. To do the latter, you can stick the following in your .emacs file: (when (and filename (string-match "~/src/linux-trees" 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)))))) + (c-set-style "linux-tabs-only"))))) This will make emacs go better with the kernel coding style for C files below ~/src/linux-trees.
Signature · 1 line
1.6.1.1.223.gc30e5
Quoted 35 lines · Teemu Likonen
With the previous Emacs tips example the kernel style was made available for files in the kernel-tree only. This patch updates the tip to add a separate cc-mode indent style ("linux-tabs-only"). This makes it easy to switch between different indent styles and also makes the kernel style easily available for any filetype mode (c++, awk, ...) that is managed by the Emacs cc-mode.
Signed-off-by Teemu Likonen <[email protected]>--- Documentation/CodingStyle | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-)Documentation/CodingStyle +10
-0@@ -483,6 +483,16 @@ values. To do the latter, you can stick the following in your .emacs file: (* (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)))@@ -490,10 +500,7 @@ values. To do the latter, you can stick the following in your .emacs file: (when (and filename
Documentation/CodingStyle values. To do the latter, you can stick the following in your .emacs file: · line 506
Quoted 10 lines
Documentation/CodingStyle +1
-4(string-match "~/src/linux-trees" 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)))))) + (c-set-style "linux-tabs-only"))))) This will make emacs go better with the kernel coding style for C files below ~/src/linux-trees.
I don't see Dan's patch merged into this one... ?
Signature · 1 line
~Randy
Quoted 1 line · Randy Dunlap (2009-01-26 09:13 -0800) wrote:
I don't see Dan's patch merged into this one... ?
That's because it's not. :-) I thought that Dan's patch is already there somewhere queued for apply, and hence I removed from my patch the parts that touch those areas in the file.
How should we proceed? I can amend Dan's patch to mine but perhaps he wants to get credit for his idea.
Quoted 7 lines · Teemu Likonen
Quoted 1 line · Randy Dunlap (2009-01-26 09:13 -0800) wrote:
I don't see Dan's patch merged into this one... ?
That's because it's not. :-) I thought that Dan's patch is already there somewhere queued for apply, and hence I removed from my patch the parts that touch those areas in the file.
Now I get it.
Quoted 2 lines
How should we proceed? I can amend Dan's patch to mine but perhaps he wants to get credit for his idea.
Agreed. I'll merge them separately. Thanks.
Signature · 1 line
~Randy