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.
21 (defun untabify (start end
)
22 "Convert all tabs in region to multiple spaces, preserving columns.
23 The variable tab-width controls the action."
27 (narrow-to-region start end
)
29 (while (search-forward "\t" nil t
) ; faster than re-search
31 (column (current-column))
32 (indent-tabs-mode nil
))
33 (skip-chars-backward "\t")
34 (delete-region start
(point))
35 (indent-to column
))))))
37 (defun tabify (start end
)
38 "Convert multiple spaces in region to tabs when possible.
39 A group of spaces is partially replaced by tabs
40 when this can be done without changing the column they end at.
41 The variable tab-width controls the action."
45 (narrow-to-region start end
)
47 (while (re-search-forward "[ \t][ \t][ \t]*" nil t
)
48 (let ((column (current-column))
50 (delete-region (match-beginning 0) (point))
51 (indent-to column
))))))