zsh-workers
 help / color / mirror / Atom feed
* [PATCH] Make _expand_alias more usable as a completer
@ 2021-05-28 21:59 Marlon Richert
  2021-06-02 23:23 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Marlon Richert @ 2021-05-28 21:59 UTC (permalink / raw)
  To: Zsh hackers list

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

When _expand_alias is invoked as a completer, if 'complete' is set to
'true', let _expand_alias always return 1. This is analogous to how
this style behaves when _expand_alias is invoked as a widget or when
the _expand completer's 'accept-exact' style is set to 'continue',
which allows you to put it at the start of the 'completer' list.

Additionally, tag alias expansions as 'expansions', rather than as
'aliases', to prevent aliases & alias expansion from being lumped into
the same group.

[-- Attachment #2: 0001-Make-_expand_alias-more-usable-as-a-completer.txt --]
[-- Type: text/plain, Size: 2590 bytes --]

From 7722347b8e408413f7b49af5e16b1b4a518c1aa9 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Sat, 29 May 2021 00:16:22 +0300
Subject: [PATCH] Make _expand_alias more usable as a completer

When _expand_alias is invoked as a completer, if 'complete' is
set to 'true', let _expand_alias always return 1. This is analogous to
how this style behaves when _expand_alias is invoked as a widget or when
the _expand completer's 'accept-exact' style is set to 'continue', which
allows you to put it at the start of the 'completer' list.

Additionally, tag alias expansions as 'expansions', rather than as
'aliases', to prevent aliases & alias expansion from being lumped into
the same group.
---
 Completion/Base/Completer/_expand_alias |  3 ++-
 Doc/Zsh/compsys.yo                      | 10 ++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Completion/Base/Completer/_expand_alias b/Completion/Base/Completer/_expand_alias
index 8240e4162..275da157c 100644
--- a/Completion/Base/Completer/_expand_alias
+++ b/Completion/Base/Completer/_expand_alias
@@ -59,7 +59,8 @@ if [[ -n $tmp ]]; then
     fi
   fi
   zstyle -T ":completion:${curcontext}:" add-space || suf=( -S '' )
-  $pre _wanted aliases expl alias compadd -UQ "$suf[@]" -- ${tmp%%[[:blank:]]##}
+  $pre _wanted expansions expl expansion compadd -UQ "$suf[@]" -- ${tmp%%[[:blank:]]##} &&
+      ! zstyle -t ":completion:${curcontext}:" complete
 elif (( $#pre )) && zstyle -t ":completion:${curcontext}:" complete; then
   $pre _aliases -s "$sel" -S ''
 else
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 89b918d60..1b01f09a8 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1295,10 +1295,12 @@ the two strings `tt(start)' and `tt(stop)'.
 )
 kindex(complete, completion style)
 item(tt(complete))(
-This is used by the tt(_expand_alias) function when invoked as a
-bindable command.  If set to `true' and the word on the command
-line is not the name of an alias, matching alias names will be
-completed.
+This is used by the tt(_expand_alias) function. When tt(_expand_alias) is 
+invoked as a bindable command, if tt(complete) is set to `true' and the word on 
+the command line is not the name of an alias, matching alias names will be 
+completed. When tt(_expand_alias) is invoked as a completer, if tt(complete) is 
+set to `true', tt(_expand_alias) will add the expansion as a match and the 
+completion system will also be allowed to continue.
 )
 kindex(complete-options, completion style)
 item(tt(complete-options))(
-- 
2.30.1 (Apple Git-130)


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

* Re: [PATCH] Make _expand_alias more usable as a completer
  2021-05-28 21:59 [PATCH] Make _expand_alias more usable as a completer Marlon Richert
@ 2021-06-02 23:23 ` Oliver Kiddle
  2021-06-03 21:42   ` Marlon Richert
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2021-06-02 23:23 UTC (permalink / raw)
  To: Zsh hackers list

On 29 May, Marlon Richert wrote:
> When _expand_alias is invoked as a completer, if 'complete' is set to
> 'true', let _expand_alias always return 1. This is analogous to how
> this style behaves when _expand_alias is invoked as a widget or when
> the _expand completer's 'accept-exact' style is set to 'continue',
> which allows you to put it at the start of the 'completer' list.

In practical tests, I'm not finding that this works too well, it ends up
removing the characters typed. From _expand_aliases, you end up with a
call to compadd -QU and later you get a compadd -Q. For testing play
around with the following:

  _foo() {
    compadd -QU 'ls -al'
    compadd -Q lsusb lsvfs
  }
  compdef _foo foo
  foo ls<tab>

I can see the motivation for the feature but it needs compstate[insert]=menu
to be usable, at least from my setup. Setting that tends to be applicable
wherever you're using -U to change what was typed so far.

It feels like a bug that this example can't recognise the unambiguous
"ls" prefix but aliases often expand to something quite different to the
initial alias name.

I also wonder if this would be better done from within _command_names
directly but I'm not sure.

Oliver


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

* Re: [PATCH] Make _expand_alias more usable as a completer
  2021-06-02 23:23 ` Oliver Kiddle
@ 2021-06-03 21:42   ` Marlon Richert
  0 siblings, 0 replies; 3+ messages in thread
From: Marlon Richert @ 2021-06-03 21:42 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh hackers list

On Thu, Jun 3, 2021 at 2:24 AM Oliver Kiddle <opk@zsh.org> wrote:
> In practical tests, I'm not finding that this works too well, it ends up
> removing the characters typed.

I cannot reproduce that. Here's what I tried:

% cd $(mktemp -d)
% print "PS1='%# ' PS2='' RPS2='< %^'\nsetopt transientrprompt" > .zshrc
% exec env -i HOME=$PWD TERM=$TERM zsh -d
% autoload -Uz compinit
% compinit
% _foo() {
compadd -QU 'ls -al'
compadd -Q lsusb lsvfs
}
% compdef _foo foo
% foo <tab>
% foo ls<tab>
ls -al  lsusb   lsvfs

It inserts the unambiguous prefix and cycles through the three
choices, without removing any characters I've typed. Am I missing
something?

> I also wonder if this would be better done from within _command_names
> directly but I'm not sure.

Actually, I feel like it could instead be added to the _expand
completer. Would that be a better idea than what I presented in this
patch? I could, for example, move the actual business logic for
expanding aliases from _expand_alias to _expand, and then have
_expand_alias call _expand to do the work.


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

end of thread, other threads:[~2021-06-03 21:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 21:59 [PATCH] Make _expand_alias more usable as a completer Marlon Richert
2021-06-02 23:23 ` Oliver Kiddle
2021-06-03 21:42   ` Marlon Richert

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git