zsh-users
 help / color / mirror / code / Atom feed
* Make Completion
@ 2013-07-10 13:28 Nick Cross
  2013-07-11  9:54 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Cross @ 2013-07-10 13:28 UTC (permalink / raw)
  To: zsh-users


Hi,

Am I right in thinking that the make completion under ZSH (5.0.2 on 
Fedora18) does not complete the command line -* options (as opposed to 
Bash which does) ? I have tried "make -<tab>" and nothing happens - in 
bash it prints out a menu of the - options (e.g. --debug).

Looking at the _make completion there  does not seem to be any 
description for the options (as opposed to e.g. in _lynx)

Thanks

Nick


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

* Re: Make Completion
  2013-07-10 13:28 Make Completion Nick Cross
@ 2013-07-11  9:54 ` Peter Stephenson
  2013-07-11 12:58   ` Nick Cross
  2013-07-11 22:15   ` Nick Cross
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Stephenson @ 2013-07-11  9:54 UTC (permalink / raw)
  To: zsh-users

On Wed, 10 Jul 2013 14:28:13 +0100
Nick Cross <zsh@goots.org> wrote:
> Am I right in thinking that the make completion under ZSH (5.0.2 on
> Fedora18) does not complete the command line -* options (as opposed to
> Bash which does) ? I have tried "make -<tab>" and nothing happens - in
> bash it prints out a menu of the - options (e.g. --debug).

Yes, it's fairly basic in terms of options, though quite smart about
looking inside makefiles.

Currently it's quite hard to update since it doesn't use _arguments.  As
a first step, this fixes that problem, so it should be much easier to
add further GNU option handling as a next step (or further variants if
desired).

Lightly tested --- I don't think I've completely broken it but 100%
satisfaction not guaranteed.

diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
index 53e2e1b..72d16bb 100644
--- a/Completion/Unix/Command/_make
+++ b/Completion/Unix/Command/_make
@@ -148,7 +148,9 @@ _make-findBasedir () {
 _make() {
 
   local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match
-  local -A TARGETS VARIABLES
+  local context state line
+  local -a option_specs
+  local -A TARGETS VARIABLES opt_args
   local ret=1
 
   _pick_variant -r is_gnu gnu=GNU unix -v -f
@@ -156,21 +158,43 @@ _make() {
   if [[ $is_gnu == gnu ]]
   then
     incl="(-|)include"
+    # TBD: update option_specs
+    option_specs=(
+      '-C[change directory first]:directory:->dir'
+      '-I[include directory for makefiles]:directory:->dir'
+      '-f[specify makefile]:makefile:->file'
+      '-o[specify file not to remake]:file not to remake:->file'
+      '-W[pretend file was modified]:file to treat as modified:->file'
+    )
   else
+    # Basic make options only.
     incl=.include
+    option_specs=(
+      '-C[change directory first]:directory:->dir'
+      '-I[include directory for makefiles]:directory:->dir'
+      '-f[specify makefile]:makefile:->file'
+      '-o[specify file not to remake]:file not to remake:->file'
+      '-W[pretend file was modified]:file to treat as modified:->file'
+    )
   fi
 
-  if [[ "$prev" == -[CI] ]]
-  then
+  _arguments -s $option_specs \
+    '*:make target:->target' && ret=0
+
+  case $state in
+    (dir)
     _files -W ${(q)$(_make-findBasedir ${words[1,CURRENT-1]})} -/ && ret=0
-  elif [[ "$prev" == -[foW] ]]
-  then
+    ;;
+
+    (file)
     _files -W ${(q)$(_make-findBasedir $words)} && ret=0
-  else
-    file="$words[(I)-f]"
-    if (( file ))
+    ;;
+
+    (target)
+    file=($opt_args[(K)(-f|--file|--makefile)])
+    file=$file[1]
+    if [[ -n $file ]]
     then
-      file=${~words[file+1]}
       [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file
       [[ -r $file ]] || file=
     else
@@ -222,7 +246,7 @@ _make() {
           compadd -S '=' -- ${(k)VARIABLES} && ret=0
       done
     fi
-  fi
+  esac
 
   return ret
 }


pws


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

* Re: Make Completion
  2013-07-11  9:54 ` Peter Stephenson
