purcell / whole-line-or-region

In Emacs, operate on current line if no region is active
114 stars 12 forks source link

whole-line-or-region-kill-region does not honor kill-read-only-ok variable #12

Closed gusbrs closed 3 years ago

gusbrs commented 3 years ago

whole-line-or-region-kill-region uses "*p" as interactive specification, and in so doing does not allow to kill text in read only buffers, even when the variable kill-read-only-ok is set to t.

This appears to be known (see the EmacsWiki page https://www.emacswiki.org/emacs/WholeLineOrRegion, at the bottom).

kill-region itself does not use the * specification. Just removing it seems to me to be what's required, and it's been working for me so far.

If you'd like, I can offer a PR on this one.

purcell commented 3 years ago

If you'd like, I can offer a PR on this one.

I haven't dug into this, but sure. If it turns out to break other things, we can reconsider later.

gusbrs commented 3 years ago

Hi @purcell .

I've been playing with this, and while testing, things got more complicated than they appeared. Let's say I found out why the * interactive specification was added to whole-line-or-region-kill-region.

As far as behaviour goes, if on a read-only buffer, with kill-read-only-ok set to nil, when calling whole-line-or-region-kill-region the function will barf, as expected, but the mark will be set at the beginning of line, and region made active, which is not expected.

This happens because whole-line-or-region-base-call indeed uses (set-mark beg), which is apparently required for the comment functions to work (they break if I change this to (push-mark beg t)).

That's probably why the EmacsWiki advice included a redundant (unless kill-read-only-ok (barf-if-buffer-read-only)). But while this is good, it is not fully general, as it does not cover the case when some characters in the buffer are read-only, while the buffer itself is not, which is dealt with explicitly in the underlying kill-region.

So I guess this is a trade-off of the package attempting to be as general as it does.

That given, if you find acceptable the redundant call to (unless kill-read-only-ok (barf-if-buffer-read-only)), leaving the case of some characters read-only uncovered, I'll prepare the PR in these lines.

purcell commented 3 years ago

Now fixed.