zsh-users
 help / color / mirror / code / Atom feed
* is there a mix of history-search-backward and history-beginning-search-backward
@ 1999-09-03 11:04 Andy Spiegl
  1999-09-08 13:02 ` Andy Spiegl
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Spiegl @ 1999-09-03 11:04 UTC (permalink / raw)
  To: zsh-users

Hi!

I just recently switched from tcsh to zsh and I really like it!
But there's on thing I can't get the way I'd like it:

I want to bind to ^P a widget that acts like
history-beginning-search-backward, but always moves the cursor to the end
of the line, like history-search-backward does.  Or said the other way:
I want history-search-backward to look at more than the first word.

Do you know a way to get this behavior?

Thanks a lot in advance,
 Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 Finger pgp.andy@spiegl.de for my PGP key
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

* Re: is there a mix of history-search-backward and history-beginning-search-backward
  1999-09-03 11:04 is there a mix of history-search-backward and history-beginning-search-backward Andy Spiegl
@ 1999-09-08 13:02 ` Andy Spiegl
  1999-09-08 15:27   ` Peter Stephenson
  1999-09-08 15:55   ` Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: Andy Spiegl @ 1999-09-08 13:02 UTC (permalink / raw)
  To: zsh-users

Hi again!

A while ago I asked:
> 
> I want to bind to ^P a widget that acts like
> history-beginning-search-backward, but always moves the cursor to the end
> of the line, like history-search-backward does.  Or said the other way:
> I want history-search-backward to look at more than the first word.
> 
> Do you know a way to get this behavior?

Does noone have any idea about this?
I don't even see a plain-old no out there. :-(

If this is not the right forum for this question, please point
me to a the right one.  If it really shouldn't be possible, where
do I send a feature request? :-)

Thanks again,
 Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 Finger pgp.andy@spiegl.de for my PGP key
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 "One cat just leads to another." - Ernest Hemingway


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

* Re: is there a mix of history-search-backward and history-beginning-search-backward
  1999-09-08 13:02 ` Andy Spiegl
@ 1999-09-08 15:27   ` Peter Stephenson
  1999-09-08 15:55     ` Andy Spiegl
  1999-09-11 22:58     ` is there a mix of history-search-backward and history-beginning-search-backward Bart Schaefer
  1999-09-08 15:55   ` Bart Schaefer
  1 sibling, 2 replies; 8+ messages in thread
From: Peter Stephenson @ 1999-09-08 15:27 UTC (permalink / raw)
  To: zsh-users

Andy Spiegl wrote:
> A while ago I asked:
> > 
> > I want to bind to ^P a widget that acts like
> > history-beginning-search-backward, but always moves the cursor to the end
> > of the line, like history-search-backward does.  Or said the other way:
> > I want history-search-backward to look at more than the first word.
> > 
> > Do you know a way to get this behavior?
> 
> Does noone have any idea about this?

Sorry, I meant to try this and then got sidetracked into things like
applying patches.

I assume you're using zsh 3.1, in which case it's not so hard:
probably you need 3.1.6 for the $LASTWIDGET test to work, which is
crucial.  I've called the functions
history-beginning-search-{back,for}ward-end.  If you shorten the
names, you will need to change the pattern matched against
$LASTWIDGET, because the functions need to know that one of the two
was called last, and hence the position to compare up to is already
set.  (Wasted ten minutes wondering why an `if' with a missing `then'
didn't work.  I think we're too lenient with the syntax.)

