From 4fae52572699770fdf4af6bc94d8b219cb401ad2 Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Wed, 10 Apr 2019 20:54:52 +0100
Subject: Copy functions using functions -c old new. Documentation and test.
---
Doc/Zsh/builtins.yo | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'Doc')
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index d7b6e88fa..9eee30d46 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -858,10 +858,11 @@ point numbers are not permitted.
)
findex(functions)
xitem(tt(functions) [ {tt(PLUS())|tt(-)}tt(UkmtTuWz) ] [ tt(-x) var(num) ] [ var(name) ... ])
+xitem(tt(functions -c) var(oldfn) var(newfn))
xitem(tt(functions -M) [tt(-s)] var(mathfn) [ var(min) [ var(max) [ var(shellfn) ] ] ])
xitem(tt(functions -M) [ tt(-m) var(pattern) ... ])
item(tt(functions +M) [ tt(-m) ] var(mathfn) ... )(
-Equivalent to tt(typeset -f), with the exception of the tt(-x),
+Equivalent to tt(typeset -f), with the exception of the tt(-c), tt(-x),
tt(-M) and tt(-W) options. For tt(functions -u) and tt(functions -U),
see tt(autoload), which provides additional options.
@@ -875,6 +876,14 @@ function or functions only. The option is turned off at the start of
nested functions (apart from anonoymous functions) unless the called
function also has the tt(-W) attribute.
+The tt(-c) option causes var(oldfn) to be copied to var(newfn). The
+copy is efficiently handled internally by reference counting. If
+var(oldfn) was marked for autoload it is first loaded and if this
+fails the copy fails. Either function may subsequently be redefined
+without affecting the other. A typical idiom is that var(oldfn) is the
+name of a library shell function which is then redefined to call
+tt(newfn), thereby installing a modified version of the function.
+
Use of the tt(-M) option may not be combined with any of the options
handled by tt(typeset -f).
--
cgit 1.4.1