zsh-users
 help / color / mirror / code / Atom feed
* Re: menuselect and history
       [not found] <20040419095235.GA1285@kopfermann.org>
@ 2004-04-19 16:23 ` Bart Schaefer
  2004-04-20 16:08   ` Felix Rosencrantz
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-04-19 16:23 UTC (permalink / raw)
  To: Matthias Kopfermann; +Cc: zsh-users

On Apr 19, 11:52am, Matthias Kopfermann wrote:
> 
> i just wondered whether it wouldn't be very cool if menuselect was
> useable with historylines.

--- 8< --- snip --- 8< ---
#compdef -k menu-select ^X:

# _history_select -- create a menu-selection of the command history

# Works only if invoked on the command word (( CURRENT == 1 )).
# Requires 4.2.0 or a recent 4.1.x for the 'n' parameter flag and
# array+=string assignments.
# BUGS:
#	This doesn't really scroll through the history, it scrolls
#	through commands in the history and re-inserts one as the
#	current history line.  So accept-line-and-down-history will
#	not work as expected, but accept-and-infer-next-history is
#	probably OK.
# TODO:
#	special case for (( HISTSIZE > 9999 ))
#	zstyle for how much of the history to include
#	use the numeric prefix to set the starting point?

emulate -L zsh
zmodload -i zsh/parameter || return 1
(( CURRENT == 1 )) || return 1

local h c
local -a histnos commands displays
histnos=(${(Onk)history})

for h in $histnos
do
  c=$history[$h]
  commands+=$c

  # Various display bugs require that we trim each selection to fit on
  # a single line.  Use a display that includes the history number.
  if [[ $#c -gt 71 ]]; then c[72,-1]=...; fi
  c=${c//$'\n'*/ ...}
  displays+=${(r:5:)${(l:4:)h}}$c
done

compadd -Q -l -V commands -d displays -a commands
--- 8< --- snip --- 8< ---


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

* Re: menuselect and history
  2004-04-19 16:23 ` menuselect and history Bart Schaefer
@ 2004-04-20 16:08   ` Felix Rosencrantz
  2004-04-22  4:57     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Felix Rosencrantz @ 2004-04-20 16:08 UTC (permalink / raw)
  To: zsh-users

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 355 bytes --]

As Matthias predicted, this is cool.  It would be even cooler if it could be
connected to the incremental search commands.  The list presented would be
winnowed as the user types the search term.

-FR.


	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢
http://photos.yahoo.com/ph/print_splash


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

* Re: menuselect and history
  2004-04-20 16:08   ` Felix Rosencrantz
@ 2004-04-22  4:57     ` Bart Schaefer
  2004-04-23  6:56       ` Felix Rosencrantz
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-04-22  4:57 UTC (permalink / raw)
  To: zsh-users

On Apr 20,  9:08am, Felix Rosencrantz wrote:
}
} As Matthias predicted, this is cool. It would be even cooler if it
} could be connected to the incremental search commands. The list
} presented would be winnowed as the user types the search term.

This might be possible, but it'd be significantly more difficult.
Menu selection just doesn't work that way -- the incremental search
commands scan through the listing, they don't narrow it -- so what
in effect you'd need to do is exit from and restart completion on
every keystroke.

However, given the _history_select function that I posted, you can
do this:

autoload -U incremental-complete-word
zle -N incremental-complete-word
bindkey '^Xi' incremental-complete-word
zstyle :incremental list yes
zstyle ':completion:incremental:*' completer _history_select ...

(where "..." are whatever completers you normally would want to try)
and then when you type C-x i on the command word you should get exactly
what you just asked for, except that you _can't_ also scroll around in
the list of choices.

This does show a bug in incremental-complete-word -- the way that it
computes its prompt pre-dates some changes in the conventions for the
values of the _lastcomp association.  (There are likely to be other
outdated things about i-c-w that are problems waiting to happen.)


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

* Re: menuselect and history
  2004-04-22  4:57     ` Bart Schaefer
@ 2004-04-23  6:56       ` Felix Rosencrantz
  2004-04-23 16:18         ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Felix Rosencrantz @ 2004-04-23  6:56 UTC (permalink / raw)
  To: zsh-users

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 459 bytes --]

Thanks Bart.  It looks like something I would want to use if it fully worked.
It has the problem you mentioned, lines cannot be selected.  It also seems to
have a problem when a space is typed, and it generates error messages.

Seems like it be a nifty feature to add to the incremental search code.

-FR.


	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢
http://photos.yahoo.com/ph/print_splash


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

* Re: menuselect and history
  2004-04-23  6:56       ` Felix Rosencrantz
@ 2004-04-23 16:18         ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2004-04-23 16:18 UTC (permalink / raw)
  To: zsh-users

On Apr 22, 11:56pm, Felix Rosencrantz wrote:
> 
> Thanks Bart. It looks like something I would want to use if it fully
> worked. It has the problem you mentioned, lines cannot be selected. It
> also seems to have a problem when a space is typed

i-c-w is completing a *word*, so when you type a space it thinks you're
at the end of the word and tries to accept a match or go on to the next
word's set of completions (which _history_select won't do, because it
only completes in the command position).


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

end of thread, other threads:[~2004-04-23 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20040419095235.GA1285@kopfermann.org>
2004-04-19 16:23 ` menuselect and history Bart Schaefer
2004-04-20 16:08   ` Felix Rosencrantz
2004-04-22  4:57     ` Bart Schaefer
2004-04-23  6:56       ` Felix Rosencrantz
2004-04-23 16:18         ` 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).