[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs kernel hacking: rm trailing ws
After reading wli on the LKML mention that emacs users leave trailing
whitespace in their files, I added this to my .emacs file.
It makes sure that when I am working on kernel sources and I save a
buffer, any trailing whitespace is removed. The rest of it is based
on Linus' advice in Documentation/CodingStyle.
(require 'cl)
(defun elc-delete-buffer-trailing-ws ()
"get rid of trailing whitespace in all lines in current buffer"
(interactive)
(message "deleting trailing whitespace!")
(save-excursion
(goto-char (point-min))
(end-of-line)
(delete-horizontal-space)
(labels ((rec ()
(let ((inhibit-field-text-motion t))
(end-of-line 2))
(delete-horizontal-space)
(if (/= (point) (point-max))
(rec))))
(rec))))
(defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel."
(interactive)
(add-hook 'local-write-file-hooks
'elc-delete-buffer-trailing-ws)
(c-mode)
(c-set-style "K&R")
(setq c-basic-offset 8))
(add-to-list 'auto-mode-alist
'("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode))
(add-to-list 'auto-mode-alist
'(".*/kernel/linux-.*/.*\\.[ch]$" . linux-c-mode))
--
--Ed L Cashin PGP public key: http://noserose.net/e/pgp/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/