Mercurial > hg > xemacs-beta
comparison lisp/prim/tabify.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Synched up with: FSF 19.30. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Commands to optimize spaces to tabs or expand tabs to spaces in a region | |
28 ;; (`tabify' and `untabify'). The variable tab-width does the obvious. | |
29 | |
30 ;;; Code: | |
31 | |
32 ;;;###autoload | |
33 (defun untabify (start end) | |
34 "Convert all tabs in region to multiple spaces, preserving columns. | |
35 Called non-interactively, the region is specified by arguments | |
36 START and END, rather than by the position of point and mark. | |
37 The variable `tab-width' controls the spacing of tab stops." | |
38 (interactive "r") | |
39 (save-excursion | |
40 (save-restriction | |
41 (narrow-to-region (point-min) end) | |
42 (goto-char start) | |
43 (let ((percent 5)) | |
44 (while (search-forward "\t" nil t) ; faster than re-search | |
45 (let ((tab-beg (point)) | |
46 (column (current-column)) | |
47 (indent-tabs-mode nil)) | |
48 (skip-chars-backward "\t" start) | |
49 (delete-region tab-beg (point)) | |
50 (indent-to column) | |
51 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent) | |
52 (progn | |
53 (message "untabify: %d%% ..." percent) | |
54 (setq percent (+ 5 percent))))))) | |
55 (message "untabify: done")))) | |
56 | |
57 ;;;###autoload | |
58 (defun tabify (start end) | |
59 "Convert multiple spaces in region to tabs when possible. | |
60 A group of spaces is partially replaced by tabs | |
61 when this can be done without changing the column they end at. | |
62 Called non-interactively, the region is specified by arguments | |
63 START and END, rather than by the position of point and mark. | |
64 The variable `tab-width' controls the spacing of tab stops." | |
65 (interactive "r") | |
66 (save-excursion | |
67 (save-restriction | |
68 ;; Include the beginning of the line in the narrowing | |
69 ;; since otherwise it will throw off current-column. | |
70 (goto-char start) | |
71 (beginning-of-line) | |
72 (narrow-to-region (point) end) | |
73 (goto-char start) | |
74 (let ((percent 5)) | |
75 (while (re-search-forward "[ \t][ \t][ \t]*" nil t) | |
76 (let ((column (current-column)) | |
77 (indent-tabs-mode t)) | |
78 (delete-region (match-beginning 0) (point)) | |
79 (indent-to column) | |
80 (if (> (/ (* 100 (- (point) start)) (- (point-max) start)) percent) | |
81 (progn | |
82 (message "tabify: %d%% ..." percent) | |
83 (setq percent (+ 5 percent))))))) | |
84 (message "tabify: done")))) | |
85 | |
86 (provide 'tabify) | |
87 | |
88 ;;; tabify.el ends here |