1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-17 10:06:13 +00:00

Fix bug in delete-indentation when region is inactive

* test/lisp/simple-tests.el: Add tests for delete-indentation.
(simple-delete-indentation-no-region): Works with no region.
(simple-delete-indentation-inactive-region): Was broken with inactive
region; now fixed.

* lisp/simple.el (delete-indentation): Check (use-region-p) before using BEG.
This commit is contained in:
Stephen Leake 2019-03-22 16:14:50 -07:00
parent c1b63af445
commit b515edb985
2 changed files with 36 additions and 1 deletions

View File

@ -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)))))

View File

@ -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 ()