zsh-users
 help / color / mirror / code / Atom feed
* zle kill-region without mark consider start of line as mark
@ 2017-11-15 10:40 ` Hadrien Lacour
  2017-11-15 11:24   ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Hadrien Lacour @ 2017-11-15 10:40 UTC (permalink / raw)
  To: zsh-users

Hello,

I have `bindkey -M emacs '^W' kill-region` in my zshrc and using it without
having set any mark will cut from the beginning of the line to the cursor.
I've tried to read zle's doc but found no mention of this behaviour.

Any idea about what's happening and how to do nothing if the mark isn't set?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zle kill-region without mark consider start of line as mark
  2017-11-15 10:40 ` zle kill-region without mark consider start of line as mark Hadrien Lacour
@ 2017-11-15 11:24   ` Peter Stephenson
  2017-11-15 13:00     ` Hadrien Lacour
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2017-11-15 11:24 UTC (permalink / raw)
  To: zsh-users

On Wed, 15 Nov 2017 11:40:34 +0100
Hadrien Lacour <hadrien.lacour@posteo.net> wrote:
> I have `bindkey -M emacs '^W' kill-region` in my zshrc and using it without
> having set any mark will cut from the beginning of the line to the cursor.
> I've tried to read zle's doc but found no mention of this behaviour.
> 
> Any idea about what's happening and how to do nothing if the mark isn't set?

Internally, there is actually no notion of the mark not being set ---
it's simply initialised to zero, and moved when ask it to be set.
Therefore, if you try and use it, it appears as if it's at the start of
the line.

The documentation doesn't make this explicit.  It could do with
mentioning the default state.

pws


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zle kill-region without mark consider start of line as mark
  2017-11-15 11:24   ` Peter Stephenson
@ 2017-11-15 13:00     ` Hadrien Lacour
  2017-11-15 13:13       ` Hadrien Lacour
  0 siblings, 1 reply; 6+ messages in thread
From: Hadrien Lacour @ 2017-11-15 13:00 UTC (permalink / raw)
  To: zsh-users

On Wed, Nov 15, 2017 at 11:24:37AM +0000, Peter Stephenson wrote:
> On Wed, 15 Nov 2017 11:40:34 +0100
> Hadrien Lacour <hadrien.lacour@posteo.net> wrote:
> > I have `bindkey -M emacs '^W' kill-region` in my zshrc and using it without
> > having set any mark will cut from the beginning of the line to the cursor.
> > I've tried to read zle's doc but found no mention of this behaviour.
> >
> > Any idea about what's happening and how to do nothing if the mark isn't set?
>
> Internally, there is actually no notion of the mark not being set ---
> it's simply initialised to zero, and moved when ask it to be set.
> Therefore, if you try and use it, it appears as if it's at the start of
> the line.
>
> The documentation doesn't make this explicit.  It could do with
> mentioning the default state.
>
> pws

Thanks, that's what I supposed too. I almost have it fixed with

markset=
my-set-mark()
{
    zle set-mark-command
	    markset=true
		}

my-kill-region()
{
    [ $markset ] && zle kill-region
	}

zle -N my-kill-region
zle -N my-set-mark

bindkey -M emacs '^@'       my-set-mark
bindkey -M emacs '^W'       my-kill-region


But I don't know how to reset markset every newline (other than doing an ugly
bindkey for Return).


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zle kill-region without mark consider start of line as mark
  2017-11-15 13:00     ` Hadrien Lacour
@ 2017-11-15 13:13       ` Hadrien Lacour
  2017-11-15 17:10         ` Mikael Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: Hadrien Lacour @ 2017-11-15 13:13 UTC (permalink / raw)
  To: zsh-users

On Wed, Nov 15, 2017 at 02:00:47PM +0100, Hadrien Lacour wrote:
> On Wed, Nov 15, 2017 at 11:24:37AM +0000, Peter Stephenson wrote:
> > On Wed, 15 Nov 2017 11:40:34 +0100
> > Hadrien Lacour <hadrien.lacour@posteo.net> wrote:
> > > I have `bindkey -M emacs '^W' kill-region` in my zshrc and using it without
> > > having set any mark will cut from the beginning of the line to the cursor.
> > > I've tried to read zle's doc but found no mention of this behaviour.
> > >
> > > Any idea about what's happening and how to do nothing if the mark isn't set?
> >
> > Internally, there is actually no notion of the mark not being set ---
> > it's simply initialised to zero, and moved when ask it to be set.
> > Therefore, if you try and use it, it appears as if it's at the start of
> > the line.
> >
> > The documentation doesn't make this explicit.  It could do with
> > mentioning the default state.
> >
> > pws
>
> Thanks, that's what I supposed too. I almost have it fixed with
>
> markset=
> my-set-mark()
> {
>     zle set-mark-command
> 	    markset=true
> 		}
>
> my-kill-region()
> {
>     [ $markset ] && zle kill-region
> 	}
>
> zle -N my-kill-region
> zle -N my-set-mark
>
> bindkey -M emacs '^@'       my-set-mark
> bindkey -M emacs '^W'       my-kill-region
>
>
> But I don't know how to reset markset every newline (other than doing an ugly
> bindkey for Return).

