emacs-devel
[Top][All Lists]
Advanced

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

Re: visual-region-mode?


From: hw
Subject: Re: visual-region-mode?
Date: Wed, 03 Oct 2018 15:59:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

address@hidden (Charles A. Roelli) writes:

>> From: hw <address@hidden>
>> Cc: address@hidden
>> Date: Thu, 27 Sep 2018 00:00:42 +0200
>>
>> > Yes, but since we have commands that offer behavior specific to active
>> > regions, we have the so-called "temporary transient mark mode" --
>> > which is a hack to get around this problem.  I'd rather have a way to
>> > explicitly activate/deactivate the region.
>> 
>> I'm not sure this is a distinct mode; it seems more like the region is
>> activated regardless of t-m-m being enabled or not and gets somehow
>> disabled eventually.
>
> For what it's worth, the doc of the variable "transient-mark-mode" says:
>
> - The pair (only . OLDVAL) enables Transient Mark mode
>   temporarily.  After any subsequent point motion command that is
>   not shift-translated, or any other action that would normally
>   deactivate the mark (e.g. buffer modification), the value of
>   ‘transient-mark-mode’ is set to OLDVAL.

That sheds some light on the definition of exchange-point-and-mark in
simple.el which I didn't fully understand.  It either activates the
region or deactivates it, i. e. there doesn't seem to be anything
temporary about it.

"Temporary" only seems to mean that the mode is enabled until the region
is deactivated.  That doesn't mean that it is actually temporary; it's
the very same mode --- or isn't it?

>> Why would I disable it permanently?  I wouldn't have highlighting, there
>> would be no way to fortify the region --- which is a requirement because
>> it can not really be disabled due to a fundamental design flaw --- and I
>> would have to narrow the buffer all the time to do something with a
>> region and to widen it afterwards.
>
> You disable "t-m-m" if you don't want a "transient" mark -- as in,
> activating and deactivating itself seemingly of its own volition.

That isn't what it does.  There are only very few cases where I expect
the region to be deactivated and it isn't deactivated, and no cases in
which the region is somehow activated all on its own.

So why would I disable t-m-m?

>> >> > and without the region randomly deactivating itself after certain
>> >> > commands as it does with "t-m-m" switched on.
>> >> 
>> >> [...]
>> >>
>> >> Are you referring to commands deactivating the region?  
>> >
>> > Yes.  See the doc of "t-m-m":
>> >
>> >             The mark is "deactivated" by changing the buffer,
>> > and after certain other operations that set the mark but whose
>> > main purpose is something else--for example, incremental search,
>> > M-<, and M->.
>> 
>> So this doesn't happen randomly but intentionally --- and you could
>> re-activate the region if you still want to do something with it.
>
> Actually, the documentation lacks at least one other case: scrolling
> that results in point moving, either with the keyboard or with the
> mouse.  That's one of several arbitrary decisions in the design of
> t-m-m.

That shows the fundamental design flaw of Emacs which doesn't allow to
separate the region and thus selections from where the cursor is.  I
don't see how you could blame t-m-m for it.

>> > I'd like to be able to carry this behavior over to commands that
>> > require an active region for certain things, like M-% does for
>> > replacing inside a region.
>> 
>> I guess the right, or consistent, way to do that might be to write more
>> antagonistic functions that imply "region", like `query-replace-region'.
>> 
>> Why don't you make a selection when you want to do something with one?
>> With t-m-m enabled, that automatically activates the region, and it is
>> much better than doing stuff with random parts of the buffer.
>
> I'd rather tells Emacs when the region is active, than the other way
> round.

So you would rather have a "persistent region", i. e. a selection like
joe has?  Unfortunately, we can't really have that (unless the zones
Drew suggested work in this way), and t-m-m is what comes closest to it.

>> Other than that, I wonder what would go wrong if you made a key binding
>> to a function that toggles `use-region-p' which you use before and
>> perhaps after calling functions you want to have a different behaviour.
>> Maybe `query-replace-region' could make use of that.
>
> This would be a binding to activate or deactivate the region, I think.
> No extra command ("query-replace-region") should be necessary.

It depends on what you prefer: extra commands to do stuff limited to the
region, consistent with such commands that already exist, or explicitly
activate the region to limit any command to do stuff with it.

The latter could be what the temporaryness for t-m-m is supposed to
cover.  I simply leave t-m-m always enabled and have a key binding to
activate the region with when I want to.  The region is also fortified,
and it does what I want.

>> Of course, functions implying "region" don't make sense when t-m-m is
>> enabled: t-m-m already implies "region" in the sense of "selection",
>> somewhat overcoming the fundamental design flaw of "the region" and the
>> idea of doing stuff randomly with parts of buffers.  The functions
>> implying "region" are merely children of this design flaw because they
>> were only invented because nobody wants to narrow and widen their
>> buffers to do something with parts of them.
>
> Narrowing still has its place in everyday editing.

What do you use it for?

>> (global-set-key "\C-x\C-x" 'my-exchange-point-and-mark)
>> (global-set-key (kbd "<C-f1>")
>>              (lambda ()
>>                "Toggle the activeness of the region."
>>                (interactive)
>>                (if mark-active (deactivate-mark)
>>                  (activate-mark t))))
>> (global-set-key [C-f2] 'my-exchange-point-and-mark)
>> (global-set-key [C-f3] 'previous-buffer)
>> (global-set-key [C-f5] 'next-buffer)
>> 
>> Those are actual keys, i. e. I press only one key for them.  It's rather
>> convenient.  (The key caps are labeled Print, Help, Record and Play.)
>> 
>> Unfortunately, it seems Unicomp is the only manufacturer still making
>> really good keyboards, and the only one for 122 keys ...  (The fine
>> keyboard started working again the next day after I banged it a little,
>> but I really like having more keys.)
>
> Neat, let us know how this approach goes.

So far, it's nice.  I need to do some programming to really find out,
and it will be a while before I get to that.

> I don't know what key we could allocate to a command that activates or
> deactivates the region, since there are not free ones left on average
> keyboards...

That's why I like to have more keys.  You could get one of these
keyboards, they're awesome.  The keyboard is part of customization.

Other than that, having C-x C-x changed already helps, and in lack of
another key, you could use it with the prefix to toggle the activeness
of the region.

>> On a side note, why is the function that activates the region called
>> activate-mark and not activate-region?  Is there some purpose or
>> distinction involved we don't know about?
>
> People use "active mark" and "active region" interchangeably, AFAIK.
> (I know I do!)

That's confusing, and you could even have it so that activating the mark
creates a persistent selection that isn't disabled after doing something
with it while activating the region activates the selection only until
you did something with it.

>> > [...]
>> > Btw, I'm culling most of the CC list since it seems no longer relevant.
>> 
>> I don't know who/what created this list; I suspect it might have been
>> gnus.
>
> Those people had responded to this thread earlier, so they ended up on
> the list automatically.

Hm, that's an interesting feature.



reply via email to

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