zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: [PATCH 0/3] completion: make: various improvements
Date: Thu, 4 Aug 2022 18:33:13 +0900	[thread overview]
Message-ID: <1D49B7B5-5B13-4700-93EF-6818676BF846@kba.biglobe.ne.jp> (raw)
In-Reply-To: <CAMP44s1pG+HBhZ9HaFG6KaKCq8oPMzygFEPSGM86cPLdsuApzA@mail.gmail.com>

As pointed out by Felipe Contreras, the biggest problem with the current
_make (with call-cammand on) is that it actually runs make to build all.
This is serious and need be fixed. I will soon push slightly modified patch
(see the end of this post) unless any problem is found.

> 2022/08/03 23:36, Felipe Contreras <felipe.contreras@gmail.com> wrote:
> 
> On Wed, Aug 3, 2022 at 3:54 AM Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>> 
>> If 'call-command' style is set to false, then these targets are not
>> offered (as a possible target).
> 
> But if you set it to true they are.
> 
> We are talking about the *current code*. The current code already has
> this behavior.

# I was thinking we were talking about how we can improve the
# current code.

Without your patch, if call-command is on, 'make <TAB>' at the top level
of the zsh source tree gives, after a very long wait, huge number of
possible targets (a few hundreds or more?), but most of them are not
valid targets.

With your patch it immediately gives about 60 candidates.
(Most of them are valid, but they still include configure.ac.)

So I thought (probably mistakenly) that part of the objectives of
the patch was to offer only valid targets. But anyway, I think it is
better to filter out invalid targets if it is easy to do so.


>> zstyle ':completion:*:make:*:' tag-order 'targets variables'
> 
> Sure, in that case those files won't be listed initially, but they
> still will be completed.

I think files are completed only if there is no matching targets.
This is enough for me, but maybe not for everyone.




The patch below is basically [1/3]+[2/3], with a few additions:

(1) In _make-parseDataBase(), filter out targets following the
line '# Not a target', and variables following '# environment'.
I think not offering environment variables is OK, but not sure
everyone agrees with this.
(2) Use make option -q instead of -s (as in your awk-version).
(3) add options -C and -S to _arguments.
(4) Do not call _make-parse{Makefile,DataBase}() when completing
options for 'make -<TAB>'.

# As you write, this is much slower than your awk-version.


diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
index ae91440f0..510368e8b 100644
--- a/Completion/Unix/Command/_make
+++ b/Completion/Unix/Command/_make
@@ -118,10 +118,34 @@ _make-parseMakefile () {
   done
 }
 
+_make-parseDataBase () {
+  local input var TAB=$'\t' IFS= skip=0
+
+  while read input
+  do
+    if [[ $skip = 1 ]]; then
+      skip=0
+      continue
+    fi
+    case "$input " in
+      (\# Not a target*|\# environment*)
+        skip=1  # skip next line
+        ;;
+      ([[:alnum:]][[:alnum:]_]#[" "$TAB]#(\?|:|::|)=*)
+        var=${input%%[ $TAB]#(\?|:|::|)=*}
+        VARIABLES[$var]=1
+        ;;
+      ([[*?[:alnum:]$][^$TAB:=%]#:[^=]*)
+        TARGETS+=( ${input%%:*} )
+        ;;
+    esac
+  done
+}
+
 _make() {
 
   local prev="$words[CURRENT-1]" file expl tmp is_gnu incl match basedir nul=$'\0'
-  local context state state_descr line
+  local curcontext=$curcontext state state_descr line
   local -a option_specs
   local -A VARIABLES VAR_ARGS opt_args
   local -aU TARGETS keys
@@ -185,7 +209,7 @@ _make() {
     )
   fi
 
-  _arguments -s $option_specs \
+  _arguments -C -S -s $option_specs \
     '*:make target:->target' && ret=0
 
   [[ $state = cdir ]] && cdir=-2
@@ -214,6 +238,10 @@ _make() {
     ;;
 
     (target)
+    # target name starting with '-' is allowed only after '--'
+    if [[ $words[CURRENT] = -* ]] && (( ${words[(i)--]} > CURRENT )); then
+      return ret
+    fi
     file=${(v)opt_args[(I)(-f|--file|--makefile)]}
     if [[ -n $file ]]
     then
@@ -239,7 +267,7 @@ _make() {
       if [[ $is_gnu == gnu ]] 
       then
         if zstyle -t ":completion:${curcontext}:targets" call-command; then
-          _make-parseMakefile < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" --always-make 2> /dev/null)
+          _make-parseDataBase < <(_call_program targets "$words[1]" -nqp --no-print-directory -f "$file" .DEFAULT 2> /dev/null)
         else
           _make-parseMakefile < $file
         fi






  reply	other threads:[~2022-08-04  9:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-30  1:03 Felipe Contreras
2022-07-30  1:03 ` [PATCH 1/3] completion: make: don't build everything Felipe Contreras
2022-07-30  1:03 ` [PATCH 2/3] completion: make: add a simpler parser Felipe Contreras
2022-07-30  1:03 ` [PATCH 3/3] completion: make: fix whitespaces Felipe Contreras
2022-08-04  8:50   ` Jun T
2022-08-04 15:57     ` Felipe Contreras
2022-08-02 10:42 ` [PATCH 0/3] completion: make: various improvements Jun T
2022-08-02 23:02   ` Felipe Contreras
2022-08-03  8:48     ` Jun T
2022-08-03 14:36       ` Felipe Contreras
2022-08-04  9:33         ` Jun T [this message]
2022-08-04 17:03           ` Felipe Contreras

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=1D49B7B5-5B13-4700-93EF-6818676BF846@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --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).