diff --git a/lisp/simple.el b/lisp/simple.el index f52bd95bf84..f76f31ad146 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -617,7 +617,8 @@ region is ignored if prefix argument is given.)" (+ (point) (length fill-prefix))))) (delete-region (point) (+ (point) (length fill-prefix)))) (fixup-whitespace) - (if (and beg + (if (and (use-region-p) + beg (not arg) (< beg (point-at-bol))) (beginning-of-line))))) diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index 08e81a7fefb..d9f059c8fc2 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el @@ -213,6 +213,40 @@ (should (= x 0))) (remove-hook 'post-self-insert-hook inc)))) + +;;; `delete-indentation' +(ert-deftest simple-delete-indentation-no-region () + "delete-indentation works when no mark is set." + ;; interactive \r returns nil for BEG END args + (unwind-protect + (with-temp-buffer + (insert (concat "zero line \n" + "first line \n" + "second line")) + (delete-indentation) + (should (string-equal + (buffer-string) + (concat "zero line \n" + "first line second line"))) + ))) + +(ert-deftest simple-delete-indentation-inactive-region () + "delete-indentation ignores inactive region." + ;; interactive \r returns non-nil for BEG END args + (unwind-protect + (with-temp-buffer + (insert (concat "zero line \n" + "first line \n" + "second line")) + (push-mark (point-min) t t) + (deactivate-mark) + (delete-indentation) + (should (string-equal + (buffer-string) + (concat "zero line \n" + "first line second line"))) + ))) + ;;; `delete-trailing-whitespace' (ert-deftest simple-delete-trailing-whitespace--bug-21766 ()