bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#22917: 24.5; comint-kill-region doesn't work when both cua-mode and


From: Lars Ingebrigtsen
Subject: bug#22917: 24.5; comint-kill-region doesn't work when both cua-mode and comint-prompt-read-only enabled
Date: Thu, 03 Dec 2020 10:41:50 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

a.c.kalker@gmail.com writes:

> Steps to reproduce:
>
> 1. Create file 'repro.el' with contents:
>
> ;; Test deleting region with read-only prompts while cua-mode is active
> (setq comint-prompt-read-only t)
> (cua-mode 1)
> ;; Copied verbatim from 'comint-prompt-read-only' docstring
> (add-hook 'comint-mode-hook
>         (lambda ()
>           (define-key comint-mode-map [remap kill-region] 'comint-kill-region)
>           (define-key comint-mode-map [remap kill-whole-line]
>             'comint-kill-whole-line)))

[...]

> 4. Hit C-x or <delete> (only when cua-mode is active) or <S-delete> or C-w
>
> 5. Retry steps 3 and 4 after disabling cua-mode with M-x cua-mode RET
>
> Expected results:
> All these keystrokes (where applicable) should delete the region,
> including any interspersed prompts.
>
> Actual results:
> With cua-mode enabled:
> 4. C-x produces the error: "Text is read-only: #<buffer *shell*>" and
> nothing is deleted.
>    <delete> produces the error: "Text is read-only" and nothing is
>    deleted.
>    <S-delete> produces the error: "Text is read-only: #<buffer *shell*>" and
> nothing is deleted.
>    C-w  produces the error: "Text is read-only: #<buffer *shell*>" and
> nothing is deleted.
> With cua-mode disabled:
> 4. <S-delete> deletes the region, without error.
>    C-w deletes the region, without error.

(This bug report unfortunately got no response at the time.)

I can reproduce the behaviour, but I'm not sure it's a bug.

By default, all these killing commands refuse to kill read-only text.
However, comint provides a variation (`comint-kill-region') that ignores
whether there's read-only text or not, because that's sometimes
convenient, and has instructions on how to rebind kill-region.

However, cua-mode binds `C-w' to `cua-cut-region', so to get that
working, you'd also have to say

(define-key comint-mode-map [remap cua-cut-region] 'comint-kill-region)

or something of the kind.  Of course, cua-cut-region doesn't work quite
the same as `kill-region', so it's not quite the same, but if you want
this to work for the kill function you're using, then rebind the command
to something that does

(defun my-cut ()
  (interactive)
  (let ((inhibit-read-only t))
    (cua-cut-region)))

or something like that.

I don't think this is something that would be natural for either comint
or cua by themselves to work around -- if you have read-only text in the
buffer, then that's supposed to bug out if you kill it, and if you want
something else to happen, then it's more natural for the user that wants
that to do something like the above, I think?

So I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]