* PATCH: pass name ($0) and zmult ($1) to user-defined widgets
@ 1998-06-12 8:38 Bart Schaefer
1998-06-12 9:37 ` Zefram
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 1998-06-12 8:38 UTC (permalink / raw)
To: zsh-workers
User-defined widgets should be able to change their behavior or repeat
their action when given a digit-argument. They also ought to have a
usable $0 when FUNCTION_ARGZERO is set; I chose to pass the widget name,
so if you bind the same function to different widgets you can test for
$0 to tweak the behavior.
Index: Doc/Zsh/zle.yo
===================================================================
--- zle.yo 1998/06/01 17:08:43 1.1.1.1
+++ zle.yo 1998/06/12 08:33:25
@@ -102,6 +102,9 @@
User-defined widgets, being implemented as shell functions,
can execute any normal shell command. They can also run other widgets
(whether built-in or user-defined) using the tt(zle) builtin command.
+When tt(FUNCTION_ARGZERO) is set, they are passed their widget name
+(not their function name) as tt($0), and if tt(digit-argument) was
+used to enter a number prefix, that prefix is passed as tt($1).
Finally, they can examine and edit the ZLE buffer being edited by
reading and setting the special parameters described below.
Index: Src/Zle/zle_main.c
===================================================================
--- zle_main.c 1998/06/01 17:08:46 1.1.1.1
+++ zle_main.c 1998/06/12 08:25:14
@@ -591,10 +591,23 @@
zsfree(msg);
feep();
} else {
+ char *name = 0, num[16];
+ LinkList args;
startparamscope();
makezleparams();
- doshfunc(l, NULL, 0, 1);
+ PERMALLOC {
+ name = ztrdup(func->nam);
+ args = newlinklist();
+ addlinknode(args, name);
+ if (zmod.flags & MOD_MULT) {
+ sprintf(num, "%d", zmult);
+ addlinknode(args, num);
+ }
+ } LASTALLOC;
+ doshfunc(l, args, 0, 1);
endparamscope();
+ freelinklist(args, (FreeFunc) NULL);
+ zsfree(name);
lastcmd = 0;
}
}
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: pass name ($0) and zmult ($1) to user-defined widgets
1998-06-12 8:38 PATCH: pass name ($0) and zmult ($1) to user-defined widgets Bart Schaefer
@ 1998-06-12 9:37 ` Zefram
1998-06-12 15:54 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 1998-06-12 9:37 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-workers
Bart Schaefer wrote:
>User-defined widgets should be able to change their behavior or repeat
>their action when given a digit-argument.
Yes. But that should not be done via positional parameters. I have
deliberately avoided passing arguments in positional parameters, so
that one widget can reliably call another without having to fiddle with
the parameters. The numeric prefix should go into a special parameter,
or be accessible by some other mechanism.
> They also ought to have a
>usable $0 when FUNCTION_ARGZERO is set; I chose to pass the widget name,
>so if you bind the same function to different widgets you can test for
>$0 to tweak the behavior.
That's a good idea.
-zefram
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: pass name ($0) and zmult ($1) to user-defined widgets
1998-06-12 9:37 ` Zefram
@ 1998-06-12 15:54 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1998-06-12 15:54 UTC (permalink / raw)
To: Zefram, zsh-workers
On Jun 12, 10:37am, Zefram wrote:
} Subject: Re: PATCH: pass name ($0) and zmult ($1) to user-defined widgets
}
} Bart Schaefer wrote:
} >User-defined widgets should be able to change their behavior or repeat
} >their action when given a digit-argument.
}
} Yes. But that should not be done via positional parameters. I have
} deliberately avoided passing arguments in positional parameters, so
} that one widget can reliably call another without having to fiddle with
} the parameters.
It seems useful to me to follow the Emacs model where the digit-argument
is an optional parameter to the function.
Further, I think the "have one widget call another" model in zsh is a bit
bent as it is. Your plan is to have all widgets, built-in or otherwise,
be on equal footing; I think that should mean that they're all callable
as shell functions, and we should do away with "zle widget-name". It's
much easer to "fiddle with the parameters" than it is to save and restore
a bunch of shared variables.
"zle widget-name" could be replaced by "execute-named-command widget-name"
if every widget acted like a shell function.
As another example, right now it's completely impossible for a user-defined
widget to initiate a history search; "zle history-search-backward" just
causes the shell to prompt the user for input, but the widget may already
have a string it wants to search for. "history-search-backward string" is
the natural way to perform that action.
Where the shared variables are useful is for persistent state; the history
list and current position in it, the editor buffer itself and the position
of the cursor and mark(s), etc.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-06-12 16:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-12 8:38 PATCH: pass name ($0) and zmult ($1) to user-defined widgets Bart Schaefer
1998-06-12 9:37 ` Zefram
1998-06-12 15:54 ` Bart Schaefer
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).