@ 2013-07-11 12:58   ` Nick Cross
  2013-07-11 13:33     ` Peter Stephenson
  2013-07-11 22:15   ` Nick Cross
  1 sibling, 1 reply; 7+ messages in thread
From: Nick Cross @ 2013-07-11 12:58 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users


Thats brilliant thanks! I'll look at completing the rest of the 
arguments - do you accept pull requests on the github mirror?

Cheers

Nick


On 11/07/13 10:54, Peter Stephenson wrote:
> On Wed, 10 Jul 2013 14:28:13 +0100
> Nick Cross <zsh@goots.org> wrote:
>> Am I right in thinking that the make completion under ZSH (5.0.2 on
>> Fedora18) does not complete the command line -* options (as opposed to
>> Bash which does) ? I have tried "make -<tab>" and nothing happens - in
>> bash it prints out a menu of the - options (e.g. --debug).
>
> Yes, it's fairly basic in terms of options, though quite smart about
> looking inside makefiles.
>
> Currently it's quite hard to update since it doesn't use _arguments.  As
> a first step, this fixes that problem, so it should be much easier to
> add further GNU option handling as a next step (or further variants if
> desired).
>
> Lightly tested --- I don't think I've completely broken it but 100%
> satisfaction not guaranteed.
>
> diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
> index 53e2e1b..72d16bb 100644
> --- a/Completion/Unix/Command/_make
> +++ b/Completion/Unix/Command/_make
> @@ -148,7 +148,9 @@ _make-findBasedir () {
>   _make() {
>
>     local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match
> -  local -A TARGETS VARIABLES
> +  local context state line
> +  local -a option_specs
> +  local -A TARGETS VARIABLES opt_args
>     local ret=1
>
>     _pick_variant -r is_gnu gnu=GNU unix -v -f
> @@ -156,21 +158,43 @@ _make() {
>     if [[ $is_gnu == gnu ]]
>     then
>       incl="(-|)include"
> +    # TBD: update option_specs
> +    option_specs=(
> +      '-C[change directory first]:directory:->dir'
> +      '-I[include directory for makefiles]:directory:->dir'
> +      '-f[specify makefile]:makefile:->file'
> +      '-o[specify file not to remake]:file not to remake:->file'
> +      '-W[pretend file was modified]:file to treat as modified:->file'
> +    )
>     else
> +    # Basic make options only.
>       incl=.include
> +    option_specs=(
> +      '-C[change directory first]:directory:->dir'
> +      '-I[include directory for makefiles]:directory:->dir'
> +      '-f[specify makefile]:makefile:->file'
> +      '-o[specify file not to remake]:file not to remake:->file'
> +      '-W[pretend file was modified]:file to treat as modified:->file'
> +    )
>     fi
>
> -  if [[ "$prev" == -[CI] ]]
> -  then
> +  _arguments -s $option_specs \
> +    '*:make target:->target' && ret=0
> +
> +  case $state in
> +    (dir)
>       _files -W ${(q)$(_make-findBasedir ${words[1,CURRENT-1]})} -/ && ret=0
> -  elif [[ "$prev" == -[foW] ]]
> -  then
> +    ;;
> +
> +    (file)
>       _files -W ${(q)$(_make-findBasedir $words)} && ret=0
> -  else
> -    file="$words[(I)-f]"
> -    if (( file ))
> +    ;;
> +
> +    (target)
> +    file=($opt_args[(K)(-f|--file|--makefile)])
> +    file=$file[1]
> +    if [[ -n $file ]]
>       then
> -      file=${~words[file+1]}
>         [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file
>         [[ -r $file ]] || file=
>       else
> @@ -222,7 +246,7 @@ _make() {
>             compadd -S '=' -- ${(k)VARIABLES} && ret=0
>         done
>       fi
> -  fi
> +  esac
>
>     return ret
>   }
>
>
> pws
>


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

* Re: Make Completion
  2013-07-11 12:58   ` Nick Cross
@ 2013-07-11 13:33     ` Peter Stephenson
  2013-07-11 14:44       ` Frank Terbeck
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2013-07-11 13:33 UTC (permalink / raw)
  To: zsh-users

On Thu, 11 Jul 2013 13:58:41 +0100
Nick Cross <nick@goots.org> wrote:
> Thats brilliant thanks! I'll look at completing the rest of the 
> arguments - do you accept pull requests on the github mirror?

As long as we get something that turns into a patch and I or someone
else knows how to retrieve it, it doesn't really matter what the original
format is.  Probably easiest if you just post the "git log -p" output
here, though, so everyone can see it before committing to the main zsh
repository.

pws


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

* Re: Make Completion
  2013-07-11 13:33     ` Peter Stephenson
@ 2013-07-11 14:44       ` Frank Terbeck
  0 siblings, 0 replies; 7+ messages in thread
From: Frank Terbeck @ 2013-07-11 14:44 UTC (permalink / raw)
  To: zsh-users; +Cc: Nick Cross

Peter Stephenson wrote:
> Nick Cross <nick@goots.org> wrote:
>> Thats brilliant thanks! I'll look at completing the rest of the 
>> arguments - do you accept pull requests on the github mirror?
>
> As long as we get something that turns into a patch and I or someone
> else knows how to retrieve it, it doesn't really matter what the original
> format is.  Probably easiest if you just post the "git log -p" output
> here, though, so everyone can see it before committing to the main zsh
> repository.

For easier consumption with git's mail-related tools, a patch series
produced by `git format-patch' mailed to the zsh-workers@zsh.org mailing
list (possibly via `git send-email') would be best.

Regards, Frank


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

* Re: Make Completion
  2013-07-11  9:54 ` Peter Stephenson
  2013-07-11 12:58   ` Nick Cross
@ 2013-07-11 22:15   ` Nick Cross
  2013-07-12  4:26     ` Bart Schaefer
  1 sibling, 1 reply; 7+ messages in thread
