1*7f2fe78bSCy Schubert;;; -*- mode: emacs-lisp; indent-tabs-mode: nil -*- 2*7f2fe78bSCy Schubert(if (not noninteractive) 3*7f2fe78bSCy Schubert (error "to be used only with -batch")) 4*7f2fe78bSCy Schubert;; Avoid vc-mode interference. 5*7f2fe78bSCy Schubert(setq vc-handled-backends nil) 6*7f2fe78bSCy Schubert 7*7f2fe78bSCy Schubert;; for debugging 8*7f2fe78bSCy Schubert(defun report-tabs () 9*7f2fe78bSCy Schubert (let ((tab-found (search-forward "\t" nil t))) 10*7f2fe78bSCy Schubert (if tab-found 11*7f2fe78bSCy Schubert (message "Tab found @%s." tab-found) 12*7f2fe78bSCy Schubert (message "No tabs found.")))) 13*7f2fe78bSCy Schubert 14*7f2fe78bSCy Schubert(defun whitespace-new () 15*7f2fe78bSCy Schubert ;; Sometimes whitespace-cleanup gets its internals confused 16*7f2fe78bSCy Schubert ;; when whitespace-mode hasn't been activated on the buffer. 17*7f2fe78bSCy Schubert (let ((whitespace-indent-tabs-mode indent-tabs-mode) 18*7f2fe78bSCy Schubert (whitespace-style '(empty trailing))) 19*7f2fe78bSCy Schubert ;; Only clean up tab issues if indent-tabs-mode is explicitly 20*7f2fe78bSCy Schubert ;; set in the file local variables. 21*7f2fe78bSCy Schubert (if (local-variable-p 'indent-tabs-mode) 22*7f2fe78bSCy Schubert (progn 23*7f2fe78bSCy Schubert (message "Enabling tab cleanups.") 24*7f2fe78bSCy Schubert (add-to-list 'whitespace-style 'indentation) 25*7f2fe78bSCy Schubert (add-to-list 'whitespace-style 'space-before-tab) 26*7f2fe78bSCy Schubert (add-to-list 'whitespace-style 'space-after-tab))) 27*7f2fe78bSCy Schubert;; (message "indent-tabs-mode=%s" indent-tabs-mode) 28*7f2fe78bSCy Schubert (message "Cleaning whitespace...") 29*7f2fe78bSCy Schubert (whitespace-cleanup))) 30*7f2fe78bSCy Schubert 31*7f2fe78bSCy Schubert;; Old style whitespace.el uses different variables. 32*7f2fe78bSCy Schubert(defun whitespace-old () 33*7f2fe78bSCy Schubert (let (whitespace-check-buffer-indent 34*7f2fe78bSCy Schubert whitespace-check-buffer-spacetab) 35*7f2fe78bSCy Schubert (if (local-variable-p 'indent-tabs-mode) 36*7f2fe78bSCy Schubert (progn 37*7f2fe78bSCy Schubert (message "Enabling tab cleanups.") 38*7f2fe78bSCy Schubert (setq whitespace-check-buffer-indent indent-tabs-mode) 39*7f2fe78bSCy Schubert (setq whitespace-check-buffer-spacetab t))) 40*7f2fe78bSCy Schubert (message "Cleaning whitespace...") 41*7f2fe78bSCy Schubert (whitespace-cleanup))) 42*7f2fe78bSCy Schubert 43*7f2fe78bSCy Schubert(while command-line-args-left 44*7f2fe78bSCy Schubert (let ((filename (car command-line-args-left)) 45*7f2fe78bSCy Schubert ;; No backup files; we have version control. 46*7f2fe78bSCy Schubert (make-backup-files nil)) 47*7f2fe78bSCy Schubert (find-file filename) 48*7f2fe78bSCy Schubert (message "Read %s." filename) 49*7f2fe78bSCy Schubert 50*7f2fe78bSCy Schubert (if (not indent-tabs-mode) 51*7f2fe78bSCy Schubert (progn 52*7f2fe78bSCy Schubert (message "Untabifying...") 53*7f2fe78bSCy Schubert (untabify (point-min) (point-max)))) 54*7f2fe78bSCy Schubert 55*7f2fe78bSCy Schubert ;; Only reindent if the file C style is guessed to be "krb5". 56*7f2fe78bSCy Schubert ;; Note that krb5-c-style.el already has a heuristic for setting 57*7f2fe78bSCy Schubert ;; the C style if the file has "c-basic-offset: 4; 58*7f2fe78bSCy Schubert ;; indent-tabs-mode: nil". 59*7f2fe78bSCy Schubert (if (equal c-indentation-style "krb5") 60*7f2fe78bSCy Schubert (c-indent-region (point-min) (point-max))) 61*7f2fe78bSCy Schubert 62*7f2fe78bSCy Schubert (if (fboundp 'whitespace-newline-mode) 63*7f2fe78bSCy Schubert (whitespace-new) 64*7f2fe78bSCy Schubert (whitespace-old)) 65*7f2fe78bSCy Schubert 66*7f2fe78bSCy Schubert (save-buffer) 67*7f2fe78bSCy Schubert (kill-buffer nil) 68*7f2fe78bSCy Schubert (setq command-line-args-left (cdr command-line-args-left)))) 69