zsh-users
 help / color / mirror / code / Atom feed
* compctl tips needed on words with common prefix
@ 1998-06-17 15:10 Paul Lew
  1998-06-17 15:34 ` Zefram
  1998-06-17 16:07 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Paul Lew @ 1998-06-17 15:10 UTC (permalink / raw)
  To: zsh-users

I am trying to define the following compctl:

	compctl -k "(ci co construct cinema)" xxx

This works fine.  Now I am adding extra:

	compctl -k "(ci co construct cinema)" \
		-x "r[co,;]" -k "(co1 co2 co3)" \
		- "r[construct,;]" -k "(cons1 cons2)" -- xxx 

I could not get 'construct' to be completed by <TAB> because the 'co'
is recognized first, i.e.,

	xxx c<TAB>
ci   cinema   co   construct

	xxx co<TAB>
co1  co1   co3

	xxx con<TAB>
nothing

  Any trick to this?  Thanks in advance...


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

* Re: compctl tips needed on words with common prefix
  1998-06-17 15:10 compctl tips needed on words with common prefix Paul Lew
@ 1998-06-17 15:34 ` Zefram
  1998-06-17 16:17   ` Paul Lew
  1998-06-17 16:07 ` Bart Schaefer
  1 sibling, 1 reply; 7+ messages in thread
From: Zefram @ 1998-06-17 15:34 UTC (permalink / raw)
  To: Paul Lew; +Cc: zsh-users

Paul Lew wrote:
>I could not get 'construct' to be completed by <TAB> because the 'co'
>is recognized first,

So put the "construct" rule before the "co" rule.

-zefram


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

* Re: compctl tips needed on words with common prefix
  1998-06-17 15:10 compctl tips needed on words with common prefix Paul Lew
  1998-06-17 15:34 ` Zefram
@ 1998-06-17 16:07 ` Bart Schaefer
  1998-06-17 16:33   ` Paul Lew
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 1998-06-17 16:07 UTC (permalink / raw)
  To: Paul Lew, zsh-users

On Jun 17, 11:10am, Paul Lew wrote:
} Subject: compctl tips needed on words with common prefix
}
} 	compctl -k "(ci co construct cinema)" \
} 		-x "r[co,;]" -k "(co1 co2 co3)" \
} 		- "r[construct,;]" -k "(cons1 cons2)" -- xxx 
} 
} I could not get 'construct' to be completed by <TAB> because the 'co'
} is recognized first

The problem is with the "r[co,;]" -- that's what is spotting the "co"
and insisting that only 1 2 or 3 may follow it.

What you mean to say, I think, is that any of (co1 co2 co3) may appear
*after* "co ".  Right?  In that case, what you want is "c[-1,co]":

	compctl -k "(ci co construct cinema)" \
		-x "c[-1,co]" -k "(co1 co2 co3)" \
		- "c[-1,construct]" -k "(cons1 cons2)" -- xxx 

The above will complete to produce command lines like

	xxx co co2 construct cons1 cinema
	xxx construct cons2 cinema co co1
	xxx co co2 ci construct cons1 cinema co co1

That is, always requiring "co co[123]" and "construct cons[12]" to be
paired, but allowing the pairs of them to appear anywhere and to be
interspersed with "ci" and "cinema".

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: compctl tips needed on words with common prefix
  1998-06-17 15:34 ` Zefram
@ 1998-06-17 16:17   ` Paul Lew
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Lew @ 1998-06-17 16:17 UTC (permalink / raw)
  To: Zefram; +Cc: Paul Lew, zsh-users

>>>>> "Zefram" == Zefram  <zefram@tao.co.uk> writes:

    lew>> I could not get 'construct' to be completed by <TAB> because
    lew>> the 'co' is recognized first,

    Zefram> So put the "construct" rule before the "co" rule.

I tried that but still does not work:

	compctl -k "(ci construct co cinema)" \
		-x "r[construct,;]" -k "(cons1 cons2)" \
		- "r[co,;]" -k "(co1 co2 co3)" -- xxx

Try it on your version.  Mines failed (both 3.1.3 and 3.0.5).


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

* Re: compctl tips needed on words with common prefix
  1998-06-17 16:07 ` Bart Schaefer