From: Nick Cross @ 2013-07-11 22:15 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users


One problem I have noticed when completing the options list is that it 
no longer seems to complete the makefile targets if the Makefile is 
selected using e.g. -f Makefile.FOO (so there is no default named 
Makefile in the directory). The 
"file=($opt_args[(K)(-f|--file|--makefile)])" does not seem to be 
returning a valid string/file

Regards

Nick


On 11/07/13 10:54, Peter Stephenson wrote:
> On Wed, 10 Jul 2013 14:28:13 +0100
> Nick Cross <zsh@goots.org> wrote:
>> Am I right in thinking that the make completion under ZSH (5.0.2 on
>> Fedora18) does not complete the command line -* options (as opposed to
>> Bash which does) ? I have tried "make -<tab>" and nothing happens - in
>> bash it prints out a menu of the - options (e.g. --debug).
>
> Yes, it's fairly basic in terms of options, though quite smart about
> looking inside makefiles.
>
> Currently it's quite hard to update since it doesn't use _arguments.  As
> a first step, this fixes that problem, so it should be much easier to
> add further GNU option handling as a next step (or further variants if
> desired).
>
> Lightly tested --- I don't think I've completely broken it but 100%
> satisfaction not guaranteed.
>
> diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
> index 53e2e1b..72d16bb 100644
> --- a/Completion/Unix/Command/_make
> +++ b/Completion/Unix/Command/_make
> @@ -148,7 +148,9 @@ _make-findBasedir () {
>   _make() {
>
>     local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match
> -  local -A TARGETS VARIABLES
> +  local context state line
> +  local -a option_specs
> +  local -A TARGETS VARIABLES opt_args
>     local ret=1
>
>     _pick_variant -r is_gnu gnu=GNU unix -v -f
> @@ -156,21 +158,43 @@ _make() {
>     if [[ $is_gnu == gnu ]]
>     then
>       incl="(-|)include"
> +    # TBD: update option_specs
> +    option_specs=(
> +      '-C[change directory first]:directory:->dir'
> +      '-I[include directory for makefiles]:directory:->dir'
> +      '-f[specify makefile]:makefile:->file'
> +      '-o[specify file not to remake]:file not to remake:->file'
> +      '-W[pretend file was modified]:file to treat as modified:->file'
> +    )
>     else
> +    # Basic make options only.
>       incl=.include
> +    option_specs=(
> +      '-C[change directory first]:directory:->dir'
> +      '-I[include directory for makefiles]:directory:->dir'
> +      '-f[specify makefile]:makefile:->file'
> +      '-o[specify file not to remake]:file not to remake:->file'
> +      '-W[pretend file was modified]:file to treat as modified:->file'
> +    )
>     fi
>
> -  if [[ "$prev" == -[CI] ]]
> -  then
> +  _arguments -s $option_specs \
> +    '*:make target:->target' && ret=0
> +
> +  case $state in
> +    (dir)
>       _files -W ${(q)$(_make-findBasedir ${words[1,CURRENT-1]})} -/ && ret=0
> -  elif [[ "$prev" == -[foW] ]]
> -  then
> +    ;;
> +
> +    (file)
>       _files -W ${(q)$(_make-findBasedir $words)} && ret=0
> -  else
> -    file="$words[(I)-f]"
> -    if (( file ))
> +    ;;
> +
> +    (target)
> +    file=($opt_args[(K)(-f|--file|--makefile)])
> +    file=$file[1]
> +    if [[ -n $file ]]
>       then
> -      file=${~words[file+1]}
>         [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file
>         [[ -r $file ]] || file=
>       else
> @@ -222,7 +246,7 @@ _make() {
>             compadd -S '=' -- ${(k)VARIABLES} && ret=0
>         done
>       fi
> -  fi
> +  esac
>
>     return ret
>   }
>
>
> pws
>


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

* Re: Make Completion
  2013-07-11 22:15   ` Nick Cross
@ 2013-07-12  4:26     ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2013-07-12  4:26 UTC (permalink / raw)
  To: zsh-users

On Jul 11, 11:15pm, Nick Cross wrote:
}
} "file=($opt_args[(K)(-f|--file|--makefile)])" does not seem to be 
} returning a valid string/file

PWS has a bit of a think-o there.  (K) means to treat the keys of the
array as patterns and compare them to the subcript expression.  What
he wants is (I), which compares the subscript as a pattern to the keys
of the array -- but that returns the keys, not the values, so what is
needed is ${(v)opt_args[(I)(-f|--file|--makefile)]} to force values
to be returned.


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

end of thread, other threads:[~2013-07-12  4:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-10 13:28 Make Completion Nick Cross
2013-07-11  9:54 ` Peter Stephenson
2013-07-11 12:58   ` Nick Cross
2013-07-11 13:33     ` Peter Stephenson
2013-07-11 14:44       ` Frank Terbeck
2013-07-11 22:15   ` Nick Cross
2013-07-12  4:26     ` 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).