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