From 3b5d77d819e1b7a94c4b14d69bddb2dddf8605ff Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 12 Oct 2014 17:52:11 +0100 Subject: 33423: expand ${(p)...} to allow ${(ps.$param.)...} --- Doc/Zsh/expn.yo | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Doc/Zsh') diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 5aab25954..a0478e78c 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1124,6 +1124,19 @@ item(tt(p))( Recognize the same escape sequences as the tt(print) builtin in string arguments to any of the flags described below that follow this argument. + +Alternatively, with this option string arguments may be in the form +tt($)var(var) in which case the value of the variable is substituted. +Note this form is strict; the string argument does not undergo general +parameter expansion. + +For example, + +example(sep=: +val=a:b:c +print ${+LPAR()ps.$sep.+RPAR()val}) + +splits the variable on a tt(:). ) item(tt(~))( Strings inserted into the expansion by any of the flags below are to -- cgit v1.2.3 From bdedf7b40b85f54979c1e9d19445f8dfbf64967d Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 23 Oct 2014 21:47:23 +0200 Subject: 33518: add support for "_ vi buffer and arguments to vi-set-buffer from a zle widget --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 36 ++++++++++++++++++++------------ Src/Zle/zle.h | 1 + Src/Zle/zle_utils.c | 2 +- Src/Zle/zle_vi.c | 24 +++++++++++++++------ Test/X02zlevi.ztst | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 20 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index f96b4e3e2..79e1701c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2014-10-23 Oliver Kiddle + * 33518: Doc/Zsh/zle.yo, Src/Zle/zle.h, Src/Zle/zle_utils.c, + Src/Zle/zle_vi.c, Test/X02zlevi.ztst: add support for "_ vi + buffer and arguments to vi-set-buffer from a zle widget + * 33514: Src/Zle/zle_utils.c: even with a named vi buffer, we should update the default buffer diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 98f38025a..881e56b19 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2180,19 +2180,29 @@ command. tt(run-help) is normally aliased to tt(man). tindex(vi-set-buffer) item(tt(vi-set-buffer) (unbound) (") (unbound))( Specify a buffer to be used in the following command. -There are 35 buffers that can be specified: -the 26 `named' buffers tt("a) to tt("z) -and the nine `queued' buffers tt("1) to tt("9). The named buffers can also -be specified as tt("A) to tt("Z). - -When a buffer is specified for a cut command, the text being cut replaces -the previous contents of the specified buffer. If a named buffer -is specified using a capital, the newly cut text is appended to the buffer -instead of overwriting it. - -If no buffer is specified for a cut command, tt("1) is used, and the -contents of tt("1) to tt("8) are each shifted along one buffer; the contents of -tt("9) is lost. +There are 37 buffers that can be specified: +the 26 `named' buffers tt("a) to tt("z), the `yank' buffer tt("0), +the nine `queued' buffers tt("1) to tt("9) and the `black hole' buffer +tt("_). The named buffers can also be specified as tt("A) to tt("Z). + +When a buffer is specified for a cut, change or yank command, the text +concerned replaces the previous contents of the specified buffer. If +a named buffer is specified using a capital, the newly cut text is +appended to the buffer instead of overwriting it. When using the tt("_) +buffer, nothing happens. This can be useful for deleting text without +affecting the normal registers. + +If no buffer is specified for a cut or change command, tt("1) is used, and +the contents of tt("1) to tt("8) are each shifted along one buffer; +the contents of tt("9) is lost. If no buffer is specified for a yank +command, tt("0") is used. Finally, a paste command without a specified +buffer will paste the text from the most recent command regardless of any +buffer that might have been used with that command. + +When called from a widget function by the tt(zle) command, the buffer +can optionally be specified with an argument. For example, + +example(zle vi-set-buffer A) ) tindex(vi-set-mark) item(tt(vi-set-mark) (unbound) (m) (unbound))( diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index 860c8217c..dd6cdcca0 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -240,6 +240,7 @@ struct modifier { #define MOD_VIBUF (1<<2) /* a vi cut buffer has been selected */ #define MOD_VIAPP (1<<3) /* appending to the vi cut buffer */ #define MOD_NEG (1<<4) /* last command was negate argument */ +#define MOD_NULL (1<<5) /* throw away text for the vi cut buffer */ /* current modifier status */ diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index f69bc77c9..46d5373fb 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -914,7 +914,7 @@ cut(int i, int ct, int flags) void cuttext(ZLE_STRING_T line, int ct, int flags) { - if (!ct) + if (!ct || zmod.flags & MOD_NULL) return; UNMETACHECK(); diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index 2555c6a00..20cece0a8 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -782,7 +782,7 @@ viputbefore(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0) + if (n < 0 || zmod.flags & MOD_NULL) return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; @@ -814,7 +814,7 @@ viputafter(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0) + if (n < 0 || zmod.flags & MOD_NULL) return 1; if (zmod.flags & MOD_VIBUF) buf = &vibuf[zmod.vibuf]; @@ -905,14 +905,26 @@ vicapslockpanic(UNUSED(char **args)) /**/ int -visetbuffer(UNUSED(char **args)) +visetbuffer(char **args) { ZLE_INT_T ch; - if ((zmod.flags & MOD_VIBUF) || - (((ch = getfullchar(0)) < ZWC('0') || ch > ZWC('9')) && + if (*args) { + ch = **args; + if (args[1] || (ch && (*args)[1])) + return 1; + } else { + ch = getfullchar(0); + } + if (ch == ZWC('_')) { + zmod.flags |= MOD_NULL; + prefixflag = 1; + return 0; + } else + zmod.flags &= ~MOD_NULL; + if ((ch < ZWC('0') || ch > ZWC('9')) && (ch < ZWC('a') || ch > ZWC('z')) && - (ch < ZWC('A') || ch > ZWC('Z')))) + (ch < ZWC('A') || ch > ZWC('Z'))) return 1; if (ch >= ZWC('A') && ch <= ZWC('Z')) /* needed in cut() */ zmod.flags |= MOD_VIAPP; diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index 19188dfb7..4a39442e1 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -10,6 +10,66 @@ %test + zletest $'yankee doodle\ebhDyy0"1P' +0:paste register 1 to get last deletion +>BUFFER: doodleyankee +>CURSOR: 6 + + zletest $'yankee\eyyodoodle\edd"0p' +0:paste register 0 to get last yank +>BUFFER: yankee +>yankee +>CURSOR: 7 + + zletest $'err\eddahello\e"hddP' +0:setting named register also sets unnamed register +>BUFFER: hello +>CURSOR: 0 + + zletest $'first\e"ay0ddasecond\e"Add"aP' +0:appending to named register +>BUFFER: firs +>second +>CURSOR: 0 + + zletest $'word\e"a"byy"bp' +0:set one and then a different register +>BUFFER: word +>word +>CURSOR: 5 + + zletest $'i\exaar\e0"a"_cewn\eP' +0:set register then set black hole register +>BUFFER: win +>CURSOR: 1 + + zletest $'double\eyy"_"0P' +0:reset register after selecting black hole +>BUFFER: double +>double +>CURSOR: 0 + +# zsh works like vi here; in vim you get the concatenated string + zletest $'first\e"addasecond\eddP' +0:retrieve unnamed register after appending +>BUFFER: second +>CURSOR: 0 + + zletest $'Z\exayankee doodle\e"_db0"_yeP' +0:yank and delete to black hole register +>BUFFER: Zyankee e +>CURSOR: 0 + + zletest $'foo\eddabar\e"_p..' +0:paste from black hole register and repeat +>BUFFER: bar +>CURSOR: 2 + + zletest $'start\eFa"ac2lnew\eX"ap..' +0:repeat paste from named register +>BUFFER: stnwararart +>CURSOR: 9 + zletest $'word\euaend' 0:undo initial change >BUFFER: end -- cgit v1.2.3 From b4f7ccecd93ca9e64c3c3c774fdaefae83d7204a Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 26 Oct 2014 17:47:42 +0000 Subject: 33531 with additions: retain status of exited background jobs. Add linked list of unwaited-for background jobs. Truncate at value of _SC_CHILD_MAX discarding oldest. Remove old lastpid_status mechanism for latest exited process only. Slightly tighten safety of permanently allocated linked lists so that this doesn't compromise signal handling. --- ChangeLog | 9 ++++ Doc/Zsh/builtins.yo | 16 ++++++ Doc/Zsh/options.yo | 8 +-- Src/exec.c | 2 - Src/init.c | 1 - Src/jobs.c | 138 ++++++++++++++++++++++++++++++++++++++++++++-------- Src/linklist.c | 4 ++ Src/signals.c | 14 +++--- 8 files changed, 157 insertions(+), 35 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 48efd1c0d..c75b870de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2014-10-26 Peter Stephenson + + * 33531 (plus fix to test job pointer and removing + lastpid_status): Doc/Zsh/builtins.yo, Doc/Zsh/options.yo, + Src/exec.c, Src/init.c, Src/jobs.c, Src/linklist.c, + Src/signals.c: retain up to CHILD_MAX statuses of exited + background processes; remove old lastpid_status mechanism; + slightly improve safety of permanently allocated linked lists. + 2014-10-24 Barton E. Schaefer * 33526: Completion/Unix/Type/_path_files: fix path prefix diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 46f40cc3a..edc335e8b 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -2059,6 +2059,22 @@ then all currently active child processes are waited for. Each var(job) can be either a job specification or the process ID of a job in the job table. The exit status from this command is that of the job waited for. + +It is possible to wait for recent processes (specified by process ID, +not by job) that were running in the background even if the process has +exited. Typically the process ID will be recorded by capturing the +value of the variable tt($!) immediately after the process has been +started. There is a limit on the number of process IDs remembered by +the shell; this is given by the value of the system configuration +parameter tt(CHILD_MAX). When this limit is reached, older process IDs +are discarded, least recently started processes first. + +Note there is no protection against the process ID wrapping, i.e. if the +wait is not executed soon enough there is a chance the process waited +for is the wrong one. A conflict implies both process IDs have been +generated by the shell, as other processes are not recorded, and that +the user is potentially interested in both, so this problem is intrinsic +to process IDs. ) findex(whence) item(tt(whence) [ tt(-vcwfpams) ] var(name) ...)( diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 068a253ac..452b258b4 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1434,10 +1434,10 @@ shell is saved for output within a subshell (for example, within a pipeline). When the option is set, the output of tt(jobs) is empty until a job is started within the subshell. -When the option is set, it becomes possible to use the tt(wait) builtin to -wait for the last job started in the background (as given by tt($!)) even -if that job has already exited. This works even if the option is turned -on temporarily around the use of the tt(wait) builtin. +In previous versions of the shell, it was necessary to enable +tt(POSIX_JOBS) in order for the builtin command tt(wait) to return the +status of background jobs that had already exited. This is no longer +the case. ) enditem() diff --git a/Src/exec.c b/Src/exec.c index 2f896d8d5..5bbd4e15d 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2942,8 +2942,6 @@ execcmd(Estate state, int input, int output, int how, int last1) close(synch[0]); if (how & Z_ASYNC) { lastpid = (zlong) pid; - /* indicate it's possible to set status for lastpid */ - lastpid_status = -2L; } else if (!jobtab[thisjob].stty_in_env && varspc) { /* search for STTY=... */ Wordcode p = varspc; diff --git a/Src/init.c b/Src/init.c index 68d36125e..655166135 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1049,7 +1049,6 @@ setupvals(void) bufstack = znewlinklist(); hsubl = hsubr = NULL; lastpid = 0; - lastpid_status = -1L; get_usage(); diff --git a/Src/jobs.c b/Src/jobs.c index bd95afb7a..18bb648d9 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -104,15 +104,6 @@ int prev_errflag, prev_breaks, errbrk_saved; /**/ int numpipestats, pipestats[MAX_PIPESTATS]; -/* - * The status associated with the process lastpid. - * -1 if not set and no associated lastpid - * -2 if lastpid is set and status isn't yet - * else the value returned by wait(). - */ -/**/ -long lastpid_status; - /* Diff two timevals for elapsed-time computations */ /**/ @@ -1309,14 +1300,6 @@ addproc(pid_t pid, char *text, int aux, struct timeval *bgtime) { Process pn, *pnlist; - if (pid == lastpid && lastpid_status != -2L) { - /* - * The status for the previous lastpid is invalid. - * Presumably process numbers have wrapped. - */ - lastpid_status = -1L; - } - DPUTS(thisjob == -1, "No valid job in addproc."); pn = (Process) zshcalloc(sizeof *pn); pn->pid = pid; @@ -1940,6 +1923,122 @@ maybeshrinkjobtab(void) unqueue_signals(); } +/* + * Definitions for the background process stuff recorded below. + * This would be more efficient as a hash, but + * - that's quite heavyweight for something not needed very often + * - we need some kind of ordering as POSIX allows us to limit + * the size of the list to the value of _SC_CHILD_MAX and clearly + * we want to clear the oldest first + * - cases with a long list of background jobs where the user doesn't + * wait for a large number, and then does wait for one (the only + * inefficient case) are rare + * - in the context of waiting for an external process, looping + * over a list isn't so very inefficient. + * Enough excuses already. + */ + +/* Data in the link list, a key (process ID) / value (exit status) pair. */ +struct bgstatus { + pid_t pid; + int status; +}; +typedef struct bgstatus *Bgstatus; +/* The list of those entries */ +LinkList bgstatus_list; +/* Count of entries. Reaches value of _SC_CHILD_MAX and stops. */ +long bgstatus_count; + +/* + * Remove and free a bgstatus entry. + */ +static void rembgstatus(LinkNode node) +{ + zfree(remnode(bgstatus_list, node), sizeof(struct bgstatus)); + bgstatus_count--; +} + +/* + * Record the status of a background process that exited so we + * can execute the builtin wait for it. + * + * We can't execute the wait builtin for something that exited in the + * foreground as it's not visible to the user, so don't bother recording. + */ + +/**/ +void +addbgstatus(pid_t pid, int status) +{ + static long child_max; + Bgstatus bgstatus_entry; + + if (!child_max) { +#ifdef _SC_CHILD_MAX + child_max = sysconf(_SC_CHILD_MAX); + if (!child_max) /* paranoia */ +#endif + { + /* Be inventive */ + child_max = 1024L; + } + } + + if (!bgstatus_list) { + bgstatus_list = znewlinklist(); + /* + * We're not always robust about memory failures, but + * this is pretty deep in the shell basics to be failing owing + * to memory, and a failure to wait is reported loudly, so test + * and fail silently here. + */ + if (!bgstatus_list) + return; + } + if (bgstatus_count == child_max) { + /* Overflow. List is in order, remove first */ + rembgstatus(firstnode(bgstatus_list)); + } + bgstatus_entry = (Bgstatus)zalloc(sizeof(*bgstatus_entry)); + if (!bgstatus_entry) { + /* See note above */ + return; + } + bgstatus_entry->pid = pid; + bgstatus_entry->status = status; + if (!zaddlinknode(bgstatus_list, bgstatus_entry)) { + zfree(bgstatus_entry, sizeof(*bgstatus_entry)); + return; + } + bgstatus_count++; +} + +/* + * See if pid has a recorded exit status. + * Note we make no guarantee that the PIDs haven't wrapped, so this + * may not be the right process. + * + * This is only used by wait, which must only work on each + * pid once, so we need to remove the entry if we find it. + */ + +static int getbgstatus(pid_t pid) +{ + LinkNode node; + Bgstatus bgstatus_entry; + + if (!bgstatus_list) + return -1; + for (node = firstnode(bgstatus_list); node; incnode(node)) { + bgstatus_entry = (Bgstatus)getdata(node); + if (bgstatus_entry->pid == pid) { + int status = bgstatus_entry->status; + rembgstatus(node); + return status; + } + } + return -1; +} /* bg, disown, fg, jobs, wait: most of the job control commands are * * here. They all take the same type of argument. Exception: wait can * @@ -2085,10 +2184,7 @@ bin_fg(char *name, char **argv, Options ops, int func) } if (retval == 0) retval = lastval2; - } else if (isset(POSIXJOBS) && - pid == lastpid && lastpid_status >= 0L) { - retval = (int)lastpid_status; - } else { + } else if ((retval = getbgstatus(pid)) < 0) { zwarnnam(name, "pid %d is not a child of this shell", pid); /* presumably lastval2 doesn't tell us a heck of a lot? */ retval = 1; diff --git a/Src/linklist.c b/Src/linklist.c index 1e364fb4e..3aa8125d9 100644 --- a/Src/linklist.c +++ b/Src/linklist.c @@ -118,6 +118,8 @@ znewlinklist(void) LinkList list; list = (LinkList) zalloc(sizeof *list); + if (!list) + return NULL; list->list.first = NULL; list->list.last = &list->node; list->list.flags = 0; @@ -152,6 +154,8 @@ zinsertlinknode(LinkList list, LinkNode node, void *dat) tmp = node->next; node->next = new = (LinkNode) zalloc(sizeof *tmp); + if (!new) + return NULL; new->prev = node; new->dat = dat; new->next = tmp; diff --git a/Src/signals.c b/Src/signals.c index 2df69f96e..e72850516 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -522,14 +522,14 @@ wait_for_processes(void) get_usage(); } /* - * Remember the status associated with $!, so we can - * wait for it even if it's exited. This value is - * only used if we can't find the PID in the job table, - * so it doesn't matter that the value we save here isn't - * useful until the process has exited. + * Accumulate a list of older jobs. We only do this for + * background jobs, which is something in the job table + * that's not marked as in the current shell or as shell builtin + * and is not equal to the current foreground job. */ - if (pn != NULL && pid == lastpid && lastpid_status != -1L) - lastpid_status = lastval2; + if (jn && !(jn->stat & (STAT_CURSH|STAT_BUILTIN)) && + jn - jobtab != thisjob) + addbgstatus(pid, (int)lastval2); } } -- cgit v1.2.3 From fd302c9837b0034962471b9288b182e2525ba1d8 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 30 Oct 2014 21:52:18 +0100 Subject: 33570, 33576: make killring/yank-pop work in vi mode after vi-put-before and vi-put-after --- ChangeLog | 6 ++++ Doc/Zsh/zle.yo | 2 +- Src/Zle/iwidgets.list | 8 ++--- Src/Zle/zle.h | 16 +++++---- Src/Zle/zle_misc.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++----- Src/Zle/zle_vi.c | 68 +------------------------------------ Test/X02zlevi.ztst | 28 ++++++++++++++++ 7 files changed, 132 insertions(+), 88 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 284029883..146f1b8c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-10-30 Oliver Kiddle + + * 33570, 33576: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle.h, + Src/Zle/zle_misc.c, Src/Zle/zle_vi.c, Test/X02zlevi.ztst: make kill- + ring/yank-pop work in vi mode after vi-put-before and vi-put-after + 2014-10-29 Barton E. Schaefer * 33566: Jun T.: Src/Modules/zselect.c: quash compiler warning diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 881e56b19..06b165963 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1786,7 +1786,7 @@ tindex(yank-pop) item(tt(yank-pop) (ESC-y) (unbound) (unbound))( Remove the text just yanked, rotate the kill-ring (the history of previously killed text) and yank the new top. Only works following -tt(yank) or tt(yank-pop). +tt(yank), tt(vi-put-before), tt(vi-put-after) or tt(yank-pop). ) tindex(vi-yank) item(tt(vi-yank) (unbound) (y) (unbound))( diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index 79d62c7b5..dc7e8008d 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -159,8 +159,8 @@ "vi-open-line-below", viopenlinebelow, 0 "vi-oper-swap-case", vioperswapcase, ZLE_LASTCOL "vi-pound-insert", vipoundinsert, 0 -"vi-put-after", viputafter, ZLE_YANK | ZLE_KEEPSUFFIX -"vi-put-before", viputbefore, ZLE_YANK | ZLE_KEEPSUFFIX +"vi-put-after", viputafter, ZLE_YANKAFTER | ZLE_KEEPSUFFIX +"vi-put-before", viputbefore, ZLE_YANKBEFORE | ZLE_KEEPSUFFIX "vi-quoted-insert", viquotedinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX "vi-repeat-change", virepeatchange, 0 "vi-repeat-find", virepeatfind, 0 @@ -182,5 +182,5 @@ "what-cursor-position", whatcursorposition, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL "where-is", whereis, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL "which-command", processcmd, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL -"yank", yank, ZLE_YANK | ZLE_KEEPSUFFIX -"yank-pop", yankpop, ZLE_YANK | ZLE_KEEPSUFFIX +"yank", yank, ZLE_YANKBEFORE | ZLE_KEEPSUFFIX +"yank-pop", yankpop, ZLE_KEEPSUFFIX | ZLE_NOTCOMMAND diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index dd6cdcca0..8a85ee342 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -203,13 +203,15 @@ struct widget { #define WIDGET_INT (1<<0) /* widget is internally implemented */ #define WIDGET_NCOMP (1<<1) /* new style completion widget */ #define ZLE_MENUCMP (1<<2) /* DON'T invalidate completion list */ -#define ZLE_YANK (1<<3) -#define ZLE_LINEMOVE (1<<4) /* command is a line-oriented movement */ -#define ZLE_LASTCOL (1<<5) /* command maintains lastcol correctly */ -#define ZLE_KILL (1<<6) -#define ZLE_KEEPSUFFIX (1<<7) /* DON'T remove added suffix */ -#define ZLE_NOTCOMMAND (1<<8) /* widget should not alter lastcmd */ -#define ZLE_ISCOMP (1<<9) /* usable for new style completion */ +#define ZLE_YANKAFTER (1<<3) +#define ZLE_YANKBEFORE (1<<4) +#define ZLE_YANK (ZLE_YANKAFTER | ZLE_YANKBEFORE) +#define ZLE_LINEMOVE (1<<5) /* command is a line-oriented movement */ +#define ZLE_LASTCOL (1<<6) /* command maintains lastcol correctly */ +#define ZLE_KILL (1<<7) +#define ZLE_KEEPSUFFIX (1<<8) /* DON'T remove added suffix */ +#define ZLE_NOTCOMMAND (1<<9) /* widget should not alter lastcmd */ +#define ZLE_ISCOMP (1<<10) /* usable for new style completion */ /* thingies */ diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index 9bc1cf6f5..3d4a9bb4e 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -475,8 +475,10 @@ copyregionaskill(char **args) /* * kct: index into kill ring, or -1 for original cutbuffer of yank. * yankb, yanke: mark the start and end of last yank in editing buffer. + * yankcs marks the cursor position preceding the last yank */ -static int kct, yankb, yanke; +static int kct, yankb, yanke, yankcs; + /* The original cutbuffer, either cutbuf or one of the vi buffers. */ static Cutbuffer kctbuf; @@ -494,8 +496,7 @@ yank(UNUSED(char **args)) kctbuf = &cutbuf; if (!kctbuf->buf) return 1; - mark = zlecs; - yankb = zlecs; + yankb = yankcs = mark = zlecs; while (n--) { kct = -1; spaceinline(kctbuf->len); @@ -506,11 +507,87 @@ yank(UNUSED(char **args)) return 0; } +static void pastebuf(Cutbuffer buf, int mult, int after) +{ + int cc; + if (buf->flags & CUTBUFFER_LINE) { + if (after) { + yankb = zlecs = findeol(); + spaceinline(buf->len + 1); + zleline[zlecs++] = ZWC('\n'); + yanke = zlecs + buf->len; + ZS_memcpy(zleline + zlecs, buf->buf, buf->len); + } else { + yankb = zlecs = findbol(); + spaceinline(buf->len + 1); + ZS_memcpy(zleline + zlecs, buf->buf, buf->len); + yanke = zlecs + buf->len + 1; + zleline[zlecs + buf->len] = ZWC('\n'); + } + vifirstnonblank(zlenoargs); + } else { + if (after && zlecs != findeol()) + INCCS(); + yankb = zlecs; + cc = buf->len; + while (mult--) { + spaceinline(cc); + ZS_memcpy(zleline + zlecs, buf->buf, cc); + zlecs += cc; + } + yanke = zlecs; + if (zlecs) + DECCS(); + } +} + +/**/ +int +viputbefore(UNUSED(char **args)) +{ + int n = zmult; + + startvichange(-1); + if (n < 0 || zmod.flags & MOD_NULL) + return 1; + if (zmod.flags & MOD_VIBUF) + kctbuf = &vibuf[zmod.vibuf]; + else + kctbuf = &cutbuf; + if (!kctbuf->buf) + return 1; + kct = -1; + yankcs = zlecs; + pastebuf(kctbuf, n, 0); + return 0; +} + +/**/ +int +viputafter(UNUSED(char **args)) +{ + int n = zmult; + + startvichange(-1); + if (n < 0 || zmod.flags & MOD_NULL) + return 1; + if (zmod.flags & MOD_VIBUF) + kctbuf = &vibuf[zmod.vibuf]; + else + kctbuf = &cutbuf; + if (!kctbuf->buf) + return 1; + kct = -1; + yankcs = zlecs; + pastebuf(kctbuf, n, 1); + return 0; +} + /**/ int yankpop(UNUSED(char **args)) { - int cc, kctstart = kct; + int kctstart = kct; Cutbuffer buf; if (!(lastcmd & ZLE_YANK) || !kring || !kctbuf) { @@ -557,11 +634,8 @@ yankpop(UNUSED(char **args)) zlecs = yankb; foredel(yanke - yankb, CUT_RAW); - cc = buf->len; - spaceinline(cc); - ZS_memcpy(zleline + zlecs, buf->buf, cc); - zlecs += cc; - yanke = zlecs; + zlecs = yankcs; + pastebuf(buf, 1, lastcmd & ZLE_YANKAFTER); return 0; } diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index 0a8b27d65..b0e696b62 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -75,7 +75,7 @@ static int inrepeat, vichgrepeat; */ /**/ -static void +void startvichange(int im) { if (im != -1) { @@ -791,72 +791,6 @@ vikillline(UNUSED(char **args)) return 0; } -/**/ -int -viputbefore(UNUSED(char **args)) -{ - Cutbuffer buf = &cutbuf; - int n = zmult; - - startvichange(-1); - if (n < 0 || zmod.flags & MOD_NULL) - return 1; - if (zmod.flags & MOD_VIBUF) - buf = &vibuf[zmod.vibuf]; - if (!buf->buf) - return 1; - if(buf->flags & CUTBUFFER_LINE) { - zlecs = findbol(); - spaceinline(buf->len + 1); - ZS_memcpy(zleline + zlecs, buf->buf, buf->len); - zleline[zlecs + buf->len] = ZWC('\n'); - vifirstnonblank(zlenoargs); - } else { - while (n--) { - spaceinline(buf->len); - ZS_memcpy(zleline + zlecs, buf->buf, buf->len); - zlecs += buf->len; - } - if (zlecs) - DECCS(); - } - return 0; -} - -/**/ -int -viputafter(UNUSED(char **args)) -{ - Cutbuffer buf = &cutbuf; - int n = zmult; - - startvichange(-1); - if (n < 0 || zmod.flags & MOD_NULL) - return 1; - if (zmod.flags & MOD_VIBUF) - buf = &vibuf[zmod.vibuf]; - if (!buf->buf) - return 1; - if(buf->flags & CUTBUFFER_LINE) { - zlecs = findeol(); - spaceinline(buf->len + 1); - zleline[zlecs++] = ZWC('\n'); - ZS_memcpy(zleline + zlecs, buf->buf, buf->len); - vifirstnonblank(zlenoargs); - } else { - if (zlecs != findeol()) - INCCS(); - while (n--) { - spaceinline(buf->len); - ZS_memcpy(zleline + zlecs, buf->buf, buf->len); - zlecs += buf->len; - } - if (zlecs) - DECCS(); - } - return 0; -} - /**/ int vijoin(UNUSED(char **args)) diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index 2af6f06e6..185980b70 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -116,6 +116,34 @@ >BUFFER: stnwararart >CURSOR: 9 + zpty_run 'bindkey -a "^P" yank-pop' + zletest $'word\C-wline\eddiSE\eP\C-P' +0:line based put before followed by character based yank-pop +>BUFFER: SwordE +>CURSOR: 4 + + zletest $'line\eddiword\C-w\eiSE\eP\C-P' +0:character based put before followed by line based yank-pop +>BUFFER: line +>SE +>CURSOR: 0 + + zletest $'one two three\C-w\C-w\C-wSE\e0p\C-P\C-P' +0:put after cycled twice with yank-pop +>BUFFER: SthreeE +>CURSOR: 5 + + zletest $'word\C-wline\eddiSE\ehp\C-P' +0:line based put after followed by character based yank-pop +>BUFFER: SwordE +>CURSOR: 5 + + zletest $'line\eddiword\C-w\eiSE\ehp\C-P' +0:character based after before followed by line based yank-pop +>BUFFER: SE +>line +>CURSOR: 3 + zletest $'word\euaend' 0:undo initial change >BUFFER: end -- cgit v1.2.3 From 31df6c4d32da203f9eaf96a6b3a28918a7a48978 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 9 Nov 2014 17:40:22 +0100 Subject: 33643: elaborate documentation of the PRIVILEGED option --- ChangeLog | 3 +++ Doc/Zsh/options.yo | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 7fbb44e15..85da0efbd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2014-11-09 Oliver Kiddle + * 33643: Doc/Zsh/options.yo: elaborate documentation of + the PRIVILEGED option + * 33639: Src/Zle/zle_vi.c, Test/X02zlevi.ztst: fix bug with vi operators on a blank line and with backward bracket matching diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 452b258b4..b9f78bfa3 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -2195,10 +2195,22 @@ pindex(NOPRIVILEGED) cindex(privileged mode) cindex(mode, privileged) item(tt(PRIVILEGED) (tt(-p), ksh: tt(-p)))( -Turn on privileged mode. This is enabled automatically on startup if the -effective user (group) ID is not equal to the real user (group) ID. Turning -this option off causes the effective user and group IDs to be set to the -real user and group IDs. This option disables sourcing user startup files. +Turn on privileged mode. Typically this is used when script is to be run +with elevated privileges. This should be done as follows directly with +the tt(-p) option to zsh so that it takes effect during startup. + +example(#!/bin/zsh -p) + +The option is enabled automatically on startup if the effective user +(group) ID is not equal to the real user (group) ID. In this case, +turning the option off causes the effective user and group IDs to be set +to the real user and group IDs. Be aware that if that fails the shell may +be running with different IDs than was intended so a script should check +for failure and act accordingly, for example: + +example(unsetopt privileged || exit) + +The tt(PRIVILEGED) option disables sourcing user startup files. If zsh is invoked as `tt(sh)' or `tt(ksh)' with this option set, tt(/etc/suid_profile) is sourced (after tt(/etc/profile) on interactive shells). Sourcing tt(~/.profile) is disabled and the contents of the -- cgit v1.2.3 From e33411990e1353e5d39379adb56e325ab92ce28c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 11 Nov 2014 19:51:05 +0000 Subject: AUTO_CD behaviour depends on SHIN_STDIN, document --- ChangeLog | 4 ++++ Doc/Zsh/options.yo | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 495a6f9c5..64d0820be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-11-11 Peter Stephenson + + * 33658: Doc/Zsh/options.yo: AUTO_CD depends on SHIN_STDIN. + 2014-11-09 Oliver Kiddle * 33599: Jun T.: Test/comptest: workaround zpty issue that diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index b9f78bfa3..076aaf44f 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -63,6 +63,10 @@ item(tt(AUTO_CD) (tt(-J)))( If a command is issued that can't be executed as a normal command, and the command is the name of a directory, perform the tt(cd) command to that directory. +This option is only applicable if the option tt(SHIN_STDIN) is set, +i.e. if commands are being read from standard input. The option +is designed for interactive use; it is recommended that tt(cd) +be used explicitly in scripts to avoid ambiguity. ) pindex(AUTO_PUSHD) pindex(NO_AUTO_PUSHD) -- cgit v1.2.3 From 13f3eec61dd806682141d45520fb4a08726831e0 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 15 Nov 2014 21:31:29 +0100 Subject: 33696: simple up/down line widgets that don't go through history lines --- ChangeLog | 3 +++ Doc/Zsh/zle.yo | 8 ++++++++ Src/Zle/iwidgets.list | 2 ++ Src/Zle/zle_hist.c | 20 ++++++++++---------- 4 files changed, 23 insertions(+), 10 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index ef22cb5eb..50b0fb881 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2014-11-15 Oliver Kiddle + * 33696: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle_hist.c: + simple up/down line widgets that don't go through history lines + * 33695: Src/Zle/zle_vi.c, Test/X02zlevi.ztst, Test/comptest: fix various vi-indent problems and vi-swap-case on a blank line diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 06b165963..854510fa1 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1078,6 +1078,10 @@ tindex(vi-beginning-of-line) item(tt(vi-beginning-of-line))( Move to the beginning of the line, without changing lines. ) +tindex(down-line) +item(tt(down-line) (unbound) (unbound) (unbound))( +Move down a line in the buffer. +) tindex(end-of-line) item(tt(end-of-line) (^E) (unbound) (unbound))( Move to the end of the line. If already at the end @@ -1170,6 +1174,10 @@ tindex(vi-rev-repeat-find) item(tt(vi-rev-repeat-find) (unbound) (,) (unbound))( Repeat the last tt(vi-find) command in the opposite direction. ) +tindex(up-line) +item(tt(up-line) (unbound) (unbound) (unbound))( +Move up a line in the buffer. +) enditem() texinode(History Control)(Modifying Text)(Movement)(Zle Widgets) subsect(History Control) diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index dc7e8008d..0401397e1 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -41,6 +41,7 @@ "digit-argument", digitargument, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_NOTCOMMAND "down-case-word", downcaseword, 0 "down-history", downhistory, 0 +"down-line", downline, ZLE_LINEMOVE | ZLE_LASTCOL "down-line-or-history", downlineorhistory, ZLE_LINEMOVE | ZLE_LASTCOL "down-line-or-search", downlineorsearch, ZLE_LINEMOVE | ZLE_LASTCOL "emacs-backward-word", emacsbackwardword, 0 @@ -112,6 +113,7 @@ "universal-argument", universalargument, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_NOTCOMMAND "up-case-word", upcaseword, 0 "up-history", uphistory, 0 +"up-line", upline, ZLE_LINEMOVE | ZLE_LASTCOL "up-line-or-history", uplineorhistory, ZLE_LINEMOVE | ZLE_LASTCOL "up-line-or-search", uplineorsearch, ZLE_LINEMOVE | ZLE_LASTCOL "vi-add-eol", viaddeol, 0 diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c index 44b39d186..bf7b5f46d 100644 --- a/Src/Zle/zle_hist.c +++ b/Src/Zle/zle_hist.c @@ -227,14 +227,14 @@ uphistory(UNUSED(char **args)) } /**/ -static int -upline(void) +int +upline(char **args) { int n = zmult; if (n < 0) { zmult = -zmult; - n = -downline(); + n = -downline(args); zmult = -zmult; return n; } @@ -270,7 +270,7 @@ int uplineorhistory(char **args) { int ocs = zlecs; - int n = upline(); + int n = upline(args); if (n) { int m = zmult, ret; @@ -300,7 +300,7 @@ int uplineorsearch(char **args) { int ocs = zlecs; - int n = upline(); + int n = upline(args); if (n) { int m = zmult, ret; @@ -316,14 +316,14 @@ uplineorsearch(char **args) } /**/ -static int -downline(void) +int +downline(char **args) { int n = zmult; if (n < 0) { zmult = -zmult; - n = -upline(); + n = -upline(args); zmult = -zmult; return n; } @@ -358,7 +358,7 @@ int downlineorhistory(char **args) { int ocs = zlecs; - int n = downline(); + int n = downline(args); if (n) { int m = zmult, ret; @@ -388,7 +388,7 @@ int downlineorsearch(char **args) { int ocs = zlecs; - int n = downline(); + int n = downline(args); if (n) { int m = zmult, ret; -- cgit v1.2.3 From 1e934556f7a91cc15e78272763dab05ea16b6d78 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 15 Nov 2014 21:33:32 +0100 Subject: 33697: new vim style vi-backward-word-end widgets --- ChangeLog | 3 +++ Doc/Zsh/zle.yo | 9 +++++++ Src/Zle/iwidgets.list | 2 ++ Src/Zle/zle_word.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 78 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 50b0fb881..f3ccb15f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2014-11-15 Oliver Kiddle + * 33697: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle_word.c: + new vim style vi-backward-word-end widgets + * 33696: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle_hist.c: simple up/down line widgets that don't go through history lines diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 854510fa1..6fe7c9bf2 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1049,6 +1049,11 @@ item(tt(vi-backward-blank-word) (unbound) (B) (unbound))( Move backward one word, where a word is defined as a series of non-blank characters. ) +tindex(vi-backward-blank-word-end) +item(tt(vi-backward-blank-word-end) (unbound) (unbound) (unbound))( +Move to the end of the previous word, where a word is defined as a +series of non-blank characters. +) tindex(backward-char) item(tt(backward-char) (^B ESC-[D) (unbound) (unbound))( Move backward one character. @@ -1069,6 +1074,10 @@ tindex(vi-backward-word) item(tt(vi-backward-word) (unbound) (b) (unbound))( Move to the beginning of the previous word, vi-style. ) +tindex(vi-backward-word-end) +item(tt(vi-backward-word-end) (unbound) (unbound) (unbound))( +Move to the end of the previous word, vi-style. +) tindex(beginning-of-line) item(tt(beginning-of-line) (^A) (unbound) (unbound))( Move to the beginning of the line. If already at the beginning diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index 0401397e1..a2bad5aa9 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -123,6 +123,8 @@ "vi-backward-delete-char", vibackwarddeletechar, ZLE_KEEPSUFFIX "vi-backward-kill-word", vibackwardkillword, ZLE_KEEPSUFFIX "vi-backward-word", vibackwardword, 0 +"vi-backward-word-end", vibackwardwordend, 0 +"vi-backward-blank-word-end", vibackwardblankwordend, 0 "vi-beginning-of-line", vibeginningofline, 0 "vi-caps-lock-panic", vicapslockpanic, ZLE_LASTCOL "vi-change", vichange, ZLE_LASTCOL diff --git a/Src/Zle/zle_word.c b/Src/Zle/zle_word.c index e59304ecd..301b18d4a 100644 --- a/Src/Zle/zle_word.c +++ b/Src/Zle/zle_word.c @@ -148,8 +148,13 @@ viforwardblankwordend(UNUSED(char **args)) { int n = zmult; - if (n < 0) - return 1; + if (n < 0) { + int ret; + zmult = -n; + ret = viforwardblankwordend(args); + zmult = n; + return ret; + } while (n--) { while (zlecs != zlell) { int pos = zlecs; @@ -180,7 +185,7 @@ viforwardwordend(char **args) if (n < 0) { int ret; zmult = -n; - ret = backwardword(args); + ret = vibackwardwordend(args); zmult = n; return ret; } @@ -334,6 +339,62 @@ vibackwardblankword(char **args) return 0; } +/**/ +int +vibackwardwordend(char **args) +{ + int n = zmult; + + if (n < 0) { + int ret; + zmult = -n; + ret = viforwardwordend(args); + zmult = n; + return ret; + } + while (n-- && zlecs > 1) { + int start = 0; + if (Z_vialnum(zleline[zlecs])) + start = 1; + else if (!ZC_iblank(zleline[zlecs])) + start = 2; + DECCS(); + while (zlecs) { + int same = (start != 1) && ZC_iblank(zleline[zlecs]); + if (start) + same |= Z_vialnum(zleline[zlecs]); + if (same == (start == 2)) + break; + DECCS(); + } + while (zlecs && ZC_iblank(zleline[zlecs])) + DECCS(); + } + return 0; +} + +/**/ +int +vibackwardblankwordend(char **args) +{ + int n = zmult; + + if (n < 0) { + int ret; + zmult = -n; + ret = viforwardblankwordend(args); + zmult = n; + return ret; + } + while (n--) { + while (zlecs && !ZC_iblank(zleline[zlecs])) + DECCS(); + while (zlecs && ZC_iblank(zleline[zlecs])) + DECCS(); + } + return 0; +} + /**/ int emacsbackwardword(char **args) -- cgit v1.2.3 From 0ea8f28e7b230315fe3fcca162a15258b618b0b2 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Mon, 17 Nov 2014 16:32:04 +0100 Subject: 33700: new widget for put in vim style visual selection mode --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 7 ++++++ Src/Zle/iwidgets.list | 1 + Src/Zle/zle_misc.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++---- Src/Zle/zle_utils.c | 2 +- 5 files changed, 70 insertions(+), 5 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 1491234a3..fc9f8e5fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2014-11-17 Oliver Kiddle + * 33700: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, + Src/Zle/zle_misc.c, Src/Zle/zle_utils.c: new widget + for put in vim style visual selection mode + * 33699: Test/X02zlevi.ztst, Test/comptest: support short delays in zle tests where we need KEYTIMEOUT to elapse diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 6fe7c9bf2..998bf4a10 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1721,6 +1721,13 @@ Insert the contents of the kill buffer after the cursor. If the kill buffer contains a sequence of lines (as opposed to characters), paste it below the current line. ) +tindex(put-replace-selection) +item(tt(put-replace-selection) (unbound) (unbound) (unbound))( +Replace the contents of the current region or selection with the +contents of the kill buffer. If the kill buffer contains a sequence of +lines (as opposed to characters), the current line will be split by the +pasted lines. +) tindex(quoted-insert) item(tt(quoted-insert) (^V) (unbound) (unbound))( Insert the next character typed into the buffer literally. diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index a2bad5aa9..070116f5f 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -89,6 +89,7 @@ "push-input", pushinput, 0 "push-line", pushline, 0 "push-line-or-edit", pushlineoredit, 0 +"put-replace-selection", putreplaceselection, ZLE_KEEPSUFFIX "quoted-insert", quotedinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX "quote-line", quoteline, 0 "quote-region", quoteregion, 0 diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index 3d4a9bb4e..3e6d1aaac 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -507,11 +507,26 @@ yank(UNUSED(char **args)) return 0; } -static void pastebuf(Cutbuffer buf, int mult, int after) +/* position: 0 is before, 1 after, 2 split the line */ +static void pastebuf(Cutbuffer buf, int mult, int position) { int cc; if (buf->flags & CUTBUFFER_LINE) { - if (after) { + if (position == 2) { + if (!zlecs) + position = 0; + else if (zlecs == zlell) + position = 1; + } + if (position == 2) { + yankb = zlecs; + spaceinline(buf->len + 2); + zleline[zlecs++] = ZWC('\n'); + ZS_memcpy(zleline + zlecs, buf->buf, buf->len); + zlecs += buf->len; + zleline[zlecs] = ZWC('\n'); + yanke = zlecs + 1; + } else if (position != 0) { yankb = zlecs = findeol(); spaceinline(buf->len + 1); zleline[zlecs++] = ZWC('\n'); @@ -526,7 +541,7 @@ static void pastebuf(Cutbuffer buf, int mult, int after) } vifirstnonblank(zlenoargs); } else { - if (after && zlecs != findeol()) + if (position == 1 && zlecs != findeol()) INCCS(); yankb = zlecs; cc = buf->len; @@ -583,6 +598,44 @@ viputafter(UNUSED(char **args)) return 0; } +/**/ +int +putreplaceselection(UNUSED(char **args)) +{ + int n = zmult; + struct cutbuffer prevbuf; + Cutbuffer putbuf; + int clear = 0; + int pos = 2; + + startvichange(-1); + if (n < 0 || zmod.flags & MOD_NULL) + return 1; + putbuf = (zmod.flags & MOD_VIBUF) ? &vibuf[zmod.vibuf] : &cutbuf; + if (!putbuf->buf) + return 1; + memcpy(&prevbuf, putbuf, sizeof(prevbuf)); + + /* if "9 was specified, prevent killregion from freeing it */ + if (zmod.vibuf == 35) { + putbuf->buf = 0; + clear = 1; + } + + zmod.flags = 0; /* flags apply to paste not kill */ + if (region_active == 2 && prevbuf.flags & CUTBUFFER_LINE) { + int a, b; + regionlines(&a, &b); + pos = (b == zlell); + } + killregion(zlenoargs); + + pastebuf(&prevbuf, n, pos); + if (clear) + free(prevbuf.buf); + return 0; +} + /**/ int yankpop(UNUSED(char **args)) @@ -635,7 +688,7 @@ yankpop(UNUSED(char **args)) zlecs = yankb; foredel(yanke - yankb, CUT_RAW); zlecs = yankcs; - pastebuf(buf, 1, lastcmd & ZLE_YANKAFTER); + pastebuf(buf, 1, !!(lastcmd & ZLE_YANKAFTER)); return 0; } diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index f56063e82..08a32c30e 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -953,7 +953,7 @@ cuttext(ZLE_STRING_T line, int ct, int flags) } else { /* Save in "1, shifting "1-"8 along to "2-"9 */ int n; - free(vibuf[34].buf); + free(vibuf[35].buf); for(n=35; n>27; n--) vibuf[n] = vibuf[n-1]; vibuf[27].buf = (ZLE_STRING_T)zalloc(ct * ZLE_CHAR_SIZE); -- cgit v1.2.3 From d29e02c1a30c136cbd8847a4dc4628da90566716 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Mon, 17 Nov 2014 23:00:49 +0100 Subject: 33704: keybindings, documentation, tests and minor fixes for vim style visual selection changes --- ChangeLog | 5 +++ Doc/Zsh/zle.yo | 38 +++++++++++++++-- Src/Zle/zle_bindings.c | 4 +- Src/Zle/zle_keymap.c | 22 +++++++++- Src/Zle/zle_refresh.c | 5 +-- Src/Zle/zle_vi.c | 8 +--- Test/X02zlevi.ztst | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ Test/comptest | 2 +- 8 files changed, 176 insertions(+), 17 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index e181b3852..6fd41e4a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2014-11-17 Oliver Kiddle + * 33704: Doc/Zsh/zle.yo, Src/Zle/zle_bindings.c, + Src/Zle/zle_keymap.c, Src/Zle/zle_refresh.c, Src/Zle/zle_vi.c, + Test/X02zlevi.ztst, Test/comptest: key bindings, documentation, + tests and minor fixes for vim style visual selection changes + * 33636: Src/Zle/iwidgets.list, Src/Zle/zle_misc.c, Src/Zle/zle_move.c, Src/Zle/zle_refresh.c, Src/Zle/zle_vi.c: add support for a linewise visual selection mode diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 998bf4a10..aa7ff4b57 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -60,12 +60,14 @@ or more names. If all of a keymap's names are deleted, it disappears. findex(bindkey, use of) tt(bindkey) can be used to manipulate keymap names. -Initially, there are six keymaps: +Initially, there are eight keymaps: startsitem() sitem(tt(emacs))(EMACS emulation) sitem(tt(viins))(vi emulation - insert mode) sitem(tt(vicmd))(vi emulation - command mode) +sitem(tt(viopp))(vi emulation - operator pending) +sitem(tt(visual))(vi emulation - selection active) sitem(tt(isearch))(incremental search mode) sitem(tt(command))(read a command name) sitem(tt(.safe))(fallback keymap) @@ -122,6 +124,21 @@ in user-defined widgets with the tt(read-command) widget, described ifzman(below)\ ifnzman(in noderef(Miscellaneous) below)\ . +subsect(Local Keymaps) +cindex(local keymaps) +While for normal editing a single keymap is used exclusively, in many +modes a local keymap allows for some keys to be customised. For example, +in an incremental search mode, a binding in the tt(isearch) keymap will +override a binding in the tt(main) keymap but all keys that are not +overriden can still be used. + +If a key sequence is defined in a local keymap, it will hide a key +sequence in the global keymap that is a prefix of that sequence. An +example of this occurs with the binding of tt(iw) in tt(viopp) as this +hides the binding of tt(i) in tt(vicmd). However, a longer sequence in +the global keymap that shares the same prefix can still apply so for +example the binding of tt(^Xa) in the global keymap will be unaffected +by the binding of tt(^Xb) in the local keymap. texinode(Zle Builtins)(Zle Widgets)(Keymaps)(Zsh Line Editor) sect(Zle Builtins) @@ -817,7 +834,10 @@ cursor remains between the new tt($LBUFFER) and the old tt($RBUFFER). ) vindex(MARK) item(tt(MARK) (integer))( -Like tt(CURSOR), but for the mark. +Like tt(CURSOR), but for the mark. With vi-mode operators that wait for +a movement command to select a region of text, setting tt(MARK) allows +the selection to extend in both directions from the the initial cursor +position. ) vindex(NUMERIC) item(tt(NUMERIC) (integer))( @@ -863,7 +883,9 @@ cursor remains between the old tt($LBUFFER) and the new tt($RBUFFER). vindex(REGION_ACTIVE) item(tt(REGION_ACTIVE) (integer))( Indicates if the region is currently active. It can be assigned 0 or 1 -to deactivate and activate the region respectively; +to deactivate and activate the region respectively. A value of 2 +activates the region in line-wise mode with the highlighted text +extending for whole lines only; ifzman(see em(Character Highlighting) below)\ ifnzman(noderef(Character Highlighting)). ) @@ -2275,6 +2297,16 @@ item(tt(vi-undo-change) (unbound) (u) (unbound))( Undo the last text modification. If repeated, redo the modification. ) +tindex(visual-mode) +item(tt(visual-mode) (unbound) (v) (unbound))( +Toggle vim-style visual selection mode. If line-wise visual mode is +currently enabled then it is changed to being character-wise. +) +tindex(visual-line-mode) +item(tt(visual-line-mode) (unbound) (V) (unbound))( +Toggle vim-style line-wise visual selection mode. If character-wise +visual mode is currently enabled then it is changed to being line-wise. +) tindex(what-cursor-position) item(tt(what-cursor-position) (^X=) (unbound) (unbound))( Print the character under the cursor, its code as an octal, decimal and diff --git a/Src/Zle/zle_bindings.c b/Src/Zle/zle_bindings.c index 682691347..50a29551d 100644 --- a/Src/Zle/zle_bindings.c +++ b/Src/Zle/zle_bindings.c @@ -376,7 +376,7 @@ int vicmdbind[128] = { /* S */ z_vichangewholeline, /* T */ z_vifindprevcharskip, /* U */ z_undefinedkey, - /* V */ z_undefinedkey, + /* V */ z_visuallinemode, /* W */ z_viforwardblankword, /* X */ z_vibackwarddeletechar, /* Y */ z_viyankwholeline, @@ -408,7 +408,7 @@ int vicmdbind[128] = { /* s */ z_visubstitute, /* t */ z_vifindnextcharskip, /* u */ z_viundochange, - /* v */ z_undefinedkey, + /* v */ z_visualmode, /* w */ z_viforwardword, /* x */ z_videletechar, /* y */ z_viyank, diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 6a7107609..216e302d0 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1277,8 +1277,10 @@ default_bindings(void) Keymap vmap = newkeymap(NULL, "viins"); Keymap emap = newkeymap(NULL, "emacs"); Keymap amap = newkeymap(NULL, "vicmd"); + Keymap oppmap = newkeymap(NULL, "viopp"); + Keymap vismap = newkeymap(NULL, "visual"); Keymap smap = newkeymap(NULL, ".safe"); - Keymap vimaps[2], kptr; + Keymap vimaps[2], vilmaps[2], kptr; char buf[3], *ed; int i; @@ -1332,6 +1334,22 @@ default_bindings(void) add_cursor_key(kptr, TCLEFTCURSOR, t_vibackwardchar, 'D'); add_cursor_key(kptr, TCRIGHTCURSOR, t_viforwardchar, 'C'); } + vilmaps[0] = oppmap; + vilmaps[1] = vismap; + for (i = 0; i < 2; i++) { + /* vi visual selection and operator pending local maps */ + kptr = vilmaps[i]; + add_cursor_key(kptr, TCUPCURSOR, t_upline, 'A'); + add_cursor_key(kptr, TCDOWNCURSOR, t_downline, 'B'); + bindkey(kptr, "k", refthingy(t_upline), NULL); + bindkey(kptr, "j", refthingy(t_downline), NULL); + } + /* escape in operator pending cancels the operation */ + bindkey(oppmap, "\33", refthingy(t_vicmdmode), NULL); + bindkey(vismap, "o", refthingy(t_exchangepointandmark), NULL); + bindkey(vismap, "p", refthingy(t_putreplaceselection), NULL); + bindkey(vismap, "x", refthingy(t_videlete), NULL); + bindkey(vismap, "~", refthingy(t_vioperswapcase), NULL); /* emacs mode: arrow keys */ add_cursor_key(emap, TCUPCURSOR, t_uplineorhistory, 'A'); @@ -1373,6 +1391,8 @@ default_bindings(void) linkkeymap(vmap, "viins", 0); linkkeymap(emap, "emacs", 0); linkkeymap(amap, "vicmd", 0); + linkkeymap(oppmap, "viopp", 0); + linkkeymap(vismap, "visual", 0); linkkeymap(smap, ".safe", 1); if (((ed = zgetenv("VISUAL")) && strstr(ed, "vi")) || ((ed = zgetenv("EDITOR")) && strstr(ed, "vi"))) diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c index f0351ad15..467629d25 100644 --- a/Src/Zle/zle_refresh.c +++ b/Src/Zle/zle_refresh.c @@ -1037,8 +1037,6 @@ zrefresh(void) region_highlights[0].start = mark; region_highlights[0].end = zlecs; } - if (invicmdmode()) - INCPOS(region_highlights[0].end); if (region_active == 2) { int origcs = zlecs; zlecs = region_highlights[0].end; @@ -1046,7 +1044,8 @@ zrefresh(void) zlecs = region_highlights[0].start; region_highlights[0].start = findbol(); zlecs = origcs; - } + } else if (invicmdmode()) + INCPOS(region_highlights[0].end); } else { region_highlights[0].start = region_highlights[0].end = -1; } diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index 3a4304ced..84cba7759 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -258,7 +258,7 @@ getvirange(int wf) pos = tmp; } - if (visual && invicmdmode()) + if (visual == 1 && invicmdmode()) INCPOS(pos); /* Was it a line-oriented move? If so, the command will have set * @@ -389,9 +389,6 @@ videletechar(char **args) startvichange(-1); - if (region_active) - return killregion(args); - /* handle negative argument */ if (n < 0) { int ret; @@ -804,9 +801,6 @@ vibackwarddeletechar(char **args) if (invicmdmode()) startvichange(-1); - if (region_active) - return killregion(args); - /* handle negative argument */ if (n < 0) { int ret; diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index 297fb9aee..94afb60eb 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -273,6 +273,115 @@ >BUFFER: one wo >CURSOR: 2 + zletest $'one two\evbcx' +0:change selection +>BUFFER: one x +>CURSOR: 5 + + zletest $'four\eOthree\eOtwo\eOone\evjjhCnew' +0:change character wise selection with C acts linewise +>BUFFER: new +>four +>CURSOR: 3 + + zletest $'x testing\ehvbx' +0:x kills selections +>BUFFER: x g +>CURSOR: 2 + + zletest $'one two\eyb0vep' +0:put over selection at start of buffer +>BUFFER: tw two +>CURSOR: 1 + + zletest $'hello\C-wbye\evhp' +0:put over selection at end of buffer +>BUFFER: bhello +>CURSOR: 5 + + zletest $'one\eotwo\eyykVp' +0:yank linewise and put over linewise selection at start of buffer +>BUFFER: two +>two +>CURSOR: 0 + + zletest $'one\eotwo\eothree\eyykVp' +0:yank linewise and put over linewise selection in middle of buffer +>BUFFER: one +>three +>three +>CURSOR: 4 + + zletest $'two\eOone\eyyjVp' +0:yank linewise and put over linewise selection at end of buffer +>BUFFER: one +>one +>CURSOR: 4 + + zletest $'one\eyhVp' +0:yank character-wise and put over linewise selection +>BUFFER: n +>CURSOR: 0 + +# vim puts a blank line above in this test + zletest $'one\eotwo\eyy0kvlp' +0:yank linewise and put over character-wise selection at start of buffer +>BUFFER: two +>e +>two +>CURSOR: 0 + + zletest $'one\eyyhvp' +0:yank linewise and put over character-wise selection in middle of buffer +>BUFFER: o +>one +>e +>CURSOR: 2 + +# vim behaviour on this one really looks like a bug + zletest $'two\eOone\eyyjvhp' +0:yank linewise and put over character-wise selection at end of buffer +>BUFFER: one +>t +>one +>CURSOR: 6 + + zletest $'abc123456789\exxxxxxxxxhv"9p0P' +0:paste last (9th) register over a selection +>BUFFER: ba9c +>CURSOR: 0 + + zletest $'one\eo\eo\eotwo\ekkVdvd' +0:delete blank line using selection +>BUFFER: one +>two +>CURSOR: 4 + + zletest $'One Two Three\e2bvw~' +0:toggle case of selection +>BUFFER: One tWO three +>CURSOR: 4 + + zletest $' ----word ---- word word---- ----\e42|daw30|daw22|daw14|daw2|daw' +0:delete all word on blanks +>BUFFER: word +>CURSOR: 0 + + zletest $' word----word word----word word \e38|daw30|daw22|daw14|daw6|daw' +0:delete all word on alphanumerics +>BUFFER: -------- +>CURSOR: 4 + + zletest $' ----word---- ----word---- ---- \e38|daw30|daw22|daw14|daw6|daw' +0:delete all word on other characters +>BUFFER: wordword +>CURSOR: 4 + + zletest $'- word word\e4|2daw' +0:delete all word with numeric argument +>BUFFER: - +>CURSOR: 0 + %clean zmodload -ui zsh/zpty diff --git a/Test/comptest b/Test/comptest index 654c0f168..c67237a9a 100644 --- a/Test/comptest +++ b/Test/comptest @@ -34,7 +34,7 @@ comptestinit () { "fpath=( $fpath )" \ "bindkey -$comptest_keymap" \ 'LISTMAX=10000000 -stty 38400 columns 80 rows 24 werase undef +stty 38400 columns 80 rows 24 werase undef tabs TERM=vt100 KEYTIMEOUT=1 setopt zle -- cgit v1.2.3 From dded99b0852f5c6847fa48cdd6ee6b74c8a8bc57 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 19 Nov 2014 15:48:58 +0000 Subject: 33679: Note on patter s in case statements They work exactly like groups in other patterns, despite contrary indications. --- ChangeLog | 8 +++++++- Doc/Zsh/grammar.yo | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 6fd41e4a9..62eb2df1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,13 @@ +2014-11-19 Peter Stephenson + + * 33679: Doc/Zsh/grammar.yo: Note that alternation in case + patterns works just like filename generation, despite + appearances to the contrary. + 2014-11-17 Oliver Kiddle * 33704: Doc/Zsh/zle.yo, Src/Zle/zle_bindings.c, - Src/Zle/zle_keymap.c, Src/Zle/zle_refresh.c, Src/Zle/zle_vi.c, + Src/Zle/zle_keX4aymap.c, Src/Zle/zle_refresh.c, Src/Zle/zle_vi.c, Test/X02zlevi.ztst, Test/comptest: key bindings, documentation, tests and minor fixes for vim style visual selection changes diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 4d04c2470..63d90dfd0 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -239,7 +239,11 @@ item(tt(case) var(word) tt(in) [ [tt(LPAR())] var(pattern) [ tt(|) var(pattern) Execute the var(list) associated with the first var(pattern) that matches var(word), if any. The form of the patterns is the same as that used for filename generation. See -noderef(Filename Generation). +noderef(Filename Generation). Note further that the whole +pattern with alternatives is treated by the shell as equivalent +to a group of patterns within parentheses, even though in +the tt(case) syntax whitespace may appear about the parentheses and the +vertical bar. If the var(list) that is executed is terminated with tt(;&) rather than tt(;;), the following list is also executed. The rule for -- cgit v1.2.3 From 58da0f495cdf2bbef6a7043f5f06c77991c79a9e Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 21 Nov 2014 01:08:25 +0100 Subject: 33730: vim style text objects for selecting words --- ChangeLog | 8 +- Doc/Zsh/zle.yo | 46 +++++++- Src/Zle/iwidgets.list | 6 + Src/Zle/textobjects.c | 321 ++++++++++++++++++++++++++++++++++++++++++++++++++ Src/Zle/zle.mdd | 3 +- Src/Zle/zle_keymap.c | 6 + Test/X02zlevi.ztst | 39 ++++++ 7 files changed, 426 insertions(+), 3 deletions(-) create mode 100644 Src/Zle/textobjects.c (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index d88596e57..9e1b0206e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-11-21 Oliver Kiddle + + * 33730: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, + Src/Zle/textobjects.c, Src/Zle/zle.mdd, Src/Zle/zle_keymap.c, + Test/X02zlevi.ztst: vim style text objects for selecting words + 2014-11-21 Peter Stephenson * Sebastien Alaiwan: 33728: Completion/Unix/Command/_bzr: @@ -20,7 +26,7 @@ 2014-11-17 Oliver Kiddle * 33704: Doc/Zsh/zle.yo, Src/Zle/zle_bindings.c, - Src/Zle/zle_keX4aymap.c, Src/Zle/zle_refresh.c, Src/Zle/zle_vi.c, + Src/Zle/zle_keymap.c, Src/Zle/zle_refresh.c, Src/Zle/zle_vi.c, Test/X02zlevi.ztst, Test/comptest: key bindings, documentation, tests and minor fixes for vim style visual selection changes diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index aa7ff4b57..f9dcd8016 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1975,7 +1975,7 @@ When a previous completion displayed a list below the prompt, this widget can be used to move the prompt below the list. ) enditem() -texinode(Miscellaneous)()(Completion)(Zle Widgets) +texinode(Miscellaneous)(Text Objects)(Completion)(Zle Widgets) subsect(Miscellaneous) startitem() tindex(accept-and-hold) @@ -2333,6 +2333,50 @@ If the last command executed was a digit as part of an argument, continue the argument. Otherwise, execute vi-beginning-of-line. ) enditem() +texinode(Text Objects)()(Miscellaneous)(Zle Widgets) +subsect(Text Objects) +cindex(text objects) +Text objects are commands that can be used to select a block of text +according to some criteria. They are a feature of the vim text editor +and so are primarily intended for use with vi operators or from visual +selection mode. However, they can also be used from vi-insert or emacs +mode. Key bindings listed below apply to the tt(viopp) and tt(visual) +keymaps. + +startitem() +tindex(select-a-blank-word) +item(tt(select-a-blank-word) (aW))( +Select a word including adjacent blanks, where a word is defined as a +series of non-blank characters. With a numeric argument, multiple words +will be selected. +) +tindex(select-a-shell-word) +item(tt(select-a-shell-word) (aa))( +Select the current command argument applying the normal rules for +quoting. +) +tindex(select-a-word) +item(tt(select-a-word) (aw))( +Select a word including adjacent blanks, using the normal vi-style word +definition. With a numeric argument, multiple words will be selected. +) +tindex(select-in-blank-word) +item(tt(select-in-blank-word) (iW))( +Select a word, where a word is defined as a series of non-blank +characters. With a numeric argument, multiple words will be selected. +) +tindex(select-in-shell-word) +item(tt(select-in-shell-word) (ia))( +Select the current command argument applying the normal rules for +quoting. If the argument begins and ends with matching quote characters, +these are not included in the selection. +) +tindex(select-in-word) +item(tt(select-in-word) (iw))( +Select a word, using the normal vi-style word definition. With a numeric +argument, multiple words will be selected. +) +enditem() texinode(Character Highlighting)()(Zle Widgets)(Zsh Line Editor) sect(Character Highlighting) diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index 26182974a..1a664e5e8 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -100,6 +100,12 @@ "reset-prompt", resetprompt, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL "reverse-menu-complete", reversemenucomplete, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_ISCOMP "run-help", processcmd, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL +"select-a-word", selectword, ZLE_KEEPSUFFIX +"select-in-word", selectword, ZLE_KEEPSUFFIX +"select-a-blank-word", selectword, ZLE_KEEPSUFFIX +"select-in-blank-word", selectword, ZLE_KEEPSUFFIX +"select-a-shell-word", selectargument, ZLE_KEEPSUFFIX +"select-in-shell-word", selectargument, ZLE_KEEPSUFFIX "self-insert", selfinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX "self-insert-unmeta", selfinsertunmeta, ZLE_MENUCMP | ZLE_KEEPSUFFIX "send-break", sendbreak, 0 diff --git a/Src/Zle/textobjects.c b/Src/Zle/textobjects.c new file mode 100644 index 000000000..7f049c5dd --- /dev/null +++ b/Src/Zle/textobjects.c @@ -0,0 +1,321 @@ +/* + * textobjects.c - ZLE module implementing Vim style text objects + * + * This file is part of zsh, the Z shell. + * + * Copyright (c) 2014 Oliver Kiddle + * All rights reserved. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and to distribute modified versions of this software for any + * purpose, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * In no event shall Oliver Kiddle or the Zsh Development Group be liable + * to any party for direct, indirect, special, incidental, or consequential + * damages arising out of the use of this software and its documentation, + * even if Oliver Kiddle and the Zsh Development Group have been advised of + * the possibility of such damage. + * + * Oliver Kiddle and the Zsh Development Group specifically disclaim any + * warranties, including, but not limited to, the implied warranties of + * merchantability and fitness for a particular purpose. The software + * provided hereunder is on an "as is" basis, and Oliver Kiddle and the + * Zsh Development Group have no obligation to provide maintenance, + * support, updates, enhancements, or modifications. + * + */ + +#include "zle.mdh" +#include "textobjects.pro" + +/* class of character: 0 is whitespace, 1 is word character, 2 is other */ +static int +wordclass(ZLE_CHAR_T x) +{ + return (ZC_iblank(x) ? 0 : ((ZC_ialnum(x) || (ZWC('_') == x)) ? 1 : 2)); +} + +static int +blankwordclass(ZLE_CHAR_T x) +{ + return (ZC_iblank(x) ? 0 : 1); +} + +/**/ +int +selectword(UNUSED(char **args)) +{ + int n = zmult; + int all = (bindk == t_selectaword || bindk == t_selectablankword); + int (*viclass)(ZLE_CHAR_T) = (bindk == t_selectaword || + bindk == t_selectinword) ? wordclass : blankwordclass; + int sclass = viclass(zleline[zlecs]); + int doblanks = all && sclass; + + if (!invicmdmode()) { + region_active = 1; + mark = zlecs; + } + if (!region_active || zlecs == mark) { + /* search back to first character of same class as the start position + * also stop at the beginning of the line */ + mark = zlecs; + while (mark) { + int pos = mark; + DECPOS(pos); + if (zleline[pos] == ZWC('\n') || viclass(zleline[pos]) != sclass) + break; + mark = pos; + } + /* similarly scan forward over characters of the same class */ + while (zlecs < zlell) { + INCCS(); + int pos = zlecs; + /* single newlines within blanks are included */ + if (all && !sclass && pos < zlell && zleline[pos] == ZWC('\n')) + INCPOS(pos); + + if (zleline[pos] == ZWC('\n') || viclass(zleline[pos]) != sclass) + break; + } + + if (all) { + int nclass = viclass(zleline[zlecs]); + /* if either start or new position is blank advance over + * a new block of characters of a common type */ + if (!nclass || !sclass) { + while (zlecs < zlell) { + INCCS(); + if (zleline[zlecs] == ZWC('\n') || + viclass(zleline[zlecs]) != nclass) + break; + } + if (n < 2) + doblanks = 0; + } + } + } else { + /* For visual mode, advance one char so repeated + * invocations select subsequent words */ + if (zlecs > mark) { + if (zlecs < zlell) + INCCS(); + } else if (zlecs) + DECCS(); + if (zlecs < mark) { + /* visual mode with the cursor before the mark: move cursor back */ + while (n-- > 0) { + int pos = zlecs; + /* first over blanks */ + if (all && (!viclass(zleline[pos]) || + zleline[pos] == ZWC('\n'))) { + all = 0; + while (pos) { + DECPOS(pos); + if (zleline[pos] == ZWC('\n')) + break; + zlecs = pos; + if (viclass(zleline[pos])) + break; + } + } else if (zlecs && zleline[zlecs] == ZWC('\n')) { + /* for in widgets pass over one newline */ + DECPOS(pos); + if (zleline[pos] != ZWC('\n')) + zlecs = pos; + } + pos = zlecs; + sclass = viclass(zleline[zlecs]); + /* now retreat over non-blanks */ + while (zleline[pos] != ZWC('\n') && + viclass(zleline[pos]) == sclass) { + zlecs = pos; + if (!pos) { + zlecs = 0; + break; + } + DECPOS(pos); + } + /* blanks again but only if there were none first time */ + if (all && zlecs) { + pos = zlecs; + DECPOS(pos); + if (!viclass(zleline[pos])) { + while (pos) { + DECPOS(pos); + if (zleline[pos] == ZWC('\n') || + viclass(zleline[pos])) + break; + zlecs = pos; + } + } + } + } + return 0; + } + n++; + doblanks = 0; + } + region_active = !!region_active; /* force to character wise */ + + /* for each digit argument, advance over further block of one class */ + while (--n > 0) { + if (zlecs < zlell && zleline[zlecs] == ZWC('\n')) + INCCS(); + sclass = viclass(zleline[zlecs]); + while (zlecs < zlell) { + INCCS(); + if (zleline[zlecs] == ZWC('\n') || + viclass(zleline[zlecs]) != sclass) + break; + } + /* for 'a' widgets, advance extra block if either consists of blanks */ + if (all) { + if (zlecs < zlell && zleline[zlecs] == ZWC('\n')) + INCCS(); + if (!sclass || !viclass(zleline[zlecs]) ) { + sclass = viclass(zleline[zlecs]); + if (n == 1 && !sclass) + doblanks = 0; + while (zlecs < zlell) { + INCCS(); + if (zleline[zlecs] == ZWC('\n') || + viclass(zleline[zlecs]) != sclass) + break; + } + } + } + } + + /* if we didn't remove blanks at either end we remove some at the start */ + if (doblanks) { + int pos = mark; + while (pos) { + DECPOS(pos); + /* don't remove blanks at the start of the line, i.e indentation */ + if (zleline[pos] == ZWC('\n')) + break; + if (!ZC_iblank(zleline[pos])) { + INCPOS(pos); + mark = pos; + break; + } + } + } + /* Adjustment: vi operators don't include the cursor position, in insert + * or emacs mode the region also doesn't but for vi visual mode it is + * included. */ + if (zlecs && zlecs > mark && !virangeflag) + DECCS(); + + return 0; +} + +/**/ +int +selectargument(UNUSED(char **args)) +{ + int ne = noerrs, ocs = zlemetacs; + int owb = wb, owe= we, oadx = addedx, ona = noaliases; + char *p; + int ll, cs; + char *linein; + int wend = 0, wcur = 0; + int n = zmult; + int *wstarts; + int tmpsz; + + if (n < 1 || 2*n > zlell + 1) + return 1; + + /* if used from emacs mode enable the region */ + if (!invicmdmode()) { + region_active = 1; + mark = zlecs; + } + + wstarts = (int *) zhalloc(n * sizeof(int)); + memset(wstarts, 0, n * sizeof(int)); + + addedx = 0; + noerrs = 1; + lexsave(); + lexflags = LEXFLAGS_ACTIVE; + linein = zlegetline(&ll, &cs); + zlemetall = ll; + zlemetacs = cs; + + if (!isfirstln && chline) { + p = (char *) zhalloc(hptr - chline + zlemetall + 2); + memcpy(p, chline, hptr - chline); + memcpy(p + (hptr - chline), linein, ll); + p[(hptr - chline) + ll] = '\0'; + inpush(p, 0, NULL); + zlemetacs += hptr - chline; + } else { + p = (char *) zhalloc(ll + 1); + memcpy(p, linein, ll); + p[ll] = '\0'; + inpush(p, 0, NULL); + } + if (zlemetacs) + zlemetacs--; + strinbeg(0); + noaliases = 1; + do { + wstarts[wcur++] = wend; + wcur %= n; + ctxtlex(); + if (tok == ENDINPUT || tok == LEXERR) + break; + wend = zlemetall - inbufct; + } while (tok != ENDINPUT && tok != LEXERR && wend <= zlemetacs); + noaliases = ona; + strinend(); + inpop(); + errflag = 0; + noerrs = ne; + lexrestore(); + zlemetacs = ocs; + wb = owb; + we = owe; + addedx = oadx; + + /* convert offsets for mark and zlecs back to ZLE internal format */ + linein[wend] = '\0'; /* a bit of a hack to get two offsets */ + free(stringaszleline(linein, wstarts[wcur], &zlecs, &tmpsz, &mark)); + + if (bindk == t_selectinshellword) { + ZLE_CHAR_T *match = ZWS("`\'\""); + ZLE_CHAR_T *lmatch = ZWS("\'({"), *rmatch = ZWS("\')}"); + ZLE_CHAR_T *ematch = match, *found; + int start, end = zlecs; + /* for 'in' widget, don't include initial blanks ... */ + while (mark < zlecs && ZC_iblank(zleline[mark])) + INCPOS(mark); + /* ... or a matching pair of quotes */ + start = mark; + if (zleline[start] == ZWC('$')) { + match = lmatch; + ematch = rmatch; + INCPOS(start); + } + found = ZS_strchr(match, zleline[start]); + if (found) { + DECPOS(end); + if (zleline[end] == ematch[found-match]) { + zlecs = end; + INCPOS(start); + mark = start; + } + } + } + + /* Adjustment: vi operators don't include the cursor position */ + if (!virangeflag) + DECCS(); + + return 0; +} diff --git a/Src/Zle/zle.mdd b/Src/Zle/zle.mdd index c6e4d11c2..dd69eff2c 100644 --- a/Src/Zle/zle.mdd +++ b/Src/Zle/zle.mdd @@ -7,7 +7,8 @@ autofeatures="b:bindkey b:vared b:zle" objects="zle_bindings.o zle_hist.o zle_keymap.o zle_main.o \ zle_misc.o zle_move.o zle_params.o zle_refresh.o \ -zle_thingy.o zle_tricky.o zle_utils.o zle_vi.o zle_word.o" +zle_thingy.o zle_tricky.o zle_utils.o zle_vi.o zle_word.o \ +textobjects.o" headers="zle.h zle_things.h" diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 216e302d0..30d25ebaa 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1343,6 +1343,12 @@ default_bindings(void) add_cursor_key(kptr, TCDOWNCURSOR, t_downline, 'B'); bindkey(kptr, "k", refthingy(t_upline), NULL); bindkey(kptr, "j", refthingy(t_downline), NULL); + bindkey(kptr, "aa", refthingy(t_selectashellword), NULL); + bindkey(kptr, "ia", refthingy(t_selectinshellword), NULL); + bindkey(kptr, "aw", refthingy(t_selectaword), NULL); + bindkey(kptr, "iw", refthingy(t_selectinword), NULL); + bindkey(kptr, "aW", refthingy(t_selectablankword), NULL); + bindkey(kptr, "iW", refthingy(t_selectinblankword), NULL); } /* escape in operator pending cancels the operation */ bindkey(oppmap, "\33", refthingy(t_vicmdmode), NULL); diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index 94afb60eb..6b7ca567e 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -380,6 +380,45 @@ zletest $'- word word\e4|2daw' 0:delete all word with numeric argument >BUFFER: - +>CURSOR: 0 + + zletest $'---- word ----word\eo \eo----\eodone\eh' \ + 'vhawmaawmbawmcawmdawmeawmfawmgv`ara`brb`crc$r$`drd`ere`frf`grg' +0:all word with existing selection and cursor before mark +>BUFFER: g---f worde ----dord +>c $ +>b--- +>aone +>CURSOR: 0 + + zletest $'---- word word----\e0lvlawmaawmbawmcawvrd`ara`brb`crc' +0:all word with existing selection and mark before cursor +>BUFFER: ---- aword bworc---d +>CURSOR: 19 + + zletest $' --ww ww---\eo\eoww\evhiwiw' m{a,b,c,d,e}iw vrE \`{a,b,c,d,e}r. +0:in word with existing selection and cursor before mark +>BUFFER: E.-.w. .w.-- +> +>ww +>CURSOR: 1 + + zletest $' --ww ww--\eO \ev0o' m{a,b,c,d,e}iw vrE \`{a,b,c,d,e}r. +0:in word with existing selection and mark before cursor +>BUFFER: . +> .-.w. .wE-- +>CURSOR: 10 + + zletest $' `one` $(echo two) " three " $\'four\'\C-v\tfive ${six:-6}\e' \ + vaaom{a,b,c,d,e,f}v \`{a,b,c,d,e,f}rX +0:all argument for different arguments +>BUFFER: X `one`X $(echo two)X" three "X$'four'XfiveX${six:-6} +>CURSOR: 0 + + zletest $'{ls `echo x` $((3+4)) "a b" $\'\\t\\n\' ${d%/}\e' \ + cia{6,5,4,3,2,1}$'\eBB' +0:in argument for different arguments +>BUFFER: 1ls `2` $(3) "4" $'5' ${6} >CURSOR: 0 %clean -- cgit v1.2.3 From 626398f37d72e00b705054b2917c9be75bd8d77b Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Fri, 21 Nov 2014 21:54:37 -0800 Subject: add menu reference to Text Objects --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 1 + 2 files changed, 5 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 8e659811f..044d39f66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-11-21 Barton E. Schaefer + + * unposted: Doc/Zsh/zle.yo: add menu reference to Text Objects + 2014-11-21 Oliver Kiddle * saga.xu: 33712: Completion/Debian/_apt: add --auto-remove diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index f9dcd8016..3693ec9d5 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1062,6 +1062,7 @@ menu(Modifying Text) menu(Arguments) menu(Completion) menu(Miscellaneous) +menu(Text Objects) endmenu() texinode(Movement)(History Control)()(Zle Widgets) subsect(Movement) -- cgit v1.2.3 From 02bca2ea0fe47611644bfc1ca8b93f215317c97d Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 22 Nov 2014 14:52:31 -0800 Subject: 33763 (cf. Baptiste Daroussin 33747): fix nested item list in generated zshmodules.1 --- ChangeLog | 5 +++++ Doc/Zsh/mod_system.yo | 1 + 2 files changed, 6 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 7008c9f83..464c8846d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-11-22 Barton E. Schaefer + + * 33763 (cf. Baptiste Daroussin 33747): Doc/Zsh/mod_system.yo: + fix nested item list in generated zshmodules.1 man page. + 2014-11-21 Barton E. Schaefer * 33750: Src/text.c: handle function autoloads for DEBUG_BEFORE_CMD diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo index dce07175f..d6b3765ff 100644 --- a/Doc/Zsh/mod_system.yo +++ b/Doc/Zsh/mod_system.yo @@ -178,6 +178,7 @@ used. vindex(sysparams) item(tt(sysparams))( A readonly associative array. The keys are: + startitem() item(tt(pid))( Returns the process ID of the current process, even in subshells. Compare -- cgit v1.2.3 From ff292af95f9bb6f07a56c162e583a145bbaa389d Mon Sep 17 00:00:00 2001 From: Stephane Chazelas Date: Sun, 23 Nov 2014 18:27:41 +0000 Subject: 33740: FAQ: another way of avoiding MULTIOs effects on pipes --- ChangeLog | 5 +++++ Doc/Zsh/expn.yo | 3 +++ Etc/FAQ.yo | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 464c8846d..0d597c73c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-11-23 Peter Stephenson + + * 33740: Stephane: Etc/FAQ.yo: Another way of avoiding MULTIO + effects on pipes. + 2014-11-22 Barton E. Schaefer * 33763 (cf. Baptiste Daroussin 33747): Doc/Zsh/mod_system.yo: diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index a0478e78c..f1334e37a 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1061,6 +1061,9 @@ for arrays which keep only the first occurrence of duplicated values item(tt(hide))( for parameters with the `hide' flag ) +item(tt(hideval))( +for parameters with the `hideval' flag +) item(tt(special))( for special parameters defined by the shell ) diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index 7d4b86ec3..eeb7c13de 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -1784,7 +1784,14 @@ sect(Why is my output duplicated with `tt(foo 2>&1 >foo.out | bar)'?) to both files when the redirector appears twice. What's going on in the first example is exactly the same, however the second redirector is disguised as a pipe. So if you want to turn this effect off, you need - to unset the option mytt(MULTIOS). + to unset the option mytt(MULTIOS), or alternatively write the following: + verb( + % { print output; print error >&2 } 2>&1 >&- >foo.out | sed 's/error/erratic/' + erratic + ) + By closing stdout with tt(>&-), we're cancelling the previous redirections + (to the pipe) and start anew with tt(>foo.out) instead of adding it as a + redirection target to stdout. sect(What are these `^' and `~' pattern characters, anyway?) -- cgit v1.2.3 From 1fec267156f86756275c2ff1faa97cdc975749e0 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 21 Nov 2014 19:48:31 +0100 Subject: 33746: read -q doc refers to -t --- ChangeLog | 4 ++++ Doc/Zsh/builtins.yo | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 009d65195..4b5a0b8df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-11-24 Peter Stephenson + + * Daniel Hahler: 33746: Doc/Zsh/builtins.yo: read -q refers to -t. + 2014-11-24 Mikael Magnusson * 33785: Src/Modules/tcp.c: Fix leaks of desthost in ztcp. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index edc335e8b..446312395 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1294,10 +1294,10 @@ item(tt(-q))( Read only one character from the terminal and set var(name) to `tt(y)' if this character was `tt(y)' or `tt(Y)' and to `tt(n)' otherwise. With this flag set the return status is zero only if the character was -`tt(y)' or `tt(Y)'. This option may be used with a timeout; if -the read times out, or encounters end of file, status 2 is returned. -Input is read from the terminal unless one of tt(-u) -or tt(-p) is present. This option may also be used within zle widgets. +`tt(y)' or `tt(Y)'. This option may be used with a timeout (see tt(-t)); if +the read times out, or encounters end of file, status 2 is returned. Input is +read from the terminal unless one of tt(-u) or tt(-p) is present. This option +may also be used within zle widgets. ) item(tt(-k) [ var(num) ])( Read only one (or var(num)) characters. All are assigned to the first -- cgit v1.2.3 From a8927bf27b57a1f49d525f628a97de9c1fce710b Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 26 Nov 2014 17:26:58 +0000 Subject: 33793: add 0b binary interpretation to integer constants --- ChangeLog | 5 +++++ Doc/Zsh/arith.yo | 3 ++- Src/math.c | 6 ++++-- Src/utils.c | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 834537d64..7b56eca4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-11-26 Peter Stephenson + + * 33793: Src/math.c, Src/utils.c, Doc/Zsh/arith.yo: Arithmetic + constants beginning 0b specify binary. + 2014-11-25 Oliver Kiddle * Jun T: 33769: Test/comptest: workaround for KEYTIMEOUT to diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo index 96dc2dc68..a620b73d1 100644 --- a/Doc/Zsh/arith.yo +++ b/Doc/Zsh/arith.yo @@ -39,7 +39,8 @@ zero status. cindex(arithmetic base) cindex(bases, in arithmetic) Integers can be in bases other than 10. -A leading `tt(0x)' or `tt(0X)' denotes hexadecimal. +A leading `tt(0x)' or `tt(0X)' denotes hexadecimal and a leading +`tt(0b)' or `tt(0B) binary. Integers may also be of the form `var(base)tt(#)var(n)', where var(base) is a decimal number between two and thirty-six representing the arithmetic base and var(n) diff --git a/Src/math.c b/Src/math.c index 266569827..438a17089 100644 --- a/Src/math.c +++ b/Src/math.c @@ -449,12 +449,14 @@ lexconstant(void) nptr++; if (*nptr == '0') { + int lowchar; nptr++; - if (*nptr == 'x' || *nptr == 'X') { + lowchar = tolower(*nptr); + if (lowchar == 'x' || lowchar == 'b') { /* Let zstrtol parse number with base */ yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1); /* Should we set lastbase here? */ - lastbase = 16; + lastbase = (lowchar == 'b') ? 2 : 16; if (isset(FORCEFLOAT)) { yyval.type = MN_FLOAT; diff --git a/Src/utils.c b/Src/utils.c index c6e7aed35..5f0c1062b 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -2082,6 +2082,8 @@ zstrtol_underscore(const char *s, char **t, int base, int underscore) base = 10; else if (*++s == 'x' || *s == 'X') base = 16, s++; + else if (*s == 'b' || *s == 'B') + base = 2, s++; else base = 8; } -- cgit v1.2.3 From 8080ca3a87049951acea497f2af8e8d6feafb966 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 27 Nov 2014 13:43:15 -0800 Subject: 33805: rewrite zshparams intro, tweak formatting I noticed that there was no explanation of the terms "variable" or "environment" anywhere. --- ChangeLog | 2 ++ Doc/Zsh/params.yo | 105 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 74 insertions(+), 33 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index d5e32cfc5..37c129996 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2014-11-27 Barton E. Schaefer + * 33805: Doc/Zsh/params.yo: rewrite intro, tweak formatting + * 33804: Completion/compinit: hide values of large arrays in typeset output by declaring with the -H attribute diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 3698829f3..dfda57281 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1,48 +1,82 @@ texinode(Parameters)(Options)(Expansion)(Top) chapter(Parameters) cindex(parameters) +cindex(variables) sect(Description) A parameter has a name, a value, and a number of attributes. A name may be any sequence of alphanumeric characters and underscores, or the single characters `tt(*)', `tt(@)', `tt(#)', `tt(?)', `tt(-)', `tt($)', or `tt(!)'. -The value may be a em(scalar) (a string), -an integer, an array (indexed numerically), or an em(associative) -array (an unordered set of name-value pairs, indexed by name). To declare -the type of a parameter, or to assign a scalar or integer value to a -parameter, use the tt(typeset) builtin. +A parameter whose name begins with an alphanumeric or underscore is also +referred to as a em(variable). + +cindex(scalar) +cindex(parameters, scalar) +cindex(parameters, array) +cindex(parameters, associative array) +cindex(hash) +The attributes of a parameter determine the em(type) of its value, often +referred to as the parameter type or variable type, and also control +other processing that may be applied to the value when it is referenced. +The value type may be a em(scalar) (a string, an integer, or a floating +point number), an array (indexed numerically), or an em(associative) +array (an unordered set of name-value pairs, indexed by name, also +referred to as a em(hash)). + +cindex(export) +cindex(environment) +cindex(environment variables) +cindex(variables, environment) +Named scalar parameters may have the em(exported), tt(-x), attribute, to +copy them into the process environment, which is then passed from the +shell to any new processes that it starts. Exported parameters are called +em(environment variables). The shell also em(imports) environment variables +at startup time and automatically marks the corresponding parameters as +exported. Some environment variables are not imported for reasons of +security or because they would interfere with the correct operation of +other shell features. + +cindex(special parameters) +cindex(parameters, special) +Parameters may also be em(special), that is, they have a predetermined +meaning to the shell. Special parameters cannot have their type changed +or their readonly attribute turned off, and if a special parameter is +unset, then later recreated, the special properties will be retained. + +To declare the type of a parameter, or to assign a string or numeric value +to a scalar parameter, use the tt(typeset) builtin. findex(typeset, use of) The value of a scalar or integer parameter may also be assigned by writing: cindex(assignment) - +ifzman() indent(var(name)tt(=)var(value)) -If the integer attribute, tt(-i), is set for var(name), the var(value) -is subject to arithmetic evaluation. Furthermore, by replacing `tt(=)' -with `tt(+=)', a parameter can be added or appended to. - In scalar assignment, var(value) is expanded as a single string, in which the elements of arrays are joined together; filename expansion is -not performed unless the option tt(GLOB_ASSIGN) is set. See -noderef(Array Parameters) for additional forms of assignment. - -To refer to the value of a parameter, write `tt($)var(name)' or +not performed unless the option tt(GLOB_ASSIGN) is set. + +When the integer attribute, tt(-i), or a floating point attribute, tt(-E) +or tt(-F), is set for var(name), the var(value) is subject to arithmetic +evaluation. Furthermore, by replacing `tt(=)' with `tt(+=)', a parameter +can be incremented or appended to. See noderef(Array Parameters) and +ifzman(em(Arithmetic Evaluation) LPAR()in zmanref(zshexpn)RPAR())\ +ifnzman(noderef(Arithmetic Evaluation)) +for additional forms of assignment. + +Note that assignment may implicitly change the attributes of a parameter. +For example, assigning a number to a variable in arithmetic evaluation may +change its type to integer or float, and with tt(GLOB_ASSIGN) assigning a +pattern to a variable may change its type to an array. + +To reference the value of a parameter, write `tt($)var(name)' or `tt(${)var(name)tt(})'. See ifzman(em(Parameter Expansion) in zmanref(zshexpn))\ ifnzman(noderef(Parameter Expansion)) -for complete details. This section also explains the effect +for complete details. That section also explains the effect of the difference between scalar and array assignment on parameter expansion. - -In the parameter lists that follow, the mark `' indicates that the -parameter is special. -Special parameters cannot have their type changed or their -readonly attribute turned off, and if a special parameter is unset, then -later recreated, the special properties will be retained. `' indicates -that the parameter does not exist when the shell initializes in tt(sh) or -tt(ksh) emulation mode. startmenu() menu(Array Parameters) menu(Positional Parameters) @@ -55,7 +89,7 @@ sect(Array Parameters) To assign an array value, write one of: findex(set, use of) cindex(array assignment) - +ifzman() indent(tt(set -A) var(name) var(value) ...) indent(var(name)tt(=LPAR())var(value) ...tt(RPAR())) @@ -63,16 +97,16 @@ If no parameter var(name) exists, an ordinary array parameter is created. If the parameter var(name) exists and is a scalar, it is replaced by a new array. Ordinary array parameters may also be explicitly declared with: findex(typeset, use of) - +ifzman() indent(tt(typeset -a) var(name)) Associative arrays em(must) be declared before assignment, by using: - +ifzman() indent(tt(typeset -A) var(name)) When var(name) refers to an associative array, the list in an assignment is interpreted as alternating keys and values: - +ifzman() indent(set -A var(name) var(key) var(value) ...) indent(var(name)tt(=LPAR())var(key) var(value) ...tt(RPAR())) @@ -81,13 +115,12 @@ assigns to the entire array, deleting any elements that do not appear in the list. To create an empty array (including associative arrays), use one of: - +ifzman() indent(tt(set -A) var(name)) indent(var(name)tt(=LPAR()RPAR())) subsect(Array Subscripts) cindex(subscripts) - Individual elements of an array may be selected using a subscript. A subscript of the form `tt([)var(exp)tt(])' selects the single element var(exp), where var(exp) is an arithmetic expression which will be subject @@ -150,7 +183,7 @@ For example, if tt(FOO) is set to `tt(foobar)', then subsect(Array Element Assignment) A subscript may be used on the left side of an assignment like so: - +ifzman() indent(var(name)tt([)var(exp)tt(]=)var(value)) In this form of assignment the element or range specified by var(exp) @@ -162,7 +195,7 @@ other elements to accommodate the new values. (This is not supported for associative arrays.) This syntax also works as an argument to the tt(typeset) command: - +ifzman() indent(tt(typeset) tt(")var(name)tt([)var(exp)tt(]"=)var(value)) The var(value) may em(not) be a parenthesized list in this case; only @@ -174,7 +207,7 @@ could be used instead. To delete an element of an ordinary array, assign `tt(LPAR()RPAR())' to that element. To delete an element of an associative array, use the tt(unset) command: - +ifzman() indent(tt(unset) tt(")var(name)tt([)var(exp)tt(]")) subsect(Subscript Flags) @@ -493,6 +526,10 @@ were never exported has been removed. texinode(Parameters Set By The Shell)(Parameters Used By The Shell)(Local Parameters)(Parameters) sect(Parameters Set By The Shell) +In the parameter lists that follow, the mark `' indicates that the +parameter is special. `' indicates that the parameter does not exist +when the shell initializes in tt(sh) or tt(ksh) emulation mode. + The following parameters are automatically set by the shell: startitem() @@ -870,7 +907,9 @@ The version number of the release of zsh. enditem() texinode(Parameters Used By The Shell)()(Parameters Set By The Shell)(Parameters) sect(Parameters Used By The Shell) -The following parameters are used by the shell. +The following parameters are used by the shell. Again, `' indicates +that the parameter is special and `' indicates that the parameter does +not exist when the shell initializes in tt(sh) or tt(ksh) emulation mode. In cases where there are two parameters with an upper- and lowercase form of the same name, such as tt(path) and tt(PATH), the lowercase form -- cgit v1.2.3 From a6bf64648b31659584b5bcd95ae3a437d1733077 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 11 Sep 2014 02:09:17 +0200 Subject: 33139: add doc example to glob broken symbolic links. --- ChangeLog | 4 ++++ Doc/Zsh/expn.yo | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 30076722e..593fe0190 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-11-28 Wayne Davison + + * 33139: Doc/Zsh/expn.yo: add example for finding broken symlinks. + 2014-11-28 Peter Stephenson * 33815: Src/Zle/zle_word.c: fix word transposition bug where diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index f1334e37a..5ed78f0c1 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -2711,6 +2711,10 @@ example(ls *(-/)) lists all directories and symbolic links that point to directories, and +example(ls *(-@)) + +lists all broken symbolic links, and + example(ls *(%W)) lists all world-writable device files in the current directory, and -- cgit v1.2.3 From af6256f8af33c37aadd8ff6d27fb39411743bac0 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 1 Dec 2014 14:28:37 +0000 Subject: 33830: META-FAQ updates. Don't mention CVS. Use correct sourceforge URL. --- ChangeLog | 5 +++++ Doc/Zsh/metafaq.yo | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 567fcc08c..c62d20290 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-12-01 Peter Stephenson + + * Jun T: 33830 plus CVS removal: Doc/Zsh/metafaq.yo: typo in + sourceforge URL; don't mention CVS. + 2014-11-30 Oliver Kiddle * 33823: Src/Zle/zle_misc.c, Test/X02zlevi.ztst: overwrite mode diff --git a/Doc/Zsh/metafaq.yo b/Doc/Zsh/metafaq.yo index 34cd70e32..a005ca0dd 100644 --- a/Doc/Zsh/metafaq.yo +++ b/Doc/Zsh/metafaq.yo @@ -27,10 +27,10 @@ cindex(acquiring zsh by FTP) cindex(availability of zsh) INCLUDEFILE(Zsh/ftp_sites.yo)\ -The up-to-date source code is available via anonymous CVS and Git from -Sourceforge. See tt(http://sourceforge.net/projects/zsh/) for details. -A summary of instructions for the CVS and Git archives can be found at -tt(http://zsh.sourceforget.net/). +The up-to-date source code is available via Git from Sourceforge. See +tt(http://sourceforge.net/projects/zsh/) for details. A summary of +instructions for the archive can be found at +tt(http://zsh.sourceforge.net/). texinode(Mailing Lists)(The Zsh FAQ)(Availability)(Introduction) sect(Mailing Lists) -- cgit v1.2.3 From 84a772396eee323d4002d07b73d6d8efcd494bca Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Fri, 28 Nov 2014 18:16:09 -0800 Subject: Unposted: minor change: "scalar or integer" to "scalar" to include floats. --- Doc/Zsh/params.yo | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index dfda57281..dcca455d8 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -47,8 +47,7 @@ To declare the type of a parameter, or to assign a string or numeric value to a scalar parameter, use the tt(typeset) builtin. findex(typeset, use of) -The value of a scalar or integer parameter may also be assigned by -writing: +The value of a scalar parameter may also be assigned by writing: cindex(assignment) ifzman() indent(var(name)tt(=)var(value)) -- cgit v1.2.3 From 231cbbc5b12f9d7135fea1e9015c100dffba91e0 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 4 Dec 2014 02:17:58 -0800 Subject: 33841: explain array append a bit better --- ChangeLog | 6 +++++- Doc/Zsh/params.yo | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index fad5d820d..c03501faf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-12-04 Barton E. Schaefer + + * 33841: Doc/Zsh/params.yo: explain array append a bit better + 2014-12-03 Mikael Magnusson * Eric Cook: 33689: Completion/Unix/Command/_cp: make cp @@ -23,7 +27,7 @@ Src/exec.c, Src/sort.c, Src/utils.c: fix types passed to sizeof detected by coverity as being wrong -2014-11-28 Barton E. Schaefer +2014-11-28 Barton E. Schaefer * 33819: Test/A06assign.ztst: regression tests for 33816 diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index dcca455d8..5833d6be9 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -94,7 +94,12 @@ indent(var(name)tt(=LPAR())var(value) ...tt(RPAR())) If no parameter var(name) exists, an ordinary array parameter is created. If the parameter var(name) exists and is a scalar, it is replaced by a new -array. Ordinary array parameters may also be explicitly declared with: +array. To append to an array without changing the existing values, use +the syntax: +ifzman() +indent(var(name)tt(+=LPAR())var(value) ...tt(RPAR())) + +Ordinary array parameters may also be explicitly declared with: findex(typeset, use of) ifzman() indent(tt(typeset -a) var(name)) @@ -110,8 +115,13 @@ indent(set -A var(name) var(key) var(value) ...) indent(var(name)tt(=LPAR())var(key) var(value) ...tt(RPAR())) Every var(key) must have a var(value) in this case. Note that this -assigns to the entire array, deleting any elements that do not appear -in the list. +assigns to the entire array, deleting any elements that do not appear in +the list. The append syntax may also be used with an associative array: +ifzman() +indent(var(name)tt(+=LPAR())var(key) var(value) ...tt(RPAR())) + +This adds a new key/value pair if the key is not already present, and +replaces the value for the existing key if it is. To create an empty array (including associative arrays), use one of: ifzman() @@ -211,7 +221,6 @@ indent(tt(unset) tt(")var(name)tt([)var(exp)tt(]")) subsect(Subscript Flags) cindex(subscript flags) - If the opening bracket, or the comma in a range, in any subscript expression is directly followed by an opening parenthesis, the string up to the matching closing one is considered to be a list of flags, as in @@ -351,16 +360,13 @@ patterns used for reverse subscripting (the `tt(r)', `tt(R)', `tt(i)', etc. flags), but it may also affect parameter substitutions that appear as part of an arithmetic expression in an ordinary subscript. -It is possible to avoid the use of subscripts in assignments to associative -array elements by using the syntax: +To avoid subscript parsing limitations in assignments to associative array +elements, use the append syntax: example( aa+=('key with "*strange*" characters' 'value string') ) -This adds a new key/value pair if the key is not already present, and -replaces the value for the existing key if it is. - The basic rule to remember when writing a subscript expression is that all text between the opening `tt([)' and the closing `tt(])' is interpreted em(as if) it were in double quotes (\ -- cgit v1.2.3 From 908abba89147f8a4e4991c4464a95ee90d1078f6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 6 Dec 2014 10:55:30 +0000 Subject: 33883: documentation for (*) glob qualifier --- ChangeLog | 8 +++++++- Completion/Zsh/Type/_globquals | 2 +- Doc/Zsh/expn.yo | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index f86b3a0fe..967f51684 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2014-12-07 Peter Stephenson + + * Daniel Shahaf: 33883: Doc/Zsh/expn.yo, + Completion/Zsh/Type/_globquals: documentation for (*) glob + qualifier. + 2014-12-07 Jun-ichi Takimoto - * 33829: Test/X02zlevi.ztst, Test/comptest: unbind ESC~ as + * 33829: Test/X02zlevi.ztst, Test/comptest: unbind ESC~ asa a more reliable workaround 2014-12-06 Mikael Magnusson diff --git a/Completion/Zsh/Type/_globquals b/Completion/Zsh/Type/_globquals index 37db161d0..042b27400 100644 --- a/Completion/Zsh/Type/_globquals +++ b/Completion/Zsh/Type/_globquals @@ -213,7 +213,7 @@ case $state in ".:plain files" "@:symbolic links" "=:sockets" - "p:name pipes (FIFOS)" + "p:named pipes (FIFOs)" "*:executable plain files" "%:device files" "r:owner-readable" diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 5ed78f0c1..8728803e0 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -2388,7 +2388,7 @@ item(tt(p))( named pipes (FIFOs) ) item(tt(*))( -executable plain files (0100) +executable plain files (0100 or 0010 or 0001) ) item(tt(%))( device files (character or block special) -- cgit v1.2.3 From 88f4e24d4c42de1072898cd0e26e3d43c7de448c Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Mon, 8 Dec 2014 17:23:23 +0100 Subject: 33924: allow vi line/characterwise mode to be forced --- ChangeLog | 6 ++++++ Doc/Zsh/zle.yo | 8 ++++++-- Src/Zle/iwidgets.list | 2 +- Src/Zle/zle.h | 2 ++ Src/Zle/zle_move.c | 12 ++++++++++++ Src/Zle/zle_vi.c | 13 +++++++++++-- Test/X02zlevi.ztst | 21 +++++++++++++++++++++ 7 files changed, 59 insertions(+), 5 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index fd6a49f22..b8af2130c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-12-08 Oliver Kiddle + + * 33924: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle.h, + Src/Zle/zle_move.c, Src/Zle/zle_vi.c, Test/X02zlevi.ztst: + allow vi line/characterwise mode to be forced + 2014-12-08 Peter Stephenson * 33927: Completion/Unix/Command/_nm: .elf files and diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 3693ec9d5..f95264232 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2301,12 +2301,16 @@ If repeated, redo the modification. tindex(visual-mode) item(tt(visual-mode) (unbound) (v) (unbound))( Toggle vim-style visual selection mode. If line-wise visual mode is -currently enabled then it is changed to being character-wise. +currently enabled then it is changed to being character-wise. If used +following an operator, it forces the subsequent movement command to be +treated as a character-wise movement. ) tindex(visual-line-mode) item(tt(visual-line-mode) (unbound) (V) (unbound))( Toggle vim-style line-wise visual selection mode. If character-wise -visual mode is currently enabled then it is changed to being line-wise. +visual mode is currently enabled then it is changed to being line-wise. If used +following an operator, it forces the subsequent movement command to be +treated as a line-wise movement. ) tindex(what-cursor-position) item(tt(what-cursor-position) (^X=) (unbound) (unbound))( diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index 1a664e5e8..40750221e 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -156,7 +156,7 @@ "vi-forward-word-end", viforwardwordend, 0 "vi-goto-column", vigotocolumn, 0 "vi-goto-mark", vigotomark, 0 -"vi-goto-mark-line", vigotomarkline, 0 +"vi-goto-mark-line", vigotomarkline, ZLE_LINEMOVE "vi-history-search-backward", vihistorysearchbackward, 0 "vi-history-search-forward", vihistorysearchforward, 0 "vi-indent", viindent, ZLE_LASTCOL diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index 8a85ee342..a46b52ded 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -243,6 +243,8 @@ struct modifier { #define MOD_VIAPP (1<<3) /* appending to the vi cut buffer */ #define MOD_NEG (1<<4) /* last command was negate argument */ #define MOD_NULL (1<<5) /* throw away text for the vi cut buffer */ +#define MOD_CHAR (1<<6) /* force character-wise movement */ +#define MOD_LINE (1<<7) /* force line-wise movement */ /* current modifier status */ diff --git a/Src/Zle/zle_move.c b/Src/Zle/zle_move.c index 939cfb1d0..d751c4333 100644 --- a/Src/Zle/zle_move.c +++ b/Src/Zle/zle_move.c @@ -511,6 +511,12 @@ exchangepointandmark(UNUSED(char **args)) int visualmode(UNUSED(char **args)) { + if (virangeflag) { + prefixflag = 1; + zmod.flags &= ~MOD_LINE; + zmod.flags |= MOD_CHAR; + return 0; + } switch (region_active) { case 1: region_active = 0; @@ -529,6 +535,12 @@ visualmode(UNUSED(char **args)) int visuallinemode(UNUSED(char **args)) { + if (virangeflag) { + prefixflag = 1; + zmod.flags &= ~MOD_CHAR; + zmod.flags |= MOD_LINE; + return 0; + } switch (region_active) { case 2: region_active = 0; diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index 249e38f15..1a11ca7d5 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -259,15 +259,24 @@ getvirange(int wf) /* Was it a line-oriented move? If so, the command will have set * * the vilinerange flag. In this case, entire lines are taken, * * rather than just the sequence of characters delimited by pos * - * and zlecs. The terminating newline is left out of the range, * + * and zlecs. The terminating newline is left out of the range, * * which the real command must deal with appropriately. At this * * point we just need to make the range encompass entire lines. */ - if(vilinerange) { + vilinerange = (zmod.flags & MOD_LINE) || + (vilinerange && !(zmod.flags & MOD_CHAR)); + if (vilinerange) { int newcs = findbol(); lastcol = zlecs - newcs; zlecs = pos; pos = findeol(); zlecs = newcs; + } else if (!visual) { + /* for a character-wise move don't include a newline at the * + * end of the range */ + int prev = pos; + DECPOS(prev); + if (zleline[prev] == ZWC('\n')) + pos = prev; } return pos; } diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index 4f2f3193d..7bb35d52f 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -287,6 +287,27 @@ >BUFFER: one wo >CURSOR: 2 + zletest $'keepnot\eo unwanted\ekhhcvj ' +0:force character-wise change to join lines +>BUFFER: keep wanted +>CURSOR: 5 + + zletest $'}\eOkeep{del\eF{dvj' +0:character-wise delete to beginning of line leaves the newline' +>BUFFER: keep +>} +>CURSOR: 3 + + zletest $'keep\eOdel\edVh' +0:force line-wise delete of line +>BUFFER: keep +>CURSOR: 0 + + zletest $'one two three\eFwdVawaX' +0:line-wise force of a text object +>BUFFER: X +>CURSOR: 1 + zletest $'one two\evbcx' 0:change selection >BUFFER: one x -- cgit v1.2.3 From d067ebcacd55472f720b2765ec686a69b25c9a90 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 7 Dec 2014 16:24:19 +0000 Subject: 33876: etc.: Separate errors and keyboards interrupts Combination of 12 commits from interrupt_abort branch. Basic strategy is to introduce bits to errflag and to set and reset them separately. Remove interrupt status on return to main keymap. Turn off ERRFLAG_INT for always block. Restore bit thereafter: we probably need a new variable in order to allow user interrupts to be reset in the always block. Add TRY_BLOCK_INTERRUPT This works the same as TRY_BLOCK_ERROR, but for a SIGINT, too. Ensure propagation of SIGINT from exited job. If received by foreground job, shell uses ERRFLAG_INT, not ERRFLAG_ERROR, to set the new state. Reset errflag before precmd() Add always block in _main_completion to fix ZLS_COLORS Ensures we get the right state of $ZLS_COLORS at the end of _main_complete even if there's an interrupt. However, the "right state" is a bit messy as it depends on styles. --- ChangeLog | 20 +++++++++++-- Completion/Base/Core/_main_complete | 21 ++++++++------ Doc/Zsh/params.yo | 11 ++++++++ Src/Modules/zpty.c | 2 +- Src/Modules/zutil.c | 8 ++++-- Src/Zle/compcore.c | 2 +- Src/Zle/compctl.c | 10 +++---- Src/Zle/compresult.c | 2 +- Src/Zle/textobjects.c | 2 +- Src/Zle/zle_hist.c | 6 ++-- Src/Zle/zle_keymap.c | 10 +++++++ Src/Zle/zle_main.c | 14 ++++++---- Src/Zle/zle_misc.c | 2 +- Src/Zle/zle_tricky.c | 20 +++++++++++-- Src/Zle/zle_utils.c | 3 +- Src/builtin.c | 22 +++++++-------- Src/exec.c | 56 +++++++++++++++++++++++-------------- Src/glob.c | 12 ++++---- Src/hist.c | 10 ++++--- Src/init.c | 29 ++++++++++++++++--- Src/input.c | 3 +- Src/jobs.c | 23 +++++++++------ Src/lex.c | 5 ++-- Src/loop.c | 28 ++++++++++++++++--- Src/params.c | 13 +++++---- Src/parse.c | 31 ++++++++++---------- Src/prompt.c | 7 +++-- Src/signals.c | 28 ++++++++++++++++--- Src/subst.c | 27 ++++++++++++------ Src/utils.c | 8 +++--- Src/zsh.h | 14 ++++++++++ 31 files changed, 315 insertions(+), 134 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 94e28ccb2..e30324894 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2014-12-11 Peter Stephenson + + * 33876: etc.: Completion/Base/Core/_main_complete, + Doc/Zsh/params.yo, Src/Modules/zpty.c, Src/Modules/zutil.c, + Src/Zle/compcore.c, Src/Zle/compctl.c, Src/Zle/compresult.c, + Src/Zle/textobjects.c, Src/Zle/zle_hist.c, Src/Zle/zle_keymap.c, + Src/Zle/zle_main.c, Src/Zle/zle_misc.c, Src/Zle/zle_tricky.c, + Src/Zle/zle_utils.c, Src/builtin.c, Src/exec.c, Src/glob.c, + Src/hist.c, Src/init.c, Src/input.c, Src/jobs.c, Src/lex.c, + Src/loop.c, Src/params.c, Src/parse.c, Src/prompt.c, + Src/signals.c, Src/subst.c, Src/utils.c, Src/zsh.h: Separate + shell errors and user interrupt flags into different bits of + errflag: ERRFLAG_ERROR and ERRFLAG_INT. Various + rationalisations to make keyboard interrupts work smoothly. + Work done on interrupt_abort branch. + 2014-12-10 Mikael Magnusson * 33948: Completion/Unix/Command/_getent, @@ -612,7 +628,7 @@ * 33354: Src/jobs.c, Test/A05execution.ztst: when backgrounding a pipeline, close all pipe descriptors in the parent; add test for both this and 33345+33346 - + 2014-10-03 Bart Schaefer * 33346: Src/parse.c: another bit of the 33345 repair @@ -2083,7 +2099,7 @@ 2013-12-20 Barton E. Schaefer * 32172; Test/A05execution.ztst: regression test for 32171 - + * 32171: Src/exec.c: fix leaked pipe descriptor that could deadlock a pipeline from a complex shell construct or function into an external command diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index bc63e83fb..d6a100777 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -43,6 +43,8 @@ local -a precommands typeset -U _lastdescr _comp_ignore _comp_colors +{ + [[ -z "$curcontext" ]] && curcontext=::: zstyle -s ":completion:${curcontext}:" insert-tab tmp || tmp=yes @@ -349,17 +351,20 @@ fi ( "$_comp_force_list" = ?* && nm -ge _comp_force_list ) ]] && compstate[list]="${compstate[list]//messages} force" -if [[ "$compstate[old_list]" = keep ]]; then - if [[ $_saved_colors_set = 1 ]]; then - ZLS_COLORS="$_saved_colors" +} always { + # Stuff we always do to clean up. + if [[ "$compstate[old_list]" = keep ]]; then + if [[ $_saved_colors_set = 1 ]]; then + ZLS_COLORS="$_saved_colors" + else + unset ZLS_COLORS + fi + elif (( $#_comp_colors )); then + ZLS_COLORS="${(j.:.)_comp_colors}" else unset ZLS_COLORS fi -elif (( $#_comp_colors )); then - ZLS_COLORS="${(j.:.)_comp_colors}" -else - unset ZLS_COLORS -fi +} # Now call the post-functions. diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 5833d6be9..391a5fb0a 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -754,6 +754,17 @@ It may be reset, clearing the error condition. See ifzman(em(Complex Commands) in zmanref(zshmisc))\ ifnzman(noderef(Complex Commands)) ) +vindex(TRY_BLOCK_INTERRUPT) +item(tt(TRY_BLOCK_INTERRUPT) )( +This variable works in a similar way to tt(TRY_BLOCK_ERROR), but +represents the status of an interrupt from the signal SIGINT, which +typically comes from the keyboard when the user types tt(^C). If set to +0, any such interrupt will be reset; otherwise, the interrupt is +propagated after the tt(always) block. + +Note that it is possible that an interrupt arrives during the execution +of the tt(always) block; this interrupt is also propagated. +) vindex(TTY) item(tt(TTY))( The name of the tty associated with the shell, if any. diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 63c79a731..7b6130c6f 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -308,7 +308,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock) prog = parse_string(zjoin(args, ' ', 1), 0); if (!prog) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; scriptname = oscriptname; ineval = oineval; return 1; diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 1cca0c4b8..c89495070 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -301,7 +301,8 @@ setstypat(Style s, char *pat, Patprog prog, char **vals, int eval) int ef = errflag; eprog = parse_string(zjoin(vals, ' ', 1), 0); - errflag = ef; + /* Keep any user interrupt error status */ + errflag = ef | (errflag & ERRFLAG_INT); if (!eprog) { @@ -394,10 +395,11 @@ evalstyle(Stypat p) unsetparam("reply"); execode(p->eval, 1, 0, "style"); if (errflag) { - errflag = ef; + /* Keep any user interrupt error status */ + errflag = ef | (errflag & ERRFLAG_INT); return NULL; } - errflag = ef; + errflag = ef | (errflag & ERRFLAG_INT); queue_signals(); if ((ret = getaparam("reply"))) diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 35d410cc6..b0c6e06f8 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1671,7 +1671,7 @@ set_comp_sep(void) noaliases = ona; strinend(); inpop(); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; noerrs = ne; lexrestore(); wb = owb; diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index 0b7a32445..d15c2d1b0 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -1879,7 +1879,7 @@ ccmakehookfn(UNUSED(Hookdef dummy), struct ccmakedat *dat) if (!m || !(m = m->next)) break; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; } redup(osi, 0); dat->lst = 1; @@ -2121,7 +2121,7 @@ getreal(char *str) if (!errflag && nonempty(l) && ((char *) peekfirst(l)) && ((char *) peekfirst(l))[0]) return dupstring(peekfirst(l)); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; return dupstring(str); } @@ -2599,7 +2599,7 @@ makecomplistlist(Compctl cc, char *s, int incmd, int compadd) makecomplistflags(cc, s, incmd, compadd); /* Reset some information variables for the next try. */ - errflag = 0; + errflag &= ~ERRFLAG_ERROR; offs = oloffs; wb = owb; we = owe; @@ -2847,7 +2847,7 @@ sep_comp_string(char *ss, char *s, int noffs) noaliases = ona; strinend(); inpop(); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; noerrs = ne; lexrestore(); wb = owb; @@ -3725,7 +3725,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) noaliases = ona; strinend(); inpop(); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; lexrestore(); /* Fine, now do full expansion. */ prefork(foo, 0); diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c index fcceb670c..93438a053 100644 --- a/Src/Zle/compresult.c +++ b/Src/Zle/compresult.c @@ -1092,7 +1092,7 @@ do_single(Cmatch m) noerrs = 1; parsestr(p); singsub(&p); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; noerrs = ne; } } else { diff --git a/Src/Zle/textobjects.c b/Src/Zle/textobjects.c index 85d014b27..37d2c0ad9 100644 --- a/Src/Zle/textobjects.c +++ b/Src/Zle/textobjects.c @@ -275,7 +275,7 @@ selectargument(UNUSED(char **args)) noaliases = ona; strinend(); inpop(); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; noerrs = ne; lexrestore(); zlemetacs = ocs; diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c index 9f65994dc..88623bb3c 100644 --- a/Src/Zle/zle_hist.c +++ b/Src/Zle/zle_hist.c @@ -853,8 +853,10 @@ pushlineoredit(char **args) free(zhline); } ret = pushline(args); - if (!isfirstln) - errflag = done = 1; + if (!isfirstln) { + errflag |= ERRFLAG_ERROR; + done = 1; + } clearlist = 1; return ret; } diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 30d25ebaa..48f210c7e 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -504,6 +504,16 @@ mod_export void selectlocalmap(Keymap m) { localkeymap = m; + if (!m) + { + /* + * No local keymap; so we are returning to the global map. If + * the user ^Ced in the local map, they probably just want to go + * back to normal editing. So remove the interrupt error + * status. + */ + errflag &= ~ERRFLAG_INT; + } } /* Reopen the currently selected keymap, in case it got deleted. This * diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index caa052b13..a2f48e13a 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -744,7 +744,7 @@ raw_getbyte(long do_keytmout, char *cptr) } if (errflag) { /* No sensible way of handling errors here */ - errflag = 0; + errflag &= ~ERRFLAG_ERROR; /* * Paranoia: don't run the hooks again this * time. @@ -882,7 +882,7 @@ getbyte(long do_keytmout, int *timeout) die = 0; if (!errflag && !retflag && !breaks && !exit_pending) continue; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; breaks = obreaks; errno = old_errno; return lastchar = EOF; @@ -1075,7 +1075,7 @@ zlecore(void) DECCS(); handleundo(); } else { - errflag = 1; + errflag |= ERRFLAG_ERROR; break; } #ifdef HAVE_POLL @@ -1233,6 +1233,10 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) zleactive = 1; resetneeded = 1; + /* + * Start of the main zle read. + * Fully reset error conditions, including user interrupt. + */ errflag = retflag = 0; lastcol = -1; initmodifier(&zmod); @@ -1658,7 +1662,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func)) } if (!t || errflag) { /* error in editing */ - errflag = 0; + errflag &= ~ERRFLAG_ERROR; breaks = obreaks; if (t) zsfree(t); @@ -1778,7 +1782,7 @@ recursiveedit(UNUSED(char **args)) zrefresh(); zlecore(); - locerror = errflag; + locerror = errflag ? 1 : 0; errflag = done = eofsent = 0; return locerror; diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index d432acf7b..23286fc20 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -1041,7 +1041,7 @@ copyprevshellword(UNUSED(char **args)) int sendbreak(UNUSED(char **args)) { - errflag = 1; + errflag |= ERRFLAG_ERROR; return 1; } diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index b15d91c8e..864f804b7 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -829,7 +829,7 @@ docomplete(int lst) if (olst == COMP_EXPAND_COMPLETE && !strcmp(ol, zlemetaline)) { zlemetacs = ocs; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; if (!compfunc) { char *p; @@ -877,6 +877,19 @@ docomplete(int lst) active = 0; makecommaspecial(0); + + /* + * As a special case, we reset user interrupts here. + * That's because completion is an intensive piece of + * computation that the user might want to interrupt separately + * from anything else going on. If they do, they probably + * want to keep the line edit buffer intact. + * + * There's a race here that the user might hit ^C just + * after completion exited anyway, but that's inevitable. + */ + errflag &= ~ERRFLAG_INT; + return dat[1]; } @@ -1394,7 +1407,8 @@ get_comp_string(void) } strinend(); inpop(); - errflag = lexflags = 0; + lexflags = 0; + errflag &= ~ERRFLAG_ERROR; if (parbegin != -1) { /* We are in command or process substitution if we are not in * a $((...)). */ @@ -2917,7 +2931,7 @@ getcurcmd(void) popheap(); strinend(); inpop(); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; unmetafy_line(); lexrestore(); diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 08a32c30e..de91182b5 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1715,7 +1715,8 @@ zlecallhook(char *name, char *arg) execzlefunc(thingy, args, 1); unrefthingy(thingy); - errflag = saverrflag; + /* Retain any user interrupt error status */ + errflag = saverrflag | (errflag & ERRFLAG_INT); retflag = savretflag; } diff --git a/Src/builtin.c b/Src/builtin.c index c2af51f2e..ad3a1925f 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -422,7 +422,7 @@ execbuiltin(LinkList args, Builtin bn) argc -= argv - argarr; if (errflag) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; return 1; } @@ -3136,7 +3136,7 @@ bin_unset(char *name, char **argv, Options ops, int func) } } returnval = errflag; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; } else { zerrnam(name, "%s: invalid element for unset", s); returnval = 1; @@ -4242,7 +4242,7 @@ bin_print(char *name, char **args, Options ops, int func) if (*argp) { width = (int)mathevali(*argp++); if (errflag) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; ret = 1; } } @@ -4272,7 +4272,7 @@ bin_print(char *name, char **args, Options ops, int func) if (*argp) { prec = (int)mathevali(*argp++); if (errflag) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; ret = 1; } } @@ -4452,7 +4452,7 @@ bin_print(char *name, char **args, Options ops, int func) zlongval = (curarg) ? mathevali(curarg) : 0; if (errflag) { zlongval = 0; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; ret = 1; } print_val(zlongval) @@ -4481,7 +4481,7 @@ bin_print(char *name, char **args, Options ops, int func) } else doubleval = 0; if (errflag) { doubleval = 0; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; ret = 1; } print_val(doubleval) @@ -4494,7 +4494,7 @@ bin_print(char *name, char **args, Options ops, int func) zulongval = (curarg) ? mathevali(curarg) : 0; if (errflag) { zulongval = 0; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; ret = 1; } print_val(zulongval) @@ -4871,7 +4871,7 @@ zexit(int val, int from_where) in_exit = -1; /* * We want to do all remaining processing regardless of preceding - * errors. + * errors, even user interrupts. */ errflag = 0; @@ -5074,7 +5074,7 @@ eval(char **argv) if (fpushed) funcstack = funcstack->prev; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; scriptname = oscriptname; ineval = oineval; @@ -6101,7 +6101,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) condlex = zshlex; if (errflag) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; lexrestore(); return 1; } @@ -6278,7 +6278,7 @@ bin_let(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int func)) while (*argv) val = matheval(*argv++); /* Errors in math evaluation in let are non-fatal. */ - errflag = 0; + errflag &= ~ERRFLAG_ERROR; /* should test for fabs(val.u.d) < epsilon? */ return (val.type == MN_INTEGER) ? val.u.l == 0 : val.u.d == 0.0; } diff --git a/Src/exec.c b/Src/exec.c index a5f877191..6a7dbb1e1 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -59,7 +59,7 @@ mod_export int noerrs; /**/ int nohistsave; -/* error/break flag */ +/* error flag: bits from enum errflag_bits */ /**/ mod_export int errflag; @@ -1601,7 +1601,8 @@ execpline(Estate state, wordcode slcode, int how, int last1) (killpg(jobtab[list_pipe_job].gleader, 0) == -1 ? 2 : 1); list_pipe_pid = pid; list_pipe_start = bgtime; - nowait = errflag = 1; + nowait = 1; + errflag |= ERRFLAG_ERROR; breaks = loops; close(synch[1]); read_loop(synch[0], &dummy, 1); @@ -1634,7 +1635,10 @@ execpline(Estate state, wordcode slcode, int how, int last1) list_pipe_child = 1; opts[INTERACTIVE] = 0; if (errbrk_saved) { - errflag = prev_errflag; + /* + * Keep any user interrupt bit in errflag. + */ + errflag = prev_errflag | (errflag & ERRFLAG_INT); breaks = prev_breaks; } break; @@ -1719,12 +1723,14 @@ execpline2(Estate state, wordcode pcode, if (pipe(synch) < 0) { zerr("pipe failed: %e", errno); - lastval = errflag = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; return; } else if ((pid = zfork(&bgtime)) == -1) { close(synch[0]); close(synch[1]); - lastval = errflag = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; return; } else if (pid) { char dummy, *text; @@ -2560,7 +2566,8 @@ execcmd(Estate state, int input, int output, int how, int last1) while (next && *next == '-' && strlen(next) >= 2) { if (!firstnode(args)) { zerr("exec requires a command to execute"); - errflag = lastval = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; goto done; } uremnode(args, firstnode(args)); @@ -2577,12 +2584,14 @@ execcmd(Estate state, int input, int output, int how, int last1) } else { if (!firstnode(args)) { zerr("exec requires a command to execute"); - errflag = lastval = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; goto done; } if (!nextnode(firstnode(args))) { zerr("exec flag -a requires a parameter"); - errflag = lastval = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; goto done; } exec_argv0 = (char *) @@ -2598,7 +2607,8 @@ execcmd(Estate state, int input, int output, int how, int last1) break; default: zerr("unknown exec flag -%c", *cmdopt); - errflag = lastval = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; return; } } @@ -2661,7 +2671,8 @@ execcmd(Estate state, int input, int output, int how, int last1) } else if (!nullcmd || !*nullcmd || opts[CSHNULLCMD] || (cflags & BINF_PREFIX)) { zerr("redirection with no command"); - errflag = lastval = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; return; } else if (!nullcmd || !*nullcmd || opts[SHNULLCMD]) { if (!args) @@ -2691,7 +2702,7 @@ execcmd(Estate state, int input, int output, int how, int last1) if (varspc) addvars(state, varspc, 0); if (errflag) - lastval = errflag; + lastval = 1; else lastval = cmdoutval; if (isset(XTRACE)) { @@ -2795,7 +2806,7 @@ execcmd(Estate state, int input, int output, int how, int last1) } } if (!nextnode(firstnode(args))) - errflag = 1; + errflag |= ERRFLAG_ERROR; } if (type == WC_FUNCDEF) { @@ -2940,7 +2951,8 @@ execcmd(Estate state, int input, int output, int how, int last1) } else if ((pid = zfork(&bgtime)) == -1) { close(synch[0]); close(synch[1]); - lastval = errflag = 1; + lastval = 1; + errflag |= ERRFLAG_ERROR; goto fatal; } if (pid) { @@ -3529,7 +3541,7 @@ execcmd(Estate state, int input, int output, int how, int last1) else exit(1); } - errflag = 1; + errflag |= ERRFLAG_ERROR; } } if (newxtrerr) { @@ -3759,8 +3771,10 @@ gethere(char **strp, int typ) parsestr(buf); - if (!errflag) - errflag = ef; + if (!errflag) { + /* Retain any user interrupt error */ + errflag = ef | (errflag & ERRFLAG_INT); + } } s = dupstring(buf); zfree(buf, bsiz); @@ -3854,7 +3868,7 @@ getoutput(char *cmd, int qt) return readoutput(stream, qt); } if (mpipe(pipes) < 0) { - errflag = 1; + errflag |= ERRFLAG_ERROR; cmdoutpid = 0; return NULL; } @@ -3864,7 +3878,7 @@ getoutput(char *cmd, int qt) /* fork error */ zclose(pipes[0]); zclose(pipes[1]); - errflag = 1; + errflag |= ERRFLAG_ERROR; cmdoutpid = 0; child_unblock(); return NULL; @@ -4274,7 +4288,7 @@ execcond(Estate state, UNUSED(int do_exec)) * into a shell error. */ if (stat == 2) - errflag = 1; + errflag |= ERRFLAG_ERROR; cmdpop(); if (isset(XTRACE)) { fprintf(xtrerr, " ]]\n"); @@ -4314,7 +4328,7 @@ execarith(Estate state, UNUSED(int do_exec)) fflush(xtrerr); } if (errflag) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; return 2; } /* should test for fabs(val.u.d) < epsilon? */ @@ -4932,7 +4946,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) (name = fname)))) { zwarn("%s: function not defined by file", name); if (noreturnval) - errflag = 1; + errflag |= ERRFLAG_ERROR; else lastval = 1; goto doneshfunc; diff --git a/Src/glob.c b/Src/glob.c index b3903f2ff..82f8d626c 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -682,7 +682,7 @@ parsecomplist(char *instr) /* Now get the next path component if there is one. */ l1 = (Complist) zhalloc(sizeof *l1); if ((l1->next = parsecomplist(instr)) == NULL) { - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } l1->pat = patcompile(NULL, compflags | PAT_ANY, NULL); @@ -728,7 +728,7 @@ parsecomplist(char *instr) return (ef && !l1->next) ? NULL : l1; } } - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } @@ -1790,7 +1790,7 @@ zglob(LinkList list, LinkNode np, int nountok) insertlinknode(list, node, ostr); return; } - errflag = 0; + errflag &= ~ERRFLAG_ERROR; zerr("bad pattern: %s", ostr); return; } @@ -1873,7 +1873,8 @@ zglob(LinkList list, LinkNode np, int nountok) tmpptr->sortstrs[iexec] = tmpptr->name; } - errflag = ef; + /* Retain any user interrupt error status */ + errflag = ef | (errflag & ERRFLAG_INT); lastval = lv; } else { /* Failed, let's be safe */ @@ -3733,7 +3734,8 @@ qualsheval(char *name, UNUSED(struct stat *buf), UNUSED(off_t days), char *str) execode(prog, 1, 0, "globqual"); ret = lastval; - errflag = ef; + /* Retain any user interrupt error status */ + errflag = ef | (errflag & ERRFLAG_INT); lastval = lv; if (!(inserts = getaparam("reply")) && diff --git a/Src/hist.c b/Src/hist.c index 7fe843a4a..a0061707c 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -287,7 +287,8 @@ ihgetc(void) c = histsubchar(c); if (c < 0) { /* bad expansion */ - errflag = lexstop = 1; + lexstop = 1; + errflag |= ERRFLAG_ERROR; return ' '; } } @@ -721,7 +722,7 @@ histsubchar(int c) noerrs = 1; parse_subst_string(sline); noerrs = one; - errflag = oef; + errflag = oef | (errflag & ERRFLAG_INT); remnulargs(sline); untokenize(sline); } @@ -880,7 +881,8 @@ hbegin(int dohist) char *hf; isfirstln = isfirstch = 1; - errflag = histdone = 0; + errflag &= ~ERRFLAG_ERROR; + histdone = 0; if (!dohist) stophist = 2; else if (dohist != 2) @@ -3182,7 +3184,7 @@ bufferwords(LinkList list, char *buf, int *index, int flags) noaliases = ona; strinend(); inpop(); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; nocomments = onc; noerrs = ne; lexrestore(); diff --git a/Src/init.c b/Src/init.c index 655166135..305908724 100644 --- a/Src/init.c +++ b/Src/init.c @@ -118,11 +118,24 @@ loop(int toplevel, int justonce) if (interact && toplevel) { int hstop = stophist; stophist = 3; + /* + * Reset all errors including the interrupt error status + * immediately, so preprompt runs regardless of what + * just happened. We'll reset again below as a + * precaution to ensure we get back to the command line + * no matter what. + */ + errflag = 0; preprompt(); if (stophist != 3) hbegin(1); else stophist = hstop; + /* + * Reset all errors, including user interupts. + * This is what allows ^C in an interactive shell + * to return us to the command line. + */ errflag = 0; } } @@ -178,7 +191,15 @@ loop(int toplevel, int justonce) /* The only permanent storage is from getpermtext() */ zsfree(cmdstr); - errflag = 0; + /* + * Note this does *not* remove a user interrupt error + * condition, even though we're at the top level loop: + * that would be inconsistent with the case where + * we didn't execute a preexec function. This is + * an implementation detail that an interrupting user + * does't care about. + */ + errflag &= ~ERRFLAG_ERROR; } if (stopmsg) /* unset 'you have stopped jobs' flag */ stopmsg--; @@ -689,7 +710,7 @@ init_term(void) { if (isset(INTERACTIVE)) zerr("can't find terminal definition for %s", term); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; termflags |= TERM_BAD; return 0; } else { @@ -1336,7 +1357,7 @@ source(char *s) if (prog) { pushheap(); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; execode(prog, 1, 0, "filecode"); popheap(); if (errflag) @@ -1379,7 +1400,7 @@ source(char *s) lineno = oldlineno; /* our current lineno */ loops = oloops; /* the # of nested loops we are in */ dosetopt(SHINSTDIN, oldshst, 1, opts); /* SHINSTDIN option */ - errflag = 0; + errflag &= ~ERRFLAG_ERROR; if (!exit_pending) retflag = 0; scriptname = old_scriptname; diff --git a/Src/input.c b/Src/input.c index 4ac7e6ec8..9552331a9 100644 --- a/Src/input.c +++ b/Src/input.c @@ -291,7 +291,8 @@ inputline(void) } if (errflag) { free(ingetcline); - return lexstop = errflag = 1; + errflag |= ERRFLAG_ERROR; + return lexstop = 1; } if (isset(VERBOSE)) { /* Output the whole line read so far. */ diff --git a/Src/jobs.c b/Src/jobs.c index 6663a40a6..a668b07e6 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -509,7 +509,7 @@ update_job(Job jn) prev_errflag = errflag; } breaks = loops; - errflag = 1; + errflag |= ERRFLAG_INT; inerrflush(); } } else { @@ -526,7 +526,7 @@ update_job(Job jn) prev_errflag = errflag; } breaks = loops; - errflag = 1; + errflag |= ERRFLAG_INT; inerrflush(); } if (somestopped && jn->stat & STAT_SUPERJOB) @@ -581,7 +581,7 @@ update_job(Job jn) breaks = loops; } else { breaks = loops; - errflag = 1; + errflag |= ERRFLAG_INT; } check_cursh_sig(sig); } @@ -1444,12 +1444,19 @@ zwaitjob(int job, int wait_cmd) restore_queue_signals(q); return 128 + last_signal; } - /* Commenting this out makes ^C-ing a job started by a function - stop the whole function again. But I guess it will stop - something else from working properly, we have to find out - what this might be. --oberon + /* Commenting this out makes ^C-ing a job started by a function + stop the whole function again. But I guess it will stop + something else from working properly, we have to find out + what this might be. --oberon + + When attempting to separate errors and interrupts, we + assumed because of the previous comment it would be OK + to remove ERRFLAG_ERROR and leave ERRFLAG_INT set, since + that's the one related to ^C. But that doesn't work. + There's something more here we don't understand. --pws + + errflag = 0; */ - errflag = 0; */ if (subsh) { killjb(jn, SIGCONT); jn->stat &= ~STAT_STOPPED; diff --git a/Src/lex.c b/Src/lex.c index b2a05448c..4addf8033 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -385,7 +385,7 @@ lexrestore(void) ecnfunc = ln->ecnfunc; hlinesz = ln->hlinesz; toklineno = ln->toklineno; - errflag = 0; + errflag &= ~ERRFLAG_ERROR; free(ln); unqueue_signals(); @@ -1737,7 +1737,8 @@ parse_subst_string(char *s) inpop(); DPUTS(cmdsp, "BUG: parse_subst_string: cmdstack not empty."); lexrestore(); - errflag = err; + /* Keep any interrupt error status */ + errflag = err | (errflag & ERRFLAG_INT); if (ctok == LEXERR) { untokenize(s); return 1; diff --git a/Src/loop.c b/Src/loop.c index 82d2fe31a..8bb1ec9dd 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -259,7 +259,8 @@ execselect(Estate state, UNUSED(int do_exec)) 0, ZLCON_SELECT); if (errflag) str = NULL; - errflag = oef; + /* Keep any user interrupt error status */ + errflag = oef | (errflag & ERRFLAG_INT); } else { str = promptexpand(prompt3, 0, NULL, NULL, NULL); zputs(str, stderr); @@ -632,6 +633,14 @@ execcase(Estate state, int do_exec) zlong try_errflag = -1; +/** + * Corresponding interrupt error status form `try' block. + */ + +/**/ +zlong +try_interrupt = -1; + /**/ zlong try_tryflag = 0; @@ -643,7 +652,7 @@ exectry(Estate state, int do_exec) Wordcode end, always; int endval; int save_retflag, save_breaks, save_contflag; - zlong save_try_errflag, save_try_tryflag; + zlong save_try_errflag, save_try_tryflag, save_try_interrupt; end = state->pc + WC_TRY_SKIP(state->pc[-1]); always = state->pc + 1 + WC_TRY_SKIP(*state->pc); @@ -670,7 +679,10 @@ exectry(Estate state, int do_exec) /* The always clause. */ save_try_errflag = try_errflag; - try_errflag = (zlong)errflag; + save_try_interrupt = try_interrupt; + try_errflag = (zlong)(errflag & ERRFLAG_ERROR); + try_interrupt = (zlong)((errflag & ERRFLAG_INT) ? 1 : 0); + /* We need to reset all errors to allow the block to execute */ errflag = 0; save_retflag = retflag; retflag = 0; @@ -682,8 +694,16 @@ exectry(Estate state, int do_exec) state->pc = always; execlist(state, 1, do_exec); - errflag = try_errflag ? 1 : 0; + if (try_errflag) + errflag |= ERRFLAG_ERROR; + else + errflag &= ~ERRFLAG_ERROR; + if (try_interrupt) + errflag |= ERRFLAG_INT; + else + errflag &= ~ERRFLAG_INT; try_errflag = save_try_errflag; + try_interrupt = save_try_interrupt; if (!retflag) retflag = save_retflag; if (!breaks) diff --git a/Src/params.c b/Src/params.c index 61edc5d08..79088d162 100644 --- a/Src/params.c +++ b/Src/params.c @@ -331,6 +331,7 @@ IPDEF5("SHLVL", &shlvl, varinteger_gsu), #define IPDEF6(A,B,F) {{NULL,A,PM_INTEGER|PM_SPECIAL|PM_DONTIMPORT},BR((void *)B),GSU(F),10,0,NULL,NULL,NULL,0} IPDEF6("OPTIND", &zoptind, varinteger_gsu), IPDEF6("TRY_BLOCK_ERROR", &try_errflag, varinteger_gsu), +IPDEF6("TRY_BLOCK_INTERRUPT", &try_interrupt, varinteger_gsu), #define IPDEF7(A,B) {{NULL,A,PM_SCALAR|PM_SPECIAL},BR((void *)B),GSU(varscalar_gsu),0,0,NULL,NULL,NULL,0} #define IPDEF7U(A,B) {{NULL,A,PM_SCALAR|PM_SPECIAL|PM_UNSET},BR((void *)B),GSU(varscalar_gsu),0,0,NULL,NULL,NULL,0} @@ -2654,7 +2655,7 @@ assignsparam(char *s, char *val, int flags) if (!isident(s)) { zerr("not an identifier: %s", s); zsfree(val); - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } queue_signals(); @@ -2783,7 +2784,7 @@ assignaparam(char *s, char **val, int flags) if (!isident(s)) { zerr("not an identifier: %s", s); freearray(val); - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } queue_signals(); @@ -2799,7 +2800,7 @@ assignaparam(char *s, char **val, int flags) zerr("%s: attempt to set slice of associative array", v->pm->node.nam); freearray(val); - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } v = NULL; @@ -2870,13 +2871,13 @@ sethparam(char *s, char **val) if (!isident(s)) { zerr("not an identifier: %s", s); freearray(val); - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } if (strchr(s, '[')) { freearray(val); zerr("nested associative arrays not yet supported"); - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } if (unset(EXECOPT)) @@ -2916,7 +2917,7 @@ setnparam(char *s, mnumber val) if (!isident(s)) { zerr("not an identifier: %s", s); - errflag = 1; + errflag |= ERRFLAG_ERROR; return NULL; } if (unset(EXECOPT)) diff --git a/Src/parse.c b/Src/parse.c index 4ceeb4eaf..c1709e03a 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -71,13 +71,14 @@ struct heredocs *hdocs; #define YYERROR(O) { tok = LEXERR; ecused = (O); return 0; } #define YYERRORV(O) { tok = LEXERR; ecused = (O); return; } -#define COND_ERROR(X,Y) do { \ - zwarn(X,Y); \ - herrflush(); \ - if (noerrs != 2) \ - errflag = 1; \ - YYERROR(ecused) \ -} while(0) +#define COND_ERROR(X,Y) \ + do { \ + zwarn(X,Y); \ + herrflush(); \ + if (noerrs != 2) \ + errflag |= ERRFLAG_ERROR; \ + YYERROR(ecused) \ + } while(0) /* @@ -506,7 +507,7 @@ par_event(void) yyerror(1); herrflush(); if (noerrs != 2) - errflag = 1; + errflag |= ERRFLAG_ERROR; ecused--; return 0; } else { @@ -2339,7 +2340,7 @@ yyerror(int noerr) zwarn("parse error"); } if (!noerr && noerrs != 2) - errflag = 1; + errflag |= ERRFLAG_ERROR; } /* @@ -3031,7 +3032,7 @@ build_dump(char *nam, char *dump, char **files, int ali, int map, int flags) file = metafy(file, flen, META_REALLOC); if (!(prog = parse_string(file, 1)) || errflag) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; close(dfd); zfree(file, flen); zwarnnam(nam, "can't read file: %s", *files); @@ -3141,7 +3142,7 @@ build_cur_dump(char *nam, char *dump, char **names, int match, int map, for (hn = shfunctab->nodes[i]; hn; hn = hn->next) if (cur_add_func(nam, (Shfunc) hn, lnames, progs, &hlen, &tlen, what)) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; close(dfd); unlink(dump); return 1; @@ -3166,7 +3167,7 @@ build_cur_dump(char *nam, char *dump, char **names, int match, int map, pattry(pprog, hn->nam) && cur_add_func(nam, (Shfunc) hn, lnames, progs, &hlen, &tlen, what)) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; close(dfd); unlink(dump); return 1; @@ -3177,13 +3178,13 @@ build_cur_dump(char *nam, char *dump, char **names, int match, int map, if (errflag || !(shf = (Shfunc) shfunctab->getnode(shfunctab, *names))) { zwarnnam(nam, "unknown function: %s", *names); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; close(dfd); unlink(dump); return 1; } if (cur_add_func(nam, shf, lnames, progs, &hlen, &tlen, what)) { - errflag = 0; + errflag &= ~ERRFLAG_ERROR; close(dfd); unlink(dump); return 1; @@ -3192,7 +3193,7 @@ build_cur_dump(char *nam, char *dump, char **names, int match, int map, } if (empty(progs)) { zwarnnam(nam, "no functions"); - errflag = 0; + errflag &= ~ERRFLAG_ERROR; close(dfd); unlink(dump); return 1; diff --git a/Src/prompt.c b/Src/prompt.c index 0cc9ef917..3552575f3 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -192,8 +192,11 @@ promptexpand(char *s, int ns, char *rs, char *Rs, unsigned int *txtchangep) if (*s == Nularg && s[1] == '\0') *s = '\0'; - /* Ignore errors and status change in prompt substitution */ - errflag = olderr; + /* + * Ignore errors and status change in prompt substitution. + * However, keep any user interrupt error that occurred. + */ + errflag = olderr | (errflag & ERRFLAG_INT); lastval = oldval; } diff --git a/Src/signals.c b/Src/signals.c index e72850516..899f1217b 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -619,7 +619,7 @@ zhandler(int sig) zexit(SIGINT, 1); if (list_pipe || chline || simple_pline) { breaks = loops; - errflag = 1; + errflag |= ERRFLAG_INT; inerrflush(); check_cursh_sig(SIGINT); } @@ -640,6 +640,11 @@ zhandler(int sig) if (idle >= 0 && idle < tmout) alarm(tmout - idle); else { + /* + * We want to exit now. + * Cancel all errors, including a user interrupt + * which is now redundant. + */ errflag = noerrs = 0; zwarn("timeout"); stopmsg = 1; @@ -1267,7 +1272,18 @@ dotrapargs(int sig, int *sigtr, void *sigfn) !(isfunc && new_trap_return == 0)) { if (isfunc) { breaks = loops; - errflag = 1; + /* + * For SIGINT we behave the same as the default behaviour + * i.e. we set the error bit indicating an interrupt. + * We do this with SIGQUIT, too, even though we don't + * handle SIGQUIT by default. That's to try to make + * it behave a bit more like its normal behaviour when + * the trap handler has told us that's what it wants. + */ + if (sig == SIGINT || sig == SIGQUIT) + errflag |= ERRFLAG_INT; + else + errflag |= ERRFLAG_ERROR; } lastval = new_trap_return; /* return triggered */ @@ -1282,8 +1298,12 @@ dotrapargs(int sig, int *sigtr, void *sigfn) */ lastval = olastval; } - if (try_tryflag) - errflag = traperr; + if (try_tryflag) { + if (traperr) + errflag |= ERRFLAG_ERROR; + else + errflag &= ~ERRFLAG_ERROR; + } breaks += obreaks; /* return not triggered: restore old flag */ retflag = oretflag; diff --git a/Src/subst.c b/Src/subst.c index 61aa1c136..43932c256 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2822,7 +2822,8 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) haserr = parse_subst_string(s); noerrs = one; if (!quoteerr) { - errflag = oef; + /* Retain user interrupt error status */ + errflag = oef | (errflag & ERRFLAG_INT); if (haserr) shtokenize(s); } else if (haserr || errflag) { @@ -3249,8 +3250,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) haserr = 1; } noerrs = one; - if (!quoteerr) - errflag = oef; + if (!quoteerr) { + /* Retain user interrupt error status */ + errflag = oef | (errflag & ERRFLAG_INT); + } if (haserr || errflag) return NULL; } @@ -3483,8 +3486,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) untokenize(*ap); } noerrs = one; - if (!quoteerr) - errflag = oef; + if (!quoteerr) { + /* Retain any user interrupt error status */ + errflag = oef | (errflag & ERRFLAG_INT); + } else if (haserr || errflag) { zerr("parse error in parameter value"); return NULL; @@ -3516,8 +3521,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) noerrs = 1; haserr = parse_subst_string(val); noerrs = one; - if (!quoteerr) - errflag = oef; + if (!quoteerr) { + /* Retain any user interrupt error status */ + errflag = oef | (errflag & ERRFLAG_INT); + } else if (haserr || errflag) { zerr("parse error in parameter value"); return NULL; @@ -4086,7 +4093,8 @@ modify(char **str, char **ptr) noerrs = 1; parse_subst_string(copy); noerrs = one; - errflag = oef; + /* Retain any user interrupt error status */ + errflag = oef | (errflag & ERRFLAG_INT); remnulargs(copy); untokenize(copy); } @@ -4161,7 +4169,8 @@ modify(char **str, char **ptr) noerrs = 1; parse_subst_string(*str); noerrs = one; - errflag = oef; + /* Retain any user interrupt error status */ + errflag = oef | (errflag & ERRFLAG_INT); remnulargs(*str); untokenize(*str); } diff --git a/Src/utils.c b/Src/utils.c index ab3d3da93..893a8ca02 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -153,7 +153,7 @@ VA_DCL if (errflag || noerrs) { if (noerrs < 2) - errflag = 1; + errflag |= ERRFLAG_ERROR; return; } @@ -161,7 +161,7 @@ VA_DCL VA_GET_ARG(ap, fmt, const char *); zwarning(NULL, fmt, ap); va_end(ap); - errflag = 1; + errflag |= ERRFLAG_ERROR; } /**/ @@ -181,7 +181,7 @@ VA_DCL VA_GET_ARG(ap, fmt, const char *); zwarning(cmd, fmt, ap); va_end(ap); - errflag = 1; + errflag |= ERRFLAG_ERROR; } /**/ @@ -330,7 +330,7 @@ zerrmsg(FILE *file, const char *fmt, va_list ap) num = va_arg(ap, int); if (num == EINTR) { fputs("interrupt\n", file); - errflag = 1; + errflag |= ERRFLAG_ERROR; return; } errmsg = strerror(num); diff --git a/Src/zsh.h b/Src/zsh.h index 031deaf3f..b366e0ff4 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2623,6 +2623,20 @@ enum trap_state { #define IN_EVAL_TRAP() \ (intrap && !trapisfunc && traplocallevel == locallevel) +/* + * Bits in the errflag variable. + */ +enum errflag_bits { + /* + * Standard internal error bit. + */ + ERRFLAG_ERROR = 1, + /* + * User interrupt. + */ + ERRFLAG_INT = 2 +}; + /***********/ /* Sorting */ /***********/ -- cgit v1.2.3 From edb9c94025cebb853142c7e91b88c991ddd21b22 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 12 Dec 2014 14:12:55 +0100 Subject: 33950: ignore KEYTIMEOUT for vi operators --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 7 +++++++ Src/Zle/iwidgets.list | 12 ++++++------ Src/Zle/zle.h | 11 ++++++----- Src/Zle/zle_keymap.c | 8 +++++++- 5 files changed, 31 insertions(+), 12 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index e30324894..cee9f0689 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-12-12 Oliver Kiddle + + * 33950: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle.h, + Src/Zle/zle_keymap.c: ignore KEYTIMEOUT for vi operators + 2014-12-11 Peter Stephenson * 33876: etc.: Completion/Base/Core/_main_complete, diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index f95264232..d49c72020 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1605,6 +1605,13 @@ Read a movement command from the keyboard, and kill from the cursor position to the endpoint of the movement. Then enter insert mode. If the command is tt(vi-change), change the current line. + +For compatibility with vi, if the command is tt(vi-forward-word) +or tt(vi-forward-blank-word), the whitespace after the word is not +included. If you prefer the more consistent behaviour with the +whitespace included use the following key binding: + +example(bindkey -a -s cw dwi) ) tindex(vi-change-eol) item(tt(vi-change-eol) (unbound) (C) (unbound))( diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index 40750221e..5e598cc79 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -134,11 +134,11 @@ "vi-backward-blank-word-end", vibackwardblankwordend, 0 "vi-beginning-of-line", vibeginningofline, 0 "vi-caps-lock-panic", vicapslockpanic, ZLE_LASTCOL -"vi-change", vichange, ZLE_LASTCOL +"vi-change", vichange, ZLE_LASTCOL | ZLE_VIOPER "vi-change-eol", vichangeeol, 0 "vi-change-whole-line", vichangewholeline, 0 "vi-cmd-mode", vicmdmode, 0 -"vi-delete", videlete, ZLE_KEEPSUFFIX | ZLE_LASTCOL +"vi-delete", videlete, ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_VIOPER "vi-delete-char", videletechar, ZLE_KEEPSUFFIX "vi-digit-or-beginning-of-line", vidigitorbeginningofline, 0 "vi-down-line-or-history", vidownlineorhistory, ZLE_LINEMOVE @@ -159,7 +159,7 @@ "vi-goto-mark-line", vigotomarkline, ZLE_LINEMOVE "vi-history-search-backward", vihistorysearchbackward, 0 "vi-history-search-forward", vihistorysearchforward, 0 -"vi-indent", viindent, ZLE_LASTCOL +"vi-indent", viindent, ZLE_LASTCOL | ZLE_VIOPER "vi-insert", viinsert, 0 "vi-insert-bol", viinsertbol, 0 "vi-join", vijoin, 0 @@ -168,7 +168,7 @@ "vi-match-bracket", vimatchbracket, 0 "vi-open-line-above", viopenlineabove, 0 "vi-open-line-below", viopenlinebelow, 0 -"vi-oper-swap-case", vioperswapcase, ZLE_LASTCOL +"vi-oper-swap-case", vioperswapcase, ZLE_LASTCOL | ZLE_VIOPER "vi-pound-insert", vipoundinsert, 0 "vi-put-after", viputafter, ZLE_YANKAFTER | ZLE_KEEPSUFFIX "vi-put-before", viputbefore, ZLE_YANKBEFORE | ZLE_KEEPSUFFIX @@ -185,9 +185,9 @@ "vi-substitute", visubstitute, 0 "vi-swap-case", viswapcase, ZLE_LASTCOL "vi-undo-change", viundochange, ZLE_KEEPSUFFIX -"vi-unindent", viunindent, ZLE_LASTCOL +"vi-unindent", viunindent, ZLE_LASTCOL | ZLE_VIOPER "vi-up-line-or-history", viuplineorhistory, ZLE_LINEMOVE -"vi-yank", viyank, ZLE_LASTCOL +"vi-yank", viyank, ZLE_LASTCOL | ZLE_VIOPER "vi-yank-eol", viyankeol, 0 "vi-yank-whole-line", viyankwholeline, 0 "visual-line-mode", visuallinemode, ZLE_MENUCMP | ZLE_LASTCOL diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index a46b52ded..3c652909e 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -207,11 +207,12 @@ struct widget { #define ZLE_YANKBEFORE (1<<4) #define ZLE_YANK (ZLE_YANKAFTER | ZLE_YANKBEFORE) #define ZLE_LINEMOVE (1<<5) /* command is a line-oriented movement */ -#define ZLE_LASTCOL (1<<6) /* command maintains lastcol correctly */ -#define ZLE_KILL (1<<7) -#define ZLE_KEEPSUFFIX (1<<8) /* DON'T remove added suffix */ -#define ZLE_NOTCOMMAND (1<<9) /* widget should not alter lastcmd */ -#define ZLE_ISCOMP (1<<10) /* usable for new style completion */ +#define ZLE_VIOPER (1<<6) /* widget reads further keys so wait if prefix */ +#define ZLE_LASTCOL (1<<7) /* command maintains lastcol correctly */ +#define ZLE_KILL (1<<8) +#define ZLE_KEEPSUFFIX (1<<9) /* DON'T remove added suffix */ +#define ZLE_NOTCOMMAND (1<<10) /* widget should not alter lastcmd */ +#define ZLE_ISCOMP (1<<11) /* usable for new style completion */ /* thingies */ diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 48f210c7e..b703ebee1 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1444,6 +1444,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) Thingy func = t_undefinedkey; char *str = NULL; int lastlen = 0, lastc = lastchar; + int timeout = 0; keybuflen = 0; keybuf[0] = 0; @@ -1461,7 +1462,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) * argument to bindkey is in the correct form for the locale. * That's beyond our control. */ - while(getkeybuf(!!lastlen) != EOF) { + while(getkeybuf(timeout) != EOF) { char *s; Thingy f; int loc = !!localkeymap; @@ -1480,6 +1481,11 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) func = f; str = s; lastc = lastchar; + + /* can be patient with vi commands that need a motion operator: * + * they wait till a key is pressed for the movement anyway */ + timeout = !(!virangeflag && !region_active && f && f->widget && + f->widget->flags & ZLE_VIOPER); } if (!ispfx) break; -- cgit v1.2.3 From 1e0064e58b2d03f34a36b0908325e9660362fc57 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 13 Dec 2014 19:34:11 +0100 Subject: 33956: document key binding changes and remove ^X binding --- Doc/Zsh/zle.yo | 16 ++++++++-------- Src/Zle/zle_bindings.c | 2 +- Src/Zle/zle_keymap.c | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'Doc/Zsh') diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index d49c72020..dd8e6286a 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1073,7 +1073,7 @@ Move backward one word, where a word is defined as a series of non-blank characters. ) tindex(vi-backward-blank-word-end) -item(tt(vi-backward-blank-word-end) (unbound) (unbound) (unbound))( +item(tt(vi-backward-blank-word-end) (unbound) (gE) (unbound))( Move to the end of the previous word, where a word is defined as a series of non-blank characters. ) @@ -1098,7 +1098,7 @@ item(tt(vi-backward-word) (unbound) (b) (unbound))( Move to the beginning of the previous word, vi-style. ) tindex(vi-backward-word-end) -item(tt(vi-backward-word-end) (unbound) (unbound) (unbound))( +item(tt(vi-backward-word-end) (unbound) (ge) (unbound))( Move to the end of the previous word, vi-style. ) tindex(beginning-of-line) @@ -1215,7 +1215,7 @@ texinode(History Control)(Modifying Text)(Movement)(Zle Widgets) subsect(History Control) startitem() tindex(beginning-of-buffer-or-history) -item(tt(beginning-of-buffer-or-history) (ESC-<) (unbound) (unbound))( +item(tt(beginning-of-buffer-or-history) (ESC-<) (gg) (unbound))( Move to the beginning of the buffer, or if already there, move to the first event in the history list. ) @@ -1728,7 +1728,7 @@ item(tt(vi-open-line-below) (unbound) (o) (unbound))( Open a line below the cursor and enter insert mode. ) tindex(vi-oper-swap-case) -item(tt(vi-oper-swap-case))( +item(tt(vi-oper-swap-case) (unbound) (g~) (unbound))( Read a movement command from the keyboard, and swap the case of all characters from the cursor position to the endpoint of the movement. @@ -2286,7 +2286,7 @@ This command is executed when a key sequence that is not bound to any command is typed. By default it beeps. ) tindex(undo) -item(tt(undo) (^_ ^Xu ^X^U) (unbound) (unbound))( +item(tt(undo) (^_ ^Xu ^X^U) (u) (unbound))( Incrementally undo the last text modification. When called from a user-defined widget, takes an optional argument indicating a previous state of the undo history as returned by the tt(UNDO_CHANGE_NO) variable; @@ -2297,11 +2297,11 @@ insert mode is reverted, the changes having been merged when command mode was selected. ) tindex(redo) -item(tt(redo))( +item(tt(redo) (unbound) (^R) (unbound))( Incrementally redo undone text modifications. ) tindex(vi-undo-change) -item(tt(vi-undo-change) (unbound) (u) (unbound))( +item(tt(vi-undo-change) (unbound) (unbound) (unbound))( Undo the last text modification. If repeated, redo the modification. ) @@ -2320,7 +2320,7 @@ following an operator, it forces the subsequent movement command to be treated as a line-wise movement. ) tindex(what-cursor-position) -item(tt(what-cursor-position) (^X=) (unbound) (unbound))( +item(tt(what-cursor-position) (^X=) (ga) (unbound))( Print the character under the cursor, its code as an octal, decimal and hexadecimal number, the current cursor position within the buffer and the column of the cursor in the current line. diff --git a/Src/Zle/zle_bindings.c b/Src/Zle/zle_bindings.c index e3337d032..2ae8c8764 100644 --- a/Src/Zle/zle_bindings.c +++ b/Src/Zle/zle_bindings.c @@ -278,7 +278,7 @@ int viinsbind[32] = { /* ^U */ z_vikillline, /* ^V */ z_viquotedinsert, /* ^W */ z_vibackwardkillword, - /* ^X */ z_selfinsert, + /* ^X */ z_undefinedkey, /* ^Y */ z_selfinsert, /* ^Z */ z_selfinsert, /* ^[ */ z_vicmdmode, diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index afba592a7..be02f3aab 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1373,6 +1373,7 @@ default_bindings(void) bindkey(amap, "gE", refthingy(t_vibackwardblankwordend), NULL); bindkey(amap, "gg", refthingy(t_beginningofbufferorhistory), NULL); bindkey(amap, "g~", refthingy(t_vioperswapcase), NULL); + bindkey(amap, "g~~", NULL, "g~g~"); /* emacs mode: arrow keys */ add_cursor_key(emap, TCUPCURSOR, t_uplineorhistory, 'A'); -- cgit v1.2.3 From 4042640eee1c95eb45e3eb773bb55ae556a0208e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 17 Dec 2014 10:53:13 +0000 Subject: zsh-users/19551: history documentation. Note in a couple of places that history file reading and writing is only done in interactive shells. --- ChangeLog | 6 ++++++ Doc/Zsh/builtins.yo | 6 ++++++ Doc/Zsh/roadmap.yo | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 522ae9768..ee3e8207a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-12-17 Peter Stephenson + + * users/19551: Doc/builtins.yo, Doc/Zsh/roadmap.yo: better + documentation that history file reading and writing is only + done in interactive shells. + 2014-12-16 Barton E. Schaefer * Jun Kuriyama: 33984: Src/builtin.c: bin_dirs() should use diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 446312395..38788d3c4 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -657,6 +657,12 @@ xitem(tt( )[ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) xitem(tt(fc) tt(-p) [ tt(-a) ] [ var(filename) [ var(histsize) [ var(savehistsize) ] ] ]) xitem(tt(fc) tt(-P)) item(tt(fc) tt(-ARWI) [ var(filename) ])( +The tt(fc) command controls the interactive history mechanism. Note +that reading and writing of history options is only performed if the +shell is interactive. Usually this is detected automatically, but +it can be forced by setting the tt(interactive) option when starting the +shell. + Select a range of commands from var(first) to var(last) from the history list. The arguments var(first) and var(last) may be specified as a diff --git a/Doc/Zsh/roadmap.yo b/Doc/Zsh/roadmap.yo index ba598e5ea..677848961 100644 --- a/Doc/Zsh/roadmap.yo +++ b/Doc/Zsh/roadmap.yo @@ -41,7 +41,9 @@ set appropriate variables, and the number of history lines retained by default is quite small (30 lines). See the description of the shell variables (referred to in the documentation as parameters) tt(HISTFILE), tt(HISTSIZE) and tt(SAVEHIST) in ifzman(zmanref(zshparam))\ -ifnzman(noderef(Parameters Used By The Shell)). +ifnzman(noderef(Parameters Used By The Shell)). Note that it's +currently only possible to read and write files saving history +when the shell is interactive, i.e. it does not work from scripts. The shell now supports the UTF-8 character set (and also others if supported by the operating system). This is (mostly) handled transparently -- cgit v1.2.3 From 33d1439fdbf56ec100dbddfa9f7472a0da59d183 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 2 Jan 2015 21:32:51 +0000 Subject: users/19667: whence -S shows intermediate steps in symlink expansion --- ChangeLog | 3 +++ Doc/Zsh/builtins.yo | 9 +++++-- Src/builtin.c | 12 +++++----- Src/utils.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 76 insertions(+), 15 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 4e125d1de..ac957d1df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-01-02 Peter Stephenson + * users/19667: Doc/Zsh/builtins.yo, Src/builtin.c, Src/utils.c: + whence -S shows intermediate steps in symlink expansion. + * 34077: Test/A07control.ztst: add some further tests for return status from "for" loops. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 38788d3c4..b4f4b6742 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1667,7 +1667,7 @@ See also the shell variable tt(STTY) for a means of initialising the tty before running external commands. ) findex(type) -item(tt(type) [ tt(-wfpams) ] var(name) ...)( +item(tt(type) [ tt(-wfpamsS) ] var(name) ...)( Equivalent to tt(whence -v). ) findex(typeset) @@ -2083,7 +2083,7 @@ the user is potentially interested in both, so this problem is intrinsic to process IDs. ) findex(whence) -item(tt(whence) [ tt(-vcwfpams) ] var(name) ...)( +item(tt(whence) [ tt(-vcwfpamsS) ] var(name) ...)( For each name, indicate how it would be interpreted if used as a command name. @@ -2126,6 +2126,11 @@ of these patterns. item(tt(-s))( If a pathname contains symlinks, print the symlink-free pathname as well. ) +item(tt(-S))( +As tt(-s), but if the pathname had to be resolved by following +multiple symlinks, the intermediate steps are printed, too. The +symlink resolved at each step might be anywhere in the path. +) enditem() ) findex(where) diff --git a/Src/builtin.c b/Src/builtin.c index 264169cb4..47d1aa06d 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -119,7 +119,7 @@ static struct builtin builtins[] = BUILTIN("times", BINF_PSPECIAL, bin_times, 0, 0, 0, NULL, NULL), BUILTIN("trap", BINF_PSPECIAL | BINF_HANDLES_OPTS, bin_trap, 0, -1, 0, NULL, NULL), BUILTIN("true", 0, bin_true, 0, -1, 0, NULL, NULL), - BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfsw", "v"), + BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfsSw", "v"), BUILTIN("typeset", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%klprtuxmz", NULL), BUILTIN("umask", 0, bin_umask, 0, 1, 0, "S", NULL), BUILTIN("unalias", 0, bin_unhash, 1, -1, 0, "ms", "a"), @@ -128,7 +128,7 @@ static struct builtin builtins[] = BUILTIN("unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fmv", NULL), BUILTIN("unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL), BUILTIN("wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL), - BUILTIN("whence", 0, bin_whence, 0, -1, 0, "acmpvfsw", NULL), + BUILTIN("whence", 0, bin_whence, 0, -1, 0, "acmpvfsSw", NULL), BUILTIN("where", 0, bin_whence, 0, -1, 0, "pmsw", "ca"), BUILTIN("which", 0, bin_whence, 0, -1, 0, "ampsw", "c"), BUILTIN("zmodload", 0, bin_zmodload, 0, -1, 0, "AFRILP:abcfdilmpue", NULL), @@ -3331,8 +3331,8 @@ bin_whence(char *nam, char **argv, Options ops, int func) if (v && !csh) zputs(*argv, stdout), fputs(" is ", stdout); zputs(buf, stdout); - if (OPT_ISSET(ops,'s')) - print_if_link(buf); + if (OPT_ISSET(ops,'s') || OPT_ISSET(ops, 'S')) + print_if_link(buf, OPT_ISSET(ops, 'S')); fputc('\n', stdout); } informed = 1; @@ -3352,8 +3352,8 @@ bin_whence(char *nam, char **argv, Options ops, int func) if (v && !csh) zputs(*argv, stdout), fputs(" is ", stdout); zputs(cnam, stdout); - if (OPT_ISSET(ops,'s')) - print_if_link(cnam); + if (OPT_ISSET(ops,'s') || OPT_ISSET(ops,'S')) + print_if_link(cnam, OPT_ISSET(ops,'S')); fputc('\n', stdout); } } else { diff --git a/Src/utils.c b/Src/utils.c index 893a8ca02..2b2a815a8 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -719,7 +719,7 @@ slashsplit(char *s) /**/ static int -xsymlinks(char *s) +xsymlinks(char *s, int full) { char **pp, **opp; char xbuf2[PATH_MAX*3], xbuf3[PATH_MAX*2]; @@ -758,14 +758,49 @@ xsymlinks(char *s) } else { ret = 1; metafy(xbuf3, t0, META_NOALLOC); + if (!full) { + /* + * If only one expansion requested, ensure the + * full path is in xbuf. + */ + zulong len = xbuflen; + if (*xbuf3 == '/') + strcpy(xbuf, xbuf3); + else if ((len += strlen(xbuf3) + 1) < sizeof(xbuf)) { + strcpy(xbuf + xbuflen, "/"); + strcpy(xbuf + xbuflen + 1, xbuf3); + } else { + *xbuf = 0; + ret = -1; + break; + } + + while (*++pp) { + zulong newlen = len + strlen(*pp) + 1; + if (newlen < sizeof(xbuf)) { + strcpy(xbuf + len, "/"); + strcpy(xbuf + len + 1, *pp); + len = newlen; + } else { + *xbuf = 01; + ret = -1; + break; + } + } + /* + * No need to update xbuflen, we're finished + * the expansion (for now). + */ + break; + } if (*xbuf3 == '/') { strcpy(xbuf, ""); - if (xsymlinks(xbuf3 + 1) < 0) + if (xsymlinks(xbuf3 + 1, 0) < 0) ret = -1; else xbuflen = strlen(xbuf); } else - if (xsymlinks(xbuf3) < 0) + if (xsymlinks(xbuf3, 0) < 0) ret = -1; else xbuflen = strlen(xbuf); @@ -787,7 +822,7 @@ xsymlink(char *s) if (*s != '/') return NULL; *xbuf = '\0'; - if (xsymlinks(s + 1) < 0) + if (xsymlinks(s + 1, 1) < 0) zwarn("path expansion failed, using root directory"); if (!*xbuf) return ztrdup("/"); @@ -796,12 +831,30 @@ xsymlink(char *s) /**/ void -print_if_link(char *s) +print_if_link(char *s, int all) { if (*s == '/') { *xbuf = '\0'; - if (xsymlinks(s + 1) > 0) - printf(" -> "), zputs(*xbuf ? xbuf : "/", stdout); + if (all) { + char *start = s + 1; + char xbuflink[PATH_MAX]; + for (;;) { + if (xsymlinks(start, 0) > 0) { + printf(" -> "); + zputs(*xbuf ? xbuf : "/", stdout); + if (!*xbuf) + break; + strcpy(xbuflink, xbuf); + start = xbuflink + 1; + *xbuf = '\0'; + } else { + break; + } + } + } else { + if (xsymlinks(s + 1, 1) > 0) + printf(" -> "), zputs(*xbuf ? xbuf : "/", stdout); + } } } -- cgit v1.2.3 From aa622e08014744c54e585e34613c2572a27f0f4b Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 4 Jan 2015 00:28:03 +0000 Subject: users/19682: document recommended use of whence --- ChangeLog | 9 +++++++-- Doc/Zsh/builtins.yo | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index b78c4c3da..d8918acb3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ +2015-01-04 Peter Stephenson + + * users/19682: Doc/Zsh/builtins.yo: document recommended use of + whence. + 2015-01-02 Peter Stephenson - * 19671: Src/builtin.c: whence -a should still work if there's a - full path already. + * users/19671: Src/builtin.c: whence -a should still work if + there's a full path already. * users/19667: Doc/Zsh/builtins.yo, Src/builtin.c, Src/utils.c: whence -S shows intermediate steps in symlink expansion. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index b4f4b6742..49c2c11c3 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -2087,6 +2087,11 @@ item(tt(whence) [ tt(-vcwfpamsS) ] var(name) ...)( For each name, indicate how it would be interpreted if used as a command name. +tt(whence) is most useful when var(name) is only the last path component +of a command, i.e. does not include a `tt(/)'; in particular, pattern +matching only succeeds if just the non-directory component of the command is +passed. + startitem() item(tt(-v))( Produce a more verbose report. @@ -2119,7 +2124,7 @@ throughout the command path. Normally only the first occurrence is printed. ) item(tt(-m))( -The arguments are taken as patterns (should be +The arguments are taken as patterns (pattern characters should be quoted), and the information is displayed for each command matching one of these patterns. ) -- cgit v1.2.3 From 62b0e611ce0d3754c4397c6a66f09049e6e28d26 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 27 Apr 2013 17:51:40 +0200 Subject: 30568: Add tetriscurses contrib function, port of tetris to zcurses --- ChangeLog | 5 + Doc/Zsh/contrib.yo | 11 ++ Functions/Misc/tetriscurses | 386 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 402 insertions(+) create mode 100644 Functions/Misc/tetriscurses (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index af07352db..372e36053 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-01-09 Mikael Magnusson + + * 30568: Doc/Zsh/contrib.yo, Functions/Misc/tetriscurses: Add + tetriscurses contrib function, port of tetris to zcurses + 2015-01-08 Peter Stephenson * Src/init.c, Src/input.c, Src/lex.c, Src/parse.c, Src/zsh.h, diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 8c5e66b17..50432432b 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3609,6 +3609,17 @@ If you quit in the middle of a game, the next invocation of the tt(tetris) widget will continue where you left off. If you lost, it will start a new game. ) +item(tt(tetriscurses))( +This is a port of the above to zcurses. The input handling is improved +a bit so that moving a block sideways doesn't automatically advance a +timestep, and the graphics use unicode block graphics. + +This version does not save the game state between invocations, and is not +invoked as a widget, but rather as: + +example(autoload -U tetriscurses +tetriscurses) +) findex(zargs) item(tt(zargs) [ var(option) ... tt(-)tt(-) ] [ var(input) ... ] [ tt(-)tt(-) var(command) [ var(arg) ... ] ])( This function has a similar purpose to GNU xargs. Instead of diff --git a/Functions/Misc/tetriscurses b/Functions/Misc/tetriscurses new file mode 100644 index 000000000..371456082 --- /dev/null +++ b/Functions/Misc/tetriscurses @@ -0,0 +1,386 @@ +# I noticed we don't ship any contrib and/or example scripts using the +# zcurses module, and also that the builtin tetris is sort of boring, so +# I figured I'd port it to curses. It works pretty well, but I noticed +# two problems with the zcurses module in the process: +# +# 1. the HAVE_USE_DEFAULT_COLORS define seems to never be defined? +# +# 2a. resizing the window causes 'zcurses input' to wait forever for a +# key, even with a timeout defined. +# +# Bart says: +# >This probably has something to do with the special-casing around wgetch() +# >for signals handled by the "trap" command. See the big comment in +# >Src/Modules/curses.c lines 1073-1103. +# +# >It may be problematic to mix curses with the generic signal handling in +# >the main shell. We may need to swap in a SIGWINCH handler wrapper while +# >the curses UI is active, and restore the main handler when leaving it. +# +# 2b. resizing the window doesn't cause an event while running the +# program, but if i resize before starting(?) i get an event RESIZE on +# my first input call. +# +# Bart says: +# >There's probably some state that needs to be cleared on entry to +# >zccmd_input() so that curses doesn't see something left over from the +# >previous signal. Unfortunately I don't know what that would be. + +if (( $LINES < 22 || $COLUMNS < 46 )); then + echo >&2 'terminal needs to be at least 22 lines and 46 columns' + return +fi + +emulate -L zsh + +typeset -a tetris_shapes +tetris_shapes=( + 0x0f00 0x4444 0x0f00 0x4444 + 0x4e00 0x4c40 0x0e40 0x4640 + 0x6600 0x6600 0x6600 0x6600 + 0x4620 0x6c00 0x4620 0x6c00 + 0x2640 0x6300 0x2640 0x6300 + 0x6440 0x8e00 0x44c0 0x0e20 + 0xc440 0x0e80 0x4460 0x2e00 +) +typeset -A tetris_rotations +tetris_rotations=( + 0x0f00 0x4444 0x4444 0x0f00 + 0x4e00 0x4c40 0x4c40 0x0e40 0x0e40 0x4640 0x4640 0x4e00 + 0x6600 0x6600 + 0x4620 0x6c00 0x6c00 0x4620 + 0x2640 0x6300 0x6300 0x2640 + 0x6440 0x8e00 0x8e00 0x44c0 0x44c0 0x0e20 0x0e20 0x6440 + 0xc440 0x0e80 0x0e80 0x4460 0x4460 0x2e00 0x2e00 0xc440 +) +local tetris_vsz=20 tetris_hsz=11 +local tetris_blankline=${(l:11:: :)} +local tetris_blankboard=${(j::):-${(l:11:: :)}${(s: :)^${(l:20:: :)}}} + +local tetris_board=$tetris_blankboard +local tetris_score=0 +local tetris_lines=0 + +local tetris_{block{,_next,_x,_y},i} + +function __tetris-next-block { + tetris_block_next=$tetris_shapes[1+RANDOM%$#tetris_shapes] +} + +function __tetris-new-block { + tetris_block=$tetris_block_next + __tetris-next-block + __tetris-draw-next-block + tetris_block_y=0 + tetris_block_x=4 + if ! __tetris-block-fits; then + __tetris-game-over + fi + __tetris-place-block "*" +} + +function __tetris-left { + __tetris-place-block " " + (( tetris_block_x-- )) + __tetris-block-fits || (( tetris_block_x++ )) + __tetris-place-block "*" +} + +function __tetris-right { + __tetris-place-block " " + (( tetris_block_x++ )) + __tetris-block-fits || (( tetris_block_x-- )) + __tetris-place-block "*" +} + +function __tetris-rotate { + __tetris-place-block " " + local save_block=$tetris_block + tetris_block=$tetris_rotations[$tetris_block] + __tetris-block-fits || tetris_block=$save_block + __tetris-place-block "*" +} + +function __tetris-drop { + __tetris-place-block " " + ((tetris_block_y++)) + while __tetris-block-fits; do + ((tetris_block_y++)) + ((tetris_score+=2)) + done + ((tetris_block_y--)) + __tetris-block-dropped +} + +function __tetris-timeout { + __tetris-place-block " " + ((tetris_block_y++)) + if __tetris-block-fits; then + __tetris-place-block "*" + return + fi + ((tetris_block_y--)) + __tetris-block-dropped +} + +function __tetris-block-dropped { + integer bonus=1 + __tetris-place-block "O" + local fl=${tetris_blankline// /O} i=$((tetris_block_y*tetris_hsz)) + repeat 4; do + if [[ $tetris_board[i+1,i+tetris_hsz] == $fl ]]; then + if (( fancygraphics )); then for char in {7..1}; do + tetris_board[i+1,i+tetris_hsz]=${tetris_blankline// /$char} + __tetris-render-screen + zcurses timeout score 50 + zcurses input score + done; fi + tetris_board[i+1,i+tetris_hsz]= + tetris_board=$tetris_blankline$tetris_board + ((tetris_score+=100*(bonus++*(tetris_lines/10+10)))) + ((tetris_lines+=1)) + if ((tetris_lines % 10 == 0)); then + ((timestep = timestep * 0.80)) + fi + fi + ((i += tetris_hsz)) + done + __tetris-new-block +} + +function __tetris-block-fits { + local y x i=$((1+tetris_block_y*tetris_hsz+tetris_block_x)) b=0x8000 + for ((y=0; y!=4; y++)); do + for ((x=0; x!=4; x++)); do + if ((tetris_block&b)); then + ((x+tetris_block_x >= 0)) || return 1 + ((x+tetris_block_x < tetris_hsz)) || return 1 + ((y+tetris_block_y >= 0)) || return 1 + ((y+tetris_block_y < tetris_vsz)) || return 1 + [[ $tetris_board[i] == " " ]] || return 1 + fi + ((b >>= 1)) + ((i++)) + done + ((i+=tetris_hsz-4)) + done + return 0 +} + +function __tetris-draw-next-block { + local tetris_preview + local y x i=1 b=0x8000 + for ((y=0; y!=4; y++)); do + tetris_preview=" " + for ((x=0; x!=4; x++)); do + ((tetris_block_next&b)) && tetris_preview[i]=\* + ((b >>= 1)) + ((i++)) + done + i=1 + zcurses move preview $((y+1)) 1 + zcurses string preview ${${${tetris_preview//O/$filled_block}//\*/$active_block}// / } + done +} + +function __tetris-place-block { + local y x i=$((1+tetris_block_y*tetris_hsz+tetris_block_x)) b=0x8000 + for ((y=0; y!=4; y++)); do + for ((x=0; x!=4; x++)); do + ((tetris_block&b)) && tetris_board[i]=$1 + ((b >>= 1)) + ((i++)) + done + ((i+=tetris_hsz-4)) + done +} + +function __tetris-render-screen { + local i x piece + setopt localoptions histsubstpattern extendedglob + local -a match mbegin mend + local -A animation + animation=( 7 ▇▇ 6 ▆▆ 5 ▅▅ 4 ▄▄ 3 ▃▃ 2 ▂▂ 1 ▁▁ ) + for (( i = 0; i < tetris_vsz; i++ )); do + zcurses move gamearea $(( i + 1 )) 1 + zcurses string gamearea ${${${${${tetris_board[1+i*tetris_hsz,(i+1)*tetris_hsz]}//O/$filled_block}//\*/$active_block}// / }//(#b)([1-7])/$animation[$match[1]]} + done + + zcurses clear score + zcurses move score 1 1 + zcurses string score "Score: $tetris_score"$'\ +'" Lines: $tetris_lines"$'\ +'" Speed: ${timestep%.*} ms" + + zcurses border gamearea + zcurses border score + zcurses border preview + zcurses refresh gamearea score preview $debug +} + +function __tetris-game-over { + gameover=1 +} + +function __tetris-new-game { + gameover=0 + timestep=1000 + tetris_score=0 + tetris_lines=0 + __tetris-next-block + __tetris-new-block + __tetris-render-screen +} + +function __tetris-game-over-screen { + __tetris-debug "Died with $tetris_score points!" + tetris_board=$tetris_blankboard + local text="You got $tetris_score points!" + local gameover_height=4 gameover_width=$(( $#text + 2 )) + zcurses addwin gameover $gameover_height $gameover_width \ + $(( off_y + (game_height-gameover_height)/2 )) \ + $(( off_x + (game_width+score_width-gameover_width)/2 )) + zcurses move gameover 1 1 + zcurses string gameover $text + text='Play again? [yn]' + zcurses move gameover 2 $(( (gameover_width - $#text)/2 )) + zcurses string gameover $text + zcurses border gameover + keepplaying= + until [[ $keepplaying = [ynq] ]]; do + zcurses input gameover keepplaying + done + zcurses delwin gameover + zcurses refresh stdscr + zcurses timeout gamearea ${timestep%.*} + __tetris-new-game +} + +function __tetris-debug { + if [[ -z $debug ]]; then + return + fi + zcurses scroll debug -1 + zcurses move debug 0 0 + zcurses string debug "$1" +} + +function __tetris-remove-wins { + local delwin + local -a delwins + delwins=(gamearea score debug gameover help preview) + for delwin in ${delwins:*zcurses_windows}; do + zcurses delwin $delwin + done +} + +function __tetris-help { + local i + local help_height=9 help_width=23 + zcurses addwin help $help_height $help_width \ + $(( off_y + (game_height - help_height) / 2 )) \ + $(( off_x + (game_width + score_width - help_width) / 2 )) + zcurses move help 1 1 + zcurses string help $'left: h, j, left\ + right: right, n, l\ + rotate: up, c, i\ + soft drop: down, t, k\ + hard drop: space\ + quit: q\ + press space to return' + zcurses border help + until [[ $i == [\ q] ]]; do + zcurses input help i + if [[ $i == q ]]; then + keepplaying=n + fi + done + zcurses delwin help + zcurses refresh stdscr +} + +zmodload zsh/curses && { + zcurses init + __tetris-remove-wins + zcurses refresh + echoti civis + local debug= + if (( ${@[(I)--debug|-d]} )); then + debug=debug + fi + local off_x off_y + local game_height=22 game_width=25 + local score_height=5 score_width=20 + local preview_height=6 preview_width=10 + local filled_block active_block + local fancygraphics + if zmodload zsh/langinfo && [[ $langinfo[CODESET] = UTF-8 ]]; then + filled_block=██ + active_block=▒▒ + fancygraphics=${@[(I)--silly]} + else + filled_block='[]' + active_block='()' + fancygraphics=0 + fi + off_x=$(( (COLUMNS-game_width-score_width-1) / 2 )) + off_y=$(( (LINES-game_height) / 2 )) + zcurses clear stdscr redraw + zcurses refresh stdscr + zcurses addwin gamearea $game_height $game_width $off_y $off_x + zcurses scroll gamearea off + zcurses addwin score $score_height $score_width \ + $off_y $(( off_x + game_width + 1 )) + zcurses scroll score off + zcurses addwin preview $preview_height $preview_width \ + $(( off_y + score_height )) $(( off_x + game_width + 1 )) + zcurses scroll preview off + if [[ -n $debug ]]; then + zcurses addwin debug $(( game_height - score_height - preview_height - 1 )) \ + $score_width \ + $(( off_y + score_height + preview_height ))\ + $(( off_x + game_width + 1 )) + fi + typeset -F SECONDS + local now prev timestep timeout key kkey keepplaying=y gameover=0 + prev=$SECONDS + __tetris-new-game + zcurses timeout gamearea 0 + while [[ $keepplaying == y ]]; do + if zcurses input gamearea key kkey; then + __tetris-debug "got input $key$kkey" + case $key$kkey in + LEFT|h|j) __tetris-left;; + RIGHT|n|l) __tetris-right;; + UP|c|i) __tetris-rotate;; + DOWN|t|k) __tetris-timeout; ((tetris_score++)); prev=$SECONDS;; + " ") __tetris-drop;; + q) break;; + F1|H) __tetris-help;; + esac + else + __tetris-debug "timed out" + __tetris-timeout + fi + now=$SECONDS + if (( prev + timestep/1000. < now )); then + (( prev += timestep/1000. )) + fi + timeout=${$(( 1000.*(prev + timestep/1000. - now) + 1 ))%.*} + if (( timeout < 0 )); then + __tetris-debug "BUG: timeout < 0" + timeout=${timestep%.*} + fi + zcurses timeout gamearea $timeout + __tetris-debug "timeout: $timeout" + + __tetris-render-screen + if [[ $gameover == 1 ]]; then + __tetris-game-over-screen + fi + done +} always { + __tetris-remove-wins + echoti cnorm + zcurses end +} -- cgit v1.2.3 From 6291d38848680b84252799d9e33110bca842efe8 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 9 Jan 2015 17:24:16 +0000 Subject: 34182: doc: to add zf_\* builtins use zmodload -m -F --- ChangeLog | 5 +++++ Doc/Zsh/mod_files.yo | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 372e36053..c4ea61b41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-01-09 Peter Stephenson + + * 34182: Doc/Zsh/mod_files.yo: to add zf_* builtins you can + use zmodload -m -F. + 2015-01-09 Mikael Magnusson * 30568: Doc/Zsh/contrib.yo, Functions/Misc/tetriscurses: Add diff --git a/Doc/Zsh/mod_files.yo b/Doc/Zsh/mod_files.yo index 5dbdae7d2..90e988474 100644 --- a/Doc/Zsh/mod_files.yo +++ b/Doc/Zsh/mod_files.yo @@ -10,7 +10,10 @@ all features now required by relevant standards committees. For all commands, a variant beginning tt(zf_) is also available and loaded automatically. Using the features capability of zmodload will let you load -only those names you want. +only those names you want. Note that it's possible to load only the +builtins with zsh-specific names using the following command: + +example(zmodload -m -F zsh/files b:zf_\*) The commands loaded by default are: -- cgit v1.2.3 From bd13ffefaba033321410f069c6fb32fab1b29fac Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Fri, 9 Jan 2015 21:57:22 -0800 Subject: users/19721: clarify context vs. style in compsys configuration --- ChangeLog | 8 ++++++++ Doc/Zsh/compsys.yo | 52 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 18 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index a78425bda..10556e5e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-01-09 Barton E. Schaefer + + * 34202: Completion/Base/Widget/_complete_debug, + Completion/compinstall, Functions/Calendar/calendar, + Functions/Zftp/zfget_match: safe tempfile creation part 3 + + * users/19721: Doc/Zsh/compsys.yo: clarify context vs. style + 2015-01-09 Peter Stephenson * 34189: Src/Zle/compcore.c, Src/Zle/compctl.c, diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 920b5903d..2cdc57a06 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -533,21 +533,41 @@ generated. subsect(Overview) When completion is attempted somewhere on the command line the -completion system first works out the context. This takes account of a +completion system begins building the context. The context represents +everything that the shell knows about the meaning of the command line +and the significance of the cursor position. This takes account of a number of things including the command word (such as `tt(grep)' or `tt(zsh)') and options to which the current word may be an argument (such as the `tt(-o)' option to tt(zsh) which takes a shell option as an argument). -This context information is condensed into a string consisting of -multiple fields separated by colons, referred to simply as `the context' -in the remainder of the documentation. This is used to look up -em(styles), context-sensitive options that can be used to configure the -completion system. The context used for lookup may vary during the same -call to the completion system. +The context starts out very generic ("we are beginning a completion") +and becomes more specific as more is learned ("the current word is in a +position that is usually a command name" or "the current word might be a +variable name" and so on). Therefore the context will vary during the +same call to the completion system. + +This context information is condensed into a string consisting of multiple +fields separated by colons, referred to simply as `the context' in the +remainder of the documentation. Note that a user of the completion system +rarely needs to compose a context string, unless for example a new +function is being written to perform completion for a new command. What a +user may need to do is compose a em(style) pattern, which is matched +against a context when needed to look up context-sensitive options that +configure the completion system. + +The next few paragraphs explain how a context is composed within the +completion function suite. Following that is discussion of how em(styles) +are defined. Styles determine such things as how the matches are +generated, similarly to shell options but with much more control. They +are defined with the tt(zstyle) builtin command (\ +ifzman(see zmanref(zshmodules))\ +ifnzman(noderef(The zsh/zutil Module))). The context string always consists of a fixed set of fields, separated -by colons and with a leading colon before the first, in the form +by colons and with a leading colon before the first. Fields which are +not yet known are left empty, but the surrounding colons appear anyway. +The fields are always in the order tt(:completion:)var(function)tt(:)var(completer)tt(:)var(command)tt(:)var(argument)tt(:)tt(tag). These have the following meaning: startitemize() @@ -628,17 +648,13 @@ described in ifzman(the section `Bindable Commands' below)\ ifnzman(noderef(Bindable Commands)). -Styles determine such things as how the matches are generated, similarly -to shell options but with much more control. They can have any number -of strings as their value. They are defined with the tt(zstyle) builtin -command (\ -ifzman(see zmanref(zshmodules))\ -ifnzman(noderef(The zsh/zutil Module))). - When looking up styles the completion system uses full context names, -including the tag. Looking up the value of a style therefore consists -of two things: the context, which may be matched as a pattern, and the -name of the style itself, which must be given exactly. +including the tag. Looking up the value of a style therefore consists of +two things: the context, which is matched to the most specific (best +fitting) style pattern, and the name of the style itself, which must be +matched exactly. The following examples demonstrate that style patterns +may be loosely defined for styles that apply broadly, or as tightly +defined as desired for styles that apply in narrower circumstances. For example, many completion functions can generate matches in a simple and a verbose form and use the tt(verbose) style to decide -- cgit v1.2.3 From 53e3d9e0638d025cd99a65011ff96d5e2680e2ec Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 9 Jan 2015 22:46:42 +0000 Subject: 34914: explanation of effect of integer promotion --- ChangeLog | 3 +++ Doc/Zsh/arith.yo | 9 +++++++++ 2 files changed, 12 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index b102fd466..89e92bb67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,9 @@ 2015-01-09 Peter Stephenson + * 34194: Doc/Zsh/arith.yo: add paragraph about integer + promotion. + * 34189: Src/Zle/compcore.c, Src/Zle/compctl.c, Src/Zle/textobjects.c, Src/Zle/zle_tricky.c, Src/builtin.c, Src/context.c, Src/exec.c, Src/hist.c, Src/init.c, Src/lex.c, diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo index a620b73d1..5c334ce9c 100644 --- a/Doc/Zsh/arith.yo +++ b/Doc/Zsh/arith.yo @@ -233,6 +233,15 @@ necessary. In addition, if any operator which requires an integer equivalents with assignment) is given a floating point argument, it will be silently rounded down to the next integer. +Users should beware that, in common with many other programming +languages but not software designed for calculation, the evaluation of +an expression in zsh is taken a term at a time and promotion of integers +to floating point does not occur in terms only containing integers. A +typical result of this is that a division such as tt(6/8) is truncated, +in this being rounded down to 0. The tt(FORCE_FLOAT) shell option can +be used in scripts or functions where floating point evaluation is +required throughout. + Scalar variables can hold integer or floating point values at different times; there is no memory of the numeric type in this case. -- cgit v1.2.3 From 626650f20e5c01fa6554da2a73dc5338a2523842 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 12 Jan 2015 11:10:07 +0000 Subject: 34253: warn in zcalc doc about integer arithmetic. C.f. warning in arithmetic doc in 34194. --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 5bbdd175a..a9a44a379 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-01-12 Peter Stephenson + + * 34253: Doc/Zsh/contrib.yo: warning on integer arithmetic + for zcalc, c.f. 34194. + 2015-01-11 Barton E. Schaefer * 34247: Test/C01arith.ztst: regression test for 34230. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 50432432b..00ede52aa 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3227,8 +3227,18 @@ A reasonably powerful calculator based on zsh's arithmetic evaluation facility. The syntax is similar to that of formulae in most programming languages; see ifzman(the section `Arithmetic Evaluation' in zmanref(zshmisc))\ -ifnzman(noderef(Arithmetic Evaluation)) for details. The mathematical -library tt(zsh/mathfunc) will be loaded if it is available; see +ifnzman(noderef(Arithmetic Evaluation)) for details. + +Non-programmers should note that, as in many other programming +languages, expressions involving only integers (whether constants +without a `tt(.)', variables containing such constants as strings, or +variables declared to be integers) are by default evaluated using +integer arithmetic, which is not how an ordinary desk calculator +operates. To force floating point operation, pass the option tt(-f); +see further notes below. + +The mathematical library tt(zsh/mathfunc) will be loaded if it is +available; see ifzman(the section `The zsh/mathfunc Module' in zmanref(zshmodules))\ ifnzman(noderef(The zsh/mathfunc Module)). The mathematical functions correspond to the raw system libraries, so trigonometric functions are -- cgit v1.2.3 From 9fcc9d6e8dd778007c0dd51860651f8256c6640c Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Tue, 13 Jan 2015 19:23:31 -0800 Subject: 34273: use "enough" colons in each completion style pattern example --- ChangeLog | 6 ++++++ Doc/Zsh/compsys.yo | 27 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index e5c3293b4..6a95824fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-01-13 Barton E. Schaefer + + * 34273: Doc/Zsh/compsys.yo: use a sufficient number of colons + in example style patterns to assure fixed strings can't match + the wrong field positions + 2015-01-13 Peter Stephenson * 34260: Eric Cook: Completion/Unix/Command/_ip: relax diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 2cdc57a06..5890f1704 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -677,7 +677,7 @@ completion for the tt(kill) builtin. If the style is set, the builtin lists full job texts and process command lines; otherwise it shows the bare job numbers and PIDs. To turn the style off for this use only: -example(zstyle ':completion:*:*:kill:*' verbose no) +example(zstyle ':completion:*:*:kill:*:*' verbose no) For even more control, the style can use one of the tags `tt(jobs)' or `tt(processes)'. To turn off verbose display only for jobs: @@ -704,10 +704,15 @@ as tt(menu) and tt(list-rows-first). Note that the order in which styles are em(defined) does not matter; the style mechanism uses the most specific possible match for a particular style to determine the set of values. More precisely, strings are -preferred over patterns (for example, `tt(:completion::complete:foo)' is -more specific than `tt(:completion::complete:*')), and longer patterns are +preferred over patterns (for example, `tt(:completion::complete:::foo)' is +more specific than `tt(:completion::complete:::*')), and longer patterns are preferred over shorter patterns. +A good rule of thumb is that any completion style pattern that needs to +include more than one wildcard (tt(*)) and that does not end in a tag +name, should include all six colons (tt(:)), possibly surrounding +additional wildcards. + Style names like those of tags are arbitrary and depend on the completion function. However, the following two sections list some of the most common tags and styles. @@ -1507,7 +1512,7 @@ For example, to make the tt(rm) command first complete only names of object files and then the names of all files if there is no matching object file: -example(zstyle ':completion:*:*:rm:*' file-patterns \ +example(zstyle ':completion:*:*:rm:*:*' file-patterns \ '*.o:object-files' '%p:all-files') To alter the default behaviour of file completion DASH()- offer files @@ -1659,7 +1664,7 @@ For example, to have names of builtin commands, shell functions and external commands appear in that order when completing in command position: -example(zstyle ':completion:*:*:-command-:*' group-order \ +example(zstyle ':completion:*:*:-command-:*:*' group-order \ builtins functions commands) ) kindex(groups, completion style) @@ -2045,7 +2050,7 @@ use the completers tt(_complete) and tt(_prefix) but allow case-insensitive completion only with tt(_complete): example(zstyle ':completion:*' completer _complete _prefix -zstyle ':completion:*:complete:*' matcher-list \ +zstyle ':completion:*:complete:*:*:*' matcher-list \ '' 'm:{a-zA-Z}={A-Za-z}') User-defined names, as explained for the tt(completer) style, are @@ -2056,9 +2061,9 @@ with case-insensitive matching, then correction, and finally partial-word completion: example(zstyle ':completion:*' completer _complete _correct _complete:foo -zstyle ':completion:*:complete:*' matcher-list \ +zstyle ':completion:*:complete:*:*:*' matcher-list \ '' 'm:{a-zA-Z}={A-Za-z}' -zstyle ':completion:*:foo:*' matcher-list \ +zstyle ':completion:*:foo:*:*:*' matcher-list \ 'm:{a-zA-Z}={A-Za-z} r:|[-_./]=* r:|=*') If the style is unset in any context no match specification is applied. @@ -2581,7 +2586,7 @@ an exception to this behavior.) For example: -example(zstyle ':completion:*:complete:-command-:*' tag-order \ +example(zstyle ':completion:*:complete:-command-:*:*' tag-order \ 'commands functions') specifies that completion in command position first offers @@ -2640,7 +2645,7 @@ repeat them all. For example, to make completion of function names in command position ignore all the completion functions starting with an underscore the first time completion is tried: -example(zstyle ':completion:*:*:-command-:*' tag-order \ +example(zstyle ':completion:*:*:-command-:*:*' tag-order \ 'functions:-non-comp *' functions zstyle ':completion:*:functions-non-comp' ignored-patterns '_*') @@ -2676,7 +2681,7 @@ try normal completion without any match specification and, if that generates no matches, try again with case-insensitive matching, restricting the effect to arguments of the command tt(foo): -example(zstyle ':completion:*:*:foo:*' tag-order '*' '*:-case' +example(zstyle ':completion:*:*:foo:*:*' tag-order '*' '*:-case' zstyle ':completion:*-case' matcher 'm:{a-z}={A-Z}') First, all the tags offered when completing after tt(foo) are tried using -- cgit v1.2.3 From 3a99ef322dafcd2cf833b2a0668436ac120df1b3 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 15 Jan 2015 13:52:08 +0000 Subject: 34280: more widespread use of FORCE_FLOAT. Add the case of variables read for use in arithmetic expressions. --- ChangeLog | 4 ++++ Doc/Zsh/options.yo | 7 ++++--- Src/math.c | 13 ++++++++++++- Test/C01arith.ztst | 10 ++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index ce150381b..1da768569 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-01-15 Peter Stephenson + * 34280: Doc/Zsh/options.yo, Src/math.c, Test/C01arith.ztst: + make FORCE_FLOAT option also cover variables when read for + use in arithmetic expressions. + * 34287 (see 34286 from Markus Trippelsdorf): Src/zsh.mdd: use -E argument for generating signal names if gcc is preprocessor. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 076aaf44f..8a0222cfd 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -496,9 +496,10 @@ pindex(NOFORCEFLOAT) cindex(floating point, forcing use of) cindex(forcing use of floating point) item(tt(FORCE_FLOAT))( -Constants in arithmetic evaluation will be treated as floating point -even without the use of a decimal point. Integers in any base -will be converted. +Constants in arithmetic evaluation will be treated as +floating point even without the use of a decimal point; the +values of integer variables will be converted to floating point when +used in arithmetic expressions. Integers in any base will be converted. ) pindex(GLOB) pindex(NO_GLOB) diff --git a/Src/math.c b/Src/math.c index db42d0f7c..c047725c5 100644 --- a/Src/math.c +++ b/Src/math.c @@ -336,16 +336,27 @@ enum prec_type { static mnumber getmathparam(struct mathvalue *mptr) { + mnumber result; if (!mptr->pval) { char *s = mptr->lval; mptr->pval = (Value)zhalloc(sizeof(struct value)); if (!getvalue(mptr->pval, &s, 1)) { mptr->pval = NULL; + if (isset(FORCEFLOAT)) { + result.type = MN_FLOAT; + result.u.d = 0.0; + return result; + } return zero_mnumber; } } - return getnumvalue(mptr->pval); + result = getnumvalue(mptr->pval); + if (isset(FORCEFLOAT) && result.type == MN_INTEGER) { + result.type = MN_FLOAT; + result.u.d = (double)result.u.l; + } + return result; } static mnumber diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst index 8e0730d8d..ea87af257 100644 --- a/Test/C01arith.ztst +++ b/Test/C01arith.ztst @@ -308,3 +308,13 @@ >2 >2 # It's hard to test for integer to float. + + integer ff1=3 ff2=4 + print $(( ff1/ff2 )) + setopt force_float + print $(( ff1/ff2 )) + unsetopt force_float +0:Variables are forced to floating point where necessary +# 0.75 is exactly representable, don't expect rounding error. +>0 +>0.75 -- cgit v1.2.3 From 0e3548994ee351a317c73c88e6c83e5e9e123f9d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 20 Jan 2015 17:31:28 +0000 Subject: 34329: add -S option to which and where --- ChangeLog | 3 +++ Doc/Zsh/builtins.yo | 4 ++-- Src/builtin.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 4b6262867..da9547d2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-01-20 Peter Stephenson + * 34329: Doc/Zsh/builtins.yo, Src/builtin.c: add -S option + to which and where. + * users/19756: Test/A04redirect.ztst: add test for case of closing file descriptor with no error message. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 49c2c11c3..dc3937108 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -2139,11 +2139,11 @@ symlink resolved at each step might be anywhere in the path. enditem() ) findex(where) -item(tt(where) [ tt(-wpms) ] var(name) ...)( +item(tt(where) [ tt(-wpmsS) ] var(name) ...)( Equivalent to tt(whence -ca). ) findex(which) -item(tt(which) [ tt(-wpams) ] var(name) ...)( +item(tt(which) [ tt(-wpamsS) ] var(name) ...)( Equivalent to tt(whence -c). ) findex(zcompile) diff --git a/Src/builtin.c b/Src/builtin.c index 9258ddb6e..1818941b2 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -129,8 +129,8 @@ static struct builtin builtins[] = BUILTIN("unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL), BUILTIN("wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL), BUILTIN("whence", 0, bin_whence, 0, -1, 0, "acmpvfsSw", NULL), - BUILTIN("where", 0, bin_whence, 0, -1, 0, "pmsw", "ca"), - BUILTIN("which", 0, bin_whence, 0, -1, 0, "ampsw", "c"), + BUILTIN("where", 0, bin_whence, 0, -1, 0, "pmsSw", "ca"), + BUILTIN("which", 0, bin_whence, 0, -1, 0, "ampsSw", "c"), BUILTIN("zmodload", 0, bin_zmodload, 0, -1, 0, "AFRILP:abcfdilmpue", NULL), BUILTIN("zcompile", 0, bin_zcompile, 0, -1, 0, "tUMRcmzka", NULL), }; -- cgit v1.2.3 From 9d25fd72553caff0008d35670544c0ab909c0224 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 24 Jan 2015 06:41:42 +0000 Subject: vcs_info hg: Support inactive bookmarks (Similar to git detached heads) --- ChangeLog | 6 ++++++ Doc/Zsh/contrib.yo | 7 +++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 04f46611b..2ca32cec1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-01-25 Daniel Shahaf + + * Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: vcs_info hg: + Support inactive bookmarks + 2015-01-23 Jun-ichi Takimoto * 34335: _yum: fix bugs in _yum_all_pkgs diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 00ede52aa..80a799766 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -927,6 +927,10 @@ kindex(get-bookmarks) item(tt(get-bookmarks))( If set to true, the tt(hg) backend will try to get a list of current bookmarks. They will be available via the `tt(%m)' replacement. + +The default is to generate a comma-separated list of all bookmark names +that refer to the currently checked out revision. If a bookmark is active, +its name is suffixed an asterisk and placed first in the list. ) kindex(use-prompt-escapes) item(tt(use-prompt-escapes))( @@ -1290,6 +1294,9 @@ tt(get-revision) and tt(get-bookmarks) styles must be true. This hook gets the names of the Mercurial bookmarks that tt(vcs_info) collected from `hg'. +If a bookmark is active, the key tt(${hook_com[hg-active-bookmark]}) is +set to its name. The key is otherwise unset. + When setting tt(ret) to non-zero, the string in tt(${hook_com[hg-bookmark-string]}) will be used in the tt(%m) escape in tt(formats) and tt(actionformats) and will be available in the global diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index cedaf5676..1274ca337 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -6,6 +6,7 @@ setopt localoptions extendedglob NO_shwordsplit local hgbase bmfile branchfile rebasefile dirstatefile mqseriesfile \ + curbmfile curbm \ mqstatusfile mqguardsfile patchdir mergedir \ r_csetid r_lrev r_branch i_bmhash i_bmname \ revformat branchformat hgactionstring hgchanges \ @@ -24,6 +25,7 @@ r_lrev='' # local revision patchdir="${hgbase}/.hg/patches" mergedir="${hgbase}/.hg/merge/" bmfile="${hgbase}/.hg/bookmarks" +curbmfile="${hgbase}/.hg/bookmarks.current" branchfile="${hgbase}/.hg/branch" rebasefile="${hgbase}/.hg/rebasestate" dirstatefile="${hgbase}/.hg/dirstate" @@ -125,8 +127,23 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-bookmarks \ [[ $i_bmhash == $r_csetid* ]] && hgbmarks+=( $i_bmname ) done < ${bmfile} + if [[ -r "$curbmfile" ]] ; then + curbm=$(<"${curbmfile}") + hook_com[hg-active-bookmark]=$curbm + else + # leave curbm empty and [hg-active-bookmark] undefined. + fi + if VCS_INFO_hook 'gen-hg-bookmark-string' "${hgbmarks[@]}"; then + # If there is an active bookmark, annotate it and put it first. + if [[ -n $curbm ]] ; then + hgbmarks[(i)$curbm]=() + hgbmarks[1,0]="${curbm}*" + fi hgbmstring=${(j:, :)hgbmarks} + # Deannotate the array, in case later code expects it to be valid. + # (The order is not restored.) + [[ -n $curbm ]] && hgbmarks[1]=${${hgbmarks[1]}[1,-2]} else hgbmstring=${hook_com[hg-bookmark-string]} fi -- cgit v1.2.3 From 5a1fdc0f1ca4f2a1de74d9c9a1ddd6e25c7643f7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Jan 2015 15:20:49 +0100 Subject: 34381: vcs_info: Documentation update This adds documentation for more hooks and styles available in vcs_info: - patch-format - nopatch-format - get-unapplied - pre-addon-quilt - set-patch-format --- ChangeLog | 4 ++++ Doc/Zsh/contrib.yo | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 38f8e3f69..60bb7a8a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-01-25 Daniel Shahaf + + * 34381: Doc/Zsh/contrib.yo: vcs_info: Documentation update + 2015-01-25 Frank Terbeck * unposted: ChangeLog: Forgot X-Seq: numbers with Daniel's last diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 80a799766..120efa20f 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -948,6 +948,21 @@ item(tt(hooks))( A list style that defines hook-function names. See bf(Hooks in vcs_info) below for details. ) +kindex(patch-format) +kindex(nopatch-format) +xitem(tt(patch-format)) +item(tt(nopatch-format))( +This pair of styles format the patch information used by the tt(%m) expando in +formats and actionformats for the tt(git) and tt(hg) backends. The value is +subject to certain tt(%)-expansions described below. +) +kindex(get-unapplied) +item(tt(get-unapplied))( +This boolean style controls whether a backend should attempt to gather a list +of unapplied patches (for example with Mercurial Queue patches). + +Used by the tt(quilt) and tt(hg) backends. +) enditem() The default values for these styles in all contexts are: @@ -979,6 +994,9 @@ sitem(tt(use-quilt))(false) sitem(tt(quilt-standalone))(false) sitem(tt(quilt-patch-dir))(empty - use tt($QUILT_PATCHES)) sitem(tt(quiltcommand))(quilt) +sitem(tt(patch-format))(var(backend dependent)) +sitem(tt(nopatch-format))(var(backend dependent)) +sitem(tt(get-unapplied))(false) endsitem() In normal tt(formats) and tt(actionformats) the following replacements are @@ -1000,11 +1018,26 @@ sitem(tt(%r))(The repository name. If tt(%R) is tt(/foo/bar/repoXY), tt(%r) is tt(repoXY).) sitem(tt(%S))(A subdirectory within a repository. If tt($PWD) is tt(/foo/bar/repoXY/beer/tasty), tt(%S) is tt(beer/tasty).) -sitem(tt(%m))(A "misc" replacement. It is at the discretion of the backend to -decide what this replacement expands to. It is currently used by the tt(hg) -and tt(git) backends to display patch information from the tt(mq) and -tt(stgit) extensions.) endsitem() +startitem() +item(tt(%m))( +A "misc" replacement. It is at the discretion of the backend to +decide what this replacement expands to. + +The tt(hg) and tt(git) backends use this expando to display patch information. +tt(hg) sources patch information from the tt(mq) extensions; tt(git) from the +tt(rebase) command and from the and tt(stgit) extension. The tt(patch-format) +and tt(nopatch-format) styles control the generated string. The former is used +when at least one patch from the patch queue has been applied, and the latter +otherwise. + +The tt(hg) backend displays bookmark information in this expando (in addition +to tt(mq) information). See the tt(get-mq) and tt(get-bookmarks) styles. Both +of these styles may be enabled at the same time. If both are enabled, both +resulting strings will be shown separated by a semicolon (that cannot currently +be customized). +) +enditem() In tt(branchformat) these replacements are done: @@ -1384,6 +1417,30 @@ If tt(ret) is set to non-zero, the string in tt(${hook_com[rev-replace]}) will be used unchanged as the `tt(%i)' replacement in the variables set by tt(vcs_info). ) +item(tt(pre-addon-quilt))( +This hook is used when tt(vcs_info)'s quilt functionality is active in "addon" +mode (quilt used on top of a real version control system). It is activated +right before any quilt specific action is taken. + +Setting the `tt(ret)' variable in this hook to a non-zero value avoids the +quilt specific to be run at all. +) +item(tt(set-patch-format))( +This hook is used to control some of the possible expansions in +tt(patch-format) and tt(nopatch-format) styles with patch queue systems such as +quilt, mqueue and the like. + +This hook is used in the tt(git), tt(hg) and tt(quilt) backends. + +The hook allows the control of the tt(%p) (tt(${hook_com[applied]})) and tt(%u) +(tt(${hook_com[unapplied]})) expansion in all backends that use the hook. With +the mercurial backend, the tt(%g) (tt(${hook_com[guards]})) expansion is +controllable in addition to that. + +If tt(ret) is set to non-zero, the string in tt(${hook_com[patch-replace]}) +will be used unchanged instead of an expanded format from tt(patch-format) or +tt(nopatch-format). +) item(tt(set-message))( Called each time before a `tt(vcs_info_msg_N_)' message is set. It takes two arguments; the first being the `N' in the message -- cgit v1.2.3 From f972b023a20e9fb67b2693ab7c5936d5c545fe55 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 25 Jan 2015 18:22:53 +0100 Subject: 34373, 34374: update completion of builtin commands, modifiers, parameter and globbing flags --- ChangeLog | 13 ++++ Completion/Unix/Command/_chown | 2 +- Completion/Unix/Command/_ln | 2 +- Completion/Unix/Type/_directories | 2 +- Completion/Zsh/Command/_command | 15 ++--- Completion/Zsh/Command/_fc | 86 +++++++++++++++++++------ Completion/Zsh/Command/_typeset | 2 +- Completion/Zsh/Command/_unhash | 11 +--- Completion/Zsh/Command/_which | 3 +- Completion/Zsh/Command/_zle | 8 ++- Completion/Zsh/Command/_zstyle | 2 +- Completion/Zsh/Context/_brace_parameter | 110 ++++++++++++++++++-------------- Completion/Zsh/Context/_subscript | 2 +- Completion/Zsh/Type/_globflags | 11 +++- Completion/Zsh/Type/_history_modifiers | 1 + Doc/Zsh/builtins.yo | 2 +- 16 files changed, 179 insertions(+), 93 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 60bb7a8a4..f11eebe4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2015-01-25 Oliver Kiddle + + * 34373, 34374: Completion/Unix/Command/_chown, + Completion/Unix/Command/_ln, Completion/Unix/Type/_directories, + Completion/Zsh/Command/_command, Completion/Zsh/Command/_fc, + Completion/Zsh/Command/_typeset, Completion/Zsh/Command/_unhash, + Completion/Zsh/Command/_which, Completion/Zsh/Command/_zle, + Completion/Zsh/Command/_zstyle, Completion/Zsh/Context/_subscript, + Completion/Zsh/Type/_globflags, Doc/Zsh/builtins.yo, + Completion/Zsh/Context/_brace_parameter, + Completion/Zsh/Type/_history_modifiers: update completion of + builtin commands, modifiers, parameter and globbing flags + 2015-01-25 Daniel Shahaf * 34381: Doc/Zsh/contrib.yo: vcs_info: Documentation update diff --git a/Completion/Unix/Command/_chown b/Completion/Unix/Command/_chown index b4539315d..7a7e5911c 100644 --- a/Completion/Unix/Command/_chown +++ b/Completion/Unix/Command/_chown @@ -1,4 +1,4 @@ -#compdef chown chgrp +#compdef chown chgrp zf_chown=chown zf_chgrp=chgrp local curcontext="$curcontext" state line expl ret=1 local suf usr grp req deref args diff --git a/Completion/Unix/Command/_ln b/Completion/Unix/Command/_ln index 12baf76a9..c903fee02 100644 --- a/Completion/Unix/Command/_ln +++ b/Completion/Unix/Command/_ln @@ -1,4 +1,4 @@ -#compdef ln gln +#compdef ln gln zf_ln local curcontext="$curcontext" state line ret=1 local -A opt_args diff --git a/Completion/Unix/Type/_directories b/Completion/Unix/Type/_directories index 702d31dc4..2125645fe 100644 --- a/Completion/Unix/Type/_directories +++ b/Completion/Unix/Type/_directories @@ -1,4 +1,4 @@ -#compdef rmdir dircmp -P -value-,*path,-default- +#compdef rmdir zf_rmdir dircmp -P -value-,*path,-default- local expl diff --git a/Completion/Zsh/Command/_command b/Completion/Zsh/Command/_command index 7cfb52c2f..4e2858676 100644 --- a/Completion/Zsh/Command/_command +++ b/Completion/Zsh/Command/_command @@ -1,14 +1,11 @@ #compdef command -local ret - # indicate if this is a precommand modifier [[ $service = command ]] && precommands+=(command) -if [[ CURRENT -ge 3 ]]; then - compset -n 2 - _normal && ret=0 -else - _path_commands "$@" && ret=0 -fi -return ret +_arguments \ + '-v[indicate result of command search]:*:command:_path_commands' \ + '-V[show result of command search in verbose form]:*:command:_path_commands' \ + '(-)-p[use default PATH to find command]' \ + ':command:_path_commands' \ + '*::arguments: _normal' diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc index 2af5980c2..133145670 100644 --- a/Completion/Zsh/Command/_fc +++ b/Completion/Zsh/Command/_fc @@ -1,21 +1,47 @@ #compdef fc history r +local curcontext="$curcontext" state state_descr line ret=1 +local list events num cmd +typeset -A opt_args local fc_common fc_hist fc_r +# hide any replacements from _arguments +local cur=${(M)#words[1,CURRENT-1]:#*=*} +words=( "${(@)words[1,CURRENT-1]:#*=*}" "${(@)words[CURRENT,-1]}" ) +(( CURRENT -= cur )) + fc_common=( + -s -S '(-A -R -W -I -p -P)-r[reverse order of the commands]' '(-A -R -W -I -e -p -P)-n[suppress line numbers]' - '(-A -R -W -I -p -P)*::commands:_command_names -e' ) +) + +if [[ -n ${words[(r)-[pa](|[ap])]} ]]; then + fc_common+=( + ':history file:_files' + ':history size:' + ':saved history size:' + ) + [[ -n ${words[(r)-(|a)p(|a)]} ]] || fc_common+='!-a:option:(-p)' +elif [[ -n ${words[(r)-*[ARWI]*]} ]]; then + fc_common+=( ':history file:_files' ) +else + fc_common=( -C "$fc_common[@]" + '(-)1:first event:->events' '2:last event:->events' + ) +fi fc_hist=( - '(-A -R -W -I -p -p)-m[treat first argument as a pattern]' - '(-A -R -W -I -e -f -E -i -t -p -P)-d[print time-stamps]' - '(-A -R -W -I -e -d -E -i -t -p -P)-f[mm/dd/yyyy format time-stamps]' - '(-A -R -W -I -e -d -f -i -t -p -P)-E[dd.mm.yyyy format time-stamps]' - '(-A -R -W -I -e -d -f -E -t -p -P)-i[yyyy-mm-dd format time-stamps]' - '(-A -R -W -I -e -d -f -E -i -p -P)-t[print time-stamps in specified format]:date format' - '(-A -R -W -I -e -p -P)-D[print elapsed times]' - '(- *)-p[push current history to stack]:history file:_files:history size: :saved history size' + '(-A -R -W -I -a -p -P 2)-m[treat argument as a pattern]' + '(-A -R -W -I -e -f -E -i -t -a -p -P)-d[print time-stamps]' + '(-A -R -W -I -e -d -E -i -t -a -p -P)-f[mm/dd/yyyy format time-stamps]' + '(-A -R -W -I -e -d -f -i -t -a -p -P)-E[dd.mm.yyyy format time-stamps]' + '(-A -R -W -I -e -d -f -E -t -a -p -P)-i[yyyy-mm-dd format time-stamps]' + '(-A -R -W -I -e -d -f -E -i -a -p -P)-t[print time-stamps in specified format]:date format' + '(-A -R -W -I -e -a -p -P)-D[print elapsed times]' + + '(-A -R -W -I -e -d -f -i -l -m -n -r -D -E -t -P)-a[with -p, automatically pop history on function return]' + '(-A -R -W -I -e -d -f -i -l -m -n -r -D -E -t -P)-p[push current history to stack]' '(- *)-P[pop history from stack]' ) @@ -23,18 +49,42 @@ fc_r='(-A -R -W -I -e)-l[list resulting commands on stdout]' case $service in history) - _arguments -s -S "$fc_common[@]" "$fc_hist[@]" && return 0 + _arguments "$fc_common[@]" "$fc_hist[@] && ret=0" ;; r) - _arguments -s -S "$fc_common[@]" "$fc_r" && return 0 + _arguments "$fc_common[@]" "$fc_r" && ret=0 ;; *) - _arguments -s -S \ - '(-A -R -W -I -l -n -d -f -E -i -D -p -P)-e[specify editor to invoke]:editor to invoke:_command_names -e' \ - '(-l -m -e -r -n -d -f -E -i -D -A -W -p -P *)-R[read history from file]:history file:_files' \ - '(-l -m -e -r -n -d -f -E -i -D -R -W -p -P *)-A[append history to file]:history file:_files' \ - '(-l -m -e -r -n -d -f -E -i -D -R -A -p -P *)-W[write history to file]:history file:_files' \ - '(-l -m -e -r -n -d -f -E -i -D -A -W -p -P *)-I[read/write new events only]:history file:_files' \ - "$fc_common[@]" "$fc_hist[@]" "$fc_r" && return 0 + _arguments "$fc_common[@]" "$fc_hist[@]" "$fc_r" \ + '(-A -R -W -I -a -l -n -d -f -E -i -r -t -D -p -P)-e+[specify editor to invoke]:editor to invoke:_command_names -e' \ + '(-a -l -m -e -r -n -d -f -t -E -i -R -D -A -W -p -P *)-'{\ +'R[read history from file]',\ +'A[append history to file]',\ +'W[write history to file]',\ +'I[read/write new events only]'} && ret=0 ;; esac + +if [[ -n $state ]]; then + if [[ -z ${line:#*=*} ]] && compset -P '*='; then + _message -e replacements 'replacement' + elif [[ -prefix [0-9] ]]; then + events=( ${(ps.\0.)"$(printf '%s:%s\0' ${(kv)history})"} ) + zformat -a list " -- " "$events[@]" + _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld list - \ + "${events[@]%%:*}" + elif [[ -prefix - ]]; then + for num cmd in ${(kv)history}; do + (( num=num - HISTNO )) + events+=( $num:$cmd ) + done + zformat -a list " -- " "$events[@]" + _wanted -2V events expl "$state_descr" compadd -ld list - \ + "${events[@]%%:*}" + else + _wanted events expl "$state_descr" compadd -S '' - \ + ${${history%%[=[:IFS:]]*}:#[0-9-]*} || _guard "[0-9]#" event + fi +fi && ret=0 + +return ret diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset index 367dbfc23..4e29c23e7 100644 --- a/Completion/Zsh/Command/_typeset +++ b/Completion/Zsh/Command/_typeset @@ -46,7 +46,7 @@ use="AEFHLRTUZafghiklmprtuxz" case ${service} in autoload) - use="UXktwz" + use="UTXktwz" func=f ;; float) use="EFHghlprtux";; diff --git a/Completion/Zsh/Command/_unhash b/Completion/Zsh/Command/_unhash index c05c27ea3..ff0c03f49 100644 --- a/Completion/Zsh/Command/_unhash +++ b/Completion/Zsh/Command/_unhash @@ -1,14 +1,9 @@ #compdef unhash -local expl state line curcontext="$curcontext" - -_arguments -C -s -S \ - '(-a -f -s *)-d[remove named directories]:*:named directory:->nameddir' \ +_arguments -s -S \ + '(-a -f -s *)-d[remove named directories]:*:named directory:compadd -k nameddirs' \ '(-d -f -s *)-a[remove aliases]:*:alias:_aliases' \ '(-a -d -f *)-s[remove suffix aliases]:*:suffix alias:_aliases -s s' \ '(-d -a -s *)-f[remove functions]:*:shell function:_functions' \ '-m[treat arguments as patterns]' \ - '(-a -d -f -m)*:command: _command_names -e' && return 0 - -[[ "$state" = nameddir ]] && - _wanted named-directories expl 'named directory' compadd -k nameddirs + '(-a -d -f -m)*:command: _command_names -e' diff --git a/Completion/Zsh/Command/_which b/Completion/Zsh/Command/_which index 07ede39fd..c43704ae8 100644 --- a/Completion/Zsh/Command/_which +++ b/Completion/Zsh/Command/_which @@ -6,7 +6,8 @@ cargs=( \ '(-v -c)-w[print command type]' \ '-p[always do a path search]' \ '-m[treat the arguments as patterns]' \ - '-s[print symlink free path as well]' \ + '(-S)-s[print symlink free path as well]' \ + '(-s)-S[show steps in the resolution of symlinks]' \ '*:commands:->command' ) farg='-f[output contents of functions]' aarg='-a[print all occurrences in path]' diff --git a/Completion/Zsh/Command/_zle b/Completion/Zsh/Command/_zle index 2bfc708e5..3ed373348 100644 --- a/Completion/Zsh/Command/_zle +++ b/Completion/Zsh/Command/_zle @@ -13,20 +13,24 @@ compwids=(accept-and-menu-complete menu-expand-or-complete reverse-menu-complete) -opts=(-A -C -D -L -M -N -R -U -a -c -l \* :) +opts=(-A -C -D -F -L -M -N -R -T -U -a -c -l -r \* :) _arguments -s -S \ "($opts)-A[define widget alias]:old widget:->widget :new widget:->widget" \ "($opts)-C[define completion widget]:new widget name:->comp-widget :completion widget:->builtin-comp-widget :widget shell function:->function" \ "($opts)-D[delete widget]:*:widget:->widget" \ - \(${(j. .)opts:#-l}')-L[with -l, list as commands]' \ + \(${(j. .)opts:#-[lFT]}')-L[with -l, list as commands]' \ \(${(j. .)opts:#-[La]}')-l+[list user-defined widgets]:*:-:->listing' \ \(${(j. .)opts:#-l}')-a[with -l, list all widgets]' \ + "(: * ${(j. .)opts:#-[Lw]})-F[install file descriptor handler]:file descriptor:_file_descriptors::handler:_functions" \ + "!($opts)-K:keymap:compadd -a keymaps" \ "($opts)-M[display message]:message: " \ "($opts)-N[define new widget]:widget name:->widget-or-function ::widget shell function:->function" \ \(${(j. .)opts:#-c}')-R+[redisplay]:*:-:->redisplay' \ \(${(j. .)opts:#-R}')-c[with -R, clear listing]' \ "($opts)-U[unget to input stack]:string: " \ + '(: *)-T[manipulate transformations]:transformation:(tc):function:_functions' \ + \(${(j. .)opts:#-T}')-r[remove transformations]' \ '(-):widget:->widget' \ '(-)*::widget args:->args' && ret=0 diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index 2ebae7132..8f6c412cc 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -322,7 +322,7 @@ while (( $#state )); do (cmdorcont) _alternative -O suf \ - 'commands:command:_command ' \ + 'commands:command:_path_commands' \ 'contexts:context:(-array-value- -brace-parameter- -command- -condition- -math- -parameter- -redirect- -subscript- -value-)' ;; diff --git a/Completion/Zsh/Context/_brace_parameter b/Completion/Zsh/Context/_brace_parameter index 2aeb12bf4..fcca4bf84 100644 --- a/Completion/Zsh/Context/_brace_parameter +++ b/Completion/Zsh/Context/_brace_parameter @@ -104,9 +104,9 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then done if [[ -z $found_percent ]]; then - flags=("%:Expand prompt sequences") + flags=("%:expand prompt sequences") else - flags=("%:Expand prompts respecting options") + flags=("%:expand prompts respecting options") fi case $q_last in (0) @@ -134,58 +134,74 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then flags+=("Q:remove one level of quoting") fi if [[ -z $found_m ]]; then - flags+=("m:Count multibyte width in padding calculation") + flags+=("m:count multibyte width in padding calculation") else - flags+=("m:Count number of character code points in padding calculation") + flags+=("m:count number of character code points in padding calculation") fi flags+=( - "#:Evaluate as numeric expression" - "@:Double-quoted splitting of scalars" - "A:Create array parameter" - "a:Sort in array index order (with O to reverse)" - "c:Count characters in an array (with \${(c)#...})" - "C:Capitalize words" - "D:Perform directory name abbreviation" - "e:Perform single-word shell expansions" - "f:Split the result on newlines" - "F:Join arrays with newlines" - "g:Process echo array sequences (needs options)" - "i:Sort case-insensitively" - "k:Subsitute keys of associative arrays" - "L:Lower case all letters" - "n:Sort decimal integers numerically" - "o:Sort in ascending order (lexically if no other sort option)" - "O:Sort in descending order (lexically if no other sort option)" - "P:Use parameter value as name of parameter for redirected lookup" - "t:Substitute type of parameter" - "u:Substitute first occurrence of each unique word" - "U:Upper case all letters" - "v:Substitute values of associative arrays (with (k))" - "V:Visibility enhancements for special characters" - "w:Count words in array or string (with \${(w)#...})" - "W:Count words including empty words (with \${(W)#...})" - "X:Report parsing errors and eXit substitution" - "z:Split words as if zsh command line" - "0:Split words on null bytes" - "p:Handle print escapes in parameter flag arguments" - "~:Treat strings in parameter flag arguments as patterns" - "j:Join arrays with specified string" - "l:Left-pad resulting words" - "r:Right-pad resulting words" - "s:Split words on specified string" - "Z:Split words as if zsh command line (with options)" - # "_:Extended flags, for future expansion" - "S:Search substrings in #, %, / expressions" - "I:Search th match in #, %, / expressions" - "B:Include index of beginning of match in #, %, / expressions" - "E:Include index of end of match in #, %, / expressions" - "M:Include matched portion in #, %, / expressions" - "N:Include length of match in #, %, expressions" - "R:Include rest (unmatched portion) in #, %, / expressions" + "#:evaluate as numeric expression" + "@:double-quoted splitting of scalars" + "A:create array parameter" + "a:sort in array index order (with O to reverse)" + "c:count characters in an array (with \${(c)#...})" + "C:capitalize words" + "D:perform directory name abbreviation" + "e:perform single-word shell expansions" + "f:split the result on newlines" + "F:join arrays with newlines" + "g:process echo array sequences (needs options)" + "i:sort case-insensitively" + "k:subsitute keys of associative arrays" + "L:lower case all letters" + "n:sort decimal integers numerically" + "o:sort in ascending order (lexically if no other sort option)" + "O:sort in descending order (lexically if no other sort option)" + "P:use parameter value as name of parameter for redirected lookup" + "t:substitute type of parameter" + "u:substitute first occurrence of each unique word" + "U:upper case all letters" + "v:substitute values of associative arrays (with (k))" + "V:visibility enhancements for special characters" + "w:count words in array or string (with \${(w)#...})" + "W:count words including empty words (with \${(W)#...})" + "X:report parsing errors and eXit substitution" + "z:split words as if zsh command line" + "0:split words on null bytes" + "p:handle print escapes or variables in parameter flag arguments" + "~:treat strings in parameter flag arguments as patterns" + "j:join arrays with specified string" + "l:left-pad resulting words" + "r:right-pad resulting words" + "s:split words on specified string" + "Z:split words as if zsh command line (with options)" + # "_:extended flags, for future expansion" + "S:search substrings in #, %, / expressions" + "I:search th match in #, %, / expressions" + "B:include index of beginning of match in #, %, / expressions" + "E:include index of end of match in #, %, / expressions" + "M:include matched portion in #, %, / expressions" + "N:include length of match in #, % expressions" + "R:include rest (unmatched portion) in #, %, / expressions" ) _describe -t flags "parameter flag" flags -Q -S '' return +elif compset -P '*:([\|\*\^]|\^\^)'; then + _arrays + return elif compset -P '*:'; then + flags=( + '-:substitute alternate value if parameter is null' + '+:susbtitute alternate value if parameter is non-null' + '=:substitute and assign alternate value if parameter is null' + '\:=:unconditionally assign value to parameter' + '?:print error if parameter is set and non-null' + '#:filter value matching pattern' + '|:set difference' + '*:set intersection' + '^:zip arrays' + '^^:zip arrays reusing values from shorter array' + ) + _describe -t flags "operator" flags -Q -S '' _history_modifiers p return fi diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript index cf1ec49a4..0ccc0c4ef 100644 --- a/Completion/Zsh/Context/_subscript +++ b/Completion/Zsh/Context/_subscript @@ -23,7 +23,7 @@ if [[ $BUFFER[1,pos-1] = (|*[[:space:]:=]##)\~\[ ]]; then elif [[ "$PREFIX" = :* ]]; then _wanted characters expl 'character class' \ compadd -p: -S ':]' alnum alpha ascii blank cntrl digit graph \ - lower print punct space upper xdigit + lower print punct space upper xdigit IFS IDENT IFSSPACE WORD elif compset -P '\('; then local match compset -S '\)*' diff --git a/Completion/Zsh/Type/_globflags b/Completion/Zsh/Type/_globflags index ca665466b..5833dc8f1 100644 --- a/Completion/Zsh/Type/_globflags +++ b/Completion/Zsh/Type/_globflags @@ -4,11 +4,17 @@ local ret=1 local -a flags if compset -P a; then - _message -e numbers 'errors' + _message -e number 'errors' return elif compset -P q; then _globquals return +elif compset -P 'c[0-9]##,'; then + _message -e number 'max repetitions' + return +elif compset -P c; then + _message -e number 'repetitions (min or exact)' + return fi flags=( @@ -17,6 +23,8 @@ flags=( 'I:case sensitive matching' 's:match start of string' 'e:match end of string' + 'U:consider all characters to be one byte' + 'u:support multibyte characters in pattern' ) [[ $compstate[context] = condition ]] && flags+=( 'b:activate backreferences' @@ -29,6 +37,7 @@ _describe -t globflags "glob flag" flags -Q -S ')' && ret=0 flags=( 'a:approximate matching' 'q:introduce glob qualifier' + 'c:match repetitions of preceding pattern' ) _describe -t globflags "glob flag" flags -Q -S '' && ret=0 diff --git a/Completion/Zsh/Type/_history_modifiers b/Completion/Zsh/Type/_history_modifiers index f8dcd45ae..658f9f346 100644 --- a/Completion/Zsh/Type/_history_modifiers +++ b/Completion/Zsh/Type/_history_modifiers @@ -66,6 +66,7 @@ while true; do list+=( "a:absolute path" "A:absolute path resolving symbolic links" + "c:PATH search for command" "g:globally apply s or &" "h:head - strip trailing path element" "t:tail - strip directories" diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index dc3937108..f3bcc3564 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -142,7 +142,7 @@ ifnzman(noderef(Aliasing)). findex(autoload) cindex(functions, autoloading) cindex(autoloading functions) -item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(UXkmtz) ] [ tt(-w) ] [ var(name) ... ])( +item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(TUXkmtz) ] [ tt(-w) ] [ var(name) ... ])( Equivalent to tt(functions -u), with the exception of tt(-X)/tt(+X) and tt(-w). -- cgit v1.2.3 From 2fa11b7c54d766d6987fb5c0008f8209e6a2529f Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 24 Jan 2015 09:42:20 -0800 Subject: 34350, 34353: document zsh/db/gdbm module, clean up a few things in the code Still core dumps at this revision if the tied parameter is forced to be a local and is not untied before end of scope. --- ChangeLog | 7 +++++++ Doc/Makefile.in | 2 +- Doc/Zsh/mod_db_gdbm.yo | 27 +++++++++++++++++++++++++++ Src/Modules/db_gdbm.c | 49 +++++++++++++++++++++++++++++-------------------- 4 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 Doc/Zsh/mod_db_gdbm.yo (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 5b3cbdf9f..96268c795 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,13 @@ * 34368: Completion/Zsh/Command/_zstyle: _zstyle vcs_info completion: Add missing styles +2015-01-24 Barton E. Schaefer + + * 34350, 34353: Doc/Makefile.in, Doc/Zsh/mod_db_gdbm.yo, + Src/Modules/db_gdbm.c: document zsh/db/gdbm module, clean up a few + things in the code. Still core dumps if the tied parameter is + forced to be a local and is not untied before end of scope. + 2015-01-23 Jun-ichi Takimoto * 34335: _yum: fix bugs in _yum_all_pkgs diff --git a/Doc/Makefile.in b/Doc/Makefile.in index 41af4a33e..a420781ee 100644 --- a/Doc/Makefile.in +++ b/Doc/Makefile.in @@ -60,7 +60,7 @@ MODDOCSRC = \ Zsh/mod_attr.yo Zsh/mod_cap.yo Zsh/mod_clone.yo \ Zsh/mod_compctl.yo Zsh/mod_complete.yo Zsh/mod_complist.yo \ Zsh/mod_computil.yo Zsh/mod_curses.yo \ -Zsh/mod_datetime.yo Zsh/mod_deltochar.yo \ +Zsh/mod_datetime.yo Zsh/mod_db_gdbm.yo Zsh/mod_deltochar.yo \ Zsh/mod_example.yo Zsh/mod_files.yo Zsh/mod_langinfo.yo \ Zsh/mod_mapfile.yo Zsh/mod_mathfunc.yo Zsh/mod_newuser.yo \ Zsh/mod_parameter.yo Zsh/mod_pcre.yo Zsh/mod_regex.yo \ diff --git a/Doc/Zsh/mod_db_gdbm.yo b/Doc/Zsh/mod_db_gdbm.yo new file mode 100644 index 000000000..6065f860e --- /dev/null +++ b/Doc/Zsh/mod_db_gdbm.yo @@ -0,0 +1,27 @@ +COMMENT(!MOD!zsh/db/gdbm +Builtins for managing associative array parameters tied to GDBM databases. +!MOD!) +The tt(zsh/db/gdbm) module is used to create "tied" associative arrays +that interface to database files. If the GDBM interface is not available, +the builtins defined by this module will report an error. This module is +also intended as a prototype for creating additional database interfaces, +so the tt(ztie) builtin may move to a more generic module in the future. + +The builtins in this module are: + +startitem() +findex(ztie) +cindex(tied array, creating) +item(tt(ztie -d db/gdbm -f) var(filename) var(arrayname))( +Open the GDBM database identified by var(filename) and, if successful, +create the associative array var(arrayname) linked to the file. Note +that var(arrayname) must be unset at the time tt(ztie) is called, and +is always created as a global parameter (as if with `tt(typeset -g)'). +) +findex(zuntie) +cindex(tied array, destroying) +item(tt(zuntie) var(arrayname) ...)( +Close the GDBM database associated with each var(arrayname) and then +unset the variable. +) +enditem() diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index 9a2a7a5b9..f079094c0 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -39,9 +39,7 @@ #include -#if 0 /* what is this for? */ static char *backtype = "db/gdbm"; -#endif static const struct gsu_scalar gdbm_gsu = { gdbmgetfn, gdbmsetfn, gdbmunsetfn }; @@ -60,33 +58,38 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) Param tied_param; if(!OPT_ISSET(ops,'d')) { - zwarnnam(nam, "you must pass `-d db/gdbm' to ztie", NULL); + zwarnnam(nam, "you must pass `-d %s'", backtype); return 1; } if(!OPT_ISSET(ops,'f')) { - zwarnnam(nam, "you must pass `-f' with a filename to ztie", NULL); + zwarnnam(nam, "you must pass `-f' with a filename", NULL); return 1; } /* Here should be a lookup of the backend type against * a registry. */ + if (strcmp(OPT_ARG(ops, 'd'), backtype) != 0) { + zwarnnam(nam, "unsupported backend type `%s'", OPT_ARG(ops, 'd')); + return 1; + } pmname = ztrdup(*args); resource_name = OPT_ARG(ops, 'f'); - if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, 0))) { - zwarnnam(nam, "cannot create the requested parameter name", NULL); - return 1; - } - dbf = gdbm_open(resource_name, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, 0); if(!dbf) { zwarnnam(nam, "error opening database file %s", resource_name); return 1; } + if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, 0))) { + zwarnnam(nam, "cannot create the requested parameter %s", pmname); + gdbm_close(dbf); + return 1; + } + tied_param->u.hash->tmpdata = (void *)dbf; return 0; @@ -98,19 +101,25 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func)) { Param pm; GDBM_FILE dbf; - - pm = (Param) paramtab->getnode(paramtab, args[0]); - if(!pm) { - zwarnnam(nam, "cannot untie %s", args[0]); - return 1; + char *pmname; + int ret = 0; + + for (pmname = *args; *args++; pmname = *args) { + pm = (Param) paramtab->getnode(paramtab, pmname); + if(!pm) { + zwarnnam(nam, "cannot untie %s", pmname); + ret = 1; + continue; + } + + dbf = (GDBM_FILE)(pm->u.hash->tmpdata); + gdbm_close(dbf); + /* free(pm->u.hash->tmpdata); */ + pm->u.hash->tmpdata = NULL; + paramtab->removenode(paramtab, pm->node.nam); } - dbf = (GDBM_FILE)(pm->u.hash->tmpdata); - gdbm_close(dbf); -/* free(pm->u.hash->tmpdata); */ - paramtab->removenode(paramtab, pm->node.nam); - - return 0; + return ret; } /**/ -- cgit v1.2.3 From 88c7badb8b0c06999b1b60495bd6778e183ee34d Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Tue, 27 Jan 2015 21:08:02 +0100 Subject: 34419: vcs_info documentation: Fix wording As suggested by Daniel Shahaf. --- ChangeLog | 4 ++++ Doc/Zsh/contrib.yo | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 4f8fdf8da..728b80503 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-01-27 Frank Terbeck + + * 34419: Doc/Zsh/contrib.yo: vcs_info documentation: Fix wording + 2015-01-27 Peter Stephenson * Daniel Shahaf: 34412: Completion/Unix/Command/_chown: complete diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 120efa20f..4f6c437c9 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1422,8 +1422,8 @@ This hook is used when tt(vcs_info)'s quilt functionality is active in "addon" mode (quilt used on top of a real version control system). It is activated right before any quilt specific action is taken. -Setting the `tt(ret)' variable in this hook to a non-zero value avoids the -quilt specific to be run at all. +Setting the `tt(ret)' variable in this hook to a non-zero value avoids any +quilt specific actions from being run at all. ) item(tt(set-patch-format))( This hook is used to control some of the possible expansions in -- cgit v1.2.3 From 6558ab611b931cc9f2fbb94ddd3d4e0dbf869b3a Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Wed, 28 Jan 2015 08:04:52 -0800 Subject: 34421: clean up typeset documentation Also remove duplicated ChangeLog entry for 34365. --- ChangeLog | 8 ++-- Doc/Zsh/builtins.yo | 122 ++++++++++++++++++++++++++++++++-------------------- 2 files changed, 79 insertions(+), 51 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index a490d1be9..69e25179f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-01-28 Barton E. Schaefer + + * 34421: Doc/Zsh/builtins.yo: clean up typeset documentation + 2015-01-28 Jun-ichi Takimoto * 34415: Completion/Unix/Type/_python_modules, @@ -51,10 +55,6 @@ tty_poll(). * 34369: Daniel Shahaf: document error / warning codes. - - * 34365: configure.ac, Src/hist.c, Src/utils.c: History lockfile - backoff: randomised time. zsleep() provides microsecond - resolution for sleep. * 34383: Src/utils.c: new ztrdup() shoud be dupstring(). diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index f3bcc3564..de5700d2f 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1708,59 +1708,87 @@ newly-created parameters, or when any attribute flags listed below are given along with the var(name). Using `tt(PLUS())' instead of minus to introduce an attribute turns it off. -If the tt(-p) option is given, parameters and values are printed in the -form of a typeset command and an assignment (which will be printed -separately for arrays and associative arrays), regardless of other flags -and options. Note that the tt(-h) flag on parameters is respected; no -value will be shown for these parameters. - -If the tt(-T) option is given, two or three arguments must be present (an -exception is that zero arguments are allowed to show the list of parameters -created in this fashion). The first two are the name of a scalar and an -array parameter (in that order) that will be tied together in the manner of -tt($PATH) and tt($path). The optional third argument is a single-character -separator which will be used to join the elements of the array to form the -scalar; if absent, a colon is used, as with tt($PATH). Only the first -character of the separator is significant; any remaining characters are -ignored. Only the scalar parameter may be assigned an initial value. Both -the scalar and the array may otherwise be manipulated as normal. If one is -unset, the other will automatically be unset too. There is no way of -untying the variables without unsetting them, or converting the type of one -of them with another tt(typeset) command; tt(+T) does not work, assigning -an array to var(SCALAR) is an error, and assigning a scalar to var(array) -sets it to be a single-element array. Note that both `tt(typeset -xT ...)' -and `tt(export -T ...)' work, but only the scalar will be marked for -export. Setting the value using the scalar version causes a split on all -separators (which cannot be quoted). It is possible to use the -same two tied variables with a different separator character in which -case the variables remain joined as before but the separator is changed. -This flag has a different meaning when used with tt(-f); see below. - -The tt(-g) (global) flag is treated specially: it means that any -resulting parameter will not be restricted to local scope. Note that this -does not necessarily mean that the parameter will be global, as the flag -will apply to any existing parameter (even if unset) from an enclosing -function. This flag does not affect the parameter after creation, hence it -has no effect when listing existing parameters, nor does the flag tt(+g) -have any effect except in combination with tt(-m) (see below). - If no var(name) is present, the names and values of all parameters are printed. In this case the attribute flags restrict the display to only those parameters that have the specified attributes, and using `tt(PLUS())' rather than `tt(-)' to introduce the flag suppresses printing of the values -of parameters when there is no parameter name. Also, if the last option -is the word `tt(PLUS())', then names are printed but values are not. +of parameters when there is no parameter name. + +The following control flags change the behavior of tt(typeset): +startitem() +item(tt(PLUS()))( +If `tt(PLUS())' appears by itself in a separate word as the last option, +then the names of all parameters (functions with tt(-f)) are printed, but +the values (function bodies) are not. No var(name) arguments may appear, +and it is an error for any other options to follow `tt(PLUS())'. The +effect of `tt(PLUS())' is as if all attribute flags which precede it were +given with a `tt(PLUS())' prefix. For example, `tt(typeset -U PLUS())' is +equivalent to `tt(typeset +U)' and displays the names of all arrays having +the uniqueness attribute, whereas `tt(typeset -f -U PLUS())' displays the +names of all autoloadable functions. If tt(PLUS()) is the only option, +then type information (array, readonly, etc.) is also printed for each +parameter. +) +item(tt(-g))( +The tt(-g) (global) means that any resulting parameter will not be +restricted to local scope. Note that this does not necessarily mean that +the parameter will be global, as the flag will apply to any existing +parameter (even if unset) from an enclosing function. This flag does not +affect the parameter after creation, hence it has no effect when listing +existing parameters, nor does the flag tt(+g) have any effect except in +combination with tt(-m) (see below). +) +item(tt(-m))( If the tt(-m) flag is given the var(name) arguments are taken as patterns -(which should be quoted). With no attribute flags, all parameters (or -functions with the tt(-f) flag) with matching names are printed (the shell -option tt(TYPESET_SILENT) is not used in this case). Note that tt(-m) is -ignored if no patterns are given. If the tt(+g) flag is combined with -tt(-m), a new local parameter is created for every matching parameter that -is not already local. Otherwise tt(-m) applies all other flags or -assignments to the existing parameters. Except when assignments are made -with var(name)tt(=)var(value), using tt(+m) forces the matching parameters -to be printed, even inside a function. +(use quoting to prevent these from being interpreted as file patterns). +With no attribute flags, all parameters (or functions with the tt(-f) +flag) with matching names are printed (the shell option tt(TYPESET_SILENT) +is not used in this case). + +If the tt(+g) flag is combined with tt(-m), a new local parameter is +created for every matching parameter that is not already local. Otherwise +tt(-m) applies all other flags or assignments to the existing parameters. + +Except when assignments are made with var(name)tt(=)var(value), using +tt(+m) forces the matching parameters to be printed, even inside a +function. Note that tt(-m) is ignored if no patterns are given. +) +item(tt(-p))( +If the tt(-p) option is given, parameters and values are printed in the +form of a typeset command and an assignment (which will be printed +separately for arrays and associative arrays), regardless of other flags +and options. Note that the tt(-H) flag on parameters is respected; no +value will be shown for these parameters. +) +item(tt(-T) [ var(scalar)[tt(=)var(value)] var(array) [ var(sep) ] ])( +This flag has a different meaning when used with tt(-f); see below. +Otherwise the tt(-T) option requires zero, two, or three arguments to be +present. With no arguments, the list of parameters created in this +fashion is shown. With two or three arguments, the first two are the name +of a scalar and of an array parameter (in that order) that will be tied +together in the manner of tt($PATH) and tt($path). The optional third +argument is a single-character separator which will be used to join the +elements of the array to form the scalar; if absent, a colon is used, as +with tt($PATH). Only the first character of the separator is significant; +any remaining characters are ignored. + +Only the scalar parameter may be assigned an initial value. Both the +scalar and the array may otherwise be manipulated as normal. If one is +unset, the other will automatically be unset too. There is no way of +untying the variables without unsetting them, nor of converting the type +of one of them with another tt(typeset) command; tt(+T) does not work, +assigning an array to var(scalar) is an error, and assigning a scalar to +var(array) sets it to be a single-element array. + +Note that both `tt(typeset -xT ...)' and `tt(export -T ...)' work, but +only the scalar will be marked for export. Setting the value using the +scalar version causes a split on all separators (which cannot be quoted). +It is possible to apply tt(-T) to two previously tied variables but with a +different separator character, in which case the variables remain joined +as before but the separator is changed. +) +enditem() If no attribute flags are given and either no tt(-m) flag is present or the tt(+m) form was used, each parameter name printed is preceded by a -- cgit v1.2.3 From 22ad56296d9f2c2f57c1e6d38ad3f4b94afc9a41 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Wed, 28 Jan 2015 09:07:25 -0800 Subject: unposted: fix other typeset doc errors --- ChangeLog | 2 ++ Doc/Zsh/builtins.yo | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 69e25179f..1fe592b07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-01-28 Barton E. Schaefer + * unposted: Doc/Zsh/builtins.yo: fix other typeset doc errors + * 34421: Doc/Zsh/builtins.yo: clean up typeset documentation 2015-01-28 Jun-ichi Takimoto diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index de5700d2f..4322aff0d 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1714,6 +1714,15 @@ those parameters that have the specified attributes, and using `tt(PLUS())' rather than `tt(-)' to introduce the flag suppresses printing of the values of parameters when there is no parameter name. +If no attribute flags are given, and either no var(name) arguments are +present or the flag tt(+m) is used, then each parameter name printed is +preceded by a list of the attributes of that parameter (tt(array), +tt(association), tt(exported), tt(float), tt(integer), tt(readonly), +or tt(undefined) for autoloaded parameters not yet loaded). If tt(+m) is +used with attribute flags, and all those flags are introduced with +tt(PLUS()), the matching parameter names are printed but their values +are not. + The following control flags change the behavior of tt(typeset): startitem() @@ -1728,7 +1737,7 @@ equivalent to `tt(typeset +U)' and displays the names of all arrays having the uniqueness attribute, whereas `tt(typeset -f -U PLUS())' displays the names of all autoloadable functions. If tt(PLUS()) is the only option, then type information (array, readonly, etc.) is also printed for each -parameter. +parameter, in the same manner as `tt(typeset +m "*")'. ) item(tt(-g))( The tt(-g) (global) means that any resulting parameter will not be @@ -1751,8 +1760,10 @@ created for every matching parameter that is not already local. Otherwise tt(-m) applies all other flags or assignments to the existing parameters. Except when assignments are made with var(name)tt(=)var(value), using -tt(+m) forces the matching parameters to be printed, even inside a -function. Note that tt(-m) is ignored if no patterns are given. +tt(+m) forces the matching parameters and their attributes to be printed, +even inside a function. Note that tt(-m) is ignored if no patterns are +given, so `tt(typeset -m)' displays attributes but `tt(typeset -a +m)' +does not. ) item(tt(-p))( If the tt(-p) option is given, parameters and values are printed in the @@ -1790,13 +1801,6 @@ as before but the separator is changed. ) enditem() -If no attribute flags are given and either no tt(-m) flag is present or -the tt(+m) form was used, each parameter name printed is preceded by a -list of the attributes of that parameter (tt(array), tt(association), -tt(exported), tt(integer), tt(readonly)). If tt(+m) is used with attribute -flags, and all those flags are introduced with tt(PLUS()), the matching -parameter names are printed but their values are not. - Attribute flags that transform the final value (tt(-L), tt(-R), tt(-Z), tt(-l), tt(u)) are only applied to the expanded value at the point of a parameter expansion expression using `tt($)'. They are not applied -- cgit v1.2.3 From 3ae6fb965f260eb1aaade68ff9c4d60d4c9c8e79 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 1 Feb 2015 14:00:24 -0800 Subject: 34446: add "ztie -r" and "zuntie -u", update documentation --- ChangeLog | 6 ++++++ Doc/Zsh/mod_db_gdbm.yo | 40 ++++++++++++++++++++++++++++++++-------- Src/Modules/db_gdbm.c | 44 ++++++++++++++++++++++++++++++++------------ 3 files changed, 70 insertions(+), 20 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 8b80a7e6f..2e2a014c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-02-01 Barton E. Schaefer + + * 34446: Doc/Zsh/mod_db_gdbm.yo, Src/Modules/db_gdbm.c: add + "ztie -r" and "zuntie -u", update documentation for this and + for 34430,34439. + 2015-02-01 Daniel Shahaf * 34411: Completion/Unix/Command/_hg: _hg completion: Complete diff --git a/Doc/Zsh/mod_db_gdbm.yo b/Doc/Zsh/mod_db_gdbm.yo index 6065f860e..90974297c 100644 --- a/Doc/Zsh/mod_db_gdbm.yo +++ b/Doc/Zsh/mod_db_gdbm.yo @@ -11,17 +11,41 @@ The builtins in this module are: startitem() findex(ztie) -cindex(tied array, creating) -item(tt(ztie -d db/gdbm -f) var(filename) var(arrayname))( +cindex(database tied array, creating) +item(tt(ztie -d db/gdbm -f) var(filename) [ tt(-r) ] var(arrayname))( Open the GDBM database identified by var(filename) and, if successful, -create the associative array var(arrayname) linked to the file. Note -that var(arrayname) must be unset at the time tt(ztie) is called, and -is always created as a global parameter (as if with `tt(typeset -g)'). +create the associative array var(arrayname) linked to the file. To create +a local tied array, the parameter must first be declared, so commands +similar to the following would be executed inside a function scope: + +example(local -A sampledb +ztie -d db/gdbm -f sample.gdbm sampledb) + +The tt(-r) option opens the database file for reading only, creating a +parameter with the readonly attribute. Without this option, using +`tt(ztie)' on a file for which the user does not have write permission is +an error. If writable, the database is opened synchronously so fields +changed in var(arrayname) are immediately written to var(filename). + +Changes to the file modes var(filename) after it has been opened do not +alter the state of var(arrayname), but `tt(typeset -r) var(arrayname)' +works as expected. ) findex(zuntie) -cindex(tied array, destroying) -item(tt(zuntie) var(arrayname) ...)( +cindex(database tied array, destroying) +item(tt(zuntie) [ tt(-u) ] var(arrayname) ...)( Close the GDBM database associated with each var(arrayname) and then -unset the variable. +unset the parameter. The tt(-u) option forces an unset of parameters +made readonly with `tt(ztie -r)'. + +This happens automatically if the parameter is explicitly unset or its +local scope (function) ends. Note that a readonly parameter may not be +explicitly unset, so the only way to unset a global parameter created with +`tt(ztie -r)' is to use `tt(zuntie -u)'. ) enditem() + +The fields of an associative array tied to GDBM are neither cached nor +otherwise stored in memory, they are read from or written to the database +on each reference. Thus, for example, the values in a readonly array may +be changed by a second writer of the same database file. diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index 9896bb536..a83e32a7b 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -48,8 +48,8 @@ static const struct gsu_hash gdbm_hash_gsu = { hashgetfn, hashsetfn, gdbmhashunsetfn }; static struct builtin bintab[] = { - BUILTIN("ztie", 0, bin_ztie, 1, -1, 0, "d:f:", NULL), - BUILTIN("zuntie", 0, bin_zuntie, 1, -1, 0, NULL, NULL), + BUILTIN("ztie", 0, bin_ztie, 1, -1, 0, "d:f:r", NULL), + BUILTIN("zuntie", 0, bin_zuntie, 1, -1, 0, "u", NULL), }; /**/ @@ -58,6 +58,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) { char *resource_name, *pmname; GDBM_FILE dbf = NULL; + int read_write = GDBM_SYNC, pmflags = PM_REMOVABLE; Param tied_param; if(!OPT_ISSET(ops,'d')) { @@ -68,6 +69,12 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) zwarnnam(nam, "you must pass `-f' with a filename", NULL); return 1; } + if (OPT_ISSET(ops,'r')) { + read_write |= GDBM_READER; + pmflags |= PM_READONLY; + } else { + read_write |= GDBM_WRCREAT; + } /* Here should be a lookup of the backend type against * a registry. @@ -79,9 +86,9 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) resource_name = OPT_ARG(ops, 'f'); - dbf = gdbm_open(resource_name, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, 0); + dbf = gdbm_open(resource_name, 0, read_write, 0666, 0); if(!dbf) { - zwarnnam(nam, "error opening database file %s", resource_name); + zwarnnam(nam, "error opening database file %s", resource_name); return 1; } @@ -101,7 +108,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) } } if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, - PM_REMOVABLE))) { + pmflags))) { zwarnnam(nam, "cannot create the requested parameter %s", pmname); gdbm_close(dbf); return 1; @@ -135,6 +142,8 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func)) } queue_signals(); + if (OPT_ISSET(ops,'u')) + gdbmuntie(pm); /* clear read-only-ness */ if (unsetparam_pm(pm, 0, 1)) { /* assume already reported */ ret = 1; @@ -250,19 +259,30 @@ scangdbmkeys(HashTable ht, ScanFunc func, int flags) /**/ static void -gdbmhashunsetfn(Param pm, UNUSED(int exp)) +gdbmuntie(Param pm) { GDBM_FILE dbf = (GDBM_FILE)(pm->u.hash->tmpdata); + HashTable ht = pm->u.hash; - if (!dbf) /* paranoia */ - return; + if (dbf) /* paranoia */ + gdbm_close(dbf); - gdbm_close(dbf); - pm->u.hash->tmpdata = NULL; + ht->tmpdata = NULL; - /* hash table is now normal, so proceed normally... */ - pm->node.flags &= ~PM_SPECIAL; + /* for completeness ... createspecialhash() should have an inverse */ + ht->getnode = ht->getnode2 = gethashnode2; + ht->scantab = NULL; + + pm->node.flags &= ~(PM_SPECIAL|PM_READONLY); pm->gsu.h = &stdhash_gsu; +} + +/**/ +static void +gdbmhashunsetfn(Param pm, UNUSED(int exp)) +{ + gdbmuntie(pm); + /* hash table is now normal, so proceed normally... */ pm->gsu.h->setfn(pm, NULL); pm->node.flags |= PM_UNSET; } -- cgit v1.2.3 From 79378d4acde71db54c4ed6636a0695741bb467fc Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 3 Feb 2015 17:12:41 +0000 Subject: users/19800: more help for $HISTORY_IGNORE --- ChangeLog | 2 ++ Doc/Zsh/params.yo | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 98c103e0c..8071ae703 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ 2015-02-03 Peter Stephenson + * users/19800: Doc/Zsh/params.yo: more help on $HISTORY_IGNORE. + * 34455: Src/Modules/db_gdbm.c: some further parameter bug fixes including memory leak and unsetting old parameter too late. diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 391a5fb0a..ee7c05412 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1052,10 +1052,25 @@ item(tt(HISTORY_IGNORE))( If set, is treated as a pattern at the time history files are written. Any potential history entry that matches the pattern is skipped. For example, if the value is `tt(fc *)' then commands that invoke the -interactive history editor are never written to the history file (compare -the tt(HIST_NO_STORE) option or the tt(zshaddhistory) hook, either of -which would prevent such commands from being added to the interactive -history at all). +interactive history editor are never written to the history file. + +Note that tt(HISTORY_IGNORE) defines a single pattern: to +specify alternatives use the `tt(+LPAR()first|second|...+RPAR())' +syntax. + +Compare the tt(HIST_NO_STORE) option or the tt(zshaddhistory) hook, +either of which would prevent such commands from being added to the +interactive history at all. If you wish to use tt(HISTORY_IGNORE) to +stop history being added in the first place, you can define the +following hook: + +example(zshaddhistory+LPAR()RPAR() { + emulate -L zsh + ## uncomment if HISTORY_IGNORE + ## should use EXTENDED_GLOB syntax + # setopt extendedglob + [[ $1 != ${~HISTORY_IGNORE} ]] +}) ) vindex(HISTSIZE) item(tt(HISTSIZE) )( -- cgit v1.2.3 From a7925f9a1ca551d43ad39e1ff24757fa9edc94c9 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Tue, 3 Feb 2015 19:26:03 -0800 Subject: unposted: fix formatting of "--". --- ChangeLog | 4 ++++ Doc/Zsh/builtins.yo | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 8071ae703..eea1882d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-02-03 Barton E. Schaefer + + * unposted: Doc/Zsh/builtins.yo: fix formatting of "--". + 2015-02-03 Jun-ichi Takimoto * 34451: Src/mem.c: use mmap() also on Mac OS X diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 4322aff0d..d5e3cf2e7 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -54,13 +54,13 @@ in a group before any non-option arguments; once the first non-option argument has been found, option processing is terminated. All builtin commands other than precommand modifiers, even those that -have no options, can be given the argument `tt(--)' to terminate option +have no options, can be given the argument `tt(-)tt(-)' to terminate option processing. This indicates that the following words are non-option arguments, but is otherwise ignored. This is useful in cases where arguments to the command may begin with `tt(-)'. For historical reasons, most builtin commands also recognize a single `tt(-)' in a separate word for this purpose; note that this is less standard and -use of `tt(--) is recommended. +use of `tt(-)tt(-)' is recommended. startitem() prefix(-) -- cgit v1.2.3 From 1a91cb7fb16423337f9d745f78bd3ae7215c2214 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 6 Feb 2015 10:46:58 +0000 Subject: users/19825: Clear statement about POSIX compatibility Right of start of manual where we already refer to ksh. --- ChangeLog | 5 +++++ Doc/Zsh/manual.yo | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index eea1882d0..6a983f0df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-02-06 Peter Stephenson + + * users/19825: Doc/Zsh/manual.yo: clear statement that zsh is + not by default POSIX compatible. + 2015-02-03 Barton E. Schaefer * unposted: Doc/Zsh/builtins.yo: fix formatting of "--". diff --git a/Doc/Zsh/manual.yo b/Doc/Zsh/manual.yo index 5184928c2..11c81501a 100644 --- a/Doc/Zsh/manual.yo +++ b/Doc/Zsh/manual.yo @@ -5,7 +5,8 @@ texitop(The Z Shell Manual) texiifinfo(\ This Info file documents Zsh, a freely available UNIX command interpreter (shell), which of the standard shells most closely resembles the Korn shell -(ksh), although it is not completely compatible. +(ksh), although it is not completely compatible. Zsh is able to emulate +POSIX shells, but its default mode is not POSIX compatible, either. cindex(version) Version version(), last updated date(). -- cgit v1.2.3 From 638bccb1c5e85da44f0dd551cc97bd522e633b4b Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 11 Feb 2015 12:52:22 +0000 Subject: users/19850: add pattern support to watch variable --- ChangeLog | 5 +++++ Doc/Zsh/params.yo | 14 +++++++++++++- Src/watch.c | 27 ++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index cca917efe..7c52b4aee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-02-11 Peter Stephenson + + * users/19850: Doc/Zsh/params.yo, Src/watch.c: watch variable + supports patterns for user, tty and host names. + 2015-02-10 Mikael Magnusson * 34488: Src/builtin.c: Fix use-after-free for print -zf and diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ee7c05412..273be21e4 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1472,15 +1472,27 @@ vindex(watch) vindex(WATCH) item(tt(watch) (tt(WATCH) ))( An array (colon-separated list) of login/logout events to report. + If it contains the single word `tt(all)', then all login/logout events are reported. If it contains the single word `tt(notme)', then all events are reported as with `tt(all)' except tt($USERNAME). + An entry in this list may consist of a username, an `tt(@)' followed by a remote hostname, -and a `tt(%)' followed by a line (tty). +and a `tt(%)' followed by a line (tty). Any of these may +be a pattern (be sure to quote this during the assignment to +tt(watch) so that it does not immediately perform file generation); +the setting of the tt(EXTENDED_GLOB) option is respected. Any or all of these components may be present in an entry; if a login/logout event matches all of them, it is reported. + +For example, with the tt(EXTENDED_GLOB) option set, the following: + +example(watch=('^(pws|barts)')) + +causes reports for activity assoicated with any user other than tt(pws) +or tt(barts). ) vindex(WATCHFMT) item(tt(WATCHFMT))( diff --git a/Src/watch.c b/Src/watch.c index 8dea0b495..fe409f91a 100644 --- a/Src/watch.c +++ b/Src/watch.c @@ -372,6 +372,27 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini) return fmt; } +/* See if the watch entry matches */ + +static int +watchlog_match(char *teststr, char *actual, int len) +{ + int ret = 0; + Patprog pprog; + char *str = dupstring(teststr); + + tokenize(str); + + if ((pprog = patcompile(str, PAT_STATIC, 0))) { + queue_signals(); + if (pattry(pprog, actual)) + ret = 1; + unqueue_signals(); + } else if (!strncmp(actual, teststr, len)) + ret = 1; + return ret; +} + /* check the List for login/logouts */ /**/ @@ -400,7 +421,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) for (vv = v; *vv && *vv != '@' && *vv != '%'; vv++); sav = *vv; *vv = '\0'; - if (strncmp(u->ut_name, v, sizeof(u->ut_name))) + if (!watchlog_match(v, u->ut_name, sizeof(u->ut_name))) bad = 1; *vv = sav; v = vv; @@ -410,7 +431,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) for (vv = ++v; *vv && *vv != '@'; vv++); sav = *vv; *vv = '\0'; - if (strncmp(u->ut_line, v, sizeof(u->ut_line))) + if (!watchlog_match(v, u->ut_line, sizeof(u->ut_line))) bad = 1; *vv = sav; v = vv; @@ -420,7 +441,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) for (vv = ++v; *vv && *vv != '%'; vv++); sav = *vv; *vv = '\0'; - if (strncmp(u->ut_host, v, strlen(v))) + if (!watchlog_match(v, u->ut_host, strlen(v))) bad = 1; *vv = sav; v = vv; -- cgit v1.2.3 From dd988542f466fd87e7353a9cd89d4b1d7b6f075d Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 14 Feb 2015 01:58:32 +0100 Subject: Fix typo from 28487 --- ChangeLog | 4 ++++ Doc/Zsh/prompt.yo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 641dfa75a..b5fc3a7f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-02-14 Mikael Magnusson + + * unposted: Doc/Zsh/prompt.yo: Fix typo from 28487. + 2015-02-13 Peter Stephenson * 34546: Src/exec.c, Test/D04parameter.ztst: fix another diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo index 17af5b0fb..65372deec 100644 --- a/Doc/Zsh/prompt.yo +++ b/Doc/Zsh/prompt.yo @@ -93,7 +93,7 @@ continuation lines and tt(PS4) for debugging with the tt(XTRACE) option; in the latter case it will also work non-interactively. ) xitem(tt(%d)) -item(tt(/))( +item(tt(%/))( Current working directory. If an integer follows the `tt(%)', it specifies a number of trailing components of the current working directory to show; zero means the whole path. A negative integer -- cgit v1.2.3 From 041a85243eb6d32e1cd1dc9f11a510c79e151433 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 16 Feb 2015 16:12:07 +0000 Subject: 34558: preexec doc fix. It was wrongly claming the first parameter was empty if the line was removed from the history. --- ChangeLog | 5 +++++ Doc/Zsh/func.yo | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 6fb13715a..f37c218c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-02-16 Peter Stephenson + + * 34558: Doc/Zsh/func.yo: preexec doc erroneously claimed $1 + was empty if line removed from history. + 2015-02-15 Barton E. Schaefer * 34551: Src/builtin.c: Avoid adding an extra "/" to the diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo index 6e9cfeee9..ace0a4051 100644 --- a/Doc/Zsh/func.yo +++ b/Doc/Zsh/func.yo @@ -247,10 +247,10 @@ findex(preexec) vindex(preexec_functions) item(tt(preexec))( Executed just after a command has been read and is about to be -executed. If the history mechanism is active (and the line was not -discarded from the history buffer), the string that the user typed is -passed as the first argument, otherwise it is an empty string. The -actual command that will be executed (including expanded aliases) is +executed. If the history mechanism is active (regardless of whether the +line was discarded from the history buffer), the string that the user +typed is passed as the first argument, otherwise it is an empty string. +The actual command that will be executed (including expanded aliases) is passed in two different forms: the second argument is a single-line, size-limited version of the command (with things like function bodies elided); the third argument contains the full text that is being -- cgit v1.2.3 From 009b6c9ff50e2a74640d39e339c49ff723712982 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 21 Feb 2015 20:01:32 -0800 Subject: 34597: Revise strftime description to correctly explain timezone handling and note signed int rollover --- ChangeLog | 5 +++++ Doc/Zsh/mod_datetime.yo | 55 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 17 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 3f8e9e0e9..05d5b9721 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-02-21 Barton E. Schaefer + + * 34597: Doc/Zsh/mod_datetime.yo: Revise strftime description to + correctly explain timezone handling and note signed int rollover + 2015-02-20 Barton E. Schaefer * 34590: Src/exec.c, Src/text.c: queue_signals() around more diff --git a/Doc/Zsh/mod_datetime.yo b/Doc/Zsh/mod_datetime.yo index 619067698..27bc78157 100644 --- a/Doc/Zsh/mod_datetime.yo +++ b/Doc/Zsh/mod_datetime.yo @@ -8,25 +8,46 @@ findex(strftime) cindex(date string, printing) xitem(tt(strftime) [ tt(-s) var(scalar) ] var(format) var(epochtime) ) item(tt(strftime) tt(-r) [ tt(-q) ] [ tt(-s) var(scalar) ] var(format) var(timestring) )( -Output the date denoted by var(epochtime) in the var(format) -specified. +Output the date denoted by var(epochtime) in the var(format) specified. +See manref(strftime)(3) for details. The zsh extensions described in +ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\ +ifnzman(noderef(Prompt Expansion)) are also available. -With the option tt(-r) (reverse), use the format var(format) to parse the -input string var(timestring) and output the number of seconds since the -epoch at which the time occurred. If no timezone is parsed, the current -timezone is used; other parameters are set to zero if not present. If -var(timestring) does not match var(format) the command returns status 1; it -will additionally print an error message unless the option tt(-q) (quiet) -is given. If var(timestring) matches var(format) but not all characters in -var(timestring) were used, the conversion succeeds; however, a warning is -issued unless the option tt(-q) is given. The matching is implemented by -the system function tt(strptime); see manref(strptime)(3). This means that -zsh format extensions are not available, however for reverse lookup they -are not required. If the function is not implemented, the command returns -status 2 and (unless tt(-q) is given) prints a message. +startitem() +item(tt(-q))( +Run quietly; suppress printing of all error messages described below. +Errors for invalid var(epochtime) values are always printed. +) +item(tt(-r))( +With the option tt(-r) (reverse), use var(format) to parse the input +string var(timestring) and output the number of seconds since the epoch at +which the time occurred. The parsing is implemented by the system +function tt(strptime); see manref(strptime)(3). This means that zsh +format extensions are not available, but for reverse lookup they are not +required. + +In most implementations of tt(strftime) any timezone in the +var(timestring) is ignored and the local timezone declared by the tt(TZ) +environment variable is used; other parameters are set to zero if not +present. + +If var(timestring) does not match var(format) the command returns status 1 +and prints an error message. If var(timestring) matches var(format) but +not all characters in var(timestring) were used, the conversion succeeds +but also prints an error message. + +If either of the system functions tt(strptime) or tt(mktime) is not +available, status 2 is returned and an error message is printed. +) +item(tt(-s) var(scalar))( +Assign the date string (or epoch time in seconds if tt(-r) is given) to +var(scalar) instead of printing it. +) +enditem() -If tt(-s) var(scalar) is given, assign the date string (or epoch time -in seconds if tt(-r) is given) to var(scalar) instead of printing it. +Note that depending on the system's declared integral time type, +tt(strftime) may produce incorrect results for epoch times greater than +2147483647 which corresponds to 2038-01-19 03:14:07 +0000. ) enditem() -- cgit v1.2.3 From 4edcacbcf39415645a92b38e1f8b89780013a6b0 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 28 Feb 2015 13:45:51 -0800 Subject: users/19934: document %D{...} for WATCHFMT --- ChangeLog | 4 ++++ Doc/Zsh/params.yo | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 4329a42ee..2efe5932c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-02-28 Barton E. Schaefer + + * users/19934: Doc/Zsh/params.yo: document %D{...} for WATCHFMT + 2015-02-27 Barton E. Schaefer * 34634: Src/glob.c: avoid infinite recursion on (/)# extendedglob diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 273be21e4..d044f8749 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1548,6 +1548,12 @@ The date in `var(mm)tt(/)var(dd)tt(/)var(yy)' format. item(tt(%D))( The date in `var(yy)tt(-)var(mm)tt(-)var(dd)' format. ) +item(tt(%D{)var(string)tt(}))( +The date formatted as var(string) using the tt(strftime) function, with +zsh extensions as described by +ifzman(EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\ +ifnzman(noderef(Prompt Expansion)). +) item(tt(%LPAR())var(x)tt(:)var(true-text)tt(:)var(false-text)tt(RPAR()))( Specifies a ternary expression. The character following the var(x) is -- cgit v1.2.3 From 42e5f591f5227d829ca27fd534c34400d92a8553 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 4 Mar 2015 02:57:20 +0000 Subject: 34640: clarify documentation for _guard function --- ChangeLog | 5 +++++ Doc/Zsh/compsys.yo | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index fb5c0a207..2be4a7f65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-04 Peter Stephenson + + * Daniel Shahaf: 34640: Doc/Zsh/compsys.yo: clarify + documentation for _guard function. + 2015-03-03 Peter Stephenson * Matthew Martin: 34637: Completion/BSD/Command/_mixerctl: diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 5890f1704..89cd05121 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4278,12 +4278,12 @@ option `tt(-)tt(-help)'. ) findex(_guard) item(tt(_guard) [ var(options) ] var(pattern descr))( -This function is intended to be used in the var(action) for -the specifications passed to tt(_arguments) and similar functions. It -returns immediately with a non-zero return status if -the string to be completed does not match the var(pattern). If the -pattern matches, the var(descr) is displayed; the function then returns -status zero if the word to complete is not empty, non-zero otherwise. +This function displays var(descr) if var(pattern) matches the string to +be completed. It is intended to be used in the var(action) for the +specifications passed to tt(_arguments) and similar functions. + +The return status is zero if the message was displayed and the word to +complete is not empty, and non-zero otherwise. The var(pattern) may be preceded by any of the options understood by tt(compadd) that are passed down from tt(_description), namely tt(-M), -- cgit v1.2.3 From 00b3085b969f46370f7cde28e9dfa10026b884c7 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 6 Mar 2015 09:50:01 +0000 Subject: 34657: document the effect of substring subscripting better --- ChangeLog | 5 +++++ Doc/Zsh/params.yo | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 74295288f..4f9f92886 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-06 Peter Stephenson + + * 34657: Doc/Zsh/params.yo: document the effect of substring + subscripting better. + 2015-03-05 Peter Stephenson * 34654: Completion/Redhat/Command/_rpm: complete absolute file diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index d044f8749..7b127bc68 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -187,7 +187,17 @@ from the end of the array tt(foo), and Subscripting may also be performed on non-array values, in which case the subscripts specify a substring to be extracted. For example, if tt(FOO) is set to `tt(foobar)', then -`tt(echo $FOO[2,5])' prints `tt(ooba)'. +`tt(echo $FOO[2,5])' prints `tt(ooba)'. Note that +some forms of subscripting described below perform pattern matching, +and in that case the substring extends from the start of the match +of the first subscript to the end of the match of the second +subscript. For example, + +example(string="abcdefghijklm" +print ${string[+LPAR()r+RPAR()d?,+LPAR()r+RPAR()h?]}) + +prints `tt(defghi)'. This is an obvious generalisation of the +rule for single-character matches. subsect(Array Element Assignment) -- cgit v1.2.3 From 2f3547689cfc8b1b1bf4cbdbd7b3714e2ab1d0a2 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 6 Mar 2015 09:51:16 +0000 Subject: 34653: move aborted vared lines to ZLE_VARED_ABORTED --- ChangeLog | 3 +++ Doc/Zsh/zle.yo | 3 ++- Src/Zle/zle_main.c | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 4f9f92886..af0d6c417 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-03-06 Peter Stephenson + * 34653: Doc/Zsh/zle.yo, Src/Zle/zle_main.c: move aborted vared + lines to ZLE_VARED_ABORTED. + * 34657: Doc/Zsh/params.yo: document the effect of substring subscripting better. diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index dd8e6286a..b8b9b8c9c 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2223,7 +2223,8 @@ item(tt(send-break) (^G ESC-^G) (unbound) (unbound))( Abort the current editor function, e.g. tt(execute-named-command), or the editor itself, e.g. if you are in tt(vared). Otherwise abort the parsing of the current line; in this case the aborted line is available in the shell -variable tt(ZLE_LINE_ABORTED). +variable tt(ZLE_LINE_ABORTED). If the editor is aborted from within +tt(vared), the variable tt(ZLE_VARED_ABORTED) is set. ) tindex(run-help) item(tt(run-help) (ESC-H ESC-h) (unbound) (unbound))( diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index a2f48e13a..cec44c0ed 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1253,7 +1253,9 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) zlecore(); if (errflag) - setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL)); + setsparam((zlecontext == ZLCON_VARED) ? + "ZLE_VARED_ABORTED" : + "ZLE_LINE_ABORTED", zlegetline(NULL, NULL)); if (done && !exit_pending && !errflag) zlecallhook(finish, NULL); -- cgit v1.2.3 From d902b55bd404902ea42f4ac780d47960e088d9fd Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 6 Mar 2015 20:32:56 +0900 Subject: 34643: clarify documentation for print and bindkey --- ChangeLog | 5 +++++ Doc/Zsh/builtins.yo | 9 ++++++--- Doc/Zsh/zle.yo | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index af0d6c417..757207ce7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-05 Jun-ichi Takimoto + + * 34643: Doc/Zsh/builtins.yo, Doc/Zsh/zle.yo: clarify which + escape sequences are recognized by print and bindkey builtins. + 2015-03-06 Peter Stephenson * 34653: Doc/Zsh/zle.yo, Src/Zle/zle_main.c: move aborted vared diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index d5e3cf2e7..dd5a80fe8 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1094,10 +1094,13 @@ item( [ tt(-R) [ tt(-en) ]] [ var(arg) ... ])( With the `tt(-f)' option the arguments are printed as described by tt(printf). With no flags or with the flag `tt(-)', the arguments are printed on the standard output as described by tt(echo), with the following differences: -the escape sequence `tt(\M-)var(x)' metafies the character +the escape sequence `tt(\M-)var(x)' (or `tt(\M)var(x)') metafies the character var(x) (sets the highest bit), -`tt(\C-)var(x)' produces a control character (`tt(\C-@)' and `tt(\C-?)' give the -characters NUL and delete), and `tt(\E)' is a synonym for `tt(\e)'. +`tt(\C-)var(x)' (or `tt(\C)var(x)') produces a control character +(`tt(\C-@)' and `tt(\C-?)' give the characters NULL and delete), +a character code in octal is represented by `tt(\)var(NNN)' +(instead of `tt(\0)var(NNN)'), +and `tt(\E)' is a synonym for `tt(\e)'. Finally, if not in an escape sequence, `tt(\)' escapes the following character and is not printed. diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index b8b9b8c9c..8fabe4b4c 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -312,6 +312,8 @@ sitem(tt(\t))(horizontal tab) sitem(tt(\v))(vertical tab) sitem(tt(\)var(NNN))(character code in octal) sitem(tt(\x)var(NN))(character code in hexadecimal) +sitem(tt(\u)var(NNNN))(unicode character code in hexadecimal) +sitem(tt(\U)var(NNNNNNNN))(unicode character code in hexadecimal) sitem(tt(\M)[tt(-)]var(X))(character with meta bit set) sitem(tt(\C)[tt(-)]var(X))(control character) sitem(tt(^)var(X))(control character) -- cgit v1.2.3 From e85906ebc970be9c5114f10dd5869c5cdaca9a65 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 10 Mar 2015 12:19:26 +0000 Subject: users/19985: improve doc of subscripting substrings further --- ChangeLog | 5 +++++ Doc/Zsh/params.yo | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index bdb177cfb..9f523eb76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-10 Peter Stephenson + + * users/19985: Doc/Zsh/params.yo: improve doc of substring + subscripting further. + 2015-03-09 Daniel Shahaf * 34673: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 7b127bc68..2f789209e 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -197,7 +197,17 @@ example(string="abcdefghijklm" print ${string[+LPAR()r+RPAR()d?,+LPAR()r+RPAR()h?]}) prints `tt(defghi)'. This is an obvious generalisation of the -rule for single-character matches. +rule for single-character matches. For a single subscript, +only a single character is referenced (not the range of characters +covered by the match). + +Note that in substring operations the second subscript is handled +differently by the tt(r) and tt(R) subscript flags: the former takes the +shortest match as the length and the latter the longest match. Hence +in the former case a tt(*) at the end is redundant while in +the latter case it matches the whole remainder of the string. This +does not affect the result of the single subscript case as here the +length of the match is irrelevant. subsect(Array Element Assignment) -- cgit v1.2.3 From 7e994fe145cd5beaadf8719468bbd682c17512b5 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 15 Mar 2015 23:33:19 -0700 Subject: 34712: clarify words that may be aliased --- ChangeLog | 4 ++++ Doc/Zsh/grammar.yo | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index abc0a6aa6..22ff7a081 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-03-15 Barton E. Schaefer + + * 34712: Doc/Zsh/grammar.yo: clarify words that may be aliased + 2015-03-15 Mikael Magnusson * unposted: Completion/Zsh/Command/_zattr: Fix completion of diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 63d90dfd0..b30e423e1 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -532,12 +532,12 @@ characters up to a newline to be ignored. texinode(Aliasing)(Quoting)(Comments)(Shell Grammar) sect(Aliasing) cindex(aliasing) -Every token in the shell input is checked to see if there +Every eligible em(word) in the shell input is checked to see if there is an alias defined for it. If so, it is replaced by the text of the alias if it is in command position (if it could be the first word of a simple command), or if the alias is global. -If the text ends with a space, the next word in the shell input +If the replacement text ends with a space, the next word in the shell input is treated as though it were in command position for purposes of alias expansion. findex(alias, use of) @@ -545,6 +545,22 @@ cindex(aliases, global) An alias is defined using the tt(alias) builtin; global aliases may be defined using the tt(-g) option to that builtin. +A em(word) is defined as: + +startitemize() +itemiz(Any plain string or glob pattern) +itemiz(Any quoted string, using any quoting method (note that the quotes +must be part of the alias definition for this to be eligible)) +itemiz(Any parameter reference or command substitution) +itemiz(Any series of the foregoing, concatenated without whitespace or +other tokens between them) +itemiz(Any reserved word (tt(case), tt(do), tt(else), etc.)) +enditemize() + +Reserved words are not eligible for aliasing when tt(POSIX_ALIASES) is set. +The tt(alias) builtin does not reject ineligible aliases, but they are not +expanded. + Alias expansion is done on the shell input before any other expansion except history expansion. Therefore, if an alias is defined for the word tt(foo), alias expansion may be avoided by quoting part of the -- cgit v1.2.3 From 236da69842863691098c4b2b603b93d3fcb90bb6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 7 Mar 2015 03:05:16 +0000 Subject: 34671 plus tweaks: Add -1 -2 -J -V -x to _describe, use them to sort 'git --fixup' hash completions --- ChangeLog | 4 ++++ Completion/Base/Utility/_describe | 35 ++++++++++++++++++++--------------- Completion/Unix/Command/_git | 2 +- Doc/Zsh/compsys.yo | 5 ++++- 4 files changed, 29 insertions(+), 17 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 094d92e65..9d399f014 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-03-16 Daniel Shahaf + * 34671 plus tweaks: Completion/Base/Utility/_describe + Completion/Unix/Command/_git Doc/Zsh/compsys.yo: Add -1 -2 -J -V + -x to _describe, use them to sort 'git --fixup' hash completions + * 34671: Completion/Unix/Command/_git: git completion: only offer recent commits' tags/heads for --fixup diff --git a/Completion/Base/Utility/_describe b/Completion/Base/Utility/_describe index 1a9f52f5d..ab7200517 100644 --- a/Completion/Base/Utility/_describe +++ b/Completion/Base/Utility/_describe @@ -6,23 +6,28 @@ local _opt _expl _tmpm _tmpd _mlen _noprefix local _type=values _descr _ret=1 _showd _nm _hide _args _grp _sep local csl="$compstate[list]" csl2 local _oargv _argv _new _strs _mats _opts _i _try=0 +local OPTIND OPTARG +local -a _jvx12 # Get the option. -if [[ "$1" = -o ]]; then - _type=options - shift -elif [[ "$1" = -O ]]; then - _type=options - _noprefix=1 - shift -elif [[ "$1" = -t ]]; then - _type="$2" - shift 2 -elif [[ "$1" = -t* ]]; then - _type="${1[3,-1]}" - shift -fi +while getopts "oOt:12JVx" _opt; do + case $_opt in + (o) + _type=options;; + (O) + _type=options + _noprefix=1 + ;; + (t) + _type="$OPTARG" + ;; + (1|2|J|V|x) + _jvx12+=(-$_opt) + esac +done +shift $(( OPTIND - 1 )) +unset _opt [[ "$_type$_noprefix" = options && ! -prefix [-+]* ]] && \ zstyle -T ":completion:${curcontext}:options" prefix-needed && @@ -53,7 +58,7 @@ fi _tags "$_type" while _tags; do - while _next_label "$_type" _expl "$_descr"; do + while _next_label $_jvx12 "$_type" _expl "$_descr"; do if (( $#_grp )); then diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index aa1124706..e5639fab2 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -5669,7 +5669,7 @@ __git_recent_commits () { expl=() _wanted heads expl 'head' compadd "$@" -a - heads && ret=0 expl=() - _describe -t commits 'commit object name' descr && ret=0 + _describe -2Vx -t commits 'commit object name' descr && ret=0 } (( $+functions[__git_blob_objects] )) || diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 89cd05121..6c6bedb21 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4140,7 +4140,7 @@ tt(compadd) when generating matches from the style value, or to the functions for the fields if they are called. ) findex(_describe) -item(tt(_describe) [ tt(-oO) | tt(-t) var(tag) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)( +item(tt(_describe) [tt(-12JVx)] [ tt(-oO) | tt(-t) var(tag) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)( This function associates completions with descriptions. Multiple groups separated by tt(-)tt(-) can be supplied, potentially with different completion options var(opts). @@ -4171,6 +4171,9 @@ tt(prefix-needed) style. With the tt(-t) option a var(tag) can be specified. The default is `tt(values)' or, if the tt(-o) option is given, `tt(options)'. +The options tt(-1), tt(-2), tt(-J), tt(-V), tt(-x) are passed to +tt(_next_label). + If selected by the tt(list-grouped) style, strings with the same description will appear together in the list. -- cgit v1.2.3 From 235e9bd1bfe35caf51ba988268e075c24e3615fe Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 16 Mar 2015 15:07:35 +0000 Subject: 34721: new glob qualifier functions before, after --- ChangeLog | 5 ++++ Doc/Zsh/calsys.yo | 35 +++++++++++++++++++------ Functions/Calendar/after | 67 +++++++++++++++++++++++++++++++++++++++++++++++ Functions/Calendar/before | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 Functions/Calendar/after create mode 100644 Functions/Calendar/before (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 9d399f014..9fc3f9822 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-16 Peter Stephenson + + * 34721: Doc/Zsh/calsys.yo, Functions/Calendar/after, + Functions/Calendar/before: new glob qualifier functions. + 2015-03-16 Daniel Shahaf * 34671 plus tweaks: Completion/Base/Utility/_describe diff --git a/Doc/Zsh/calsys.yo b/Doc/Zsh/calsys.yo index 0d7abbf86..6b5fe27fb 100644 --- a/Doc/Zsh/calsys.yo +++ b/Doc/Zsh/calsys.yo @@ -10,9 +10,9 @@ or future events, details of which are stored in a text file (typically tt(calendar) in the user's home directory). The version provided here includes a mechanism for alerting the user when an event is due. -In addition a function tt(age) is provided that can be used in a glob -qualifier; it allows files to be selected based on their modification -times. +In addition functions tt(age), tt(before) and tt(after) are provided +that can be used in a glob qualifier; they allow files to be selected +based on their modification times. The format of the tt(calendar) file and the dates used there in and in the tt(age) function are described first, then the functions that can @@ -122,10 +122,10 @@ enditemize() Here, square brackets indicate optional elements, possibly with alternatives. Fractions of a second are recognised but ignored. For absolute times (the normal format require by the tt(calendar) file and the -tt(age) function) a date is mandatory but a time of day is not; the time -returned is at the start of the date. One variation is allowed: if -tt(a.m.) or tt(p.m.) or one of their variants is present, an hour without a -minute is allowed, e.g. tt(3 p.m.). +tt(age), tt(before) and tt(after) functions) a date is mandatory but a +time of day is not; the time returned is at the start of the date. One +variation is allowed: if tt(a.m.) or tt(p.m.) or one of their variants +is present, an hour without a minute is allowed, e.g. tt(3 p.m.). Time zones are not handled, though if one is matched following a time specification it will be removed to allow a surrounding date to be @@ -605,8 +605,10 @@ left in a file with the suffix tt(.old). enditem() subsect(Glob qualifiers) -findex(age) +startitem() +item(tt(age))( +findex(age) The function tt(age) can be autoloaded and use separately from the calendar system, although it uses the function tt(calendar_scandate) for date formatting. It requires the tt(zsh/stat) builtin, but uses @@ -675,6 +677,23 @@ example(print *+LPAR()e-age :file1 :file2-+RPAR()) matches all files modified no earlier than tt(file1) and no later than tt(file2); precision here is to the nearest second. +) +xitem(tt(after)) +item(tt(before))( +findex(after) +findex(before) +The functions tt(after) and tt(before) are simpler versions of tt(age) +that take just one argument. The argument is parsed similarly to an +argument of tt(age); if it is not given the variable tt(AGEREF) is +consulted. As the names of the functions suggest, a file matches if its +modification time is after or before the time and date specified. If +a time only is given the date is today. + +The two following examples are therefore equivalent: +example(print *+LPAR()e-after 12:00-RPAR() +print *+LPAR()e-after today:12:00-RPAR()) +) +enditem() texinode(Calendar Styles)(Calendar Utility Functions)(Calendar System User Functions)(Calendar Function System) sect(Styles) diff --git a/Functions/Calendar/after b/Functions/Calendar/after new file mode 100644 index 000000000..7fb0166f7 --- /dev/null +++ b/Functions/Calendar/after @@ -0,0 +1,67 @@ +# Glob qualifier function, e.g +# +# print *(e:after 2014/08/01:) +# print *(e-after today:12:00-) +# +# If named before: +# Match files modified before a given time. +# +# If named after: +# Match files modified after a given time. Use as glob qualifier. +# N.B.: "after" actually includes the given time as it is to second +# precision (it would be inconvenient to exclude the first second of a date). +# It should therefore more logically be called "from", but that's a less +# obvious name. +# +# File to test is in $REPLY. +# +# Similar to age, but only takes at most one data, which is +# compared directly with the current time. + +emulate -L zsh + +zmodload -F zsh/stat b:zstat +zmodload -i zsh/parameter + +autoload -Uz calendar_scandate + +local timefmt +local -a vals tmp + +[[ -e $REPLY ]] || return 1 +zstat -A vals +mtime -- $REPLY || return 1 + +if (( $# == 1 )); then + if [[ $1 = :* ]]; then + timefmt="%Y/%m/%d:%H:%M:%S" + zstat -A tmp -F $timefmt +mtime -- ${1#:} || return 1 + local AGEREF=$tmp[1] + else + local AGEREF=$1 + fi +fi + +integer mtime=$vals[1] date1 date2 +local REPLY REPLY2 + +# allow a time only (meaning today) +if calendar_scandate -t $AGEREF; then + date1=$REPLY + + case $0 in + (after) + (( mtime >= date1 )) + ;; + + (before) + (( mtime < date1 )) + ;; + + (*) + print "$0: must be named 'after' or 'before'" >&2 + return 1 + ;; + esac +else + return 1 +fi diff --git a/Functions/Calendar/before b/Functions/Calendar/before new file mode 100644 index 000000000..7fb0166f7 --- /dev/null +++ b/Functions/Calendar/before @@ -0,0 +1,67 @@ +# Glob qualifier function, e.g +# +# print *(e:after 2014/08/01:) +# print *(e-after today:12:00-) +# +# If named before: +# Match files modified before a given time. +# +# If named after: +# Match files modified after a given time. Use as glob qualifier. +# N.B.: "after" actually includes the given time as it is to second +# precision (it would be inconvenient to exclude the first second of a date). +# It should therefore more logically be called "from", but that's a less +# obvious name. +# +# File to test is in $REPLY. +# +# Similar to age, but only takes at most one data, which is +# compared directly with the current time. + +emulate -L zsh + +zmodload -F zsh/stat b:zstat +zmodload -i zsh/parameter + +autoload -Uz calendar_scandate + +local timefmt +local -a vals tmp + +[[ -e $REPLY ]] || return 1 +zstat -A vals +mtime -- $REPLY || return 1 + +if (( $# == 1 )); then + if [[ $1 = :* ]]; then + timefmt="%Y/%m/%d:%H:%M:%S" + zstat -A tmp -F $timefmt +mtime -- ${1#:} || return 1 + local AGEREF=$tmp[1] + else + local AGEREF=$1 + fi +fi + +integer mtime=$vals[1] date1 date2 +local REPLY REPLY2 + +# allow a time only (meaning today) +if calendar_scandate -t $AGEREF; then + date1=$REPLY + + case $0 in + (after) + (( mtime >= date1 )) + ;; + + (before) + (( mtime < date1 )) + ;; + + (*) + print "$0: must be named 'after' or 'before'" >&2 + return 1 + ;; + esac +else + return 1 +fi -- cgit v1.2.3 From 32b4cb0e73cdb01c467a0484e906d28d7c104c64 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Wed, 18 Mar 2015 18:01:54 -0700 Subject: 34734: further aliasing adjustments and doc restrict token aliasing (34641) to global aliases; tighten up POSIX_ALIASES to better match spec; update Aliasing doc to cover this and clarify older behavior 2015-03-18 Peter Stephenson * 34723: configure.ac: turn off fixed site function directory if --- ChangeLog | 7 +++++++ Doc/Zsh/grammar.yo | 29 +++++++++++++++++++---------- Src/lex.c | 10 ++++++++-- Test/A02alias.ztst | 2 +- 4 files changed, 35 insertions(+), 13 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 871ef73eb..37d7c7962 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-03-18 Barton E. Schaefer + + * 34734: Doc/Zsh/grammar.yo, Src/lex.c, Test/A02alias.ztst: + restrict token aliasing (34641) to global aliases; tighten + up POSIX_ALIASES to better match spec; update Aliasing doc + to cover this and clarify older behavior + 2015-03-18 Peter Stephenson * 34723: configure.ac: turn off fixed site function directory if diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index b30e423e1..522ad0472 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -538,8 +538,7 @@ If so, it is replaced by the text of the alias if it is in command position (if it could be the first word of a simple command), or if the alias is global. If the replacement text ends with a space, the next word in the shell input -is treated as though it were in command position for purposes of alias -expansion. +is always eligible for purposes of alias expansion. findex(alias, use of) cindex(aliases, global) An alias is defined using the tt(alias) builtin; global aliases @@ -555,22 +554,32 @@ itemiz(Any parameter reference or command substitution) itemiz(Any series of the foregoing, concatenated without whitespace or other tokens between them) itemiz(Any reserved word (tt(case), tt(do), tt(else), etc.)) +itemiz(With global aliasing, any command separator, any redirection +operator, and `tt(LPAR())' or `tt(RPAR())' when not part of a glob pattern) enditemize() -Reserved words are not eligible for aliasing when tt(POSIX_ALIASES) is set. -The tt(alias) builtin does not reject ineligible aliases, but they are not -expanded. +It is not presently possible to alias the `tt(LPAR()LPAR())' token that +introduces arithmetic expressions, because until a full statement has been +parsed, it cannot be distinguished from two consecutive `tt(LPAR())' +tokens introducing nested subshells. + +When tt(POSIX_ALIASES) is set, only plain unquoted strings are eligible +for aliasing. The tt(alias) builtin does not reject ineligible aliases, +but they are not expanded. Alias expansion is done on the shell input before any other expansion except history expansion. Therefore, if an alias is defined for the word tt(foo), alias expansion may be avoided by quoting part of the word, e.g. tt(\foo). Any form of quoting works, although there is nothing to prevent an alias being defined for the quoted form such as -tt(\foo) as well. For use with completion, which would remove an -initial backslash followed by a character that isn't special, it may be -more convenient to quote the word by starting with a single quote, -i.e. tt('foo); completion will automatically add the trailing single -quote. +tt(\foo) as well. Also, if a separator such as tt(&&) is aliased, +tt(\&&) turns into the two tokens tt(\&) and tt(&), each of which may +have been aliased separately. Similarly for tt(\<<), tt(\>|), etc. + +For use with completion, which would remove an initial backslash followed +by a character that isn't special, it may be more convenient to quote the +word by starting with a single quote, i.e. tt('foo); completion will +automatically add the trailing single quote. There is a commonly encountered problem with aliases illustrated by the following code: diff --git a/Src/lex.c b/Src/lex.c index 494ea8870..1eb0bc7d7 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1740,12 +1740,13 @@ checkalias(void) if (!noaliases && isset(ALIASESOPT) && (!isset(POSIXALIASES) || - !reswdtab->getnode(reswdtab, zshlextext))) { + (tok == STRING && !reswdtab->getnode(reswdtab, zshlextext)))) { char *suf; an = (Alias) aliastab->getnode(aliastab, zshlextext); if (an && !an->inuse && - ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) { + ((an->node.flags & ALIAS_GLOBAL) || + (incmdpos && tok == STRING) || inalmore)) { inpush(an->text, INP_ALIAS, an); if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL)) aliasspaceflag = 1; @@ -1784,6 +1785,8 @@ exalias(void) if (!tokstr) { zshlextext = tokstrings[tok]; + if (tok == NEWLIN) + return 0; return checkalias(); } else { VARARR(char, copy, (strlen(tokstr) + 1)); @@ -1791,6 +1794,9 @@ exalias(void) if (has_token(tokstr)) { char *p, *t; + if (isset(POSIXALIASES)) + return 0; + zshlextext = p = copy; for (t = tokstr; (*p++ = itok(*t) ? ztokens[*t++ - Pound] : *t++);); diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst index 36dfa241e..314ec036a 100644 --- a/Test/A02alias.ztst +++ b/Test/A02alias.ztst @@ -43,7 +43,7 @@ 0:Alias expansion works at the end of parsed strings >foo - alias '&&=(){ return $?; } && ' + alias -g '&&=(){ return $?; } && ' alias not_the_print_command=print eval 'print This is output && print And so is this -- cgit v1.2.3 From ddf96cf933a67913d64b9cfe196c870481452539 Mon Sep 17 00:00:00 2001 From: Han Pingtian Date: Mon, 23 Mar 2015 18:18:50 +0800 Subject: 34769: incorrect doc of process time calculation --- ChangeLog | 5 +++++ Doc/Zsh/params.yo | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index d8f18feff..86d4e4c05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-25 Peter Stephenson + + * Han Pingtian: 34769: incorrect description of process time + calculation. + 2015-03-25 Peter Stephenson * 34776: Src/hist.c, Src/zsh.h: suppressing alias expansions diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 2f789209e..9d06b6af6 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1445,7 +1445,7 @@ sitem(tt(%U))(CPU seconds spent in user mode.) sitem(tt(%S))(CPU seconds spent in kernel mode.) sitem(tt(%E))(Elapsed time in seconds.) sitem(tt(%P))(The CPU percentage, computed as -(100*tt(%U)PLUS()tt(%S))/tt(%E).) +100*(tt(%U)PLUS()tt(%S))/tt(%E).) sitem(tt(%W))(Number of times the process was swapped.) sitem(tt(%X))(The average amount in (shared) text space used in kilobytes.) sitem(tt(%D))(The average amount in (unshared) data/stack space used in -- cgit v1.2.3 From 26cfae830c076dff8289b8a8edc6580b285286de Mon Sep 17 00:00:00 2001 From: Han Pingtian Date: Fri, 27 Mar 2015 07:05:00 +0800 Subject: 34785: fix typo in SHINSTDIN doc --- ChangeLog | 2 ++ Doc/Zsh/options.yo | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 490499a8d..75ed142af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-03-27 Peter Stephenson + * Han Pingtian: 34785: Doc/Zsh/options.yo: fix typo in SHINSTDIN. + * 34787: Test/W01history.ztst: new tests. 2015-03-26 Peter Stephenson diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 8a0222cfd..359ecb94e 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -2248,7 +2248,7 @@ taken as a file to run will instead be treated as a normal positional parameter. Note that setting or unsetting this option on the command line does not necessarily affect the state the option will have while the shell is -running - that is purely an indicator of whether on not commands are +running - that is purely an indicator of whether or not commands are em(actually) being read from standard input. The value of this option can only be changed via flags supplied at invocation of the shell. -- cgit v1.2.3 From 5b2bb68364ba025b312168d12a0f43b38b4e6268 Mon Sep 17 00:00:00 2001 From: Han Pingtian Date: Tue, 31 Mar 2015 11:28:35 +0800 Subject: 34822: correction to GLOB_SUBST doc --- ChangeLog | 5 +++++ Doc/Zsh/options.yo | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index f597527a9..b506d9829 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ Completion/Unix/Type/_net_interfaces: improve matching of devices already on command line in ip completion. +2015-03-31 Peter Stephenson + + * Han Pingtian: 34822: Doc/Zsh/options.yo: correction to + GLOB_SUBST doc. + 2015-03-29 Peter Stephenson * 34817: Src/hist.c, Src/lex.c: catch some errors earlier when diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 359ecb94e..19920ca53 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -540,7 +540,7 @@ pindex(GLOBSUBST) pindex(NOGLOBSUBST) item(tt(GLOB_SUBST) )( Treat any characters resulting from parameter expansion as being -eligible for file expansion and filename generation, and any +eligible for filename expansion and filename generation, and any characters resulting from command substitution as being eligible for filename generation. Braces (and commas in between) do not become eligible for expansion. -- cgit v1.2.3 From 1278156dc39a048c118e94fa3cea5373f56cf319 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 3 Apr 2015 02:11:02 +0900 Subject: 34836: fix description of '%-0<<' in prompt.yo --- ChangeLog | 4 ++++ Doc/Zsh/prompt.yo | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 51078fb8a..ed5762394 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-03-05 Jun-ichi Takimoto + + * 34836: Doc/Zsh/prompt.yo: fix description of '%-0<<' + 2015-04-01 Daniel Shahaf * 34814: Completion/Unix/Command/_git: completion: git: Fix diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo index 65372deec..08dcded24 100644 --- a/Doc/Zsh/prompt.yo +++ b/Doc/Zsh/prompt.yo @@ -367,7 +367,8 @@ truncated while turning off truncation from there on. For example, the prompt '%10<...<%~%<<%# ' will print a truncated representation of the current directory, followed by a `tt(%)' or `tt(#)', followed by a space. Without the `tt(%<<)', those two characters would be included -in the string to be truncated. Note that `tt(%-0<<)' is a distinct +in the string to be truncated. Note that `tt(%-0<<)' is not equivalent +to `tt(%<<)' but specifies that the prompt is truncated at the right margin. Truncation applies only within each individual line of the prompt, as delimited by embedded newlines (if any). If the total length of any line -- cgit v1.2.3 From f5e7c4c839e9d5dbd325f563e7584b07f4835f52 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 3 Apr 2015 21:40:25 +0900 Subject: 34840: minor format fixes in prompt.yo --- ChangeLog | 6 +++++- Doc/Zsh/prompt.yo | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index ed5762394..5c6e6c332 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2015-03-05 Jun-ichi Takimoto +2015-04-03 Jun-ichi Takimoto + + * 34840: Doc/Zsh/prompt.yo: minor format fixes + +2015-04-02 Jun-ichi Takimoto * 34836: Doc/Zsh/prompt.yo: fix description of '%-0<<' diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo index 08dcded24..307587678 100644 --- a/Doc/Zsh/prompt.yo +++ b/Doc/Zsh/prompt.yo @@ -274,7 +274,7 @@ The value of the first element of the tt(psvar) array parameter. Following the `tt(%)' with an integer gives that element of the array. Negative integers count from the end of the array. ) -item(tt(%LPAR())var(x.true-text.false-text)tt(RPAR()))( +item(tt(%LPAR())var(x)tt(.)var(true-text)tt(.)var(false-text)tt(RPAR()))( Specifies a ternary expression. The character following the var(x) is arbitrary; the same character is used to separate the text for the `true' result from that for the `false' result. @@ -364,7 +364,7 @@ level (i.e. truncations inside a `tt(%LPAR())' are separate), which ever comes first. In particular, a truncation with argument zero (e.g., `tt(%<<)') marks the end of the range of the string to be truncated while turning off truncation from there on. For example, the -prompt '%10<...<%~%<<%# ' will print a truncated representation of the +prompt `tt(%10<...<%~%<<%# )' will print a truncated representation of the current directory, followed by a `tt(%)' or `tt(#)', followed by a space. Without the `tt(%<<)', those two characters would be included in the string to be truncated. Note that `tt(%-0<<)' is not equivalent @@ -375,7 +375,7 @@ delimited by embedded newlines (if any). If the total length of any line of the prompt after truncation is greater than the terminal width, or if the part to be truncated contains embedded newlines, truncation behavior is undefined and may change in a future version of the shell. Use -`tt(%-var(n)LPAR()l.var(true-text).var(false-text)RPAR())' to remove parts +`tt(%-)var(n)tt(LPAR()l.)var(true-text)tt(.)var(false-text)tt(RPAR())' to remove parts of the prompt when the available space is less than var(n). ) enditem() -- cgit v1.2.3 From be5f561fa4cfd2f9c705fc24bdbc096070586a74 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Tue, 7 Apr 2015 20:40:57 +0900 Subject: 34850: make URLs in html/pdf docs clickable --- ChangeLog | 7 +++++++ Doc/META-FAQ.yo | 1 + Doc/Zsh/contrib.yo | 28 ++++++++++++++-------------- Doc/Zsh/ftp_sites.yo | 14 +++++++------- Doc/Zsh/manual.yo | 6 +++--- Doc/Zsh/metafaq.yo | 14 +++++++------- Doc/Zsh/roadmap.yo | 2 +- Doc/zman.yo | 1 + Doc/ztexi.yo | 1 + 9 files changed, 42 insertions(+), 32 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 1cb94c46c..8872e0d9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-04-07 Jun-ichi Takimoto + + * 34850: Doc/zman.yo, Doc/ztexi.yo, Doc/META-FAQ.yo, + Doc/Zsh/contrib.yo, Doc/Zsh/ftp_sites.yo, Doc/Zsh/manual.yo, + Doc/Zsh/metafaq.yo, Doc/Zsh/roadmap.yo: make URLs in html/pdf + docs clickable + 2015-04-06 Barton E. Schaefer * 34851: Src/builtin.c: fix thinko from 34093 that short-circuited diff --git a/Doc/META-FAQ.yo b/Doc/META-FAQ.yo index bfdb76b77..992844ec1 100644 --- a/Doc/META-FAQ.yo +++ b/Doc/META-FAQ.yo @@ -19,6 +19,7 @@ ARG1 def(em)(1)(ARG1) def(bf)(1)(ARG1) def(tt)(1)(ARG1) +def(uref)(1)(ARG1) def(var)(1)(ARG1) def(nofill)(1)(ARG1) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 4f6c437c9..ab9e7427d 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -595,22 +595,22 @@ In order to do that, you may use the tt(vcs_info) function. The following VCSs are supported, showing the abbreviated name by which they are referred to within the system: startsitem() -sitem(Bazaar (tt(bzr)))(http://bazaar-vcs.org/) -sitem(Codeville (tt(cdv)))(http://codeville.org/) -sitem(Concurrent Versioning System (tt(cvs)))(http://www.nongnu.org/cvs/) -sitem(Darcs (tt(darcs)))(http://darcs.net/) -sitem(Fossil (tt(fossil)))(http://fossil-scm.org/) -sitem(Git (tt(git)))(http://git-scm.com/) -sitem(GNU arch (tt(tla)))(http://www.gnu.org/software/gnu-arch/) -sitem(Mercurial (tt(hg)))(http://mercurial.selenic.com/) -sitem(Monotone (tt(mtn)))(http://monotone.ca/) -sitem(Perforce (tt(p4)))(http://www.perforce.com/) -sitem(Subversion (tt(svn)))(http://subversion.tigris.org/) -sitem(SVK (tt(svk)))(http://svk.bestpractical.com/) +sitem(Bazaar (tt(bzr)))(uref(http://bazaar.canonical.com/)) +sitem(Codeville (tt(cdv)))(uref(http://freecode.com/projects/codeville/)) +sitem(Concurrent Versioning System (tt(cvs)))(uref(http://www.nongnu.org/cvs/)) +sitem(Darcs (tt(darcs)))(uref(http://darcs.net/)) +sitem(Fossil (tt(fossil)))(uref(http://fossil-scm.org/)) +sitem(Git (tt(git)))(uref(http://git-scm.com/)) +sitem(GNU arch (tt(tla)))(uref(http://www.gnu.org/software/gnu-arch/)) +sitem(Mercurial (tt(hg)))(uref(http://mercurial.selenic.com/)) +sitem(Monotone (tt(mtn)))(uref(http://monotone.ca/)) +sitem(Perforce (tt(p4)))(uref(http://www.perforce.com/)) +sitem(Subversion (tt(svn)))(uref(http://subversion.apache.org/)) +sitem(SVK (tt(svk)))(uref(http://svk.bestpractical.com/)) endsitem() There is also support for the patch management system tt(quilt) -(http://savannah.nongnu.org/projects/quilt). See tt(Quilt Support) +(uref(http://savannah.nongnu.org/projects/quilt)). See tt(Quilt Support) below for details. To load tt(vcs_info): @@ -2061,7 +2061,7 @@ accented characters, the two keys are a base character followed by a code for the accent, while for other special characters the two characters together form a mnemonic for the character to be inserted. The two-character codes are a subset of those given by RFC 1345 (see for -example tt(http://www.faqs.org/rfcs/rfc1345.html)). +example uref(http://www.faqs.org/rfcs/rfc1345.html)). The function may optionally be followed by up to two characters which replace one or both of the characters read from the keyboard; if both diff --git a/Doc/Zsh/ftp_sites.yo b/Doc/Zsh/ftp_sites.yo index 62c1bff06..804d975f3 100644 --- a/Doc/Zsh/ftp_sites.yo +++ b/Doc/Zsh/ftp_sites.yo @@ -1,15 +1,15 @@ startitem() item(Primary site)( -nofill(tt(ftp://ftp.zsh.org/pub/) -tt(http://www.zsh.org/pub/)) +nofill(uref(ftp://ftp.zsh.org/pub/) +uref(http://www.zsh.org/pub/)) ) item(Australia)( -nofill(tt(ftp://ftp.zsh.org/pub/) -tt(http://www.zsh.org/pub/) -tt(http://mirror.dejanseo.com.au/pub/zsh/)) +nofill(uref(ftp://ftp.zsh.org/pub/) +uref(http://www.zsh.org/pub/) +uref(http://mirror.dejanseo.com.au/pub/zsh/)) ) item(Hungary)( -nofill(tt(ftp://ftp.cs.elte.hu/pub/zsh/) -tt(http://www.cs.elte.hu/pub/zsh/)) +nofill(uref(ftp://ftp.cs.elte.hu/pub/zsh/) +uref(http://www.cs.elte.hu/pub/zsh/)) ) enditem() diff --git a/Doc/Zsh/manual.yo b/Doc/Zsh/manual.yo index 11c81501a..e0b0f14cb 100644 --- a/Doc/Zsh/manual.yo +++ b/Doc/Zsh/manual.yo @@ -185,16 +185,16 @@ produce a nicely formatted printed manual. item(The HTML manual)( An HTML version of this manual is available at the Zsh web site via: -tt(http://zsh.sourceforge.net/Doc/). +uref(http://zsh.sourceforge.net/Doc/). (The HTML version is produced with bf(texi2html), which may be obtained -from tt(http://www.nongnu.org/texi2html/). The command is +from uref(http://www.nongnu.org/texi2html/). The command is `tt(texi2html --output . --ifinfo --split=chapter --node-files zsh.texi)'. If necessary, upgrade to version 1.78 of texi2html.) ) enditem() For those who do not have the necessary tools to process texinfo, -precompiled documentation (PostScript, dvi, info and HTML formats) +precompiled documentation (PostScript, dvi, PDF, info and HTML formats) is available from the zsh archive site or its mirrors, in the file tt(zsh-doc.tar.gz). (See noderef(Availability) for a list of sites.) diff --git a/Doc/Zsh/metafaq.yo b/Doc/Zsh/metafaq.yo index a005ca0dd..6cb299ad1 100644 --- a/Doc/Zsh/metafaq.yo +++ b/Doc/Zsh/metafaq.yo @@ -28,9 +28,9 @@ cindex(availability of zsh) INCLUDEFILE(Zsh/ftp_sites.yo)\ The up-to-date source code is available via Git from Sourceforge. See -tt(http://sourceforge.net/projects/zsh/) for details. A summary of +uref(http://sourceforge.net/projects/zsh/) for details. A summary of instructions for the archive can be found at -tt(http://zsh.sourceforge.net/). +uref(http://zsh.sourceforge.net/). texinode(Mailing Lists)(The Zsh FAQ)(Availability)(Introduction) sect(Mailing Lists) @@ -75,18 +75,18 @@ maintained by Karsten Thygesen tt(). The mailing lists are archived; the archives can be accessed via the administrative addresses listed above. There is also a hypertext archive, maintained by Geoff Wing tt(), available at -tt(http://www.zsh.org/mla/). +uref(http://www.zsh.org/mla/). texinode(The Zsh FAQ)(The Zsh Web Page)(Mailing Lists)(Introduction) sect(The Zsh FAQ) Zsh has a list of Frequently Asked Questions (FAQ), maintained by Peter Stephenson tt(). It is regularly posted to the newsgroup bf(comp.unix.shell) and the bf(zsh-announce) mailing list. The latest version can be found at any of the Zsh FTP sites, or at -tt(http://www.zsh.org/FAQ/). The contact address for FAQ-related matters +uref(http://www.zsh.org/FAQ/). The contact address for FAQ-related matters is tt(). texinode(The Zsh Web Page)(The Zsh Userguide)(The Zsh FAQ)(Introduction) sect(The Zsh Web Page) -Zsh has a web page which is located at tt(http://www.zsh.org/). This is +Zsh has a web page which is located at uref(http://www.zsh.org/). This is maintained by Karsten Thygesen tt(), of SunSITE Denmark. The contact address for web-related matters is tt(). texinode(The Zsh Userguide)(See Also)(The Zsh Web Page)(Introduction) @@ -95,10 +95,10 @@ A userguide is currently in preparation. It is intended to complement the manual, with explanations and hints on issues where the manual can be cabbalistic, hierographic, or downright mystifying (for example, the word `hierographic' does not exist). It can be viewed in its current state at -tt(http://zsh.sourceforge.net/Guide/). At the time of writing, chapters +uref(http://zsh.sourceforge.net/Guide/). At the time of writing, chapters dealing with startup files and their contents and the new completion system were essentially complete. sect(The Zsh Wiki) -A `wiki' website for zsh has been created at tt(http://www.zshwiki.org/). +A `wiki' website for zsh has been created at uref(http://www.zshwiki.org/). This is a site which can be added to and modified directly by users without any special permission. You can add your own zsh tips and configurations. diff --git a/Doc/Zsh/roadmap.yo b/Doc/Zsh/roadmap.yo index 677848961..bd064e2b2 100644 --- a/Doc/Zsh/roadmap.yo +++ b/Doc/Zsh/roadmap.yo @@ -49,7 +49,7 @@ The shell now supports the UTF-8 character set (and also others if supported by the operating system). This is (mostly) handled transparently by the shell, but the degree of support in terminal emulators is variable. There is some discussion of this in the shell FAQ, -http://zsh.dotsrc.org/FAQ/ . Note in particular that for combining +uref(http://www.zsh.org/FAQ/). Note in particular that for combining characters to be handled the option tt(COMBINING_CHARS) needs to be set. Because the shell is now more sensitive to the definition of the character set, note that if you are upgrading from an older version of diff --git a/Doc/zman.yo b/Doc/zman.yo index 3329cb975..73cc186e0 100644 --- a/Doc/zman.yo +++ b/Doc/zman.yo @@ -32,6 +32,7 @@ COMMENT(--- emphasised text ---) def(em)(1)(NOTRANS(\fI)ARG1+NOTRANS(\fP)) def(bf)(1)(NOTRANS(\fB)ARG1+NOTRANS(\fP)) def(tt)(1)(NOTRANS(\fB)ARG1+NOTRANS(\fP)) +def(uref)(1)(NOTRANS(\fB)ARG1+NOTRANS(\fP)) def(var)(1)(NOTRANS(\fI)ARG1+NOTRANS(\fP)) COMMENT(--- man page headers ---) diff --git a/Doc/ztexi.yo b/Doc/ztexi.yo index 636896117..699567724 100644 --- a/Doc/ztexi.yo +++ b/Doc/ztexi.yo @@ -38,6 +38,7 @@ COMMENT(--- emphasised text ---) def(em)(1)(+NOTRANS(@emph{)ARG1+NOTRANS(})) def(bf)(1)(+NOTRANS(@cite{)ARG1+NOTRANS(})) def(tt)(1)(+NOTRANS(@t{)ARG1+NOTRANS(})) +def(uref)(1)(+NOTRANS(@t{@uref{)ARG1+NOTRANS(}})) def(var)(1)(+NOTRANS(@var{)ARG1+NOTRANS(})) COMMENT(--- man page headers ---) -- cgit v1.2.3 From cea8b471f62e6aabbbe038180d355703a0b5c2c1 Mon Sep 17 00:00:00 2001 From: Han Pingtian Date: Sat, 4 Apr 2015 06:30:15 +0800 Subject: users/20078: HIST_BEEP doc --- ChangeLog | 4 ++++ Doc/Zsh/options.yo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 646726337..8eba2ca89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-04-13 Peter Stephenson + + * Han Pingtian: users/20078: Doc/Zsh/options.yo: HIST_BEEP doc. + 2015-04-10 Clint Adams * 34874: Completion/Unix/Command/_cabal: completion for cabal diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 19920ca53..854025628 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -809,7 +809,7 @@ pindex(NOHISTBEEP) cindex(history beeping) cindex(beep, history) item(tt(HIST_BEEP) )( -Beep when an attempt is made to access a history entry which +Beep in ZLE when a widget attempts to access a history entry which isn't there. ) pindex(HIST_EXPIRE_DUPS_FIRST) -- cgit v1.2.3 From 20982001b1ba4dd5a133f4b0b8994735758b815b Mon Sep 17 00:00:00 2001 From: Han Pingtian Date: Sat, 11 Apr 2015 07:20:12 +0800 Subject: 34875: CSH_JUNKIE_HISTORY doc --- ChangeLog | 2 ++ Doc/Zsh/options.yo | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 8eba2ca89..e4ffaa46a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-04-13 Peter Stephenson + * Han Pingtian: 34875: Doc/Zsh/options.yo: CSH_JUNKIE_HISTORY doc. + * Han Pingtian: users/20078: Doc/Zsh/options.yo: HIST_BEEP doc. 2015-04-10 Clint Adams diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 854025628..f0d6f1d3c 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1846,8 +1846,8 @@ cindex(history style, csh) item(tt(CSH_JUNKIE_HISTORY) )( A history reference without an event specifier will always refer to the previous command. Without this option, such a history reference refers -to the same event as the previous history reference, defaulting to the -previous command. +to the same event as the previous history reference on the current +command line, defaulting to the previous command. ) pindex(CSH_JUNKIE_LOOPS) pindex(NO_CSH_JUNKIE_LOOPS) -- cgit v1.2.3 From 959aa75423c56f57ea7f8fa9f7a7baa32caf46ac Mon Sep 17 00:00:00 2001 From: Han Pingtian Date: Mon, 13 Apr 2015 06:24:25 +0800 Subject: 34880: POSIX_TRAPS doc --- ChangeLog | 2 ++ Doc/Zsh/options.yo | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index e4ffaa46a..504df73e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-04-13 Peter Stephenson + * Han Pingtian: 34880: Doc/Zsh/options.yo: POSIX_TRAPS doc. + * Han Pingtian: 34875: Doc/Zsh/options.yo: CSH_JUNKIE_HISTORY doc. * Han Pingtian: users/20078: Doc/Zsh/options.yo: HIST_BEEP doc. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index f0d6f1d3c..20d9fc2a8 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -2097,7 +2097,7 @@ pindex(NOPOSIXTRAPS) cindex(traps, on function exit) cindex(traps, POSIX compatibility) item(tt(POSIX_TRAPS) )( -When the is option is set, the usual zsh behaviour of executing +When this option is set, the usual zsh behaviour of executing traps for tt(EXIT) on exit from shell functions is suppressed. In that case, manipulating tt(EXIT) traps always alters the global trap for exiting the shell; the tt(LOCAL_TRAPS) option is -- cgit v1.2.3 From ccb1cf2d10aa674caf2aa73599110aed1127ad26 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Mon, 12 Dec 2011 14:13:55 +0100 Subject: 34902: Doc: Explain the numeric argument and be consistent about what we call it --- ChangeLog | 6 ++++++ Doc/Zsh/compsys.yo | 2 +- Doc/Zsh/contrib.yo | 18 +++++++++--------- Doc/Zsh/zle.yo | 31 +++++++++++++++++++++---------- 4 files changed, 37 insertions(+), 20 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 05d4cf094..ec8423c02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-04-16 Mikael Magnusson + + * 34902: Doc/Zsh/compsys.yo, Doc/Zsh/contrib.yo, Doc/Zsh/zle.yo: + explain the numeric argument and be consistent about what we + call it. + 2015-04-15 Peter Stephenson * 34901: Test/A04redirect.ztst: Test for the foregoing. diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 6c6bedb21..45afe2448 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1860,7 +1860,7 @@ tested for all tags valid for the current completion, then the tt(default) tag. The cursor will be moved back to the previous line if this style is `true' for all types of match. Note that unlike the tt(ALWAYS_LAST_PROMPT) option this is independent of the -numeric prefix argument. +numeric argument. ) kindex(known-hosts-files) item(tt(known-hosts-files))( diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index ab9e7427d..24be63eb9 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1928,7 +1928,7 @@ described immediately above, i.e. using styles to decide the word boundaries. However, it is not a replacement for any existing function. The basic behaviour is to delete the word around the cursor. There is no -numeric prefix handling; only the single word around the cursor is +numeric argument handling; only the single word around the cursor is considered. If the widget contains the string tt(kill), the removed text will be placed in the cutbuffer for future yanking. This can be obtained by defining tt(kill-whole-word-match) as follows: @@ -1994,14 +1994,14 @@ full history line. Note that leading zeroes must be typed (they are only shown when necessary for removing ambiguity). The entire history is searched; there is no distinction between forwards and backwards. -With a prefix argument, the search is not anchored to the start of +With a numeric argument, the search is not anchored to the start of the line; the string typed by the use may appear anywhere in the line in the history. If the widget name contains `tt(-end)' the cursor is moved to the end of the line inserted. If the widget name contains `tt(-space)' any space in the text typed is treated as a wildcard and can match anything (hence -a leading space is equivalent to giving a prefix argument). Both +a leading space is equivalent to giving a numeric argument). Both forms can be combined, for example: example(zle -N history-beginning-search-menu-space-end \ @@ -2031,8 +2031,8 @@ vindex(incarg, use of) item(tt(incarg))( Typing the keystrokes for this widget with the cursor placed on or to the left of an integer causes that integer to be incremented by one. With a -numeric prefix argument, the number is incremented by the amount of the -argument (decremented if the prefix argument is negative). The shell +numeric argument, the number is incremented by the amount of the +argument (decremented if the numeric argument is negative). The shell parameter tt(incarg) may be set to change the default increment to something other than one. @@ -2506,7 +2506,7 @@ This function may replace the tt(insert-last-word) widget, like so: example(zle -N insert-last-word smart-insert-last-word) -With a numeric prefix, or when passed command line arguments in a call +With a numeric argument, or when passed command line arguments in a call from another widget, it behaves like tt(insert-last-word), except that words in comments are ignored when tt(INTERACTIVE_COMMENTS) is set. @@ -2535,12 +2535,12 @@ The effect is similar to the function of the same name in Emacs. Transpose the current line with the previous line and move the cursor to the start of the next line. Repeating this (which can be done by -providing a positive numeric prefix argument) has the effect of moving +providing a positive numeric argument) has the effect of moving the line above the cursor down by a number of lines. -With a negative numeric prefix argument, requires two lines above the +With a negative numeric argument, requires two lines above the cursor. These two lines are transposed and the cursor moved to the -start of the previous line. Using a numeric prefix less than -1 +start of the previous line. Using a numeric argument less than -1 has the effect of moving the line above the cursor up by minus that number of lines. ) diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 8fabe4b4c..ffce54c84 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -40,6 +40,17 @@ the following setting: example(zle_highlight=(none)) +In many places, references are made to the tt(numeric argument). This can +by default be entered in emacs mode by holding the alt key and typing +a number, or pressing escape before each number, and in vi command mode +by typing the number before entering a command. Generally the numeric +argument causes the next command entered to be repeated the specified +number of times, unless otherwise noted below. See also +ifzman(the em(Arguments) subsection of the em(Widgets) section )\ +ifnzman(noderef(Arguments) )\ +for some other ways the numeric argument can be modified. The default +bindings mentioned here use the tt(digit-argument) widget. + startmenu() menu(Keymaps) menu(Zle Builtins) @@ -649,9 +660,9 @@ item(var(widget) tt([ -n) var(num) tt(]) tt([ -Nw ] [ -K) var(keymap) tt(]) var( Invoke the specified widget. This can only be done when ZLE is active; normally this will be within a user-defined widget. -With the options tt(-n) and tt(-N), the current numerical argument will be +With the options tt(-n) and tt(-N), the current numeric argument will be saved and then restored after the call to tt(widget); `tt(-n) var(num)' -sets the numerical argument temporarily to var(num), while `tt(-N)' sets it +sets the numeric argument temporarily to var(num), while `tt(-N)' sets it to the default, i.e. as if there were none. With the option tt(-K), var(keymap) will be used as the current keymap @@ -1492,7 +1503,7 @@ reexamined. Note that negative numbers should be preceded by a If two arguments are given, the second specifies the word on the command line in normal array index notation (as a more natural alternative to the -prefix argument). Hence 1 is the first word, and -1 (the default) is the +numeric argument). Hence 1 is the first word, and -1 (the default) is the last word. If a third argument is given, its value is ignored, but it is used to @@ -1889,14 +1900,14 @@ spaces; if instead it is followed by tt(-2), then tt(forward-char), move backward two spaces. Inside a widget function, if passed an argument, i.e. `tt(zle -universal-argument) var(num)', the numerical argument will be set to +universal-argument) var(num)', the numeric argument will be set to var(num); this is equivalent to `tt(NUMERIC=)var(num)'. ) tindex(argument-base) item(tt(argument-base))( Use the existing numeric argument as a numeric base, which must be in the range 2 to 36 inclusive. Subsequent use of tt(digit-argument) and -tt(universal-argument) will input a new prefix in the given base. +tt(universal-argument) will input a new numeric argument in the given base. The usual hexadecimal convention is used: the letter tt(a) or tt(A) corresponds to 10, and so on. Arguments in bases requiring digits from 10 upwards are more conveniently input with tt(universal-argument), since @@ -2053,9 +2064,9 @@ Reads a key sequence, then prints the function bound to that sequence. tindex(exchange-point-and-mark) item(tt(exchange-point-and-mark) (^X^X) (unbound) (unbound))( Exchange the cursor position (point) with the position of the mark. -Unless a negative prefix argument is given, the region between +Unless a negative numeric argument is given, the region between point and mark is activated so that it can be highlighted. -If a zero prefix argument is given, the region is activated but +If a zero numeric argument is given, the region is activated but point and mark are not swapped. ) tindex(execute-named-cmd) @@ -2268,7 +2279,7 @@ Set the specified mark at the cursor position. tindex(set-mark-command) item(tt(set-mark-command) (^@) (unbound) (unbound))( Set the mark at the cursor position. If called with a negative -prefix argument, do not set the mark but deactivate the region so that +numeric argument, do not set the mark but deactivate the region so that it is no longer highlighted (it is still usable for other purposes). Otherwise the region is marked as active. ) @@ -2426,8 +2437,8 @@ tt(set-mark-command). The region is only highlighted if it is active, which is the case if tt(set-mark-command) or tt(exchange-point-and-mark) has been called and the line has not been subsequently modified. The region can be deactivated by calling tt(set-mark-command) with a -negative prefix argument, or reactivated by calling -tt(exchange-point-and-mark) with a zero prefix argument. Note +negative numeric argument, or reactivated by calling +tt(exchange-point-and-mark) with a zero numeric argument. Note that whether or not the region is active has no effect on its use within widgets, it simply determines whether it is highlighted. ) -- cgit v1.2.3 From 89c2129905d067b2d52c70f5b453561bb782da89 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 25 Apr 2015 10:50:16 -0700 Subject: 34961: sysparams[pid] and sysparams[ppid] added to variables index --- ChangeLog | 3 +++ Doc/Zsh/mod_system.yo | 2 ++ 2 files changed, 5 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index a76808be2..9dd9bcc2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-04-25 Barton E. Schaefer + * 34961: Doc/Zsh/mod_system.yo: sysparams[pid] and sysparams[ppid] + added to variables index + * 34961: Src/compat.c, Src/init.c: replace a couple of free() with zfree() for consistency. diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo index d6b3765ff..7101e37dc 100644 --- a/Doc/Zsh/mod_system.yo +++ b/Doc/Zsh/mod_system.yo @@ -181,10 +181,12 @@ A readonly associative array. The keys are: startitem() item(tt(pid))( +vindex(pid, sysparams) Returns the process ID of the current process, even in subshells. Compare tt($$), which returns the process ID of the main shell process. ) item(tt(ppid))( +vindex(ppid, sysparams) Returns the process ID of the parent of the current process, even in subshells. Compare tt($PPID), which returns the process ID of the parent of the main shell process. -- cgit v1.2.3 From 9d0e3bde2a0511f31918e193ce76c427ef673961 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 25 Apr 2015 10:58:55 -0700 Subject: 34961: minor wording clarification --- ChangeLog | 2 ++ Doc/Zsh/compsys.yo | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index d86846ff2..8daba04c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-04-25 Barton E. Schaefer + * 34961: Doc/Zsh/compsys.yo: minor wording clarification + * 34961: Src/Modules/datetime.c: $TZ is implicitly local in builtin strftime (originally workers/34602 from workers/34596) diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 45afe2448..b699502ca 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -354,7 +354,7 @@ tt(all): no further completion is attempted; a string containing the substring tt(patterns): no pattern completion functions will be called; a string containing tt(default): the function for the `tt(-default-)' context will not be called, but -functions defined for commands will +functions defined for commands will be. ) kindex(-math-, completion context) item(tt(-math-))( -- cgit v1.2.3 From bf258a1c07a9cf1119f83d1d15310b02b94f4d67 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 29 Apr 2015 15:54:49 +0100 Subject: 34992: POSIX fix for readonly variables. With POSIXBUILTINS, variables can be marked readonly if unset. Also, variables can't have the readonly flag removed. --- ChangeLog | 7 +++++++ Doc/Zsh/builtins.yo | 7 +++++++ Src/builtin.c | 37 +++++++++++++++++++++++++++++++++---- Src/params.c | 6 +++++- Test/B02typeset.ztst | 17 +++++++++++++++++ 5 files changed, 69 insertions(+), 5 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index a5987b764..2d2fb1b5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-04-29 Peter Stephenson + + * 34992: Doc/Zsh/builtins.yo, Src/builtin.c, Src/params.c, + Test/B02typeset.ztst: With POSXIBUILTINS, parameters can be + marked readonly if unset and in any case can't subsequently be + marked not readonly. + 2015-04-28 Peter Stephenson * 34989: Src/exec.c: AUTOCD needs to pass -- to cd to avoid diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index dd5a80fe8..985d19e11 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1933,6 +1933,13 @@ item(tt(-r))( The given var(name)s are marked readonly. Note that if var(name) is a special parameter, the readonly attribute can be turned on, but cannot then be turned off. + +If the tt(POSIX_BUILTINS) option is set, the readonly attribute is +more restrictive: unset variables can be marked readonly and cannot then +be set; furthermore, the readonly attribute cannot be removed from any +variable. Note that in zsh (unlike other shells) it is still possible +to create a local variable of the same name as this is considered a +different variable (though this variable, too, can be marked readonly). ) item(tt(-t))( Tags the named parameters. Tags have no special meaning to the shell. diff --git a/Src/builtin.c b/Src/builtin.c index de0101405..0a57489ea 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -1931,8 +1931,12 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), * locallevel as an unset one we use the pm struct anyway: that's * handled in createparam(). Here we just avoid using it for the * present tests if it's unset. + * + * POSIXBUILTINS horror: we need to retain the 'readonly' flag + * of an unset parameter. */ - usepm = pm && !(pm->node.flags & PM_UNSET); + usepm = pm && (!(pm->node.flags & PM_UNSET) || + (isset(POSIXBUILTINS) && (pm->node.flags & PM_READONLY))); /* * We need to compare types with an existing pm if special, @@ -2032,6 +2036,20 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), else if (newspecial != NS_NONE && strcmp(pname, "SECONDS") == 0) newspecial = NS_SECONDS; + if (isset(POSIXBUILTINS)) { + /* + * Stricter rules about retaining readonly attribute in this case. + */ + if ((on & PM_READONLY) && (!usepm || (pm->node.flags & PM_UNSET)) && + !value) + on |= PM_UNSET; + else if (usepm && (pm->node.flags & PM_READONLY) && + !(on & PM_READONLY)) { + zerr("read-only variable: %s", pm->node.nam); + return NULL; + } + } + /* * A parameter will be local if * 1. we are re-using an existing local parameter @@ -2078,9 +2096,15 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), } if (usepm == 2) /* do not change the PM_UNSET flag */ pm->node.flags = (pm->node.flags | (on & ~PM_READONLY)) & ~off; - else + else { + /* + * Keep unset if using readonly in POSIX mode. + */ + if (!(on & PM_READONLY) || !isset(POSIXBUILTINS)) + off |= PM_UNSET; pm->node.flags = (pm->node.flags | - (on & ~PM_READONLY)) & ~(off | PM_UNSET); + (on & ~PM_READONLY)) & ~off; + } if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) { if (typeset_setwidth(cname, pm, ops, on, 0)) return NULL; @@ -2256,7 +2280,12 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), * readonly flag */ pm = createparam(pname, on & ~PM_READONLY); - DPUTS(!pm, "BUG: parameter not created"); + if (!pm) { + if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z | + PM_INTEGER | PM_EFLOAT | PM_FFLOAT)) + zerrnam(cname, "can't change variable attribute: %s", pname); + return NULL; + } if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) { if (typeset_setwidth(cname, pm, ops, on, 0)) return NULL; diff --git a/Src/params.c b/Src/params.c index e8a90104c..d53b6ca7e 100644 --- a/Src/params.c +++ b/Src/params.c @@ -874,10 +874,14 @@ createparam(char *name, int flags) DPUTS(oldpm && oldpm->level > locallevel, "BUG: old local parameter not deleted"); if (oldpm && (oldpm->level == locallevel || !(flags & PM_LOCAL))) { + if (isset(POSIXBUILTINS) && (oldpm->node.flags & PM_READONLY)) { + zerr("read-only variable: %s", name); + return NULL; + } if (!(oldpm->node.flags & PM_UNSET) || (oldpm->node.flags & PM_SPECIAL)) { oldpm->node.flags &= ~PM_UNSET; if ((oldpm->node.flags & PM_SPECIAL) && oldpm->ename) { - Param altpm = + Param altpm = (Param) paramtab->getnode(paramtab, oldpm->ename); if (altpm) altpm->node.flags &= ~PM_UNSET; diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index 51ebc6535..f4fb8ecb9 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -468,3 +468,20 @@ 0:retying arrays to same array works >foo bar >goo car + + ( + setopt POSIXBUILTINS + readonly pbro + print ${+pbro} >&2 + (typeset pbro=3) + (pbro=4) + typeset -r pbro # idempotent (no error)... + print ${+pbro} >&2 # ...so still readonly... + typeset +r pbro # ...can't turn it off + ) +1:Readonly with POSIX_BUILTINS +?0 +?(eval):5: read-only variable: pbro +?(eval):6: read-only variable: pbro +?0 +?(eval):9: read-only variable: pbro -- cgit v1.2.3 From 0e797d79ce0af34f20ec5fa86a4ed92554a968f9 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 1 May 2015 09:55:04 +0100 Subject: 35007: Note in doc about scope of ZLE parameters --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 15 +++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 2d2fb1b5a..0f563bd92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-05-01 Peter Stephenson + + * 35007: Doc/Zsh/zle.yo: note about scope of ZLE parameters. + 2015-04-29 Peter Stephenson * 34992: Doc/Zsh/builtins.yo, Src/builtin.c, Src/params.c, diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index ffce54c84..653678eba 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -743,6 +743,21 @@ local scope, like parameters created in a function using tt(local). Inside completion widgets and traps called while ZLE is active, these parameters are available read-only. +Note that the parameters appear as local to any ZLE widget in +which they appear. Hence if it is desired to override them this needs +to be done within a nested function: + +example(widget-function+LPAR()+RPAR() { + # $WIDGET here refers to the special variable + # that is local inside widget-function + +LPAR()+RPAR() { + # This anonymous nested function allows WIDGET + # to be used as a local variable. The -h + # removes the special status of the variable. + local -h WIDGET + } +}) + startitem() vindex(BUFFER) item(tt(BUFFER) (scalar))( -- cgit v1.2.3 From 938751d2636f1b45b438f345b89861f1b0ed628e Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 1 May 2015 22:09:49 +0900 Subject: 35008: clarify description of 'exec' and 'return' --- ChangeLog | 5 +++++ Doc/Zsh/builtins.yo | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 0f563bd92..21db71ddc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-05-01 Jun-ichi Takimoto + + * 35008: Doc/Zsh/builtins.yo: clarify description of 'exec' and + 'return' + 2015-05-01 Peter Stephenson * 35007: Doc/Zsh/zle.yo: note about scope of ZLE parameters. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 985d19e11..c4acf7672 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -198,7 +198,7 @@ cindex(exiting loops) cindex(loops, exiting) item(tt(break) [ var(n) ])( Exit from an enclosing tt(for), tt(while), -tt(until), tt(select) or tt(repeat) loop. If var(n) +tt(until), tt(select) or tt(repeat) loop. If an arithmetic expression var(n) is specified, then break var(n) levels instead of just one. ) findex(builtin) @@ -291,7 +291,7 @@ cindex(continuing loops) item(tt(continue) [ var(n) ])( Resume the next iteration of the enclosing tt(for), tt(while), tt(until), tt(select) or -tt(repeat) loop. If var(n) is specified, break out of +tt(repeat) loop. If an arithmetic expression var(n) is specified, break out of var(n)-1 loops and resume at the var(n)th enclosing loop. ) alias(declare)(typeset) @@ -615,16 +615,21 @@ the same as if the commands had been executed directly by the shell; if there are no var(args) or they contain no commands (i.e. are an empty string or whitespace) the return status is zero. ) -item(tt(exec) [ tt(-cl) ] [ tt(-a) var(argv0) ] var(simple command))( -Replace the current shell with an external command rather than forking. +item(tt(exec) [ tt(-cl) ] [ tt(-a) var(argv0) ] [ var(command) [ var(arg) ... ]])( +Replace the current shell with an external var(command) rather than forking. With tt(-c) clear the environment; with tt(-l) prepend tt(-) to the tt(argv[0]) string of the command executed (to simulate a login shell); with tt(-a) var(argv0) set the tt(argv[0]) string of the command executed. See noderef(Precommand Modifiers). + +cindex(redirection, current shell's I/O) +If var(command) is omitted but any redirections are specified, +then the redirections will take effect in the current shell. ) findex(exit) item(tt(exit) [ var(n) ])( -Exit the shell with the exit status specified by var(n); if none +Exit the shell with the exit status specified by an arithmetic +expression var(n); if none is specified, use the exit status from the last command executed. pindex(IGNORE_EOF, use of) An EOF condition will also cause the shell to exit, unless @@ -1409,7 +1414,8 @@ findex(return) cindex(functions, returning from) item(tt(return) [ var(n) ])( Causes a shell function or `tt(.)' script to return to -the invoking script with the return status specified by var(n). If var(n) +the invoking script with the return status specified by +an arithmetic expression var(n). If var(n) is omitted, the return status is that of the last command executed. -- cgit v1.2.3