1 ;; Tab conversion commands for Emacs
2 ;; Copyright (C) 1985 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 (defun untabify (start end
)
23 "Convert all tabs in region to multiple spaces, preserving columns.
24 The variable tab-width controls the action."
28 (narrow-to-region start end
)
30 (while (search-forward "\t" nil t
) ; faster than re-search
32 (column (current-column))
33 (indent-tabs-mode nil
))
34 (skip-chars-backward "\t")
35 (delete-region start
(point))
36 (indent-to column
))))))
39 (defun tabify (start end
)
40 "Convert multiple spaces in region to tabs when possible.
41 A group of spaces is partially replaced by tabs
42 when this can be done without changing the column they end at.
43 The variable tab-width controls the action."
47 (narrow-to-region start end
)
49 (while (re-search-forward "[ \t][ \t][ \t]*" nil t
)
50 (let ((column (current-column))
52 (delete-region (match-beginning 0) (point))
53 (indent-to column
))))))