From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27543 invoked from network); 12 Jun 2007 21:58:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=no version=3.2.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 12 Jun 2007 21:58:50 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 60549 invoked from network); 12 Jun 2007 21:58:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 Jun 2007 21:58:45 -0000 Received: (qmail 16094 invoked by alias); 12 Jun 2007 21:58:42 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23554 Received: (qmail 16084 invoked from network); 12 Jun 2007 21:58:42 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 12 Jun 2007 21:58:42 -0000 Received: (qmail 60261 invoked from network); 12 Jun 2007 21:58:42 -0000 Received: from mtaout02-winn.ispmail.ntl.com (81.103.221.48) by a.mx.sunsite.dk with SMTP; 12 Jun 2007 21:58:38 -0000 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20070612215836.PTXO4.mtaout02-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Tue, 12 Jun 2007 22:58:36 +0100 Received: from pwslaptop.csr.com ([81.107.45.67]) by aamtaout03-winn.ispmail.ntl.com with ESMTP id <20070612215836.QSMZ26699.aamtaout03-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Tue, 12 Jun 2007 22:58:36 +0100 Received: from pwslaptop.csr.com (pwslaptop.csr.com [127.0.0.1]) by pwslaptop.csr.com (8.13.8/8.13.7) with ESMTP id l5CLuPA7004068 for ; Tue, 12 Jun 2007 22:56:25 +0100 Message-Id: <200706122156.l5CLuPA7004068@pwslaptop.csr.com> From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: Calling a zle widget from a function In-Reply-To: Message from Peter Stephenson of "Tue, 12 Jun 2007 18:51:53 BST." <200706121751.l5CHpr8D015577@news01.csr.com> Date: Tue, 12 Jun 2007 22:56:25 +0100 Peter Stephenson wrote: > (It would be nice if sched provided an array to access scheduled events > but it doesn't. That's an easy tweak I may look at.) Here it is. Now you can do integer ind=${zsh_scheduled_events[(I)*my_scheduled_fn*]} (( ind )) && sched -$ind Index: Doc/Zsh/mod_sched.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_sched.yo,v retrieving revision 1.3 diff -u -r1.3 mod_sched.yo --- Doc/Zsh/mod_sched.yo 11 Sep 2006 20:04:07 -0000 1.3 +++ Doc/Zsh/mod_sched.yo 12 Jun 2007 21:57:25 -0000 @@ -1,7 +1,8 @@ COMMENT(!MOD!zsh/sched A builtin that provides a timed execution facility within the shell. !MOD!) -The tt(zsh/sched) module makes available one builtin command: +The tt(zsh/sched) module makes available one builtin command and one +parameter. startitem() findex(sched) @@ -40,3 +41,19 @@ output that updates a terminal emulator's title bar. ) enditem() + +startitem() +vindex(zsh_scheduled_events) +item(zsh_scheduled_events)( +A readonly array corresponding to the events scheduled by the +tt(sched) builtin. The indices of the array correspond to the numbers +shown when tt(sched) is run with no arguments (provided that the +tt(KSH_ARRAYS) option is not set). The value of the +corresponding element is the same as the text shown to the right +of the index in the tt(sched) listing. + +The tt(sched) builtin should be used for manipulating the events. Note +that this will have an immediate effect on the contents of the array, +so that indices may become invalid. +) +enditem() Index: Doc/Zsh/params.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v retrieving revision 1.37 diff -u -r1.37 params.yo --- Doc/Zsh/params.yo 21 May 2007 09:30:25 -0000 1.37 +++ Doc/Zsh/params.yo 12 Jun 2007 21:57:25 -0000 @@ -712,6 +712,10 @@ Expands to the basename of the command used to invoke this instance of zsh. ) +item(tt(zsh_scheduled_events))( +See ifzman(the section `The zsh/sched Module' in zmanref(zshmodules))\ +ifnzman(noderef(The zsh/sched Module)). +) vindex(ZSH_VERSION) item(tt(ZSH_VERSION))( The version number of this zsh. Index: Src/Builtins/sched.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Builtins/sched.c,v retrieving revision 1.10 diff -u -r1.10 sched.c --- Src/Builtins/sched.c 12 Jun 2007 15:37:20 -0000 1.10 +++ Src/Builtins/sched.c 12 Jun 2007 21:57:25 -0000 @@ -145,6 +145,40 @@ } } +/* + * Format event sch. If sn is zero, allocate string on the heap + * and return it; if non-zero, print with that as scheduled event + * number. + */ + +static +char *schedtext(struct schedcmd *sch, int sn) +{ + char *str, tbuf[40], *flagstr, *endstr; + time_t t; + struct tm *tmp; + + t = sch->time; + tmp = localtime(&t); + ztrftime(tbuf, 20, "%a %b %e %k:%M;%S", tmp); + if (sch->flags & SCHEDFLAG_TRASH_ZLE) + flagstr = "-o "; + else + flagstr = ""; + if (*sch->cmd == '-') + endstr = "-- "; + else + endstr = ""; + if (sn) { + printf("%3d %s %s%s%s\n", sn, tbuf, flagstr, endstr, sch->cmd); + return NULL; + } else { + str = (char *)zhalloc(48 + strlen(sch->cmd)); + sprintf(str, "%s %s%s%s", tbuf, flagstr, endstr, sch->cmd); + return str; + } +} + /**/ static int bin_sched(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) @@ -204,22 +238,8 @@ /* given no arguments, display the schedule list */ if (!*argptr) { - char tbuf[40], *flagstr, *endstr; - - for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++) { - t = sch->time; - tm = localtime(&t); - ztrftime(tbuf, 20, "%a %b %e %k:%M:%S", tm); - if (sch->flags & SCHEDFLAG_TRASH_ZLE) - flagstr = "-o "; - else - flagstr = ""; - if (*sch->cmd == '-') - endstr = "-- "; - else - endstr = ""; - printf("%3d %s %s%s%s\n", sn, tbuf, flagstr, endstr, sch->cmd); - } + for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++) + (void)schedtext(sch, 1); return 0; } else if (!argptr[1]) { /* other than the two cases above, sched * @@ -332,14 +352,43 @@ return 0; } + +/**/ +static char ** +schedgetfn(UNUSED(Param pm)) +{ + int i; + struct schedcmd *sch; + char **ret, **aptr; + + for (i = 0, sch = schedcmds; sch; sch = sch->next, i++) + ; + + aptr = ret = zhalloc(sizeof(char **) * (i+1)); + for (sch = schedcmds; sch; sch = sch->next, aptr++) + *aptr = schedtext(sch, 0); + *aptr = NULL; + + return ret; +} + + static struct builtin bintab[] = { BUILTIN("sched", 0, bin_sched, 0, -1, 0, NULL, NULL), }; +static const struct gsu_array sched_gsu = +{ schedgetfn, arrsetfn, stdunsetfn }; + +static struct paramdef partab[] = { + SPECIALPMDEF("zsh_scheduled_events", PM_ARRAY|PM_READONLY, + &sched_gsu, NULL, NULL) +}; + static struct features module_features = { bintab, sizeof(bintab)/sizeof(*bintab), NULL, 0, - NULL, 0, + partab, sizeof(partab)/sizeof(*partab), NULL, 0, 0 }; Index: Src/Builtins/sched.mdd =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Builtins/sched.mdd,v retrieving revision 1.2 diff -u -r1.2 sched.mdd --- Src/Builtins/sched.mdd 26 Nov 2000 20:01:03 -0000 1.2 +++ Src/Builtins/sched.mdd 12 Jun 2007 21:57:25 -0000 @@ -3,5 +3,6 @@ load=yes autobins="sched" +autoparams="zsh_scheduled_events" objects="sched.o"