Disregard this, I just forgot to reset markset in the second widget.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zle kill-region without mark consider start of line as mark
  2017-11-15 13:13       ` Hadrien Lacour
@ 2017-11-15 17:10         ` Mikael Magnusson
  2017-11-15 18:00           ` Hadrien Lacour
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2017-11-15 17:10 UTC (permalink / raw)
  To: Hadrien Lacour; +Cc: Zsh Users

       REGION_ACTIVE (integer)
              Indicates if the region is currently active.  It can be
assigned 0  or
              1  to  deactivate  and  activate the region
respectively. A value of 2
              activates the region in  line-wise  mode  with  the
highlighted  text
              extending for whole lines only; see Character Highlighting below.


On Wed, Nov 15, 2017 at 2:13 PM, Hadrien Lacour
<hadrien.lacour@posteo.net> wrote:
> On Wed, Nov 15, 2017 at 02:00:47PM +0100, Hadrien Lacour wrote:
>> On Wed, Nov 15, 2017 at 11:24:37AM +0000, Peter Stephenson wrote:
>> > On Wed, 15 Nov 2017 11:40:34 +0100
>> > Hadrien Lacour <hadrien.lacour@posteo.net> wrote:
>> > > I have `bindkey -M emacs '^W' kill-region` in my zshrc and using it without
>> > > having set any mark will cut from the beginning of the line to the cursor.
>> > > I've tried to read zle's doc but found no mention of this behaviour.
>> > >
>> > > Any idea about what's happening and how to do nothing if the mark isn't set?
>> >
>> > Internally, there is actually no notion of the mark not being set ---
>> > it's simply initialised to zero, and moved when ask it to be set.
>> > Therefore, if you try and use it, it appears as if it's at the start of
>> > the line.
>> >
>> > The documentation doesn't make this explicit.  It could do with
>> > mentioning the default state.
>> >
>> > pws
>>
>> Thanks, that's what I supposed too. I almost have it fixed with
>>
>> markset=
>> my-set-mark()
>> {
>>     zle set-mark-command
>>           markset=true
>>               }
>>
>> my-kill-region()
>> {
>>     [ $markset ] && zle kill-region
>>       }
>>
>> zle -N my-kill-region
>> zle -N my-set-mark
>>
>> bindkey -M emacs '^@'       my-set-mark
>> bindkey -M emacs '^W'       my-kill-region
>>
>>
>> But I don't know how to reset markset every newline (other than doing an ugly
>> bindkey for Return).
>
> Disregard this, I just forgot to reset markset in the second widget.



-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: zle kill-region without mark consider start of line as mark
  2017-11-15 17:10         ` Mikael Magnusson
@ 2017-11-15 18:00           ` Hadrien Lacour
  0 siblings, 0 replies; 6+ messages in thread
From: Hadrien Lacour @ 2017-11-15 18:00 UTC (permalink / raw)
  To: zsh-users

On Wed, Nov 15, 2017 at 06:10:29PM +0100, Mikael Magnusson wrote:
>        REGION_ACTIVE (integer)
>               Indicates if the region is currently active.  It can be
> assigned 0  or
>               1  to  deactivate  and  activate the region
> respectively. A value of 2
>               activates the region in  line-wise  mode  with  the
> highlighted  text
>               extending for whole lines only; see Character Highlighting below.
>
>
> On Wed, Nov 15, 2017 at 2:13 PM, Hadrien Lacour
> <hadrien.lacour@posteo.net> wrote:
> > On Wed, Nov 15, 2017 at 02:00:47PM +0100, Hadrien Lacour wrote:
> >> On Wed, Nov 15, 2017 at 11:24:37AM +0000, Peter Stephenson wrote:
> >> > On Wed, 15 Nov 2017 11:40:34 +0100
> >> > Hadrien Lacour <hadrien.lacour@posteo.net> wrote:
> >> > > I have `bindkey -M emacs '^W' kill-region` in my zshrc and using it without
> >> > > having set any mark will cut from the beginning of the line to the cursor.
> >> > > I've tried to read zle's doc but found no mention of this behaviour.
> >> > >
> >> > > Any idea about what's happening and how to do nothing if the mark isn't set?
> >> >
> >> > Internally, there is actually no notion of the mark not being set ---
> >> > it's simply initialised to zero, and moved when ask it to be set.
> >> > Therefore, if you try and use it, it appears as if it's at the start of
> >> > the line.
> >> >
> >> > The documentation doesn't make this explicit.  It could do with
> >> > mentioning the default state.
> >> >
> >> > pws
> >>
> >> Thanks, that's what I supposed too. I almost have it fixed with
> >>
> >> markset=
> >> my-set-mark()
> >> {
> >>     zle set-mark-command
> >>           markset=true
> >>               }
> >>
> >> my-kill-region()
> >> {
> >>     [ $markset ] && zle kill-region
> >>       }
> >>
> >> zle -N my-kill-region
> >> zle -N my-set-mark
> >>
> >> bindkey -M emacs '^@'       my-set-mark
> >> bindkey -M emacs '^W'       my-kill-region
> >>
> >>
> >> But I don't know how to reset markset every newline (other than doing an ugly
> >> bindkey for Return).
> >
> > Disregard this, I just forgot to reset markset in the second widget.
>
>
>
> --
> Mikael Magnusson

Thanks, this the perfect solution (I saw it, but didn't understand it when
reading the man). Now, I wonder why it's no the default.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-11-15 18:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20171115104211epcas1p297804141d5350c2100e76f849759952d@epcas1p2.samsung.com>
2017-11-15 10:40 ` zle kill-region without mark consider start of line as mark Hadrien Lacour
2017-11-15 11:24   ` Peter Stephenson
2017-11-15 13:00     ` Hadrien Lacour
2017-11-15 13:13       ` Hadrien Lacour
2017-11-15 17:10         ` Mikael Magnusson
2017-11-15 18:00           ` Hadrien Lacour

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).