From: "Daniel Shahaf" <d.s@daniel.shahaf.name>
To: "Zsh Users" <zsh-users@zsh.org>
Subject: Re: prevent some lines directly coming from the history from being executed
Date: Sun, 29 May 2022 22:55:18 +0000 [thread overview]
Message-ID: <41f13468-b9b9-4b64-845a-aadbcc3b8472@www.fastmail.com> (raw)
In-Reply-To: <CAH+w=7YZ_011kAYa0y515MxdOL8i1myJS7xm7JCjo+vnN3qOAQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2763 bytes --]
Bart Schaefer wrote on Sat, 28 May 2022 18:43 +00:00:
> On Sat, May 28, 2022 at 3:06 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>> +cindex(widgets, shadowing standard)
>
> "Shadow(ing)" is not a term I'd think to search for in this context.
> Wrap, override, overload, replace, re-implement, ...?
>
Most of these terms imply particular semantics (e.g., "wrap" implies the
new definition calls the old one). I think "shadow" is the right term
here, so how about:
+cindex(widgets, shadowing standard)
+cindex(widgets, overriding standard)
+User-defined widgets may shadow (override) standard widgets: for instance,
>> +However, each standard widget `var(foo)' is also available under the
>> +name `tt(.)var(foo)', and this name can't be rebound to a different widget.
>
> I would probably have used something like var(std) or even
> var(stdwidg) here, but that's a nit.
>
Personally I find it easier to read with "foo", but I suppose that's
a matter of taste. I'll write it whichever way is the house style.
>> +Therefore, for forward compatibility with future versions of the shell,
>> +it is recommended that user-defined widgets should not have names
>> starting with `tt(.)'.
>
> It's actually prohibited to name a user-defined widget the same as one
> of the reserved dot-names, so this recommendation could be more
> specific.
>
OK, can spell out the problem. Wouldn't that make the paragraph a bit
of a wall of text, though? Also, it would further break the flow
(example, recommendation, rationale of the recommendation, continuation
of example). That flow was one of the things that I wasn't happy about
regarding the v1 of the patch.
+Therefore, for forward compatibility with future versions of the shell,
+it is recommended that user-defined widgets should not have names
-starting with `tt(.)'.
+starting with `tt(.)'. (If a user-defined widget is named `tt(.)var(some-name)'
+and a future version of the shell introduces a built-in `var(some-name)' widget,
+the user-defined widget's definition will raise an error under that future
+version of the shell.)
>> +then tt(myfunc) would have been called again, effecting a bottomless
>> +recursion.
>
> Perhaps my old-fogey-ness (or USA-centrism) is showing, but I've never
> seen the word "bottomless" used in this context before, only
> "infinite" or more rarely "endless". Another nit, as it doesn't
> really change the clarity, just mentioning because I found it curious.
Prior art:
(1995) https://github.com/freebsd/freebsd-src/commit/cd02a0b741846be432ea4646890e617c8c3b445d
(2003) https://www.freebsd.org/cgi/man.cgi?query=exit&apropos=0&sektion=3&manpath=FreeBSD+5.0-RELEASE&arch=default&format=html
It does seem to be rather rare, though.
Thanks for the review!
Daniel
[-- Attachment #2: v2.txt --]
[-- Type: text/plain, Size: 2622 bytes --]
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -746,17 +746,46 @@ ifnzman(noderef(Standard Widgets)).
Other built-in widgets can be defined by other modules (see
ifzman(zmanref(zshmodules))\
ifnzman(noderef(Zsh Modules))\
-). Each built-in widget has two names: its normal canonical name, and the
-same name preceded by a `tt(.)'. The `tt(.)' name is special: it can't be
-rebound to a different widget. This makes the widget available even when
-its usual name has been redefined.
+).
User-defined widgets are defined using `tt(zle -N)', and implemented
as shell functions. When the widget is executed, the corresponding
shell function is executed, and can perform editing (or other) actions.
-It is recommended that user-defined widgets should not have names
+
+cindex(widgets, shadowing standard)
+cindex(widgets, overriding standard)
+User-defined widgets may shadow (override) standard widgets: for instance,
+after `tt(zle -N self-insert myfunc)', any invocation of the standard
+tt(self-insert) widget (including every keypress that appends an alphanumeric
+or space character to the command line) would invoke the user-defined
+function tt(myfunc) rather than the standard implementation of that widget.
+However, each standard widget `var(foo)' is also available under the
+name `tt(.)var(foo)', and this name can't be rebound to a different widget.
+This makes the standard widget available to be called or bound even when
+its usual name has been redefined.
+Therefore, for forward compatibility with future versions of the shell,
+it is recommended that user-defined widgets should not have names
-starting with `tt(.)'.
+starting with `tt(.)'. (If a user-defined widget is named `tt(.)var(some-name)'
+and a future version of the shell introduces a built-in `var(some-name)' widget,
+the user-defined widget's definition will raise an error under that future
+version of the shell.)
+Continuing the example, tt(myfunc) would typically invoke the built-in widget
+it is replacing using the dot-prefix syntax:
+
+example(zle -N self-insert myfunc
+myfunc+LPAR()+RPAR() {
+ [[ $KEYS == [aeiou] ]] && zle .self-insert -- "$@"
+ zle .self-insert -- "$@"
+})
+
+This example causes vowels to be inserted twice.
+
+Note the use of the dot-prefix syntax. If the tt(self-insert) widget had been
+invoked without the dot DASH()- that is, as `tt(zle self-insert -- "$@")' DASH()-
+then tt(myfunc) would have been called again, effecting a bottomless
+recursion.
+
texinode(User-Defined Widgets)(Standard Widgets)(Zle Widgets)(Zsh Line Editor)
sect(User-Defined Widgets)
cindex(widgets, user-defined)
next prev parent reply other threads:[~2022-05-29 22:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-24 15:47 Vincent Lefevre
2022-05-24 18:58 ` Bart Schaefer
2022-05-25 2:54 ` Vincent Lefevre
2022-05-25 3:59 ` Bart Schaefer
2022-05-25 8:49 ` Vincent Lefevre
2022-05-26 1:25 ` Bart Schaefer
2022-05-26 14:36 ` Vincent Lefevre
2022-05-26 15:53 ` Daniel Shahaf
2022-05-26 16:13 ` Peter Stephenson
2022-05-27 12:40 ` Daniel Shahaf
2022-05-28 0:07 ` Vincent Lefevre
2022-05-28 10:06 ` Daniel Shahaf
2022-05-28 18:43 ` Bart Schaefer
2022-05-29 22:55 ` Daniel Shahaf [this message]
2022-05-30 4:04 ` Bart Schaefer
2022-05-30 9:07 ` Peter Stephenson
2022-06-02 9:59 ` Daniel Shahaf
2022-06-02 10:19 ` Daniel Shahaf
2022-06-02 9:59 ` Daniel Shahaf
2022-05-30 9:02 ` Vincent Lefevre
2022-06-02 10:17 ` Daniel Shahaf
2022-06-02 13:54 ` Vincent Lefevre
2022-05-26 16:37 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=41f13468-b9b9-4b64-845a-aadbcc3b8472@www.fastmail.com \
--to=d.s@daniel.shahaf.name \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).