Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Proposed patches for make completion bugs



Hello,

I've been using zsh for years and it is excellent.  One thing that I
realized recently was that it was not completing the "make" command
correctly, so I investigated, using version 5.0.7 as a base.  As far as I
can tell, my problems resulted from two issues.  The first was that zsh did
not recognize the ?= or ::= forms of variable assignment in at least GNU
make.  This should be corrected with this patch:

diff -rup a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
--- a/Completion/Unix/Command/_make    2013-11-27 14:00:19.000000000 -0500
+++ b/Completion/Unix/Command/_make    2015-04-27 20:17:05.000000000 -0400
@@ -64,18 +64,18 @@ _make-parseMakefile () {
   while read input
   do
     case "$input " in
-      # VARIABLE = value
-      ([[:alnum:]][[:alnum:]_]#[ $TAB]#=*)
-      var=${input%%[ $TAB]#=*}
+      # VARIABLE = value OR VARIABLE ?= value
+      ([[:alnum:]][[:alnum:]_]#[ $TAB]#(\?|)=*)
+      var=${input%%[ $TAB]#(\?|)=*}
       val=${input#*=}
       val=${val##[ $TAB]#}
       VARIABLES[$var]=$val
       ;;

-      # VARIABLE := value
+      # VARIABLE := value OR VARIABLE ::= value
       # Evaluated immediately
-      ([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
-      var=${input%%[ $TAB]#:=*}
+      ([[:alnum:]][[:alnum:]_]#[ $TAB]#:(:|)=*)
+      var=${input%%[ $TAB]#:(:|)=*}
       val=${input#*=}
       val=${val##[ $TAB]#}
       val=$(_make-expandVars $val)

The second issue is that as far as I can tell, expansion of "make"
variables was not happening at all.  This should be addressed by this
separate second patch, although I may have induced regressions of which I
am unaware.  I wasn't 100% sure what the original intent was for the
_make-expandVars function, but my cases appear to be fixed.

diff -rup a/Completion/Unix/Command/_make c/Completion/Unix/Command/_make
--- a/Completion/Unix/Command/_make    2013-11-27 14:00:19.000000000 -0500
+++ c/Completion/Unix/Command/_make    2015-04-27 20:17:17.000000000 -0400
@@ -7,51 +7,52 @@ _make-expandVars() {
   local open close var val front ret tmp=$1

   front=${tmp%%\$*}
+  tmp=${tmp#$front}
   case $tmp in
-    (\(*) # Variable of the form $(foobar)
+    (\$\(*) # Variable of the form $(foobar)
     open='('
     close=')'
     ;;

-    ({*) # ${foobar}
+    (\${*) # ${foobar}
     open='{'
     close='}'
     ;;

-    ([[:alpha:]]*) # $foobar. This is exactly $(f)oobar.
+    (\$[[:alpha:]]*) # $foobar. This is exactly $(f)oobar.
     open=''
     close=''
-    var=${(s::)var[1]}
+    var=${(s::)tmp[2]}
     ;;

-    (\$*) # Escaped $.
+    (\$\$*) # Escaped $.
     print -- "${front}\$$(_make-expandVars ${tmp#\$})"
     return
     ;;

     (*) # Nothing left to substitute.
-    print -- $tmp
+    print -- ${front}${tmp}
     return
     ;;
   esac

   if [[ -n $open ]]
   then
-    var=${tmp#$open}
+    var=${tmp#\$$open}
     var=${var%%$close*}
   fi

   case $var in
     ([[:alnum:]_]#)
     val=${VARIABLES[$var]}
-    ret=${ret//\$$open$var$close/$val}
+    ret=${tmp//\$$open$var$close/$val}
     ;;

     (*)
     # Improper variable name. No replacement.
     # I'm not sure if this is desired behavior.
     front+="\$$open$var$close"
-    ret=${ret/\$$open$var$close/}
+    ret=${tmp/\$$open$var$close/}
     ;;
   esac

The sourceforge site for zsh indicated that proposed patches should be sent
to this email address, but please email me if I should do anything
different, or if you need more info.  Hopefully I've included all the
correct patch text. With luck, these two changes will make it into a future
version of zsh!

Thanks,
Jared


Messages sorted by: Reverse Date, Date, Thread, Author