From 377e2400b7b6fc21ff333791461d615538b18cb9 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 24 Sep 2015 18:46:27 -0700 Subject: 36623: document bracketed-paste-magic and url-quote-magic; add cross-reference to vim text object widgets --- Doc/Zsh/contrib.yo | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 741d4ad07..b966e781c 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1705,7 +1705,10 @@ item(tt(select-word-style), tt(match-word-context), tt(match-words-by-style))( The eight `tt(-match)' functions are drop-in replacements for the builtin widgets without the suffix. By default they behave in a similar way. However, by the use of styles and the function tt(select-word-style), -the way words are matched can be altered. +the way words are matched can be altered. For comparison, the widgets +described in ifzman(zmanref(zshzle) under Text Objects)\ +ifnzman(noderef(Text Objects)) use fixed definitions of words, compatible +with the tt(vim) editor. The simplest way of configuring the functions is to use tt(select-word-style), which can either be called as a normal function with @@ -1895,6 +1898,100 @@ The tt(word-context) style is implemented by the function tt(match-word-context). This should not usually need to be called directly. ) +tindex(bracketed-paste-magic) +item(bracketed-paste-magic)( +The tt(bracketed-paste) widget (see ifzman(subsection Miscellaneous in +zmanref(zshzle))ifnzman(noderef(Miscellaneous) in noderef(Zle Widgets))) +inserts pasted text literally into the editor buffer rather than interpret +it as keystrokes. This disables some common usages where the self-insert +widget is replaced in order to accomplish some extra processing. An +example is the contributed tt(url-quote-magic) widget described below. + +The tt(bracketed-paste-magic) widget is meant to replace tt(bracketed-paste) +with a wrapper that re-enables these self-insert actions, and other +actions as selected by zstyles. Therefore this widget is installed with +ifzman() +example(autoload -Uz bracketed-paste-magic +zle -N bracketed-paste bracketed-paste-magic) + +Other than enabling some widget processing, tt(bracketed-paste-magic) +attempts to replicate tt(bracketed-paste) as faithfully as possible. + +The following zstyles may be set to control processing of pasted text. +All are looked up in the context `tt(:bracketed-paste-magic)'. + +startitem() +item(tt(active-widgets))( +A list of patterns matching widget names that should be activated during +the paste. All other key sequences are processed as self-insert-unmeta. +The default is `tt(self-*)' so any user-defined widgets named with that +prefix are active along with the builtin self-insert. + +If this style is not set (explicitly deleted) or set to an empty value, +no widgets are active and the pasted text is inserted literally. If the +value includes `tt(undefined-key)', any unknown sequences are discarded +from the pasted text. +) +item(tt(inactive-keys))( +The inverse of tt(active-widgets), a list of key sequences that always use +tt(self-insert-unmeta) even when bound to an active widget. Note that +this is a list of literal key sequences, not patterns. +) +item(tt(paste-init))( +A list of function names, called in widget context (but not as widgets). +The functions are called in order until one of them returns a non-zero +status. The parameter `tt(PASTED)' contains the initial state of the +pasted text. All other ZLE parameters such as `tt(BUFFER)' have their +normal values and side-effects, and full history is available, so for +example tt(paste-init) functions may move words from tt(BUFFER) into +tt(PASTED) to make those words visible to the tt(active-widgets). + +A non-zero return from a tt(paste-init) function does em(not) prevent the +paste itself from proceeding. + +Loading tt(bracketed-paste-magic) defines tt(backward-extend-paste), a +helper function for use in tt(paste-init). + +example(zstyle :bracketed-paste-magic paste-init \ + backward-extend-paste) + +When a paste would insert into the middle of a word or append text to a +word already on the line, tt(backward-extend-paste) moves the prefix +from tt(LBUFFER) into tt(PASTED) so that the tt(active-widgets) see the +full word so far. This may be useful with tt(url-quote-magic). +) +item(tt(paste-finish))( +Another list of function names called in order until one returns non-zero. +These functions are called em(after) the pasted text has been processed +by the tt(active-widgets), but em(before) it is inserted into `tt(BUFFER)'. +ZLE parameters have their normal values and side-effects. + +A non-zero return from a tt(paste-finish) function does em(not) prevent +the paste itself from proceeding. + +Loading tt(bracketed-paste-magic) also defines tt(quote-paste), a helper +function for use in tt(paste-finish). + +example(zstyle :bracketed-paste-magic paste-finish \ + quote-paste +zstyle :bracketed-paste-magic:finish quote-style \ + qqq) + +When the pasted text is inserted into tt(BUFFER), it is quoted per the +tt(quote-style) value. To forcibly turn off the built-in numeric prefix +quoting of tt(bracketed-paste), use: + +example(zstyle :bracketed-paste-magic:finish quote-style \ + none) +) +enditem() + +em(Important:) During tt(active-widgets) processing of the paste (after +tt(paste-init) and before tt(paste-finish)), tt(BUFFER) starts empty and +history is restricted, so cursor motions, etc., may not pass outside of +the pasted content. Text assigned to tt(BUFFER) by the active widgets +is copied back into tt(PASTED) before tt(paste-finish). +) tindex(copy-earlier-word) item(tt(copy-earlier-word))( This widget works like a combination of tt(insert-last-word) and @@ -2557,6 +2654,69 @@ 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. ) +tindex(url-quote-magic) +item(tt(url-quote-magic))( +This widget replaces the built-in tt(self-insert) to make it easier to +type URLs as command line arguments. As you type, the input character is +analyzed and, if it may need quoting, the current word is checked for a +URI scheme. If one is found and the current word is not already in +quotes, a backslash is inserted before the input character. + +Styles to control quoting behavior: + +startitem() +item(tt(url-metas))( +This style is looked up in the context `tt(:url-quote-magic:)var(scheme)' +(where var(scheme) is that of the current URL, e.g. "tt(ftp)"). The value +is a string listing the characters to be treated as globbing +metacharacters when appearing in a URL using that scheme. The default is +to quote all zsh extended globbing characters, excluding 'tt(<)' and +'tt(>)' but including braces (as in brace expansion). See also +tt(url-seps). +) +item(tt(url-seps))( +Like tt(url-metas), but lists characters that should be considered command +separators, redirections, history references, etc. The default is to +quote the standard set of shell separators, excluding those that overlap +with the extended globbing characters, but including 'tt(<)' and +'tt(>)' and the first character of tt($histchars). +) +item(tt(url-globbers))( +This style is looked up in the context `tt(:url-quote-magic)'. The values +form a list of command names that are expected to do their own globbing +on the URL string. This implies that they are aliased to use the +`tt(noglob)' modifier. When the first word on the line matches one of the +values em(and) the URL refers to a local file (see tt(url-local-schema)), +only the tt(url-seps) characters are quoted; the tt(url-metas) are left +alone, allowing them to affect command-line parsing, completion, etc. The +default values are a literal `tt(noglob)' plus (when the tt(zsh/parameter) +module is available) any commands aliased to the helper function +`tt(urlglobber)' or its alias `tt(globurl)'. +) +item(tt(url-local-schema))( +This style is always looked up in the context `tt(:urlglobber)', even +though it is used by both url-quote-magic and urlglobber. The values form +a list of URI schema that should be treated as referring to local files by +their real local path names, as opposed to files which are specified +relative to a web-server-defined document root. The defaults are +"tt(ftp)" and "tt(file)". +) +item(tt(url-other-schema))( +Like tt(url-local-schema), but lists all other URI schema upon which +tt(urlglobber) and tt(url-quote-magic) should act. If the URI on the +command line does not have a scheme appearing either in this list or in +tt(url-local-schema), it is not magically quoted. The default values are +"tt(http)", "tt(https)", and "tt(ftp)". When a scheme appears both here +and in tt(url-local-schema), it is quoted differently depending on whether +the command name appears in tt(url-globbers). +) +enditem() + +Loading tt(url-quote-magic) also defines a helper function `tt(urlglobber)' +and aliases `tt(globurl)' to `tt(noglob urlglobber)'. This function takes +a local URL apart, attempts to pattern-match the local file portion of the +URL path, and then puts the results back into URL format again. +) tindex(which-command) item(tt(which-command))( This function is a drop-in replacement for the builtin widget -- cgit v1.2.3 From 649d06a8cdd9948e3d49fa717f9088d8a87a6262 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 25 Sep 2015 21:30:34 +0100 Subject: 36630: new function zsh_directory_name_generic --- ChangeLog | 5 + Doc/Zsh/contrib.yo | 187 ++++++++++++++++++++++++++++- Doc/Zsh/manual.yo | 1 + Functions/Chpwd/zsh_directory_name_generic | 151 +++++++++++++++++++++++ 4 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 Functions/Chpwd/zsh_directory_name_generic (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index ef35827d2..7055836fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-09-25 Peter Stephenson + + * 36630: Doc/Zsh/contrib.yo, Doc/Zsh/manual.yo, + Functions/Chpwd/zsh_directory_name_generic: new helper function. + 2015-09-24 Barton E. Schaefer * 36623: Doc/Zsh/contrib.yo: document bracketed-paste-magic and diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index b966e781c..330c6f588 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -12,6 +12,7 @@ such as shell functions, look for comments in the function source files. startmenu() menu(Utilities) menu(Recent Directories) +menu(Other Directory Functions) menu(Version Control Information) menu(Prompt Themes) menu(ZLE Functions) @@ -324,7 +325,7 @@ options tt(-Uz) are appropriate. ) enditem() -texinode(Recent Directories)(Version Control Information)(Utilities)(User Contributions) +texinode(Recent Directories)(Other Directory Functions)(Utilities)(User Contributions) cindex(recent directories, maintaining list of) cindex(directories, maintaining list of recent) findex(cdr) @@ -585,7 +586,189 @@ avoid side effects if the change to the directory is to be invisible at the command line. See the contents of the function tt(chpwd_recent_dirs) for more details. -texinode(Version Control Information)(Prompt Themes)(Recent Directories)(User Contributions) +texinode(Other Directory Functions)(Version Control Information)(Recent Directories)(User Contributions) +cindex(directories, named, dynamic, helper function) +cindex(dynamic directory naming, helper function) +cindex(named directories, dynamic, helper function) +findex(zsh_directory_name_generic) +sect(Abbreviated dynamic references to directories) + +The dynamic directory naming system is described in the subsection +em(Dynamic named directories) of +ifzman(the section em(Filename Expansion) in zmanref(expn))\ +ifnzman(noderef(Filename Expansion)). In this, a reference to +tt(~[)var(...)tt(]) is expanded by a function found by the hooks +mechanism. + +The contributed function tt(zsh_directory_name_generic) provides a +system allowing the user to refer to directories with only a limited +amount of new code. It supports all three of the standard interfaces +for directory naming: converting from a name to a directory, converting +in the reverse direction to find a short name, and completion of names. + +The main feature of this function is a path-like syntax, +combining abbreviations at multiple levels separated by ":". +As an example, ~[g:p:s] might specify: +startitem() +item(tt(g))( +The top level directory for your git area. This first component +has to match, or the function will retrun indicating another +directory name hook function should be tried. +) +item(tt(p))( +The name of a project within your git area. +) +item(tt(s))( +The source area within that project. +) +enditem() +This allows you to collapse references to long hierarchies to a very +compact form, particularly if the hierarchies are similar across different +areas of the disk. + +Name components may be completed: if a description is shown at the top +of the list of completions, it includes the path to which previous +components expand, while the description for an individual completion +shows the path segment it would add. No additional configuration is +needed for this as the completion system is aware of the dynamic +directory name mechanism. + +subsect(Usage) + +To use the function, first define a wrapper function for your specific +case. We'll assume it's to be autoloaded. This can have any name but +we'll refer to it as zdn_mywrapper. This wrapper function will define +various variables and then call this function with the same arguments +that the wrapper function gets. This configuration is described below. + +Then arrange for the wrapper to be run as a zsh_directory_name hook: + +example(autoload -Uz add-zsh-hook zsh_diretory_name_generic zdn_mywrapper +add-zsh-hook -U zsh_directory_name zdn_mywrapper) + +subsect(Configuration) + +The wrapper function should define a local associative array zdn_top. +Alternatively, this can be set with a style called tt(mapping). The +context for the style is tt(:zdn:)var(wrapper-name) where +var(wrapper-name) is the function calling zsh_directory_name_generic; +for example: + +example(zstyle :zdn:zdn_mywrapper: mapping zdn_mywrapper_top) + +The keys in this associative array correspond to the first component of +the name. The values are matching directories. They may have an +optional suffix with a slash followed by a colon and the name of a +variable in the same format to give the next component. (The slash +before the colon is to disambiguate the case where a colon is needed in +the path for a drive. There is otherwise no syntax for escaping this, +so path components whose names start with a colon are not supported.) A +special component tt(:default:) specifies a variable in the form +tt(/:)var(var) (the path section is ignored and so is usually empty) +that will be used for the next component if no variable is given for the +path. Variables referred to within tt(zdn_top) have the same format as +tt(zdn_top) itself, but contain relative paths. + +For example, + +example(local -A zdn_top=( + g ~/git + ga ~/alternate/git + gs /scratch/$USER/git/:second2 + :default: /:second1 +)) + +This specifies the behaviour of a directory referred to as tt(~[g:...]) +or tt(~[ga:...]) or tt(~[gs:...]). Later path components are optional; +in that case tt(~[g]) expands to tt(~/git), and so on. tt(gs) expands +to tt(/scratch/$USER/git) and uses the associative array tt(second2) to +match the second component; tt(g) and tt(ga) use the associative array +tt(second1) to match the second component. + +When expanding a name to a directory, if the first component is not tt(g) or +tt(ga) or tt(gs), it is not an error; the function simply returns 1 so that a +later hook function can be tried. However, matching the first component +commits the function, so if a later component does not match, an error +is printed (though this still does not stop later hooks from being +executed). + +For components after the first, a relative path is expected, but note that +multiple levels may still appear. Here is an example of tt(second1): + +example(local -A second1=( + p myproject + s somproject + os otherproject/subproject/:third +)) + +The path as found from tt(zdn_top) is extended with the matching +directory, so tt(~[g:p]) becomes tt(~/git/myproject). The slash between +is added automatically (it's not possible to have a later component +modify the name of a directory already matched). Only tt(os) specifies +a variable for a third component, and there's no tt(:default:), so it's +an error to use a name like tt(~[g:p:x]) or tt(~[ga:s:y]) because +there's nowhere to look up the tt(x) or tt(y). + +The associative arrays need to be visible within this function; the +generic function therefore uses internal variable names beginning +tt(_zdn_) in order to avoid clashes. Note that the variable tt(reply) +needs to be passed back to the shell, so should not be local in the +calling function. + +The function does not test whether directories assembled by component +actually exist; this allows the system to work across automounted +file systems. The error from the command trying to use a non-existent +directory should be sufficient to indicate the problem. + +subsect(Complete example) + +Here is a full fictitious but usable autoloadable definition of the +example function defined by the code above. So tt(~[gs:p:s]) expands +to tt(/scratch/$USER/git/myscratchproject/top/srcdir) (with tt($USER) +also expanded). + +example(local -A zdn_top=( + g ~/git + ga ~/alternate/git + gs /scratch/$USER/git/:second2 + :default: /:second1 +) + +local -A second1=( + p myproject + s somproject + os otherproject/subproject/:third +) + +local -A second2=( + p myscratchproject + s somescratchproject +) + +local -A third=( + s top/srcdir + d top/documentation +) + +# autoload not needed if you did this at initialisation... +autoload -Uz zsh_directory_name_generic +zsh_directory_name_generic "$@) + +It is also possible to use global associative arrays, suitably named, +and set the style for the context of your wrapper function to +refer to this. Then your set up code would contain the following: + +example(typeset -A zdn_mywrapper_top=(...) +# ... and so on for other associative arrays ... +zstyle ':zdn:zdn_mywrapper:' mapping zdn_mywrapper_top +autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper +add-zsh-hook -U zsh_directory_name zdn_mywrapper) + +and the function tt(zdn_mywrapper) would contain only the following: + +example(zsh_directory_name_generic "$@") + +texinode(Version Control Information)(Prompt Themes)(Other Directory Functions)(User Contributions) sect(Gathering information from version control systems) cindex(version control utility) diff --git a/Doc/Zsh/manual.yo b/Doc/Zsh/manual.yo index 86c72c0ff..119849e4c 100644 --- a/Doc/Zsh/manual.yo +++ b/Doc/Zsh/manual.yo @@ -164,6 +164,7 @@ User Contributions menu(Utilities) menu(Recent Directories) +menu(Other Directory Functions) menu(Version Control Information) menu(Prompt Themes) menu(ZLE Functions) diff --git a/Functions/Chpwd/zsh_directory_name_generic b/Functions/Chpwd/zsh_directory_name_generic new file mode 100644 index 000000000..9430c95e4 --- /dev/null +++ b/Functions/Chpwd/zsh_directory_name_generic @@ -0,0 +1,151 @@ +## zsh_directory_name_generic +# +# This function is useful as a hook function for the zsh_directory_name +# facility. +# +# See the zsh-contrib manual page for more. + +emulate -L zsh +setopt extendedglob +local -a match mbegin mend + +# The variable containing the top level mapping. +local _zdn_topvar + +zmodload -i zsh/parameter +zstyle -s ":zdn:${funcstack[2]}:" mapping _zdn_topvar || _zdn_topvar=zdn_top + +if (( ! ${(P)#_zdn_topvar} )); then + print -r -- "$0: $_zdn_topver is not set" >&2 + return 1 +fi + +local _zdn_var=$_zdn_topvar +local -A _zdn_assoc + +if [[ $1 = n ]]; then + # Turning a name into a directory. + local _zdn_name=$2 + local -a _zdn_words + local _zdn_dir _zdn_cpt + + _zdn_words=(${(s.:.)_zdn_name}) + while (( ${#_zdn_words} )); do + if [[ -z ${_zdn_var} ]]; then + print -r -- "$0: too many components in directory name \`$_zdn_name'" >&2 + return 1 + fi + + # Subscripting (P)_zdn_var directly seems not to work. + _zdn_assoc=(${(Pkv)_zdn_var}) + _zdn_cpt=${_zdn_assoc[${_zdn_words[1]}]} + shift _zdn_words + + if [[ -z $_zdn_cpt ]]; then + # If top level component, just try another expansion + if [[ $_zdn_var != $_zdn_top ]]; then + # Committed to this expansion, so report failure. + print -r -- "$0: no expansion for directory name \`$_zdn_name'" >&2 + fi + return 1 + fi + if [[ $_zdn_cpt = (#b)(*)/:([[:IDENT:]]##) ]]; then + _zdn_cpt=$match[1] + _zdn_var=$match[2] + else + # may be empty + _zdn_var=${${_zdn_assoc[:default:]}##*/:} + fi + _zdn_dir=${_zdn_dir:+$_zdn_dir/}$_zdn_cpt + done + if (( ${#_zdn_dir} )); then + typeset -ag reply + reply=($_zdn_dir) + return 0 + fi +elif [[ $1 = d ]]; then + # Turning a directory into a name. + local _zdn_dir=$2 + local _zdn_rest=$_zdn_dir + local -a _zdn_cpts + local _zdn_pref _zdn_pref_raw _zdn_matched _zdn_cpt _zdn_name + + while [[ -n $_zdn_var && -n $_zdn_rest ]]; do + _zdn_assoc=(${(Pkv)_zdn_var}) + # Sorting in descending order will ensure prefixes + # come after longer strings with that perfix, so + # we match more specific directory names preferentially. + _zdn_cpts=(${(Ov)_zdn_assoc}) + _zdn_cpt='' + for _zdn_pref_raw in $_zdn_cpts; do + _zdn_pref=${_zdn_pref_raw%/:*} + [[ -z $_zdn_pref ]] && continue + if [[ $_zdn_rest = $_zdn_pref(#b)(/|)(*) ]]; then + _zdn_cpt=${(k)_zdn_assoc[(r)$_zdn_pref_raw]} + # if we matched a /, too, add it... + _zdn_matched+=$_zdn_pref$match[1] + _zdn_rest=$match[2] + break + fi + done + if [[ -n $_zdn_cpt ]]; then + _zdn_name+=${_zdn_name:+${_zdh_name}:}$_zdn_cpt + if [[ ${_zdn_assoc[$_zdn_cpt]} = (#b)*/:([[:IDENT:]]##) ]]; then + _zdn_var=$match[1] + else + _zdn_var=${${_zdn_assoc[:default:]}##*/:} + fi + else + break + fi + done + if [[ -n $_zdn_name ]]; then + # matched something, so report that. + integer _zdn_len=${#_zdn_matched} + [[ $_zdn_matched[-1] = / ]] && (( _zdn_len-- )) + typeset -ag reply + reply=($_zdn_name $_zdn_len) + return 0 + fi + # else let someone else have a go. +elif [[ $1 = c ]]; then + # Completion + + if [[ -n $SUFFIX ]]; then + _message "Can't complete in the middle of a dynamic directory name" + else + local -a _zdn_cpts + local _zdn_word _zdn_cpt _zdn_desc _zdn_sofar expl + + while [[ -n ${_zdn_var} && ${PREFIX} = (#b)([^:]##):* ]]; do + _zdn_word=$match[1] + compset -P '[^:]##:' + _zdn_assoc=(${(Pkv)_zdn_var}) + _zdn_cpt=${_zdn_assoc[$_zdn_word]} + # We only complete at the end so must match here + [[ -z $_zdn_cpt ]] && return 1 + if [[ $_zdn_cpt = (#b)(*)/:([[:IDENT:]]##) ]]; then + _zdn_cpt=$match[1] + _zdn_var=$match[2] + else + _zdn_var=${${_zdn_assoc[:default:]}##*/:} + fi + _zdn_sofar+=${_zdn_sofar:+${_zdn_sofar}/}$_zdn_cpt + done + if [[ -n $_zdn_var ]]; then + _zdn_assoc=(${(Pkv)_zdn_var}) + local -a _zdn_cpts + for _zdn_cpt _zdn_desc in ${(kv)_zdn_assoc}; do + [[ $_zdn_cpt = :* ]] && continue + _zdn_cpts+=(${_zdn_cpt}:${_zdn_desc%/:[[:IDENT:]]##}) + done + _describe -t dirnames "directory name under ${_zdn_sofar%%/}" \ + _zdn_cpts -S: -r ':]' + return + fi + fi +fi + +# Failed +return 1 +## end -- cgit v1.2.3 From 196e6a0ec022fb2fc22820a346b5f206a3cf40ac Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 1 Oct 2015 15:55:01 +0100 Subject: 36735: add ~/.zcalcrc handling to zcalc --- ChangeLog | 2 ++ Doc/Zsh/contrib.yo | 8 ++++++++ Functions/Misc/zcalc | 4 ++++ 3 files changed, 14 insertions(+) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index 4a9d1cebc..a51dc4795 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-10-01 Peter Stephenson + * 36735: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: ~/.zcalcrc. + * Andrew Janke: 36729: MACHINES, NEWS, README: fix some typos. * 36722: Completion/Unix/Command/_git: allow range to complete diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 330c6f588..635f9b010 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3657,6 +3657,14 @@ 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. +If the file tt(~/.zcalcrc) exists it will be sourced inside the function +once it is set up and about to process the command line. This +can be used, for example, to set shell options; tt(emulate -L zsh) +and tt(setopt extendedglob) are in effect at this point. Any +failure to source the file if it exists is treated as fatal. +As with other initialisation files, the directory tt($ZDOTDIR) is used +instead of tt($HOME) if it is set. + The mathematical library tt(zsh/mathfunc) will be loaded if it is available; see ifzman(the section `The zsh/mathfunc Module' in zmanref(zshmodules))\ diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 63f67adb0..17700e48b 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -120,6 +120,10 @@ autoload -Uz zmathfuncdef float PI E (( PI = 4 * atan(1), E = exp(1) )) +if [[ -f "${ZDOTDIR:-$HOME}/.zcalcrc" ]]; then + . "${ZDOTDIR:-$HOME}/.zcalcrc" || return 1 +fi + # Process command line while [[ -n $1 && $1 = -(|[#-]*|f|e) ]]; do optlist=${1[2,-1]} -- cgit v1.2.3 From bab1fc50436f23402696cd5236c0689c4d4dbd59 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 14 Oct 2015 14:23:16 +0100 Subject: 36856: cdr -p/-P to prune directory list --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 12 ++++++++++++ Functions/Chpwd/cdr | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 6 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index ae61df68d..2e31d243b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-10-14 Peter Stephenson + + * 36856: Doc/Zsh/contrib.yo, Functions/Chpwd/cdr: add -p and -P + options to cdr for pruning the directory list. + 2015-10-11 Barton E. Schaefer * 36841: Completion/Base/Widget/_complete_help: factor out and diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 635f9b010..d367d8b0f 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -415,6 +415,18 @@ newlines, where I have in any case no sympathy); directories are in unabbreviated from and contain an absolute path, i.e. they start with tt(/). Usually the first entry should be left as the current directory. ) +item(tt(-p ')var(pattern)tt('))( +Prunes any items in the directory list that match the given extended glob +pattern; the pattern needs to be quoted from immediate expansion on the +command line. The pattern is matched against each completely expanded +file name in the list; the full string must match, so wildcards at the +end (e.g. tt('*removeme*')) are needed to remove entries with a given +substring. + +If output is to a terminal, then the function will print the new list +after pruning and prompt for confirmation by the user. This output and +confirmation step can be skipped by using tt(-P) instead of tt(-p). +) enditem() subsect(Configuration) diff --git a/Functions/Chpwd/cdr b/Functions/Chpwd/cdr index 4f399106b..4bed88b13 100644 --- a/Functions/Chpwd/cdr +++ b/Functions/Chpwd/cdr @@ -51,6 +51,13 @@ # (and only /). Usually the first entry should be left as the current # directory. # +# "cdr -p 'pattern'" prunes anything matching the given extended glob +# pattern from the directory list. The match is against the fully +# expanded directory path and the full string must match (use wildcards +# at the ends if needed). If output is going to a terminal, the +# function will print the new list for the user to confrim; this can be +# skipped by giving -P instead of -p. +# # Details of directory handling # ============================= # @@ -217,11 +224,11 @@ setopt extendedglob autoload -Uz chpwd_recent_filehandler chpwd_recent_add -integer list set_reply i bad edit -local opt dir +integer list set_reply i bad edit force_prune +local opt dir prune local -aU dirs -while getopts "elr" opt; do +while getopts "elp:P:r" opt; do case $opt in (e) edit=1 @@ -231,6 +238,12 @@ while getopts "elr" opt; do list=1 ;; + ([pP]) + prune=$OPTARG + edit=1 + [[ $opt = P ]] && force_prune=1 + ;; + (r) set_reply=1 ;; @@ -278,10 +291,22 @@ if [[ $PWD != $reply[1] ]]; then fi if (( edit )); then - local compcontext='directories:directory:_path_files -/' -IFS=' + if [[ -n $prune ]]; then + reply=(${reply:#$~prune}) + if [[ force_prune -eq 0 && -t 1 ]]; then + print -nrl "New list:" $reply 'Accept? ' + if ! read -q; then + print + return 1 + fi + print + fi + else + local compcontext='directories:directory:_path_files -/' + IFS=' ' vared reply || return 1 -chpwd_recent_filehandler $reply + fi + chpwd_recent_filehandler $reply fi # Skip current directory if present (may have been pruned). -- cgit v1.2.3 From 8e9a68ad14655c1949b1a04d5715a5caa8c344ee Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Oct 2015 12:29:39 +0000 Subject: unposted: vcs_info docs: Typo fix. --- ChangeLog | 4 ++++ Doc/Zsh/contrib.yo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index e383ab9b6..84f1b9856 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-10-22 Daniel Shahaf + + * unposted: Doc/Zsh/contrib.yo: vcs_info docs: Typo fix. + 2015-10-21 Barton E. Schaefer * unposted: Src/math.c: strdup should be ztrdup diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index d367d8b0f..cb68952a4 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1332,7 +1332,7 @@ otherwise would be something like `svn' or `cvs') will be set to identifier is the second element. tt(vcs_info) will have filled in a proper value for the "repository's" root directory and the string containing the information about quilt's state will be available as the `misc' replacement -(and tt(%Q) for compatibility with `addon' mode. +(and tt(%Q) for compatibility with `addon' mode). What is left to discuss is how `standalone' mode is detected. The detection itself is a series of searches for directories. You can have this detection -- cgit v1.2.3 From 1eef57b3d15af235430ad2b5e2940ded375e69d2 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 30 Oct 2015 16:59:04 +0000 Subject: 37027: allow subword context to discriminate between words --- ChangeLog | 3 +++ Doc/Zsh/contrib.yo | 7 ++++--- Functions/Zle/match-word-context | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index d29e1e4c0..ed5cd5e6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ 2015-10-30 Peter Stephenson + * 37027: Doc/Zsh/contrib.yo, Functions/Zle/match-word-context: + add editing word context to allow detecting being between words. + * 37022: Doc/Zsh/expn.yo, Doc/Zsh/options.yo, Src/glob.c, Src/options.c, Src/zsh.h: add GLOB_STAR_SHORT option to allow shorthand ** for **/* and *** for ***/*. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index cb68952a4..f74f7d709 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2016,9 +2016,10 @@ matched against each var(pattern) in turn until one matches; if it does, the context is extended by a colon and the corresponding var(subcontext). Note that the test is made against the original word on the line, with no stripping of quotes. Special handling is done between words: the current -context is examined and if it contains the string tt(back), the word before -the cursor is considered, else the word after cursor is considered. Some -examples are given below. +context is examined and if it contains the string tt(between) the word +is set to a single space; else if it is contains the string tt(back), +the word before the cursor is considered, else the word after cursor is +considered. Some examples are given below. The style tt(skip-whitespace-first) is only used with the tt(forward-word) widget. If it is set to true, then tt(forward-word) diff --git a/Functions/Zle/match-word-context b/Functions/Zle/match-word-context index 7f1154498..8793483f4 100644 --- a/Functions/Zle/match-word-context +++ b/Functions/Zle/match-word-context @@ -7,7 +7,7 @@ setopt extendedglob local -a worcon bufwords local pat tag lastword word backword forword -integer iword +integer iword between zstyle -a $curcontext word-context worcon || return 0 @@ -25,13 +25,18 @@ if [[ $lastword = ${bufwords[iword]} ]]; then # If the word immediately left of the cursor is complete, # we're not on it for forward operations. forword=${bufwords[iword+1]} + # If, furthermore, we're on whitespace, then we're between words. + # It can't be significant whitespace because the previous word is complete. + [[ $RBUFFER[1] = [[:space:]] ]] && between=1 else # We're on a word. forword=${bufwords[iword]} fi backword=${bufwords[iword]} -if [[ $curcontext = *back* ]]; then +if [[ between -ne 0 && $curcontext = *between* ]]; then + word=' ' +elif [[ $curcontext = *back* ]]; then word=$backword else word=$forword -- cgit v1.2.3 From d5ba08af4933fdef596f5151b3e903868d352f65 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 13 Nov 2015 01:02:37 +0900 Subject: unposted: a few cosmetic format fixes in docs --- ChangeLog | 4 ++++ Doc/Zsh/builtins.yo | 3 +-- Doc/Zsh/contrib.yo | 5 ++--- Doc/Zsh/func.yo | 3 +-- Doc/Zsh/grammar.yo | 3 +-- Doc/Zsh/mod_pcre.yo | 8 ++------ Doc/Zsh/params.yo | 4 +--- Doc/Zsh/zle.yo | 5 +++-- 8 files changed, 15 insertions(+), 20 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index 3fd4d9908..46bb02f48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * 37090: Doc/zman.yo, Doc/ztexi.yo: handle blank lines correctly in yodl macro example() + * unposted: Doc/Zsh/builtins.yo, Doc/Zsh/contrib.yo, + Doc/Zsh/func.yo, Doc/Zsh/grammar.yo, Doc/Zsh/mod_pcre.yo, + Doc/Zsh/params.yo, Doc/Zsh/zle.yo: cosmetic format fix + 2015-11-12 Peter Stephenson * 37096: Src/subst.c, Test/D04parameter.ztst: make top-level diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 985e7267f..49806e4d8 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -558,8 +558,7 @@ For example: example(emulate sh -c 'fni+LPAR()RPAR() { setopt cshnullglob; } fno+LPAR()RPAR() { fni; }' -fno -) +fno) The two functions tt(fni) and tt(fno) are defined with sticky tt(sh) emulation. tt(fno) is then executed, causing options associated diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index f74f7d709..07a5eb08e 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1755,7 +1755,7 @@ a customised bookmark string for the tt(hg) backend. Again, we start off by registering a function: example(zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks) -And then we define the `tt(+vi-hgbookmarks) function: +And then we define the `tt(+vi-hgbookmarks)' function: example( function +vi-hgbookmarks+LPAR()RPAR() { # The default is to connect all bookmark names by @@ -1780,8 +1780,7 @@ function +vi-hgbookmarks+LPAR()RPAR() { # something other than the default zero: ret=1 return 0 -} -) +}) Some longer examples and code snippets which might be useful are available in the examples file located at Misc/vcs_info-examples in the Zsh source diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo index ace0a4051..d500a78ae 100644 --- a/Doc/Zsh/func.yo +++ b/Doc/Zsh/func.yo @@ -111,8 +111,7 @@ arguments, at the end. For example, suppose the autoload file tt(func) contains example(func+LPAR()RPAR() { print This is func; } -print func is initialized -) +print func is initialized) then `tt(func; func)' with tt(KSH_AUTOLOAD) set will produce both messages on the first call, but only the message `tt(This is func)' on the second diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 83968fedf..2a76964f3 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -421,8 +421,7 @@ works, but example(if true { # Does not work! print yes -} -) +}) does em(not), since the test is not suitably delimited. ) diff --git a/Doc/Zsh/mod_pcre.yo b/Doc/Zsh/mod_pcre.yo index d6b4bd15d..c2817f519 100644 --- a/Doc/Zsh/mod_pcre.yo +++ b/Doc/Zsh/mod_pcre.yo @@ -54,8 +54,7 @@ used to implement the "find all non-overlapping matches" functionality. A simple example of "find all non-overlapping matches": -example( -string="The following zip codes: 78884 90210 99513" +example(string="The following zip codes: 78884 90210 99513" pcre_compile -m "\d{5}" accum=() pcre_match -b -- $string @@ -64,10 +63,7 @@ while [[ $? -eq 0 ]] do accum+=$MATCH pcre_match -b -n $b[2] -- $string done -print -l $accum - - -) +print -l $accum) ) enditem() diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ba2856b34..b896e2d70 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -383,9 +383,7 @@ as part of an arithmetic expression in an ordinary subscript. To avoid subscript parsing limitations in assignments to associative array elements, use the append syntax: -example( - aa+=('key with "*strange*" characters' 'value string') -) +example(aa+=('key with "*strange*" characters' 'value string')) The basic rule to remember when writing a subscript expression is that all text between the opening `tt([)' and the closing `tt(])' is interpreted diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 05bb14829..7047b43d9 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2274,6 +2274,7 @@ the command line or key bindings temporarily. The following widget, tt(caps-lock), serves as an example. + example(self-insert-ucase+LPAR()RPAR() { LBUFFER+=${(U)KEYS[-1]} } @@ -2293,8 +2294,8 @@ zle -D save-caps-lock (( stat )) && zle send-break -return $stat -) +return $stat) + This causes typed letters to be inserted capitalised until either tt(accept-line) (i.e. typically the return key) is typed or the tt(caps-lock) widget is invoked again; the later is handled by saving -- cgit v1.2.3