zsh-users
 help / color / mirror / code / Atom feed
* Re: matlab-history-beginning-search-backward
@ 2009-10-03 23:36 Guido van Steen
  2009-10-03 23:52 ` matlab-history-beginning-search-backward Guido van Steen
  0 siblings, 1 reply; 7+ messages in thread
From: Guido van Steen @ 2009-10-03 23:36 UTC (permalink / raw)
  To: zsh-users, Peter Stephenson

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

Thank you Peter, 

I amended the widget slightly. With this version the searched pattern is shown again when you search-forward beyond the first match. As far as I can tell that is how history works in Matlab and Fish. 

Attached for users who also like this behavior. 

Best wishes, 

Guido 

--- On Fri, 10/2/09, Peter Stephenson <pws@csr.com> wrote:

> From: Peter Stephenson <pws@csr.com>
> Subject: Re: matlab-history-beginning-search-backward
> To: zsh-users@sunsite.dk
> Date: Friday, October 2, 2009, 10:48 AM
> Guido van Steen wrote:
> > * Which part of the code makes sure that the commands
> retrieved
> > from history are "shown" on the command line?
> 
> Assigning to HISTNO moves to the given line number in the
> history.  zsh
> remembers edits to history lines until you hit
> <return> on the line you
> actually want to execute; the next time you look at the
> history it's
> back the way it was.
> 
> > * Why does the cursor position matter, and how can one
> make sure
> > that the cursor moves to the right position before the
> widget is
> > invoked?
> 
> As far as the widget is concerned, the cursor position only
> matters at
> the start in order to find the string to the left which is
> used for the
> search.  If you execute the widget again (forward or
> backward) without
> any other command in between it will use the same search
> string (no
> matter where the cursor is).  If you move the cursor
> (or in fact execute
> any other command) and execute the widget again it will
> look again at
> the string to the left.
> 
> Some people like the cursor placed specially after the
> execution of
> history commands; this function doesn't have any support
> for that, so
> it's always left at the end.
> 
> -- 
> Peter Stephenson <pws@csr.com> 
>           Software Engineer
> Tel: +44 (0)1223 692070         
>          Cambridge Silicon
> Radio Limited
> Churchill House, Cambridge Business Park, Cowley Road,
> Cambridge, CB4 0WZ, UK
> 
> 
> Member of the CSR plc group of companies. CSR plc
> registered in England and Wales, registered number 4187346,
> registered office Churchill House, Cambridge Business Park,
> Cowley Road, Cambridge, CB4 0WZ, United Kingdom
>


      

[-- Attachment #2: history-substring-search-backward --]
[-- Type: application/octet-stream, Size: 1205 bytes --]

#!/usr/bin/env zsh 
# make sure vim that vim sees this file as a file with zsh syntax 

# history-substring-search-backward
# can also be used for the widget history-substring-search-forward.

emulate -L zsh
setopt extendedglob

zmodload -i zsh/parameter

if [[ $LASTWIDGET = history-substring-search-* ]]; then
	# here's one I prepared earlier
	search=$ZLE_HISTORY_SUBSTRING_MATCH
else
	# We need to quote metacharacters in the search string
	# since they are otherwise active in the reverse subscript.
	# We need to avoid quoting other characters since they aren't
	# and just stay quoted, rather annoyingly.
	search=${LBUFFER//(#m)[\][()\\*?#<>~^]/\\$MATCH}
	ZLE_HISTORY_SUBSTRING_MATCH=$search
fi

local -aU matches

matches=(${(kon)history[(R)*${search}*]})

# Filter out any match that's the same as the original.
# Note this isn't a pattern this time.

if [[ $WIDGET = *forward* ]]; then # arrow-down 
	eval "matches=(\${matches:#<-$HISTNO>})"
	if [[ ${#matches} == 0 ]]; then 
	    HISTNO=$HISTCMD
	else 
		HISTNO=${matches[1]}
	fi 
else # $WIDGET = *backward* arrow-up
	eval "matches=(\${matches:#<$HISTNO->})"
	if [[ ${#matches} == 0 ]]; then 
		return 1
	else 
		HISTNO=${matches[-1]}
	fi
fi



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

end of thread, other threads:[~2009-10-03 23:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <140222.25175.qm@web65614.mail.ac4.yahoo.com>
2009-09-30 19:53 ` matlab-history-beginning-search-backward Peter Stephenson
2009-09-30 22:38   ` matlab-history-beginning-search-backward Guido van Steen
2009-10-01  8:38   ` matlab-history-beginning-search-backward Peter Stephenson
2009-10-01 20:58     ` matlab-history-beginning-search-backward Guido van Steen
2009-10-02  8:48       ` matlab-history-beginning-search-backward Peter Stephenson
2009-10-03 23:36 matlab-history-beginning-search-backward Guido van Steen
2009-10-03 23:52 ` matlab-history-beginning-search-backward Guido van Steen

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