zsh-workers
 help / color / mirror / code / Atom feed
From: Jared Ahern <jared.ahern@gmail.com>
To: zsh-workers@zsh.org
Subject: Proposed patches for make completion bugs
Date: Mon, 27 Apr 2015 20:45:55 -0400	[thread overview]
Message-ID: <CA+80RYdqaKGNXE9J9gnT7uNcbmPmqoUHjw+w=N_+jwC+gm_7Lg@mail.gmail.com> (raw)

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

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

             reply	other threads:[~2015-04-28  0:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-28  0:45 Jared Ahern [this message]
2015-04-28  8:34 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+80RYdqaKGNXE9J9gnT7uNcbmPmqoUHjw+w=N_+jwC+gm_7Lg@mail.gmail.com' \
    --to=jared.ahern@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).