(compute_char_face): Don't use NULL.
[bpt/emacs.git] / lisp / tabify.el
CommitLineData
c88ab9ce
ER
1;;; tabify.el --- tab conversion commands for Emacs
2
040d52ec 3;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
a2535589 4
58142744
ER
5;; Maintainer: FSF
6
a2535589
JA
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software; you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
e5167999 11;; the Free Software Foundation; either version 2, or (at your option)
a2535589
JA
12;; any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs; see the file COPYING. If not, write to
21;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
d9ecc911
ER
23;;; Commentary:
24
25;; Commands to optimize spaces to tabs or expand tabs to spaces in a region
26;; (`tabify' and `untabify'). The variable tab-width does the obvious.
27
22a89ee8 28;;; Code:
a2535589 29
f9f9507e 30;;;###autoload
a2535589
JA
31(defun untabify (start end)
32 "Convert all tabs in region to multiple spaces, preserving columns.
e47b2570
RS
33Called non-interactively, the region is specified by arguments
34START and END, rather than by the position of point and mark.
35The variable `tab-width' controls the spacing of tab stops."
a2535589
JA
36 (interactive "r")
37 (save-excursion
38 (save-restriction
5119b412 39 (narrow-to-region (point-min) end)
a2535589
JA
40 (goto-char start)
41 (while (search-forward "\t" nil t) ; faster than re-search
2d8e81a5 42 (let ((tab-beg (point))
a2535589
JA
43 (column (current-column))
44 (indent-tabs-mode nil))
2d8e81a5
RS
45 (skip-chars-backward "\t" start)
46 (delete-region tab-beg (point))
a2535589
JA
47 (indent-to column))))))
48
f9f9507e 49;;;###autoload
a2535589
JA
50(defun tabify (start end)
51 "Convert multiple spaces in region to tabs when possible.
52A group of spaces is partially replaced by tabs
53when this can be done without changing the column they end at.
e47b2570
RS
54Called non-interactively, the region is specified by arguments
55START and END, rather than by the position of point and mark.
56The variable `tab-width' controls the spacing of tab stops."
a2535589
JA
57 (interactive "r")
58 (save-excursion
59 (save-restriction
60 (narrow-to-region start end)
61 (goto-char start)
62 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
63 (let ((column (current-column))
64 (indent-tabs-mode t))
65 (delete-region (match-beginning 0) (point))
66 (indent-to column))))))
c88ab9ce 67
85588571
RS
68(provide 'tabify)
69
c88ab9ce 70;;; tabify.el ends here