annotate lisp/prim/tabify.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 0132846995bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; tabify.el --- tab conversion commands for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Commands to optimize spaces to tabs or expand tabs to spaces in a region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; (`tabify' and `untabify'). The variable tab-width does the obvious.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun untabify (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Convert all tabs in region to multiple spaces, preserving columns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Called non-interactively, the region is specified by arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 START and END, rather than by the position of point and mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 The variable `tab-width' controls the spacing of tab stops."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (narrow-to-region (point-min) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (let ((percent 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (while (search-forward "\t" nil t) ; faster than re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (let ((tab-beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (column (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (indent-tabs-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (skip-chars-backward "\t" start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (delete-region tab-beg (point))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
51 ;; XEmacs change -- show progress
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (indent-to column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (message "untabify: %d%% ..." percent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (setq percent (+ 5 percent)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (message "untabify: done"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (defun tabify (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "Convert multiple spaces in region to tabs when possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 A group of spaces is partially replaced by tabs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 when this can be done without changing the column they end at.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Called non-interactively, the region is specified by arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 START and END, rather than by the position of point and mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 The variable `tab-width' controls the spacing of tab stops."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; Include the beginning of the line in the narrowing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; since otherwise it will throw off current-column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (narrow-to-region (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (let ((percent 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (let ((column (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (indent-tabs-mode t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (delete-region (match-beginning 0) (point))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
81 ;; XEmacs change -- show progress
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (indent-to column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (message "tabify: %d%% ..." percent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq percent (+ 5 percent)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (message "tabify: done"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (provide 'tabify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; tabify.el ends here