diff options
| author | Karl Heuer | 1997-06-21 00:35:11 +0000 |
|---|---|---|
| committer | Karl Heuer | 1997-06-21 00:35:11 +0000 |
| commit | bb8143d9b8db2e808ea6688b4567e07afaced72c (patch) | |
| tree | 6baedbd23ec5645c2102621464b0a99515cadf77 /lisp/tabify.el | |
| parent | f4ce0bd71e4ddac1e5daf081785b67a8685d8fb4 (diff) | |
| download | emacs-bb8143d9b8db2e808ea6688b4567e07afaced72c.tar.gz emacs-bb8143d9b8db2e808ea6688b4567e07afaced72c.zip | |
(untabify): Handle consecutive tabs all at once.
(tabify-regexp): New var.
(tabify): Use it.
Diffstat (limited to 'lisp/tabify.el')
| -rw-r--r-- | lisp/tabify.el | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lisp/tabify.el b/lisp/tabify.el index c5d76fcc211..971e1715eea 100644 --- a/lisp/tabify.el +++ b/lisp/tabify.el | |||
| @@ -40,13 +40,20 @@ The variable `tab-width' controls the spacing of tab stops." | |||
| 40 | (narrow-to-region (point-min) end) | 40 | (narrow-to-region (point-min) end) |
| 41 | (goto-char start) | 41 | (goto-char start) |
| 42 | (while (search-forward "\t" nil t) ; faster than re-search | 42 | (while (search-forward "\t" nil t) ; faster than re-search |
| 43 | (forward-char -1) | ||
| 43 | (let ((tab-beg (point)) | 44 | (let ((tab-beg (point)) |
| 44 | (column (current-column)) | 45 | (indent-tabs-mode nil) |
| 45 | (indent-tabs-mode nil)) | 46 | column) |
| 46 | (skip-chars-backward "\t" start) | 47 | (skip-chars-forward "\t") |
| 48 | (setq column (current-column)) | ||
| 47 | (delete-region tab-beg (point)) | 49 | (delete-region tab-beg (point)) |
| 48 | (indent-to column)))))) | 50 | (indent-to column)))))) |
| 49 | 51 | ||
| 52 | (defvar tabify-regexp "[ \t][ \t]+" | ||
| 53 | "Regexp matching whitespace that tabify should consider. | ||
| 54 | Usually this will be \"[ \\t][ \\t]+\" to match two or more spaces or tabs. | ||
| 55 | \"^[ \\t]+\" is also useful, for tabifying only initial whitespace.") | ||
| 56 | |||
| 50 | ;;;###autoload | 57 | ;;;###autoload |
| 51 | (defun tabify (start end) | 58 | (defun tabify (start end) |
| 52 | "Convert multiple spaces in region to tabs when possible. | 59 | "Convert multiple spaces in region to tabs when possible. |
| @@ -64,7 +71,7 @@ The variable `tab-width' controls the spacing of tab stops." | |||
| 64 | (beginning-of-line) | 71 | (beginning-of-line) |
| 65 | (narrow-to-region (point) end) | 72 | (narrow-to-region (point) end) |
| 66 | (goto-char start) | 73 | (goto-char start) |
| 67 | (while (re-search-forward "[ \t][ \t][ \t]*" nil t) | 74 | (while (re-search-forward tabify-regexp nil t) |
| 68 | (let ((column (current-column)) | 75 | (let ((column (current-column)) |
| 69 | (indent-tabs-mode t)) | 76 | (indent-tabs-mode t)) |
| 70 | (delete-region (match-beginning 0) (point)) | 77 | (delete-region (match-beginning 0) (point)) |