Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Calling a zle widget from a function



On Tue, 12 Jun 2007 23:01:50 +0100
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> Having done this, it just occurred to me it might be more useful to
> have a ":" between the date and the command string, and maybe to
> indicate the "-o" in some more useful way for processing
> non-interactively.  That's a task for tomorrow, I think.

This makes zsh_scheduled_events more useful for its intended purpose, and
updates calendar to use it.

Index: Doc/Zsh/mod_sched.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_sched.yo,v
retrieving revision 1.4
diff -u -r1.4 mod_sched.yo
--- Doc/Zsh/mod_sched.yo	12 Jun 2007 22:01:38 -0000	1.4
+++ Doc/Zsh/mod_sched.yo	14 Jun 2007 13:09:51 -0000
@@ -48,9 +48,13 @@
 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.
+tt(KSH_ARRAYS) option is not set).  The value of the array
+consists of the scheduled time in seconds since the epoch
+(see ifnzman(The zsh/datetime Module)\
+ifzman(the section `The zsh/datetime Module') for facilities for
+using this number), followed by a colon, followed by any options
+(which may be empty but will be preceeded by a `tt(-)' otherwise),
+followed by a colon, followed by the command to be executed.
 
 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,
Index: Functions/Calendar/calendar
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Calendar/calendar,v
retrieving revision 1.3
diff -u -r1.3 calendar
--- Functions/Calendar/calendar	26 Mar 2007 14:33:33 -0000	1.3
+++ Functions/Calendar/calendar	14 Jun 2007 13:09:51 -0000
@@ -352,13 +352,8 @@
   if [[ -n $sched ]]; then
     if [[ $next -ge 0 ]]; then
       # Remove any existing calendar scheduling.
-      # Luckily sched doesn't delete its schedule in a subshell.
-      sched | while read line; do
-	if [[ $line = (#b)[[:space:]]#(<->)[[:space:]]##*[[:space:]]'calendar -s'* ]]; then
-	  # End of pipeline run in current shell, so delete directly.
-	  sched -1 $match[1]
-	fi
-      done
+      i=${"${(@)zsh_scheduled_events#*:*:}"[(I)calendar -s*]}
+      (( i )) && sched -$i
       $sched $next calendar "${calopts[@]}" $next $next
     else
       $showprog $start $stop \
Index: Src/Builtins/sched.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Builtins/sched.c,v
retrieving revision 1.11
diff -u -r1.11 sched.c
--- Src/Builtins/sched.c	12 Jun 2007 22:01:39 -0000	1.11
+++ Src/Builtins/sched.c	14 Jun 2007 13:09:55 -0000
@@ -145,40 +145,6 @@
     }
 }
 
-/*
- * 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))
@@ -238,8 +204,24 @@
 
     /* given no arguments, display the schedule list */
     if (!*argptr) {
-	for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++)
-	    (void)schedtext(sch, 1);
+	for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++) {
+	    char 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 = "";
+	    printf("%3d %s %s%s%s\n", sn, tbuf, flagstr, endstr, sch->cmd);
+	}
 	return 0;
     } else if (!argptr[1]) {
 	/* other than the two cases above, sched *
@@ -365,8 +347,19 @@
 	;
 
     aptr = ret = zhalloc(sizeof(char **) * (i+1));
-    for (sch = schedcmds; sch; sch = sch->next, aptr++)
-	*aptr = schedtext(sch, 0);
+    for (sch = schedcmds; sch; sch = sch->next, aptr++) {
+	char tbuf[40], *flagstr;
+	time_t t;
+
+	t = sch->time;
+	sprintf(tbuf, "%ld", t);
+	if (sch->flags & SCHEDFLAG_TRASH_ZLE)
+	    flagstr = "-o";
+	else
+	    flagstr = "";
+	*aptr = (char *)zhalloc(5 + strlen(tbuf) + strlen(sch->cmd));
+	sprintf(*aptr, "%s:%s:%s", tbuf, flagstr, sch->cmd);
+    }
     *aptr = NULL;
 
     return ret;


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



Messages sorted by: Reverse Date, Date, Thread, Author