1 ;;; tabify.el --- tab conversion commands for XEmacs
3 ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
7 ;; This file is part of XEmacs.
9 ;; XEmacs is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; XEmacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ;;; Synched up with: FSF 19.34.
28 ;; Commands to optimize spaces to tabs or expand tabs to spaces in a region
29 ;; (`tabify' and `untabify'). The variable tab-width does the obvious.
34 (defun untabify (start end)
35 "Convert all tabs in region to multiple spaces, preserving columns.
36 Called non-interactively, the region is specified by arguments
37 START and END, rather than by the position of point and mark.
38 The variable `tab-width' controls the spacing of tab stops."
42 (narrow-to-region (point-min) end)
45 (while (search-forward "\t" nil t) ; faster than re-search
46 (let ((tab-beg (point))
47 (column (current-column))
48 (indent-tabs-mode nil))
49 (skip-chars-backward "\t" start)
50 (delete-region tab-beg (point))
51 ;; XEmacs change -- show progress
53 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent)
55 (message "untabify: %d%% ..." percent)
56 (setq percent (+ 5 percent)))))))
57 (message "untabify: done")))
61 (defun tabify (start end)
62 "Convert multiple spaces in region to tabs when possible.
63 A group of spaces is partially replaced by tabs
64 when this can be done without changing the column they end at.
65 Called non-interactively, the region is specified by arguments
66 START and END, rather than by the position of point and mark.
67 The variable `tab-width' controls the spacing of tab stops."
71 ;; Include the beginning of the line in the narrowing
72 ;; since otherwise it will throw off current-column.
75 (narrow-to-region (point) end)
78 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
79 (let ((column (current-column))
81 (delete-region (match-beginning 0) (point))
82 ;; XEmacs change -- show progress
84 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent)
86 (message "tabify: %d%% ..." percent)
87 (setq percent (+ 5 percent)))))))
88 (message "tabify: done"))))
92 ;;; tabify.el ends here