untabify-file.el
1 ;;; untabify-file.el --- automatic untabify files before save 2 3 ;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com> 4 5 ;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>, 6 7 ;; Keywords: ruby rails languages oop 8 ;; $URL: svn+ssh://rubyforge/var/svn/emacs-rails/trunk/rails.el $ 9 ;; $Id: rails.el 149 2007-03-29 15:07:49Z dimaexe $ 10 11 ;;; License 12 13 ;; This program is free software; you can redistribute it and/or 14 ;; modify it under the terms of the GNU General Public License 15 ;; as published by the Free Software Foundation; either version 2 16 ;; of the License, or (at your option) any later version. 17 18 ;; This program is distributed in the hope that it will be useful, 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 ;; GNU General Public License for more details. 22 23 ;; You should have received a copy of the GNU General Public License 24 ;; along with this program; if not, write to the Free Software 25 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 27 ;;; Code: 28 29 (require 'cl) 30 (require 'custom) 31 32 (defcustom untabify-exclude-list 33 '(makefile-mode 34 makefile-bsdmake-mode 35 change-log-mode 36 "Makefile$") 37 "List of regexp or modes to which is not applied untabify." 38 :group 'untabify) 39 40 (defun untabify-before-write () 41 "Strip all trailing whitespaces and untabify buffer before 42 save." 43 (when (and (eq this-command 'save-buffer) 44 (not (find nil 45 untabify-exclude-list 46 :if #'(lambda (r) 47 (typecase r 48 (string (string-match r (buffer-name))) 49 (symbol (eq major-mode r))))))) 50 (save-excursion 51 (untabify (point-min) (point-max)) 52 (delete-trailing-whitespace)))) 53 54 ;(add-hook 'write-file-hooks 'untabify-before-write) 55 56 (provide 'untabify-file)