diff options
author | Karl Heuer <kwzh@gnu.org> | 1997-06-21 00:35:11 +0000 |
---|---|---|
committer | Karl Heuer <kwzh@gnu.org> | 1997-06-21 00:35:11 +0000 |
commit | bb8143d9b8db2e808ea6688b4567e07afaced72c (patch) | |
tree | 6baedbd23ec5645c2102621464b0a99515cadf77 /lisp/tabify.el | |
parent | f4ce0bd71e4ddac1e5daf081785b67a8685d8fb4 (diff) | |
download | emacs-bb8143d9b8db2e808ea6688b4567e07afaced72c.tar.gz |
(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." (narrow-to-region (point-min) end) (goto-char start) (while (search-forward "\t" nil t) ; faster than re-search + (forward-char -1) (let ((tab-beg (point)) - (column (current-column)) - (indent-tabs-mode nil)) - (skip-chars-backward "\t" start) + (indent-tabs-mode nil) + column) + (skip-chars-forward "\t") + (setq column (current-column)) (delete-region tab-beg (point)) (indent-to column)))))) +(defvar tabify-regexp "[ \t][ \t]+" + "Regexp matching whitespace that tabify should consider. +Usually this will be \"[ \\t][ \\t]+\" to match two or more spaces or tabs. +\"^[ \\t]+\" is also useful, for tabifying only initial whitespace.") + ;;;###autoload (defun tabify (start end) "Convert multiple spaces in region to tabs when possible. @@ -64,7 +71,7 @@ The variable `tab-width' controls the spacing of tab stops." (beginning-of-line) (narrow-to-region (point) end) (goto-char start) - (while (re-search-forward "[ \t][ \t][ \t]*" nil t) + (while (re-search-forward tabify-regexp nil t) (let ((column (current-column)) (indent-tabs-mode t)) (delete-region (match-beginning 0) (point)) |