From: Gareth H. <ga...@va...> - 2001-03-04 06:47:19
|
Keith Whitwell wrote: > > Brian Paul wrote: > > > > > Log message: > > used indent to clean-up the code > > Hooray! Speaking of whitespace cleanups, I like having this in my .emacs file: (defun gth-rm-trailing-spaces () "Remove trailing whitespace from all lines in the current buffer." (interactive) (if (or (eq major-mode 'c-mode) (eq major-mode 'asm-mode) (eq major-mode 'makefile-mode)) (progn (message "removing trailing whitespace...") (save-excursion (goto-char (point-min)) (while (re-search-forward "[ \t]+$" nil t) (delete-region (match-beginning 0) (save-excursion (end-of-line) (point)))))))) (defun gth-rm-trailing-blank-lines () "Remove trailing blank lines from the current buffer." (interactive) (if (or (eq major-mode 'c-mode) (eq major-mode 'asm-mode) (eq major-mode 'makefile-mode)) (progn (message "removing extra lines at end of file...") (save-excursion (goto-char (point-max)) (while (and (eq 0 (forward-line -1)) (looking-at "^[ \t]*$"))) (delete-matching-lines "^[ \t]*$"))))) (add-hook 'write-file-hooks 'gth-rm-trailing-spaces) (add-hook 'write-file-hooks 'gth-rm-trailing-blank-lines) Every time you save, it strips trailing whitespace and trailing blank lines from the file. -- Gareth |