diff --git a/etc/NEWS b/etc/NEWS index 7a4eab4800d..3b9e06f99d9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1822,6 +1822,13 @@ restart Emacs. --- *** Support of 'electric-layout-mode' added. +--- +*** DEL now deletes the text in the active region when point is between indentation. +The command 'python-indent-dedent-line-backspace' (by default bound to +'DEL') now deletes the text in the region and deactivates the mark if +Transient Mark mode is enabled, the mark is active, and prefix argument +is 1. + ** Tmm Menubar --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index f4f0518dbfd..8b5ffae57d6 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1967,10 +1967,13 @@ indentation levels from right to left." (defun python-indent-dedent-line-backspace (arg) "De-indent current line. -Argument ARG is passed to `backward-delete-char-untabify' when -point is not in between the indentation." +Argument ARG is passed to `backward-delete-char-untabify' when point is +not in between the indentation or when Transient Mark mode is enabled, +the mark is active, and ARG is 1." (interactive "*p") - (unless (python-indent-dedent-line) + (when (or + (and (use-region-p) (= arg 1)) + (not (python-indent-dedent-line))) (backward-delete-char-untabify arg))) (put 'python-indent-dedent-line-backspace 'delete-selection 'supersede) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 2c00f47d82c..d65ef39abb4 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -3780,6 +3780,24 @@ if x: (pos-bol) (pos-eol)) "abcdef"))))) +(ert-deftest python-indent-dedent-line-backspace-4 () + "Delete the text in the region instead of de-indentation. Bug#48695." + (dolist (test '((1 4) (2 0))) + (python-tests-with-temp-buffer + " +if True: + x () + if False: +" + (let ((current-prefix-arg (list (car test)))) + (python-tests-look-at "if False:") + (end-of-line) + (transient-mark-mode) + (set-mark (point)) + (backward-word 2) + (call-interactively #'python-indent-dedent-line-backspace) + (should (= (current-indentation) (cadr test))))))) + (ert-deftest python-bob-infloop-avoid () "Test that strings at BOB don't confuse syntax analysis. Bug#24905" (python-tests-with-temp-buffer