@ 1998-06-17 16:33   ` Paul Lew
  1998-06-17 18:27     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Lew @ 1998-06-17 16:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Paul Lew, zsh-users

>>>>> "Bart" == Bart Schaefer <schaefer@brasslantern.com> writes:

    Bart> On Jun 17, 11:10am, Paul Lew wrote:
    Bart> } Subject: compctl tips needed on words with common prefix
    Bart> }
    Bart> } 	compctl -k "(ci co construct cinema)" \
    Bart> } 		-x "r[co,;]" -k "(co1 co2 co3)" \
    Bart> } 		- "r[construct,;]" -k "(cons1 cons2)" -- xxx 
    Bart> } 
    Bart> } I could not get 'construct' to be completed by <TAB>
    Bart> } because the 'co' is recognized first

    Bart> The problem is with the "r[co,;]" -- that's what is spotting
    Bart> the "co" and insisting that only 1 2 or 3 may follow it.

    Bart> What you mean to say, I think, is that any of (co1 co2 co3)
    Bart> may appear *after* "co ".  Right?  In that case, what you
    Bart> want is "c[-1,co]":

    Bart> compctl -k "(ci co construct cinema)" \
    Bart> -x "c[-1,co]" -k "(co1 co2 co3)" \
    Bart> - "c[-1,construct]" -k "(cons1 cons2)" -- xxx 

    Bart> The above will complete to produce command lines like

    Bart> xxx co co2 construct cons1 cinema
    Bart> xxx construct cons2 cinema co co1
    Bart> xxx co co2 ci construct cons1 cinema co co1

That works.  But my situation is a little different, what I would like
is to have "co1 co2 co3" be part of the completion words as long as
there is a word "co" in front, i.e.,

      xxx co co1 co2	       or
      xxx co co3 co1 co2

Do c[offset,string] require a fixed offset or can be a range?  Use -1
as offset will only work for the 1st word.  Also, I still want to be
able to complete the 'construct'.  Any option left?  Thanks...


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

* Re: compctl tips needed on words with common prefix
  1998-06-17 16:33   ` Paul Lew
@ 1998-06-17 18:27     ` Bart Schaefer
  1998-06-18  2:58       ` Paul Lew
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 1998-06-17 18:27 UTC (permalink / raw)
  To: Paul Lew, zsh-users

On Jun 17, 12:33pm, Paul Lew wrote:
} Subject: Re: compctl tips needed on words with common prefix
}
} >>>>> "Bart" == Bart Schaefer <schaefer@brasslantern.com> writes:
} 
}     Bart> What you mean to say, I think, is that any of (co1 co2 co3)
}     Bart> may appear *after* "co ".  Right?  In that case, what you
}     Bart> want is "c[-1,co]":
} 
}     Bart> compctl -k "(ci co construct cinema)" \
}     Bart> -x "c[-1,co]" -k "(co1 co2 co3)" \
}     Bart> - "c[-1,construct]" -k "(cons1 cons2)" -- xxx 
} 
} That works.  But my situation is a little different, what I would like
} is to have "co1 co2 co3" be part of the completion words as long as
} there is a word "co" in front, i.e.,
} 
}       xxx co co1 co2	       or
}       xxx co co3 co1 co2
} 
} Do c[offset,string] require a fixed offset or can be a range?

Yes, the offset must be fixed for c[].

} Also, I still want to be able to complete the 'construct'.

Your best bet might be to go with compctl -K and write yourself a function
to perform the pattern matching.  The built-in mechanisms aren't designed
to deal easily with so many words with common prefixes.  (If your command
looked like "xxx -co co1 co2 -construct cons1" then it'd be much easier.)

Here's a sample that illustrates two possible approaches to your problem
that don't use a -K function:

	compctl -k "(ci co construct cinema)" \
	-x "c[-1,co]" -k "(co1 co2 co3)" \
	- "C[-1,co[123]]" -k "(co1 co2 co3 construct)" \
	- "c[-1,construct], C[-1,cons[12]]" -k "(cons1 cons2)" -- xxx

The first approach is to use separate rules "c[-1,co]" and "C[-1,co[123]]"
which tell what to complete after a word matching "co" and after a word
matching the glob pattern "co[123]", respectively.  This requires that you
maintain the (co1 co2 co3) list in two places, and also keep the glob up
to date, if those items in the -k list ever change.

The second uses alternative patterns "c[-1,construct], C[-1,cons[12]]"
which match either "construct" or the glob "cons[12]".  This is a bit
simpler to maintain (one list and the equivalent glob) but does not permit
you e.g. to complete "co" following "cons1".

Good luck.  (I hesitate to inquire further about the "xxx cinema" part ...)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: compctl tips needed on words with common prefix
  1998-06-17 18:27     ` Bart Schaefer
@ 1998-06-18  2:58       ` Paul Lew
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Lew @ 1998-06-18  2:58 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

>>>>> "Bart" == Bart Schaefer <schaefer@brasslantern.com> writes:

    Bart> Good luck.  (I hesitate to inquire further about the "xxx
    Bart> cinema" part ...)

That light up my day, I just made up command name 'xxx' (my usual temp
file name) and I need a word starts with ci so I chose cinema.  What a
combo!

Actually, I was trying to define the compctl for ode (a source code
control system used internally inside DEC).  ode has similar command
structure as cvs so I took the cvs completion package you wrote and
modify for ode, unfortunately, there is 'co' and 'construct' which
mess things up.  Fortunately there there are no common prefix in cvs,
otherwise you will face the same problem.

Thanks for the tips anyway.


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

end of thread, other threads:[~1998-06-18  3:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-17 15:10 compctl tips needed on words with common prefix Paul Lew
1998-06-17 15:34 ` Zefram
1998-06-17 16:17   ` Paul Lew
1998-06-17 16:07 ` Bart Schaefer
1998-06-17 16:33   ` Paul Lew
1998-06-17 18:27     ` Bart Schaefer
1998-06-18  2:58       ` Paul Lew

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).