From: "Nikolay Aleksandrovich Pavlov (ZyX)" <kp-pav@yandex.ru>
To: mathieu stumpf guntz <psychoslave@culture-libre.org>,
Bart Schaefer <schaefer@brasslantern.com>,
Zsh Users <zsh-users@zsh.org>
Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command?
Date: Sat, 30 Dec 2017 01:59:17 +0300 [thread overview]
Message-ID: <7406281514588357@web30o.yandex.ru> (raw)
In-Reply-To: <71ef7896-39f8-66fe-f8f8-c7c81b11e2ce@culture-libre.org>
29.12.2017, 13:53, "mathieu stumpf guntz" <psychoslave@culture-libre.org>:
> Le 29/12/2017 à 09:47, Bart Schaefer a écrit :
>> You're missing a semicolon after the "C". That's the reason you get
>
> Thank you. For some reason however, the seconde run of `export LANC=C;
> enable -r else; if true; then echo 'yep'; else echo 'nop'; fi; disable
> -r else` will return an error message with the system local anyway:
>
> % enable -r else;
> % export LANC=C; enable -r else; if true; then echo 'yep'; else echo
> 'nop'; fi; disable -r else
> yep
> % export LANC=C; enable -r else; if true; then echo 'yep'; else echo
> 'nop'; fi; disable -r else
> yep
> zsh: else: commande inconnue.
>
>> If I understand your question, the answer is "no": you can't execute
>> the front part of an "if" until the "fi" has been read. See my
>> previous email "fully parsed before executed."
>
> I'm rather estonished by this lake of possibility to make the equivalent
> of an "\n" in the middle of a line, but OK.
>
> So the idea would be to have something like
>
> % whence -w else
> else: reserved
> % enable -r else; "\n" whence -w else; if true; then echo 'yep';
> else echo 'nop'; fi; disable -r else
> else: reserved
> yep
> % whence -w else
> else: none
> % enable -r else; "\n" whence -w else; if true; then echo 'yep';
> else echo 'nop'; fi; disable -r else
> else: reserved
> yep
>
> But "\n" doesn't work here as a substitution of an effective linefeed.
>> (Well, you could switch to csh, which does execute every line as it
>> goes along, even in complex structures. But no, not in zsh.)
>
> Nice to know, thank you.
If you do not like any part of shell syntax, want to use ZLE for Python REPL or whatever there is a thing which 100% works: just override accept-line widget and have zshaddhistory hook to put original line into history. For example I am using the following to have more extensive escaping for `:h`, `zmw` and `zpy` “commands”:
function zshaddhistory()
{
emulate -L zsh
if (( ${+_HISTLINE} && ${#_HISTLINE} )) ; then
print -sr -- "${_HISTLINE}"
unset _HISTLINE
elif (( 0x20==#1 )) ; then
return 1
elif (( ${#1} )) ; then
print -sr -- "${1%%$'\n'}"
fi
fc -p
}
function _-accept-line()
{
emulate -L zsh
local -r autopushd=${options[autopushd]}
options[autopushd]=off
cd $PWD || cd
options[autopushd]=$autopushd
if [[ ${BUFFER[1,3]} == ":h " ]] ; then
typeset -g _HISTLINE=$BUFFER
BUFFER=":h ${(q)BUFFER[4,-1]}"
elif [[ ${BUFFER[1,4]} == "zmw " ]] ; then
typeset -g _HISTLINE=$BUFFER
BUFFER="zmw "${(j. .)${(q)${(z)BUFFER[5,-1]}}}
elif [[ ${BUFFER[1,4]} == "zpy " ]] ; then
typeset -g _HISTLINE=$BUFFER
BUFFER="zpython ${(qqq)BUFFER[5,-1]}"
fi
zle .accept-line
}
zle -N accept-line _-accept-line
The main problem with this approach is that you will have to do more parsing yourself then you probably preferred to have to do though.
next prev parent reply other threads:[~2017-12-29 23:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-28 15:07 mathieu stumpf guntz
2017-12-28 15:19 ` mathieu stumpf guntz
2017-12-29 8:47 ` Bart Schaefer
2017-12-29 10:51 ` mathieu stumpf guntz
2017-12-29 19:15 ` Bart Schaefer
2017-12-29 19:29 ` mathieu stumpf guntz
2017-12-29 19:49 ` Bart Schaefer
2017-12-29 20:27 ` Ray Andrews
2017-12-29 23:45 ` Bart Schaefer
2017-12-30 1:07 ` Bart Schaefer
2017-12-30 9:50 ` mathieu stumpf guntz
2017-12-30 10:05 ` Frank Terbeck
2017-12-30 17:22 ` Ray Andrews
2017-12-30 22:06 ` Bart Schaefer
2017-12-30 23:00 ` Ray Andrews
2017-12-30 17:16 ` Ray Andrews
2017-12-30 22:23 ` mathieu stumpf guntz
2017-12-30 23:06 ` Ray Andrews
2017-12-30 23:32 ` mathieu stumpf guntz
2017-12-30 9:36 ` mathieu stumpf guntz
2017-12-30 17:39 ` Ray Andrews
2017-12-29 22:59 ` Nikolay Aleksandrovich Pavlov (ZyX) [this message]
2017-12-29 8:38 ` Bart Schaefer
2017-12-29 10:24 ` mathieu stumpf guntz
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=7406281514588357@web30o.yandex.ru \
--to=kp-pav@yandex.ru \
--cc=psychoslave@culture-libre.org \
--cc=schaefer@brasslantern.com \
--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).