From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27120 invoked by alias); 29 Dec 2017 23:05:36 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23027 Received: (qmail 25040 invoked by uid 1010); 29 Dec 2017 23:05:36 -0000 X-Qmail-Scanner-Diagnostics: from forward3p.cmail.yandex.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(77.88.31.18):SA:0(-2.6/5.0):. Processed in 2.743823 secs); 29 Dec 2017 23:05:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: kp-pav@yandex.ru X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1514588358; bh=wWSoPg+xuPA7aU2MQegGUgmNxQXWtWBUA2Se1guK1WU=; h=From:To:In-Reply-To:References:Subject:Message-Id:Date; b=pKxueztBzmAFBoO0rUOx+RkizS8bNLARzTFZDXN+Oo3xwGwubqCUim7oD9k9Pbd9R vciFNu0+FHGblZOPryDLMyOgGGcAozvzve+mjiQ3KxIOeeZ3Vc+ZRRDboFascmxlLK QrKB+qyFyWrXCKEDbvIcxGiBdw7FjukA2iSzvh/I= Authentication-Results: mxback3o.mail.yandex.net; dkim=pass header.i=@yandex.ru From: "Nikolay Aleksandrovich Pavlov (ZyX)" To: mathieu stumpf guntz , Bart Schaefer , Zsh Users In-Reply-To: <71ef7896-39f8-66fe-f8f8-c7c81b11e2ce@culture-libre.org> References: <71ef7896-39f8-66fe-f8f8-c7c81b11e2ce@culture-libre.org> Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command? MIME-Version: 1.0 Message-Id: <7406281514588357@web30o.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Sat, 30 Dec 2017 01:59:17 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 29.12.2017, 13:53, "mathieu stumpf guntz" : > 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.