zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: _xwit
@ 2000-03-27 11:00 Sven Wischnowsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 2000-03-27 11:00 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> ...
> 
> But, this doesn't work because [[ -prefix [0-9]# ]] is failed even
> when $PREFIX is empty:
> 
> Z(2):akr@is27e1u11% Src/zsh -f
> is27e1u11% bindkey -e; autoload -U compinit; compinit -D; compdef _tst tst
> is27e1u11% _tst () { if [[ -prefix [0-9]# ]]; then compadd succ; else compadd fail; fi } 
> is27e1u11% tst <TAB>
> ->
> is27e1u11% tst fail 

Oops. Wrong security test.

Bye
 Sven

diff -ru ../z.old/Src/Zle/complete.c Src/Zle/complete.c
--- ../z.old/Src/Zle/complete.c	Mon Mar 27 12:49:45 2000
+++ Src/Zle/complete.c	Mon Mar 27 12:58:11 2000
@@ -740,7 +740,7 @@
 		char *p, sav;
 
 		if (!(l = strlen(compprefix)))
-		    return 0;
+		    return ((na == 1 || na == -1) && pattry(pp, compprefix));
 		if (na < 0) {
 		    p = compprefix + l;
 		    na = -na;
@@ -766,7 +766,7 @@
 		char *p;
 
 		if (!(ol = l = strlen(compsuffix)))
-		    return 0;
+		    return ((na == 1 || na == -1) && pattry(pp, compsuffix));
 		if (na < 0) {
 		    p = compsuffix;
 		    na = -na;

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: _xwit
  2000-03-24 13:33 ` Tanaka Akira
@ 2000-03-24 18:38   ` Tanaka Akira
  0 siblings, 0 replies; 5+ messages in thread
From: Tanaka Akira @ 2000-03-24 18:38 UTC (permalink / raw)
  To: zsh-workers

In article <rsq7les4hn9.fsf@crane.jaist.ac.jp>,
  Tanaka Akira <akr@jaist.ac.jp> writes:

> Since I found that `xwit -keyrepeat 10 -<TAB>' runs _message, it is
> fixed as follows.

> -        \( "/[0-9]##$nul/" ":_message keycode" \
> -	  \( "/-$nul/" "/[0-9]##$nul/" ":_message 'last keycode'" \| \) \) \# \
> +        \( "/[0-9]##$nul/" ":[[ -prefix [0-9]## ]] && _message keycode" \
> +	  \( "/-$nul/" "/[0-9]##$nul/" ":[[ -prefix [0-9]## ]] && _message 'last keycode'" \| \) \) \# \

Oops.  Since [0-9]## doesn't match empty string, `xwit -keyrepeat
<TAB>' didn't show the message.  It should be [0-9]#.

Index: Completion/X/_xwit
===================================================================
RCS file: /projects/zsh/zsh/Completion/X/_xwit,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 _xwit
--- Completion/X/_xwit	2000/03/24 13:34:17	1.1.1.3
+++ Completion/X/_xwit	2000/03/24 18:33:43
@@ -39,8 +39,8 @@
     \| "/iconmove$nul/" "$guard" "/$word/" ":_message x" "/$word/" ":_message y" \
     \| "/id$nul/" "$guard" "/$word/" ":_x_window" \
     \| "/(no|)keyrepeat$nul/" "$guard" \
-        \( "/[0-9]##$nul/" ":[[ -prefix [0-9]## ]] && _message keycode" \
-	  \( "/-$nul/" "/[0-9]##$nul/" ":[[ -prefix [0-9]## ]] && _message 'last keycode'" \| \) \) \# \
+        \( "/[0-9]##$nul/" ":[[ -prefix [0-9]# ]] && _message keycode" \
+	  \( "/-$nul/" "/[0-9]##$nul/" ":[[ -prefix [0-9]# ]] && _message 'last keycode'" \| \) \) \# \
     \| "/names$nul/" "$guard" "/$word/" ":_x_window -n" \# \
     \| "/[]/" ':_xwit_compopts' \
     \) \

But, this doesn't work because [[ -prefix [0-9]# ]] is failed even
when $PREFIX is empty:

Z(2):akr@is27e1u11% Src/zsh -f
is27e1u11% bindkey -e; autoload -U compinit; compinit -D; compdef _tst tst
is27e1u11% _tst () { if [[ -prefix [0-9]# ]]; then compadd succ; else compadd fail; fi } 
is27e1u11% tst <TAB>
->
is27e1u11% tst fail 
-- 
Tanaka Akira


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

* Re: PATCH: _xwit
  2000-03-24 12:54 Sven Wischnowsky
@ 2000-03-24 13:33 ` Tanaka Akira
  2000-03-24 18:38   ` Tanaka Akira
  0 siblings, 1 reply; 5+ messages in thread
From: Tanaka Akira @ 2000-03-24 13:33 UTC (permalink / raw)
  To: zsh-workers

In article <200003241254.NAA26008@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> Hm. If I parsed _xwit correctly (which I'm not sure about, because I
> haven't really understood _regex_arguments yet):
> 
>   _arguments '-keyrepeat:*[0-9]##:keycode: ' ...
> 
> What have I missed?

-keyrepeat and -nokeyrepeat takes a sequence of words.  The words is
sequence of:
1) a keycode represended as an integer (one word)
2) a keycode range represented as an integer, hyphen and an integer
(three words)

For example,

  xwit -nokeyrepeat 61 - 69 128 

disables autorepeat for keys `q', `w', `e', `r', `t', `y' and ` '. 
(On my keyboard, of course.)

The arguments for -keyrepeats is end before next option as:

  xwit -nokeyrepeat 61 - 69 128 -sync

So, '-keyrepeat:*[0-9]##:keycode: ' doesn't work because [0-9]##
matches to the first argument: `61'.

If _arguments have a form like `:*pattern:message:action' but the
pattern is matched against to a argument *next* to an arguments for
the option, we can use _arguments for _xwit.

> If the tag alias changes make it in, this would become what is shown
> in the patch below.

Wow.  Thanks.

> The patch also shows one of the way to do this with tag aliases. Unless 
> we find a way to put that into _regex_arguments, that is. We would
> need the descriptions and tags there then but it doesn't handle them,
> right? Sigh.

Hm.  I'll read changed tag stuff...

Since I found that `xwit -keyrepeat 10 -<TAB>' runs _message, it is
fixed as follows.

Index: Completion/X/_xwit
===================================================================
RCS file: /projects/zsh/zsh/Completion/X/_xwit,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 _xwit
--- Completion/X/_xwit	2000/03/24 12:56:54	1.1.1.2
+++ Completion/X/_xwit	2000/03/24 13:29:35
@@ -39,8 +39,8 @@
     \| "/iconmove$nul/" "$guard" "/$word/" ":_message x" "/$word/" ":_message y" \
     \| "/id$nul/" "$guard" "/$word/" ":_x_window" \
     \| "/(no|)keyrepeat$nul/" "$guard" \
-        \( "/[0-9]##$nul/" ":_message keycode" \
-	  \( "/-$nul/" "/[0-9]##$nul/" ":_message 'last keycode'" \| \) \) \# \
+        \( "/[0-9]##$nul/" ":[[ -prefix [0-9]## ]] && _message keycode" \
+	  \( "/-$nul/" "/[0-9]##$nul/" ":[[ -prefix [0-9]## ]] && _message 'last keycode'" \| \) \) \# \
     \| "/names$nul/" "$guard" "/$word/" ":_x_window -n" \# \
     \| "/[]/" ':_xwit_compopts' \
     \) \
-- 
Tanaka Akira


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

* Re: PATCH: _xwit
@ 2000-03-24 12:54 Sven Wischnowsky
  2000-03-24 13:33 ` Tanaka Akira
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 2000-03-24 12:54 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> This is a completion function for xwit.
> 
> I used _regex_arguments for parsing a command line since xwit has the
> option -keyrepeat which cannot be handled by _arguments.  -keyrepeat
> takes variable length of arguments for it, but the last argument is
> featureless --- just a integer.  So _arguments cannot detect end of
> the option.

Hm. If I parsed _xwit correctly (which I'm not sure about, because I
haven't really understood _regex_arguments yet):

  _arguments '-keyrepeat:*[0-9]##:keycode: ' ...

What have I missed?

> ...
>
> +_wanted colormapids expl 'colormap id' || return 1
>
> +compadd "$expl[@]" "$@" "$desc[@]" - "${(@)list%% *}" 

If the tag alias changes make it in, this would become what is shown
in the patch below.

> ...
>
> +_xwit_compopts () {
> +  local expl
> +  _description options expl option
> +  compadd "$expl[@]" - ${(k)no[(R)*~0]} || compadd "$expl[@]" - ${(k)no}

The patch also shows one of the way to do this with tag aliases. Unless 
we find a way to put that into _regex_arguments, that is. We would
need the descriptions and tags there then but it doesn't handle them,
right? Sigh.


Bye
 Sven

diff -ru ../z.old/Completion/X/_x_colormapid Completion/X/_x_colormapid
--- ../z.old/Completion/X/_x_colormapid	Fri Mar 24 13:46:31 2000
+++ Completion/X/_x_colormapid	Fri Mar 24 13:48:33 2000
@@ -2,7 +2,7 @@
 
 local expl list desc
 
-_wanted colormapids expl 'colormap id' || return 1
+_wanted colormapids || return 1
 
 list=(${(f)"$(xprop -root -f RGB_COLOR_MAP 32xcccccccxx ': $0\n'|awk -F'[ ():]' '/^[a-zA-Z_]+\(RGB_COLOR_MAP\)/ {print $5, "--", $1}')"})
 
@@ -12,4 +12,4 @@
   desc=()
 fi
 
-compadd "$expl[@]" "$@" "$desc[@]" - "${(@)list%% *}" 
+_loop colormapids expl 'colormap id' compadd "$@" "$desc[@]" - "${(@)list%% *}" 
diff -ru ../z.old/Completion/X/_xwit Completion/X/_xwit
--- ../z.old/Completion/X/_xwit	Fri Mar 24 13:46:31 2000
+++ Completion/X/_xwit	Fri Mar 24 13:52:01 2000
@@ -16,8 +16,8 @@
 
 _xwit_compopts () {
   local expl
-  _description options expl option
-  compadd "$expl[@]" - ${(k)no[(R)*~0]} || compadd "$expl[@]" - ${(k)no}
+  _wanted options expl option compadd - ${(k)no[(R)*~0]} ||
+      _loop options expl option compadd - ${(k)no}
 }
 
 _regex_arguments _xwit_parse \

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* PATCH: _xwit
@ 2000-03-24 11:26 Tanaka Akira
  0 siblings, 0 replies; 5+ messages in thread
From: Tanaka Akira @ 2000-03-24 11:26 UTC (permalink / raw)
  To: zsh-workers

This is a completion function for xwit.

I used _regex_arguments for parsing a command line since xwit has the
option -keyrepeat which cannot be handled by _arguments.  -keyrepeat
takes variable length of arguments for it, but the last argument is
featureless --- just a integer.  So _arguments cannot detect end of
the option.

Index: Completion/Base/_regex_arguments
===================================================================
RCS file: /projects/zsh/zsh/Completion/Base/_regex_arguments,v
retrieving revision 1.1.1.14
diff -u -r1.1.1.14 _regex_arguments
--- Completion/Base/_regex_arguments	2000/01/19 01:17:24	1.1.1.14
+++ Completion/Base/_regex_arguments	2000/03/24 09:06:47
@@ -64,7 +64,7 @@
 _regex_arguments () {
   local regex funcname="$1"
   shift
-  regex=(${@/(#b):(*)/":_ra_comp ${(qqqq)match[1]}"})
+  regex=(${@:/(#b):(*)/":_ra_comp ${(qqqq)match[1]}"})
 
   eval \
   "$funcname"' () {
--- /dev/null	Fri Mar 24 11:42:38 2000
+++ Completion/X/_x_colormapid	Mon Mar  6 00:45:05 2000
@@ -0,0 +1,15 @@
+#autoload
+
+local expl list desc
+
+_wanted colormapids expl 'colormap id' || return 1
+
+list=(${(f)"$(xprop -root -f RGB_COLOR_MAP 32xcccccccxx ': $0\n'|awk -F'[ ():]' '/^[a-zA-Z_]+\(RGB_COLOR_MAP\)/ {print $5, "--", $1}')"})
+
+if zstyle -T ":completion:${curcontext}:colormap-id" verbose; then
+  desc=(-ld list)
+else
+  desc=()
+fi
+
+compadd "$expl[@]" "$@" "$desc[@]" - "${(@)list%% *}" 
--- /dev/null	Fri Mar 24 11:42:38 2000
+++ Completion/X/_xwit	Fri Mar 24 20:19:29 2000
@@ -0,0 +1,97 @@
+#compdef xwit
+
+local word=$'[^\0]#\0'
+local nul=$'\0'
+
+local guard='-_xwit_guard -${match[1]%?}'
+
+_xwit_guard () {
+  local opt="$1" o
+  (( no[$opt]-- ))
+  for o in ${=eo[$opt]}; do
+    no[$o]=0
+  done 
+  :
+}
+
+_xwit_compopts () {
+  local expl
+  _description options expl option
+  compadd "$expl[@]" - ${(k)no[(R)*~0]} || compadd "$expl[@]" - ${(k)no}
+}
+
+_regex_arguments _xwit_parse \
+  "/$word/" \
+  \( \
+    "/-/+" \
+    \( "/display$nul/" "$guard" "/$word/" ":_x_display" \
+    \| "/(sync|pop|open|iconify|unmap|root|current|select|(no|)(save|backingstore|saveunder))$nul/" "$guard" \
+    \| "/resize$nul/" "$guard" "/$word/" ":_message width" "/$word/" ":_message height" \
+    \| "/rows$nul/" "$guard" "/$word/" ":_message rows" \
+    \| "/columns$nul/" "$guard" "/$word/" ":_message columns" \
+    \| "/(r|)move$nul/" "$guard" "/$word/" ":_message x" "/$word/" ":_message y" \
+    \| "/(r|)warp$nul/" "$guard" "/$word/" ":_message x" "/$word/" ":_message y" \
+    \| "/colormap$nul/" "$guard" "/$word/" ":_x_colormapid" \
+    \| "/(name|label)$nul/" "$guard" "/$word/" ":_x_name" \
+    \| "/iconname$nul/" "$guard" "/$word/" ":_x_name" \
+    \| "/bitmap$nul/" "$guard" "/$word/" ":_files -g \\*.xbm" \
+    \| "/mask$nul/" "$guard" "/$word/" ":_files -g \\*.xbm" \
+    \| "/iconmove$nul/" "$guard" "/$word/" ":_message x" "/$word/" ":_message y" \
+    \| "/id$nul/" "$guard" "/$word/" ":_x_window" \
+    \| "/(no|)keyrepeat$nul/" "$guard" \
+        \( "/[0-9]##$nul/" ":_message keycode" \
+	  \( "/-$nul/" "/[0-9]##$nul/" ":_message 'last keycode'" \| \) \) \# \
+    \| "/names$nul/" "$guard" "/$word/" ":_x_window -n" \# \
+    \| "/[]/" ':_xwit_compopts' \
+    \) \
+  \) \#
+
+_xwit () {
+  typeset -A no eo
+
+  no=(
+    -display 1
+    -sync 1
+    -pop 1 -open 0
+    -iconify 1
+    -unmap 1
+    -root 1
+    -current 1
+    -select 1
+    -save 1
+    -backingstore 1
+    -saveunder 1
+    -nosave 1
+    -nobackingstore 1
+    -nosaveunder 1
+    -resize 1
+    -rows 1
+    -columns 1
+    -move 1
+    -rmove 1
+    -warp 1
+    -rwarp 1
+    -colormap 1
+    -name 1 -label 0
+    -iconname 1
+    -bitmap 1
+    -mask 1
+    -iconmove 1
+    -id 1
+    -keyrepeat 1
+    -nokeyrepeat 1
+    -names 1
+  )
+
+  eo=(
+    -root    '-root -current -select -id -names'
+    -current '-root -current -select -id -names'
+    -select  '-root -current -select -id -names'
+    -id      '-root -current -select -id -names'
+    -names   '-root -current -select -id -names'
+  )
+
+  _xwit_parse
+}
+
+[[ -o kshautoload ]] || _xwit "$@"
-- 
Tanaka Akira


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

end of thread, other threads:[~2000-03-27 11:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-27 11:00 PATCH: _xwit Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
2000-03-24 12:54 Sven Wischnowsky
2000-03-24 13:33 ` Tanaka Akira
2000-03-24 18:38   ` Tanaka Akira
2000-03-24 11:26 Tanaka Akira

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