0
|
1 ;;; tabify.el --- tab conversion commands for XEmacs
|
|
2
|
|
3 ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
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)
|
|
12 ;; any later version.
|
|
13
|
|
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.
|
|
18
|
|
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
|
2
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
0
|
23
|
2
|
24 ;;; Synched up with: FSF 19.34.
|
0
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
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.
|
|
30
|
|
31 ;;; Code:
|
|
32
|
|
33 ;;;###autoload
|
|
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."
|
|
39 (interactive "r")
|
|
40 (save-excursion
|
|
41 (save-restriction
|
|
42 (narrow-to-region (point-min) end)
|
|
43 (goto-char start)
|
|
44 (let ((percent 5))
|
|
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))
|
2
|
51 ;; XEmacs change -- show progress
|
0
|
52 (indent-to column)
|
|
53 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent)
|
|
54 (progn
|
|
55 (message "untabify: %d%% ..." percent)
|
|
56 (setq percent (+ 5 percent)))))))
|
|
57 (message "untabify: done"))))
|
|
58
|
|
59 ;;;###autoload
|
|
60 (defun tabify (start end)
|
|
61 "Convert multiple spaces in region to tabs when possible.
|
|
62 A group of spaces is partially replaced by tabs
|
|
63 when this can be done without changing the column they end at.
|
|
64 Called non-interactively, the region is specified by arguments
|
|
65 START and END, rather than by the position of point and mark.
|
|
66 The variable `tab-width' controls the spacing of tab stops."
|
|
67 (interactive "r")
|
|
68 (save-excursion
|
|
69 (save-restriction
|
|
70 ;; Include the beginning of the line in the narrowing
|
|
71 ;; since otherwise it will throw off current-column.
|
|
72 (goto-char start)
|
|
73 (beginning-of-line)
|
|
74 (narrow-to-region (point) end)
|
|
75 (goto-char start)
|
|
76 (let ((percent 5))
|
|
77 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
|
|
78 (let ((column (current-column))
|
|
79 (indent-tabs-mode t))
|
|
80 (delete-region (match-beginning 0) (point))
|
2
|
81 ;; XEmacs change -- show progress
|
0
|
82 (indent-to column)
|
|
83 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent)
|
|
84 (progn
|
|
85 (message "tabify: %d%% ..." percent)
|
|
86 (setq percent (+ 5 percent)))))))
|
|
87 (message "tabify: done"))))
|
|
88
|
|
89 (provide 'tabify)
|
|
90
|
|
91 ;;; tabify.el ends here
|