Commit 2fec7b33 authored by Bart Van Assche's avatar Bart Van Assche Committed by Jonathan Corbet

Documentation/CodingStyle: Use directory-local variables for emacs settings

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.
Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Alison Chaiken <alison@she-devel.com>
Cc: Joe Perches <joe@perches.com>
Cc: Federico Vaga <federico.vaga@vaga.pv.it>
Cc: Geyslan G. Bem <geyslan@gmail.com>
Cc: Tiago Natel de Moura <tiago4orion@gmail.com>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent d96bedb2
...@@ -595,26 +595,43 @@ values. To do the latter, you can stick the following in your .emacs file: ...@@ -595,26 +595,43 @@ values. To do the latter, you can stick the following in your .emacs file:
(* (max steps 1) (* (max steps 1)
c-basic-offset))) c-basic-offset)))
(add-hook 'c-mode-common-hook (dir-locals-set-class-variables
(lambda () 'linux-kernel
;; Add kernel style '((c-mode . (
(c-add-style (c-basic-offset . 8)
"linux-tabs-only" (c-label-minimum-indentation . 0)
'("linux" (c-offsets-alist (c-offsets-alist . (
(arglist-cont-nonempty (arglist-close . c-lineup-arglist-tabs-only)
c-lineup-gcc-asm-reg (arglist-cont-nonempty .
c-lineup-arglist-tabs-only)))))) (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only))
(arglist-intro . +)
(add-hook 'c-mode-hook (brace-list-intro . +)
(lambda () (c . c-lineup-C-comments)
(let ((filename (buffer-file-name))) (case-label . 0)
;; Enable kernel mode for the appropriate files (comment-intro . c-lineup-comment)
(when (and filename (cpp-define-intro . +)
(string-match (expand-file-name "~/src/linux-trees") (cpp-macro . -1000)
filename)) (cpp-macro-cont . +)
(setq indent-tabs-mode t) (defun-block-intro . +)
(setq show-trailing-whitespace t) (else-clause . 0)
(c-set-style "linux-tabs-only"))))) (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 This will make emacs go better with the kernel coding style for C
files below ``~/src/linux-trees``. files below ``~/src/linux-trees``.
......
...@@ -600,26 +600,43 @@ segue nel vostro file .emacs: ...@@ -600,26 +600,43 @@ segue nel vostro file .emacs:
(* (max steps 1) (* (max steps 1)
c-basic-offset))) c-basic-offset)))
(add-hook 'c-mode-common-hook (dir-locals-set-class-variables
(lambda () 'linux-kernel
;; Add kernel style '((c-mode . (
(c-add-style (c-basic-offset . 8)
"linux-tabs-only" (c-label-minimum-indentation . 0)
'("linux" (c-offsets-alist (c-offsets-alist . (
(arglist-cont-nonempty (arglist-close . c-lineup-arglist-tabs-only)
c-lineup-gcc-asm-reg (arglist-cont-nonempty .
c-lineup-arglist-tabs-only)))))) (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only))
(arglist-intro . +)
(add-hook 'c-mode-hook (brace-list-intro . +)
(lambda () (c . c-lineup-C-comments)
(let ((filename (buffer-file-name))) (case-label . 0)
;; Enable kernel mode for the appropriate files (comment-intro . c-lineup-comment)
(when (and filename (cpp-define-intro . +)
(string-match (expand-file-name "~/src/linux-trees") (cpp-macro . -1000)
filename)) (cpp-macro-cont . +)
(setq indent-tabs-mode t) (defun-block-intro . +)
(setq show-trailing-whitespace t) (else-clause . 0)
(c-set-style "linux-tabs-only"))))) (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)
Questo farà funzionare meglio emacs con lo stile del kernel per i file che Questo farà funzionare meglio emacs con lo stile del kernel per i file che
si trovano nella cartella ``~/src/linux-trees``. si trovano nella cartella ``~/src/linux-trees``.
......
...@@ -535,26 +535,43 @@ Documentation/doc-guide/ 和 scripts/kernel-doc 以获得详细信息。 ...@@ -535,26 +535,43 @@ Documentation/doc-guide/ 和 scripts/kernel-doc 以获得详细信息。
(* (max steps 1) (* (max steps 1)
c-basic-offset))) c-basic-offset)))
(add-hook 'c-mode-common-hook (dir-locals-set-class-variables
(lambda () 'linux-kernel
;; Add kernel style '((c-mode . (
(c-add-style (c-basic-offset . 8)
"linux-tabs-only" (c-label-minimum-indentation . 0)
'("linux" (c-offsets-alist (c-offsets-alist . (
(arglist-cont-nonempty (arglist-close . c-lineup-arglist-tabs-only)
c-lineup-gcc-asm-reg (arglist-cont-nonempty .
c-lineup-arglist-tabs-only)))))) (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only))
(arglist-intro . +)
(add-hook 'c-mode-hook (brace-list-intro . +)
(lambda () (c . c-lineup-C-comments)
(let ((filename (buffer-file-name))) (case-label . 0)
;; Enable kernel mode for the appropriate files (comment-intro . c-lineup-comment)
(when (and filename (cpp-define-intro . +)
(string-match (expand-file-name "~/src/linux-trees") (cpp-macro . -1000)
filename)) (cpp-macro-cont . +)
(setq indent-tabs-mode t) (defun-block-intro . +)
(setq show-trailing-whitespace t) (else-clause . 0)
(c-set-style "linux-tabs-only"))))) (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)
这会让 emacs 在 ``~/src/linux-trees`` 下的 C 源文件获得更好的内核代码风格。 这会让 emacs 在 ``~/src/linux-trees`` 下的 C 源文件获得更好的内核代码风格。
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment