* [PATCH] Update emacs indentation instructions.
@ 2008-01-19 22:53 David Brown
2008-01-20 1:40 ` Johannes Weiner
0 siblings, 1 reply; 3+ messages in thread
From: David Brown @ 2008-01-19 22:53 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel, David Brown
For quite some time now, Emacs has supported multiple coding styles,
including one very close to the Linux style. Update the Emacs
configuration instructions in the documentation to reflect this.
Signed-off-by: David Brown <lkml@davidb.org>
---
Documentation/CodingStyle | 39 ++++++++++++++++++---------------------
1 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index b49b92e..4511b99 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -456,27 +456,24 @@ uses are less than desirable (in fact, they are worse than random
typing - an infinite number of monkeys typing into GNU emacs would never
make a good program).
-So, you can either get rid of GNU emacs, or change it to use saner
-values. To do the latter, you can stick the following in your .emacs file:
-
-(defun linux-c-mode ()
- "C mode with adjusted defaults for use with the Linux kernel."
- (interactive)
- (c-mode)
- (c-set-style "K&R")
- (setq tab-width 8)
- (setq indent-tabs-mode t)
- (setq c-basic-offset 8))
-
-This will define the M-x linux-c-mode command. When hacking on a
-module, if you put the string -*- linux-c -*- somewhere on the first
-two lines, this mode will be automatically invoked. Also, you may want
-to add
-
-(setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode)
- auto-mode-alist))
-
-to your .emacs file if you want to have linux-c-mode switched on
+Fortunately, modern versions of GNU emacs support different indentation
+styles. If you want to use the Linux kernel style for all C code, place
+the following in your .emacs file:
+
+(setq c-default-style "linux")
+
+If you only want to use Linux indenting on Linux source files, you can
+insert something like the following:
+
+(defun my-c-mode-hook ()
+ (c-set-style
+ (if (and (buffer-file-name)
+ (string-match "/usr/src/linux" (buffer-file-name)))
+ "linux"
+ "free-group-style")))
+(add-hook 'c-mode-hook 'my-c-mode-hook)
+
+to your .emacs file if you want to have linux style switched on
automagically when you edit source files under /usr/src/linux.
But even if you fail in getting emacs to do sane formatting, not
--
1.5.3.8
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Update emacs indentation instructions.
2008-01-19 22:53 [PATCH] Update emacs indentation instructions David Brown
@ 2008-01-20 1:40 ` Johannes Weiner
2008-01-20 4:53 ` David Brown
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Weiner @ 2008-01-20 1:40 UTC (permalink / raw)
To: David Brown; +Cc: Linus Torvalds, linux-kernel
Hi,
David Brown <lkml@davidb.org> writes:
> +Fortunately, modern versions of GNU emacs support different indentation
> +styles. If you want to use the Linux kernel style for all C code, place
> +the following in your .emacs file:
> +
> +(setq c-default-style "linux")
This variable is not defined when emacs starts up. Best is to always
use a hook.
So I'd suggest either
(add-hook 'c-mode-hook (lambda () (c-set-style "linux")))
or for the conditional case
(add-hook 'c-mode-hook
(lambda ()
(c-set-style
(or (and (string-match "/usr/src/linux"
(or (buffer-file-name) ""))
"linux")
"free-group-style"))))
Perhaps the logic could be a bit more readable :-)
Other than that, good idea to finally remove this ugly recommendation!
Hannes
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Update emacs indentation instructions.
2008-01-20 1:40 ` Johannes Weiner
@ 2008-01-20 4:53 ` David Brown
0 siblings, 0 replies; 3+ messages in thread
From: David Brown @ 2008-01-20 4:53 UTC (permalink / raw)
To: Johannes Weiner; +Cc: Linus Torvalds, linux-kernel
On Sun, Jan 20, 2008 at 02:40:29AM +0100, Johannes Weiner wrote:
>> +(setq c-default-style "linux")
>
>This variable is not defined when emacs starts up. Best is to always
>use a hook.
Both of these examples are directly copied out of the emacs manual.
Setting a variable before a module is loaded will override the default set
in the module. No need to use a hook for something simple like this.
c-default-style is defined with 'defcustom':
Declare SYMBOL as a customizable variable that defaults to VALUE.
DOC is the variable documentation.
Neither SYMBOL nor VALUE need to be quoted.
If SYMBOL is not already bound, initialize it to VALUE.
so the intent is to allow the user to override the value by setting it
before the module is loaded.
Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-01-20 5:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-19 22:53 [PATCH] Update emacs indentation instructions David Brown
2008-01-20 1:40 ` Johannes Weiner
2008-01-20 4:53 ` David Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).