Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 2/4] Completion: Append to precommands in _normal
- X-seq: zsh-workers 44200
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH 2/4] Completion: Append to precommands in _normal
- Date: Mon, 1 Apr 2019 22:08:50 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=ofR1BhHAcqYgqkjeVej6Qy3LphSD5itNRk8I2CSyq8o=; b=gIw/yNpVnoFXSB8VNPLMrtm2qExt/iJXcur/ja9Slvg2ddHebrAu95fjeoIiOW3Iis 6+t4cTaZMbdOPiS6y12eVdh5pi/MSqcal9RFdIjlLPfh9BId5KavM8qWNrqReCmlWQp+ LXneXshc7cuzNYsFlhXBiHfckofWF3OxjXsongMqDOtAPUHD7JJ7RairiFMcRCH6gJB2 5b8QRNSgp7yUJN9IKqbAEBdVppn0KozRtwxZfzSxI7f9LR2iQpYBqhKkbtPnFvW73Ivb pZ1dusXrHgqKPP3eON8m+qxpZUu+ZBnFAgjupLF99tAUVRkJR6hvZBhs6Rvq0Y2UdQEc 0EiA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Rather than change all invocations of _normal to
{ precommands+=($service); _normal; }
add the -p option which does the same.
I don't have the ability to test texi, so that part is cargo-culted from
elsewhere in the file. Please review for sanity.
---
Completion/Base/Core/_normal | 5 +++--
Completion/Linux/Command/_setsid | 4 +---
Completion/Zsh/Command/_builtin | 4 +---
Completion/Zsh/Command/_command | 5 +----
Completion/Zsh/Command/_exec | 4 +---
Completion/Zsh/Command/_precommand | 5 +----
Doc/Zsh/compsys.yo | 13 ++++++++++---
7 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/Completion/Base/Core/_normal b/Completion/Base/Core/_normal
index fe336e303..7732837ac 100644
--- a/Completion/Base/Core/_normal
+++ b/Completion/Base/Core/_normal
@@ -1,10 +1,11 @@
#compdef -command-line-
-local _comp_command1 _comp_command2 _comp_command
+local _comp_command1 _comp_command2 _comp_command precommand
local -A opts
-zparseopts -A opts -D - s
+zparseopts -A opts -D - p+:-=precommand s
(( $+opts[-s] )) || _compskip=
+(( $#precommand )) && precommands+=(${precommand#-p})
# Check for a history reference to complete modifiers.
# $PREFIX has a quoted form of the !, so we can't test that
diff --git a/Completion/Linux/Command/_setsid b/Completion/Linux/Command/_setsid
index a8107e582..f3aef500a 100644
--- a/Completion/Linux/Command/_setsid
+++ b/Completion/Linux/Command/_setsid
@@ -1,7 +1,5 @@
#compdef setsid
-[[ $service == setsid ]] && precommands+=( setsid )
-
_arguments -s -S -A '-*' : \
'(: * -)'{-h,--help}'[display help information]' \
'(: * -)'{-V,--version}'[display version information]' \
@@ -9,4 +7,4 @@ _arguments -s -S -A '-*' : \
'(-f --fork)'{-f,--fork}'[always fork]' \
'(-w --wait)'{-w,--wait}'[wait for program to exit, and use same return code]' \
'1: :_path_commands' \
- '*:: : _normal'
+ '*:: : _normal -p $service'
diff --git a/Completion/Zsh/Command/_builtin b/Completion/Zsh/Command/_builtin
index a77af9879..ffb7b8c8d 100644
--- a/Completion/Zsh/Command/_builtin
+++ b/Completion/Zsh/Command/_builtin
@@ -1,11 +1,9 @@
#compdef builtin
-precommands+=(builtin)
-
if (( $CURRENT > 2 )); then
shift words
(( CURRENT -- ))
- _normal
+ _normal -p $service
else
local expl
diff --git a/Completion/Zsh/Command/_command b/Completion/Zsh/Command/_command
index 4e2858676..46e4ffc81 100644
--- a/Completion/Zsh/Command/_command
+++ b/Completion/Zsh/Command/_command
@@ -1,11 +1,8 @@
#compdef command
-# indicate if this is a precommand modifier
-[[ $service = command ]] && precommands+=(command)
-
_arguments \
'-v[indicate result of command search]:*:command:_path_commands' \
'-V[show result of command search in verbose form]:*:command:_path_commands' \
'(-)-p[use default PATH to find command]' \
':command:_path_commands' \
- '*::arguments: _normal'
+ '*::arguments: _normal -p $service'
diff --git a/Completion/Zsh/Command/_exec b/Completion/Zsh/Command/_exec
index 8de341a02..2498b57c0 100644
--- a/Completion/Zsh/Command/_exec
+++ b/Completion/Zsh/Command/_exec
@@ -1,9 +1,7 @@
#compdef exec
-[[ $service == exec ]] && precommands+=( exec )
-
_arguments -s -S -A '-*' : \
'-a+[set argv\[0\] to specified string]:argv[0] string' \
'-c[clear environment]' \
'-l[simulate login shell (prepend - to argv\[0\])]' \
- '*:: : _normal'
+ '*:: : _normal -p $service'
diff --git a/Completion/Zsh/Command/_precommand b/Completion/Zsh/Command/_precommand
index c9eef78af..fd88074c0 100644
--- a/Completion/Zsh/Command/_precommand
+++ b/Completion/Zsh/Command/_precommand
@@ -1,9 +1,6 @@
#compdef - nohup eval time rusage noglob nocorrect catchsegv aoss hilite eatmydata
-# precommands is made local in _main_complete
-precommands+=($words[1])
-
shift words
(( CURRENT-- ))
-_normal
+_normal -p $service
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index ba49fe298..af47f1fdb 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -4658,7 +4658,7 @@ fi
return ret)
)
findex(_normal)
-item(tt(_normal))(
+xitem(tt(_normal) [ tt(-p) var(precommand) ])(
This is the standard function called to handle completion outside
any special tt(-)var(context)tt(-). It is called both to complete the command
word and also the arguments for a command. In the second case,
@@ -4670,8 +4670,15 @@ array and the tt($CURRENT) parameter after those have been modified.
For example, the function tt(_precommand), which
completes after pre-command specifiers such as tt(nohup), removes the
first word from the tt(words) array, decrements the tt(CURRENT) parameter,
-then calls tt(_normal) again. The effect is that `tt(nohup) var(cmd ...)'
-is treated in the same way as `var(cmd ...)'.
+then calls `tt(_normal) tt(-p) tt($service)'. The effect is that
+`tt(nohup) var(cmd ...)' is treated in the same way as `var(cmd ...)'.
+
+startitem()
+item(tt(-p) var(precommand))(
+Append var(precommand) to the list of precommands. Should be used in
+nearly all cases.
+)
+enditem()
If the command name matches one of the patterns given by one of the
options tt(-p) or tt(-P) to tt(compdef), the corresponding completion
--
2.21.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author