From a8d17f35a29d9875e94e28c8405d350b57fd1e80 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Fri, 10 May 2019 07:28:54 +0000 Subject: [PATCH] Make uncomment-region remove obtrusive spaces before tabs. These spaces were typically inserted earlier by comment-region. This patch makes these two complementary functions closer to inverses. * lisp/newcomment.el (uncomment-region-default-1): Remove spaces before a tab where the comment opener has just been removed. --- lisp/newcomment.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 9d919ccbbea..ab2be080a33 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -1001,7 +1001,15 @@ This function is the default value of `uncomment-region-function'." (re-search-forward sre (line-end-position) t)) (replace-match "" t t nil (if (match-end 2) 2 1))))) ;; Go to the end for the next comment. - (goto-char (point-max)))))) + (goto-char (point-max))) + ;; Remove any obtrusive spaces left preceding a tab at `spt'. + (when (and (eq (char-after spt) ?\t) (eq (char-before spt) ? ) + (> tab-width 0)) + (save-excursion + (goto-char spt) + (let* ((fcol (current-column)) + (slim (- (point) (mod fcol tab-width)))) + (delete-char (- (skip-chars-backward " " slim))))))))) (set-marker end nil)) (defun uncomment-region-default (beg end &optional arg) -- 2.39.2