From: Alan Mackenzie Date: Fri, 10 May 2019 07:28:54 +0000 (+0000) Subject: Make uncomment-region remove obtrusive spaces before tabs. X-Git-Tag: emacs-27.0.90~2930 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a8d17f35a29d9875e94e28c8405d350b57fd1e80;p=emacs.git 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. --- 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)