summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Lohmar <i.lohmar@gmail.com>2015-12-12 12:20:00 +0100
committerIngo Lohmar <i.lohmar@gmail.com>2015-12-12 12:22:00 +0100
commit404e70e75a82d7035e701b0f803cb232f1d862d3 (patch)
tree642860f5839c70f77ef18eef583fa8f02869b900
parenta998a23ee8713808ac1fe3d1523ea1861be4da57 (diff)
Tabify indentation for non-nil indent-tabs-mode
When indent-tabs-mode is t, replace spaces in the indentation by tabs, just as we do the opposite when the mode is nil.
-rw-r--r--ws-butler.el19
1 files changed, 12 insertions, 7 deletions
diff --git a/ws-butler.el b/ws-butler.el
index 93f5252..900af1e 100644
--- a/ws-butler.el
+++ b/ws-butler.el
@@ -133,20 +133,25 @@ Also see `require-final-newline'."
(defun ws-butler-clean-region (beg end)
"Delete trailing blanks in region BEG END.
-If `indent-tabs-mode' is nil, then tabs in indentation is
-replaced by spaces."
+If `indent-tabs-mode' is nil, then tabs in indentation are
+replaced by spaces, and vice versa if t."
(interactive "*r")
(ws-butler-with-save
(narrow-to-region beg end)
;; _much slower would be: (replace-regexp "[ \t]+$" "")
(goto-char (point-min))
(while (not (eobp))
- ;; convert leading tabs to spaces
- (unless indent-tabs-mode
- (let ((eol (point-at-eol)))
- (skip-chars-forward " " (point-at-eol))
+ ;; convert leading tabs to spaces or v.v.
+ (let ((eol (point-at-eol)))
+ (if indent-tabs-mode
+ (progn
+ (skip-chars-forward "\t" eol)
+ (when (eq (char-after) ?\ )
+ (tabify (point) (progn (skip-chars-forward " \t" eol)
+ (point)))))
+ (skip-chars-forward " " eol)
(when (eq (char-after) ?\t )
- (untabify (point) (progn (skip-chars-forward " \t" (point-at-eol))
+ (untabify (point) (progn (skip-chars-forward " \t" eol)
(point))))))
(end-of-line)
(delete-horizontal-space)