I might put these in the Functions/Zle directory (after Bart has found out
whatever's wrong with them).


# function history-beginning-search-forward-end {
# history-beginning-search-forward, with cursor at end.

integer ocursor=$CURSOR stat

if [[ $LASTWIDGET = history-beginning-search-(back|for)ward-end ]]; then
  # Last widget called set $hbs_pos.
  CURSOR=$hbs_pos
else
  hbs_pos=$CURSOR
fi

if zle history-beginning-search-forward; then
  # success, go to end of line
  zle end-of-line
else
  # failure, restore position
  CURSOR=$ocursor
  return 1
fi
# }

# function history-beginning-search-backward-end {
# history-beginning-search-backward, with cursor at end.

integer ocursor=$CURSOR stat

if [[ $LASTWIDGET = history-beginning-search-(back|for)ward-end ]]; then
  # Last widget called set $hbs_pos.
  CURSOR=$hbs_pos
else
  hbs_pos=$CURSOR
fi

if zle history-beginning-search-backward; then
  # success, go to end of line
  zle end-of-line
else
  # failure, restore position
  CURSOR=$ocursor
  return 1
fi
# }

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

* Re: is there a mix of history-search-backward and history-beginning-search-backward
  1999-09-08 15:27   ` Peter Stephenson
@ 1999-09-08 15:55     ` Andy Spiegl
  1999-09-08 16:18       ` Oliver Kiddle
  1999-09-08 16:58       ` unsubscribe tbabin@nortelnetworks.com Timothy Babin
  1999-09-11 22:58     ` is there a mix of history-search-backward and history-beginning-search-backward Bart Schaefer
  1 sibling, 2 replies; 8+ messages in thread
From: Andy Spiegl @ 1999-09-08 15:55 UTC (permalink / raw)
  To: zsh-users

Hi Peter,

thanks a lot!  I am (once again) impressed by the possibilities of zsh!
Just one problem:
how do I set the functions up so that I can bind them to my keys?
I put the file into ~/.zsh.funcs/ directory, autoloaded it and
called bindkey:
 bindkey "^P"        history-beginning-search-backward-end
 bindkey "^N"        history-beginning-search-forward-end

But when I press ^P I get to see:
 No such widget `history-beginning-search-backward-end'

I am fairly new to zsh and haven't really understood the concept of
loadable functions...

> I assume you're using zsh 3.1,
3.1.6 even.

> # function history-beginning-search-forward-end {
I removed the comment sign, too.

Thanks again!
 Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 Finger pgp.andy@spiegl.de for my PGP key
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 But he was probably like most CS majors:  spending all the time in the 
 computer labs, eating out of vending machines, majoring in the four major 
 food groups: sugar, starch, chocolate and caffeine, he probably was 5'6" 
 and weighed 250, with a face like a pepperoni pizza behind Coke bottles.  


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

* Re: is there a mix of history-search-backward and history-beginning-search-backward
  1999-09-08 13:02 ` Andy Spiegl
  1999-09-08 15:27   ` Peter Stephenson
@ 1999-09-08 15:55   ` Bart Schaefer
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 1999-09-08 15:55 UTC (permalink / raw)
  To: zsh-users

On Sep 8,  3:02pm, Andy Spiegl wrote:
} Subject: Re: is there a mix of history-search-backward and history-beginni
}
} Hi again!

Hello ...

} A while ago I asked:
} > 
} > I want to bind to ^P a widget that acts like
} > history-beginning-search-backward, but always moves the cursor to the end
} > of the line, like history-search-backward does.  Or said the other way:
} > I want history-search-backward to look at more than the first word.
} > 
} > Do you know a way to get this behavior?
} 
} Does noone have any idea about this?

Everyone is probably waiting for everyone else to answer.  Now you'll
probably get this answer several times.

In 3.0.6, there really is no satisfactory way to get this behavior.  The
closest you can come is to use this kind of binding:

	bindkey '^Xp' history-beginning-search-backward
	bindkey -s '^P' '^X^X^Xp^E'

The first binding is just something to hang the real thing you want to
execute on, so that you can refer to it in the second binding.  The second
binding maps ctrl-P to the sequence exchange-point-and-mark (^X^X) followed
by history-beginning-search-backward (^Xp) followed by end-of-line (^E).
The problem is that you have to remember to set the mark with ctrl-space
(or whatever you have bound to set-mark-command) before you begin to press
ctrl-P repeatedly, or exchange-point-and-mark will jump to the wrong place:
zsh resets the mark each time a new prompt is displayed.

In 3.1.6, you can create a custom widget as I just saw that PWS has already
explained, so I won't repeat him.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: is there a mix of history-search-backward and  history-beginning-search-backward
  1999-09-08 15:55     ` Andy Spiegl
@ 1999-09-08 16:18       ` Oliver Kiddle
  1999-09-08 16:58       ` unsubscribe tbabin@nortelnetworks.com Timothy Babin
  1 sibling, 0 replies; 8+ messages in thread
From: Oliver Kiddle @ 1999-09-08 16:18 UTC (permalink / raw)
  To: Andy Spiegl; +Cc: zsh-users

Andy Spiegl wrote:

> how do I set the functions up so that I can bind them to my keys?
> I put the file into ~/.zsh.funcs/ directory, autoloaded it and
> called bindkey:
>  bindkey "^P"        history-beginning-search-backward-end
>  bindkey "^N"        history-beginning-search-forward-end
> 
> But when I press ^P I get to see:
>  No such widget `history-beginning-search-backward-end'

You need to do:
zle -N history-beginning-search-backward-end
before the bindkey.

Oliver Kiddle


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

* unsubscribe tbabin@nortelnetworks.com
  1999-09-08 15:55     ` Andy Spiegl
  1999-09-08 16:18       ` Oliver Kiddle
@ 1999-09-08 16:58       ` Timothy Babin
  1 sibling, 0 replies; 8+ messages in thread
From: Timothy Babin @ 1999-09-08 16:58 UTC (permalink / raw)
  To: zsh-users

usubscribe tbabin@nortelnetworks.com


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

* Re: is there a mix of history-search-backward and history-beginning-search-backward
  1999-09-08 15:27   ` Peter Stephenson
  1999-09-08 15:55     ` Andy Spiegl
@ 1999-09-11 22:58     ` Bart Schaefer
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 1999-09-11 22:58 UTC (permalink / raw)
  To: zsh-users

On Sep 8,  5:27pm, Peter Stephenson wrote:
> Subject: Re: is there a mix of history-search-backward and history-beginni
>
> I might put these in the Functions/Zle directory (after Bart has found out
> whatever's wrong with them).

I don't see anything wrong with them except that there doesn't seem to be
any use of the "stat" local paramter.  With a tad more cleverness, though,
you can get away with only one function:

function history-search-end {
    integer ocursor=$CURSOR

    if [[ $LASTWIDGET = history-beginning-search-*-end ]]; then
      # Last widget called set $hbs_pos.
      CURSOR=$hbs_pos
    else
      hbs_pos=$CURSOR
    fi

    if zle .${WIDGET%-end}; then
      # success, go to end of line
      zle .end-of-line
    else
      # failure, restore position
      CURSOR=$ocursor
      return 1
    fi
}
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end

While we're on the subject, I've been fooling with insert-and-predict.  The
version below seems to work pretty well, but the history-search-forward in
delete-backward-and-predict is less than ideal because of zsh's habit of
leaving edits behind in the history list until the next trashzle().  That
means that if you do some editing and then continue searching backwards,
when you search forward again you may find an edited history line, which
is probably not what you want.  Using ((-CURSOR)) rather than actually
deleting the character minimizes this effect, but assignment to LBUFFER in
either function can leave junk behind.  Any clever fixes for this?

I think this is now clean enough that you could actually run with predict
turned on most of the time.

predict-on() {
    zle -N self-insert insert-and-predict
    zle -N magic-space insert-and-predict
    zle -N backward-delete-char delete-backward-and-predict
}
predict-off() {
    zle -A .self-insert self-insert
    zle -A .magic-space magic-space
    zle -A .backward-delete-char backward-delete-char
}
insert-and-predict () {
  emulate -L zsh
  if [[ ${RBUFFER[1]} = ${KEYS[-1]} ]]
  then
    # same as what's typed, just move on
    ((++CURSOR))
  else
    LBUFFER="$LBUFFER$KEYS"
    if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]]
    then
      zle .history-beginning-search-backward || RBUFFER=""
    fi
  fi
  return 0
}
delete-backward-and-predict() {
  emulate -L zsh
  if [[ -n "$LBUFFER" ]]
  then
    # If the last widget was e.g. a motion, then probably the intent is
    # to actually edit the line, not change the search prefix.
    if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]]
    then
      ((--CURSOR))
      zle .history-beginning-search-forward || RBUFFER=""
      return 0
    else
      # Depending on preference, you might call "predict-off" here,
      # and also set up forward deletions to turn off prediction.
      LBUFFER="$LBUFFER[1,-2]"
    fi
  fi
}
zle -N insert-and-predict
zle -N predict-on
zle -N predict-off


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

end of thread, other threads:[~1999-09-11 22:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-03 11:04 is there a mix of history-search-backward and history-beginning-search-backward Andy Spiegl
1999-09-08 13:02 ` Andy Spiegl
1999-09-08 15:27   ` Peter Stephenson
1999-09-08 15:55     ` Andy Spiegl
1999-09-08 16:18       ` Oliver Kiddle
1999-09-08 16:58       ` unsubscribe tbabin@nortelnetworks.com Timothy Babin
1999-09-11 22:58     ` is there a mix of history-search-backward and history-beginning-search-backward Bart Schaefer
1999-09-08 15:55   ` Bart Schaefer

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).