zsh-users
 help / color / mirror / code / Atom feed
* are there some ways to get things like isearch-{start,end}-position?
@ 2011-09-24  6:26 md 1983
  2011-09-24 18:17 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: md 1983 @ 2011-09-24  6:26 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

I want to upon exiting isearch mode always place the cursor in ZLE at the
position as specified by the variable "isearch_start" in zsh's source code,
no matter it's a forward or backward search.

Now ZLE has special parameters like CURSOR and MARK but it seems there are
currently no special parameters about the range for "the area of the
command line matched by the search string or pattern".

Or are there some other configuration that I could use to achieve this goal
(to place the cursor at the start position of matched isearch area
independent of the search direction)?

thanks!!

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

* Re: are there some ways to get things like isearch-{start,end}-position?
  2011-09-24  6:26 are there some ways to get things like isearch-{start,end}-position? md 1983
@ 2011-09-24 18:17 ` Bart Schaefer
  2011-09-25  4:06   ` Madsen Zhang
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2011-09-24 18:17 UTC (permalink / raw)
  To: zsh-users

On Sep 24,  2:26pm, md 1983 wrote:
} 
} I want to upon exiting isearch mode always place the cursor in ZLE at
} the position as specified by the variable "isearch_start" in zsh's
} source code, no matter it's a forward or backward search.

You should be able to use the special zle-isearch-exit widget and the
$LASTSEARCH variable to find the point in the buffer that was matched
by the search.  Here's a crude effort:

