Annotation of 43BSD/contrib/emacs/lisp/tabify.el, revision 1.1.1.1

1.1       root        1: ;; Tab conversion commands for Emacs
                      2: ;; Copyright (C) 1985 Richard M. Stallman.
                      3: 
                      4: ;; This file is part of GNU Emacs.
                      5: 
                      6: ;; GNU Emacs is distributed in the hope that it will be useful,
                      7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      8: ;; accepts responsibility to anyone for the consequences of using it
                      9: ;; or for whether it serves any particular purpose or works at all,
                     10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     11: ;; License for full details.
                     12: 
                     13: ;; Everyone is granted permission to copy, modify and redistribute
                     14: ;; GNU Emacs, but only under the conditions described in the
                     15: ;; GNU Emacs General Public License.   A copy of this license is
                     16: ;; supposed to have been given to you along with GNU Emacs so you
                     17: ;; can know your rights and responsibilities.  It should be in a
                     18: ;; file named COPYING.  Among other things, the copyright notice
                     19: ;; and this notice must be preserved on all copies.
                     20: 
                     21: 
                     22: (defun untabify (start end)
                     23:   "Convert all tabs in region to multiple spaces, preserving columns.
                     24: The variable tab-width controls the action."
                     25:   (interactive "r")
                     26:   (save-excursion
                     27:     (save-restriction
                     28:       (narrow-to-region start end)
                     29:       (goto-char start)
                     30:       (while (search-forward "\t" nil t)       ; faster than re-search
                     31:        (let ((start (point))
                     32:              (column (current-column))
                     33:              (indent-tabs-mode nil))
                     34:          (skip-chars-backward "\t")
                     35:          (delete-region start (point))
                     36:          (indent-to column))))))
                     37: 
                     38: (defun tabify (start end)
                     39:   "Convert multiple spaces in region to tabs when possible.
                     40: A group of spaces is partially replaced by tabs
                     41: when this can be done without changing the column they end at.
                     42: The variable tab-width controls the action."
                     43:   (interactive "r")
                     44:   (save-excursion
                     45:     (save-restriction
                     46:       (narrow-to-region start end)
                     47:       (goto-char start)
                     48:       (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
                     49:        (let ((column (current-column))
                     50:              (indent-tabs-mode t))
                     51:          (delete-region (match-beginning 0) (point))
                     52:          (indent-to column))))))

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.