Documentation/CodingStyle: Use directory-local variables for emacs
PATCH 1/1 Documentation/CodingStyle: Use directory-local variables for emacs
In emacs 23.1 support for directory-local variables was added (see also
https://lists.gnu.org/archive/html/info-gnu-emacs/2009-07/msg00000.html).
Simplify the settings in coding-style.rst by using that feature. Additionally, do not inherit any settings from emacs' linux coding style to minimize dependencies on the version of emacs that is being used.
I have verified with several large and nontrivial kernel source files that the new settings format code according to what checkpatch expects.
--- Documentation/process/coding-style.rst | 57 +++++++++++++++++--------- 1 file changed, 37 insertions(+), 20 deletions(-)
Changes compared to v1:
- Removed top-level .dir-locals.el file again and updated coding-style.rst instead.
- Restored the humourous paragraph about emacs.
- Left out Italian and Chinese translations.
Documentation/process/coding-style.rst +37 -20
@@ -592,26 +592,43 @@ 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 (expand-file-name "~/src/linux-trees") - filename)) - (setq indent-tabs-mode t) - (setq show-trailing-whitespace t) - (c-set-style "linux-tabs-only"))))) + (dir-locals-set-class-variables + 'linux-kernel + '((c-mode . ( + (c-basic-offset . 8) + (c-label-minimum-indentation . 0) + (c-offsets-alist . ( + (arglist-close . c-lineup-arglist-tabs-only) + (arglist-cont-nonempty . + (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only)) + (arglist-intro . +) + (brace-list-intro . +) + (c . c-lineup-C-comments) + (case-label . 0) + (comment-intro . c-lineup-comment) + (cpp-define-intro . +) + (cpp-macro . -1000) + (cpp-macro-cont . +) + (defun-block-intro . +) + (else-clause . 0) + (func-decl-cont . +) + (inclass . +) + (inher-cont . c-lineup-multi-inher) + (knr-argdecl-intro . 0) + (label . -1000) + (statement . 0) + (statement-block-intro . +) + (statement-case-intro . +) + (statement-cont . +) + (substatement . +) + )) + (indent-tabs-mode . t) + (show-trailing-whitespace . t) + )))) + + (dir-locals-set-directory-class + (expand-file-name "~/src/linux-trees") + 'linux-kernel) This will make emacs go better with the kernel coding style for C files below ``~/src/linux-trees``.
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH 1/1 Documentation/CodingStyle: Move emacs settings into .dir-locals.el
For new kernel developers who use emacs it is tedious to follow the instructions in Documentation/process/coding-style.rst for configuring emacs. Make it easier for emacs users by moving these settings into the top-level .dir-locals.el file. Emacs supports directory-local variables since version 23.1, released in 2009. See also
https://lists.gnu.org/archive/html/info-gnu-emacs/2009-07/msg00000.html
The settings in .dir-locals.el are not identical to those in Documentation/process/coding-style.rst. The most important difference is that "(arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only)" (which is not a valid alist) has been changed into "(arglist-cont-nonempty . c-lineup-arglist)". I have verified with several large and nontrivial kernel source files that the settings in .dir-locals.el format code according to what checkpatch expects.
The Italian and Chinese translations of the modified paragraphs have been generated by Google Translate.
--- .dir-locals.el | 41 +++++++++++++++ Documentation/process/coding-style.rst | 49 ++---------------- .../it_IT/process/coding-style.rst | 50 ++----------------- .../translations/zh_CN/coding-style.rst | 43 +--------------- 4 files changed, 53 insertions(+), 130 deletions(-) create mode 100644 .dir-locals.el
.dir-locals.el new file +41 -0
@@ -0,0 +1,41 @@ +;; Emacs settings for Linux kernel C code. + +( + (c-mode . ( + (c-basic-offset . 8) + (c-cleanup-list . (brace-else-brace)) + (c-hanging-braces-alist . ( + (arglist-cont-nonempty) + (block-close . c-snug-do-while) + (brace-entry-open) + (brace-list-open) + (substatement-open after) + )) + (c-label-minimum-indentation . 0) + (c-offsets-alist . ( + (arglist-cont-nonempty . c-lineup-arglist) + (arglist-intro . +) + (brace-list-intro . +) + (c . c-lineup-C-comments) + (case-label . 0) + (comment-intro . c-lineup-comment) + (cpp-define-intro . +) + (cpp-macro . -1000) + (cpp-macro-cont . +) + (defun-block-intro . +) + (else-clause . 0) + (func-decl-cont . +) + (inclass . +) + (inher-cont . c-lineup-multi-inher) + (knr-argdecl-intro . 0) + (label . 0) + (statement . 0) + (statement-block-intro . +) + (statement-case-intro . +) + (statement-cont . +) + (substatement . +) + )) + (indent-tabs-mode . t) + ) + ) +)
Documentation/process/coding-style.rst +5 -44
55 lines not on this page · raw message
Documentation/translations/it_IT/process/coding-style.rst +5 -45
56 lines not on this page · raw message
Documentation/translations/zh_CN/coding-style.rst +2 -41
49 lines not on this page · raw message
Signature · 1 line
2.20.1.415.g653613c723-goog
Re: [PATCH] Documentation/CodingStyle: Move emacs settings into .dir-locals.el
Quoted 3 lines · Bart Van Assche
For new kernel developers who use emacs it is tedious to follow the instructions in
Documentation/process/coding-style.rstfor configuring [... ]
Please ignore this patch - this is the old version (v1). The other patch, the one this is a reply to, is version 2.
Bart.
Federico Vaga
maintainerQuoted 17 lines · CET Bart Van Assche
In emacs 23.1 support for directory-local variables was added (see also
https://lists.gnu.org/archive/html/info-gnu-emacs/2009-07/msg00000.html).
Simplify the settings incoding-style.rstby using that feature. Additionally, do not inherit any settings from emacs' linux coding style to minimize dependencies on the version of emacs that is being used.I have verified with several large and nontrivial kernel source files that the new settings format code according to what checkpatch expects.
Signed-off-by Bart Van Assche <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Geyslan G. Bem <[email protected]>Cc Tiago Natel de Moura <[email protected]>Cc Alison Chaiken <[email protected]>Cc Joe Perches <[email protected]>Cc Federico Vaga <[email protected]>Cc Li Yang <[email protected]>
Quoted 8 lines
--- Documentation/process/coding-style.rst | 57 +++++++++++++++++--------- 1 file changed, 37 insertions(+), 20 deletions(-)Changes compared to v1:
- Removed top-level .dir-locals.el file again and updatedcoding-style.rstinstead. - Restored the humourous paragraph about emacs.
- Left out Italian and Chinese translations.
Since now there are only code changes, I think you can apply them on both Italian and Chinese translations.
As a general comment, I personally think that it worth to mention the fact that the user can take this code (actually part of it) and put it in a .dir- locals.el file in the top-level directory.
Quoted 69 lines
(quoted diff) +0
-0
b/Documentation/process/coding-style.rstindex277c113376a6..5013883aec8e100644Documentation/process/coding-style.rst +37
-19@@ -592,26 +592,43 @@ 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 (expand-file-name "~/src/linux-trees") - filename)) - (setq indent-tabs-mode t) - (setq show-trailing-whitespace t) - (c-set-style "linux-tabs-only"))))) + (dir-locals-set-class-variables + 'linux-kernel + '((c-mode . ( + (c-basic-offset . 8) + (c-label-minimum-indentation . 0) + (c-offsets-alist . ( + (arglist-close . c-lineup-arglist-tabs-only) + (arglist-cont-nonempty . + (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only)) + (arglist-intro . +) + (brace-list-intro . +) + (c . c-lineup-C-comments) + (case-label . 0) + (comment-intro . c-lineup-comment) + (cpp-define-intro . +) + (cpp-macro . -1000) + (cpp-macro-cont . +) + (defun-block-intro . +) + (else-clause . 0) + (func-decl-cont . +) + (inclass . +) + (inher-cont . c-lineup-multi-inher) + (knr-argdecl-intro . 0) + (label . -1000) + (statement . 0) + (statement-block-intro . +) + (statement-case-intro . +) + (statement-cont . +) + (substatement . +) + )) + (indent-tabs-mode . t) + (show-trailing-whitespace . t) + )))) + + (dir-locals-set-directory-class + (expand-file-name "~/src/linux-trees") + 'linux-kernel) This will make emacs go better with the kernel coding style for C files below ``~/src/linux-trees``.
Quoted 14 lines · Federico Vaga
Quoted 13 lines · CET Bart Van Assche
In emacs 23.1 support for directory-local variables was added (see also
https://lists.gnu.org/archive/html/info-gnu-emacs/2009-07/msg00000.html).
Simplify the settings incoding-style.rstby using that feature. Additionally, do not inherit any settings from emacs' linux coding style to minimize dependencies on the version of emacs that is being used.I have verified with several large and nontrivial kernel source files that the new settings format code according to what checkpatch expects.
Documentation/process/coding-style.rst|57 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+----------1 file changed, 37 insertions(+-), 20 deletions(-)
Quoted 7 lines
Quoted 4 lines
Changes compared to v1:
- Removed top-level .dir-locals.el file again and updatedcoding-style.rstinstead. - Restored the humourous paragraph about emacs.
- Left out Italian and Chinese translations.Since now there are only code changes, I think you can apply them on both Italian and Chinese translations.
Good point.
Quoted 3 lines
As a general comment, I personally think that it worth to mention the fact that the user can take this code (actually part of it) and put it in a .dir- locals.el file in the top-level directory.
I'm not sure we should recommend this. Settings in ~/.emacs are not affected by git clean -f -x but .dir-locals.el is removed by that command.
Thanks,
Bart.
Quoted 6 lines · Bart Van Assche
Quoted 3 lines
As a general comment, I personally think that it worth to mention the fact that the user can take this code (actually part of it) and put it in a .dir- locals.el file in the top-level directory.
I'm not sure we should recommend this. Settings in ~/.emacs are not affected by git clean -f -x but .dir-locals.el is removed by that command.
Why not add the file to .gitignore, possibly in a separate patch?
-- Alison
---
Alison Chaiken [email protected]
http://she-devel.com
The real trolley problem is that trolleys are underfunded. -- Alex Roy
Quoted 9 lines · Alison Chaiken
Quoted 6 lines · Bart Van Assche
Quoted 3 lines
As a general comment, I personally think that it worth to mention the fact that the user can take this code (actually part of it) and put it in a .dir- locals.el file in the top-level directory.
I'm not sure we should recommend this. Settings in ~/.emacs are not affected by git clean -f -x but .dir-locals.el is removed by that command.
Why not add the file to .gitignore, possibly in a separate patch?
Hi Alison,
I think that git clean -f -x also removes files specified in .gitignore. From the git-clean man page:
-x
Don't use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.
Bart.