zle-isearch-exit() {
  local match mbegin mend
  setopt extendedglob
  [[ -n $LASTSEARCH ]] || return 0
  : ${BUFFER#(#b)(*)$LASTSEARCH}
  CURSOR=$mend[1]
  return 0
}
zle -N zle-isearch-exit

I agree that it would be nice to pass the search region at least to
zle-isearch-exit and zle-isearch-update if not to make them generally
available.


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

* Re: are there some ways to get things like isearch-{start,end}-position?
  2011-09-24 18:17 ` Bart Schaefer
@ 2011-09-25  4:06   ` Madsen Zhang
  2012-03-27  6:58     ` Madsen Zhang
  0 siblings, 1 reply; 6+ messages in thread
From: Madsen Zhang @ 2011-09-25  4:06 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 936 bytes --]

Fantastic solution:).

Bart, thank you very much!!



On Sun, Sep 25, 2011 at 2:17 AM, Bart Schaefer <schaefer@brasslantern.com>wrote:

> On Sep 24,  2:26pm, md 1983 wrote:
> }
> } I want to upon exiting isearch mode always place the cursor in ZLE at
> } the position as specified by the variable "isearch_start" in zsh's
> } source code, no matter it's a forward or backward search.
>
> You should be able to use the special zle-isearch-exit widget and the
> $LASTSEARCH variable to find the point in the buffer that was matched
> by the search.  Here's a crude effort:
>
> zle-isearch-exit() {
>  local match mbegin mend
>  setopt extendedglob
>  [[ -n $LASTSEARCH ]] || return 0
>  : ${BUFFER#(#b)(*)$LASTSEARCH}
>  CURSOR=$mend[1]
>  return 0
> }
> zle -N zle-isearch-exit
>
> I agree that it would be nice to pass the search region at least to
> zle-isearch-exit and zle-isearch-update if not to make them generally
> available.
>

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

* Re: are there some ways to get things like isearch-{start,end}-position?
  2011-09-25  4:06   ` Madsen Zhang
@ 2012-03-27  6:58     ` Madsen Zhang
  2012-03-27 13:59       ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Madsen Zhang @ 2012-03-27  6:58 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1477 bytes --]

if the last isearch direction is available, the following script, based on
the one from Bart Schaefer, should work in both forward and backward
isearch:

zle-isearch-exit() {
    if [[ $ISEARCHDIR -eq 1 ]]; then
        local match mbegin mend
        setopt extendedglob
        [[ -n $LASTSEARCH ]] || return 0
        : ${LBUFFER%(#b)(*)$LASTSEARCH}
        CURSOR=$mend[1]
    fi

    return 0
}
zle -N zle-isearch-exit



On Sun, Sep 25, 2011 at 12:06 PM, Madsen Zhang <md11235@gmail.com> wrote:

> Fantastic solution:).
>
> Bart, thank you very much!!
>
>
>
> On Sun, Sep 25, 2011 at 2:17 AM, Bart Schaefer <schaefer@brasslantern.com>wrote:
>
>> On Sep 24,  2:26pm, md 1983 wrote:
>> }
>> } I want to upon exiting isearch mode always place the cursor in ZLE at
>> } the position as specified by the variable "isearch_start" in zsh's
>> } source code, no matter it's a forward or backward search.
>>
>> You should be able to use the special zle-isearch-exit widget and the
>> $LASTSEARCH variable to find the point in the buffer that was matched
>> by the search.  Here's a crude effort:
>>
>> zle-isearch-exit() {
>>  local match mbegin mend
>>  setopt extendedglob
>>  [[ -n $LASTSEARCH ]] || return 0
>>  : ${BUFFER#(#b)(*)$LASTSEARCH}
>>  CURSOR=$mend[1]
>>  return 0
>> }
>> zle -N zle-isearch-exit
>>
>> I agree that it would be nice to pass the search region at least to
>> zle-isearch-exit and zle-isearch-update if not to make them generally
>> available.
>>
>
>

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

* Re: are there some ways to get things like isearch-{start,end}-position?
  2012-03-27  6:58     ` Madsen Zhang
@ 2012-03-27 13:59       ` Bart Schaefer
  2012-03-29  6:33         ` Madsen Zhang
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2012-03-27 13:59 UTC (permalink / raw)
  To: zsh-users

On Mar 27,  2:58pm, Madsen Zhang wrote:
>
> if the last isearch direction is available, the following script, based on
> the one from Bart Schaefer, should work in both forward and backward
> isearch:
> 
> zle-isearch-exit() {
>     if [[ $ISEARCHDIR -eq 1 ]]; then
>         local match mbegin mend
>         setopt extendedglob
>         [[ -n $LASTSEARCH ]] || return 0
>         : ${LBUFFER%(#b)(*)$LASTSEARCH}
>         CURSOR=$mend[1]
>     fi
> 
>     return 0
> }
> zle -N zle-isearch-exit

You can set ISEARCHDIR for yourself by putting a little wrapper function
around history-incremental-search-*.

hist-inc-search-save-direction() {
    if [[ $WIDGET = *-forward ]]; then
        typeset -g ISEARCHDIR=1
        zle .history-incremental-search-forward "$@"
    else
        typeset -g ISEARCHDIR=-1
        zle .history-incremental-search-backward "$@"
    fi
}
zle -N history-incremental-search-forward hist-inc-search-save-direction
zle -N history-incremental-search-backward hist-inc-search-save-direction

I'm not sure I got the semantics of ISEARCHDIR the way you wanted them,
but you get the idea.


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

* Re: are there some ways to get things like isearch-{start,end}-position?
  2012-03-27 13:59       ` Bart Schaefer
@ 2012-03-29  6:33         ` Madsen Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Madsen Zhang @ 2012-03-29  6:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1384 bytes --]

Good, it works gracefully. your definition of ISEARCHDIR is the same with
what I desired.

Bart, thank you very much :)!

On Tue, Mar 27, 2012 at 9:59 PM, Bart Schaefer <schaefer@brasslantern.com>wrote:

> On Mar 27,  2:58pm, Madsen Zhang wrote:
> >
> > if the last isearch direction is available, the following script, based
> on
> > the one from Bart Schaefer, should work in both forward and backward
> > isearch:
> >
> > zle-isearch-exit() {
> >     if [[ $ISEARCHDIR -eq 1 ]]; then
> >         local match mbegin mend
> >         setopt extendedglob
> >         [[ -n $LASTSEARCH ]] || return 0
> >         : ${LBUFFER%(#b)(*)$LASTSEARCH}
> >         CURSOR=$mend[1]
> >     fi
> >
> >     return 0
> > }
> > zle -N zle-isearch-exit
>
> You can set ISEARCHDIR for yourself by putting a little wrapper function
> around history-incremental-search-*.
>
> hist-inc-search-save-direction() {
>    if [[ $WIDGET = *-forward ]]; then
>        typeset -g ISEARCHDIR=1
>        zle .history-incremental-search-forward "$@"
>    else
>        typeset -g ISEARCHDIR=-1
>        zle .history-incremental-search-backward "$@"
>    fi
> }
> zle -N history-incremental-search-forward hist-inc-search-save-direction
> zle -N history-incremental-search-backward hist-inc-search-save-direction
>
> I'm not sure I got the semantics of ISEARCHDIR the way you wanted them,
> but you get the idea.
>

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

end of thread, other threads:[~2012-03-29  6:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-24  6:26 are there some ways to get things like isearch-{start,end}-position? md 1983
2011-09-24 18:17 ` Bart Schaefer
2011-09-25  4:06   ` Madsen Zhang
2012-03-27  6:58     ` Madsen Zhang
2012-03-27 13:59       ` Bart Schaefer
2012-03-29  6:33         ` Madsen Zhang

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