zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] select-bracketed: set nocprecedences to force native precedence ordering
@ 2018-11-06 23:34 Joey Pabalinas
  2018-11-06 23:40 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Joey Pabalinas @ 2018-11-06 23:34 UTC (permalink / raw)
  To: zsh-workers

With cprecedences set, expressions like `1 + (idx-1) & ~1` are evaluated as
`(1 + (idx-1)) & ~1` instead of the intended `1 + ((idx-1) & ~1)`. Set the
nocprecedences option and add clarifying parenthesis to the ambiguous
expressions.

Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
---
 Functions/Zle/select-bracketed | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Functions/Zle/select-bracketed b/Functions/Zle/select-bracketed
index d467bb8047466faa32..add5b70f0c9fd72215 100644
--- a/Functions/Zle/select-bracketed
+++ b/Functions/Zle/select-bracketed
@@ -10,17 +10,17 @@
 #	for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
 #	  bindkey -M $m $c select-bracketed
 #	done
 #     done
 
-setopt localoptions noksharrays
+setopt localoptions nocprecedences noksharrays
 
 local style=${${1:-$KEYS}[1]} matching="(){}[]<>bbBB"
 local -i find=${NUMERIC:-1} idx=${matching[(I)[${${1:-$KEYS}[2]}]]}%9
 (( idx )) || return 1 # no corresponding closing bracket
-local lmatch=${matching[1 + (idx-1) & ~1]}
-local rmatch=${matching[1 + (idx-1) | 1]}
+local lmatch=${matching[1 + ((idx-1) & ~1)]}
+local rmatch=${matching[1 + ((idx-1) | 1)]}
 local -i start=CURSOR+1 end=CURSOR+1 rfind=find
 
 [[ $BUFFER[start] = "$rmatch" ]] && (( start--, end-- ))
 if (( REGION_ACTIVE  && MARK != CURSOR)); then
   (( MARK < CURSOR && (start=end=MARK+1) ))
-- 
Cheers,
Joey Pabalinas


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] select-bracketed: set nocprecedences to force native precedence ordering
  2018-11-06 23:34 [PATCH] select-bracketed: set nocprecedences to force native precedence ordering Joey Pabalinas
@ 2018-11-06 23:40 ` Bart Schaefer
  2018-11-06 23:47   ` Joey Pabalinas
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2018-11-06 23:40 UTC (permalink / raw)
  To: Joey Pabalinas; +Cc: zsh-workers

On Tue, Nov 6, 2018 at 3:34 PM Joey Pabalinas <joeypabalinas@gmail.com> wrote:
>
> Set the
> nocprecedences option and add clarifying parenthesis to the ambiguous
> expressions.

Not that I object to unsetting cprecedences, but is it necessary to do
so if you've rearranged the parens?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] select-bracketed: set nocprecedences to force native precedence ordering
  2018-11-06 23:40 ` Bart Schaefer
@ 2018-11-06 23:47   ` Joey Pabalinas
  2018-11-07  6:28     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Joey Pabalinas @ 2018-11-06 23:47 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Joey Pabalinas, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 532 bytes --]

On Tue, Nov 06, 2018 at 03:40:59PM -0800, Bart Schaefer wrote:
> Not that I object to unsetting cprecedences, but is it necessary to do
> so if you've rearranged the parens?

It isn't, but in my opinion expressions like this always have a tendency
to confuse. I find it helpful to add the parentheses even when not needed
if for no other reason than to make mentally parsing the code easier.

If you think it's a bit superfluous then I don't mind removing that part and
sending a quick v2.

-- 
Cheers,
Joey Pabalinas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] select-bracketed: set nocprecedences to force native precedence ordering
  2018-11-06 23:47   ` Joey Pabalinas
@ 2018-11-07  6:28     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2018-11-07  6:28 UTC (permalink / raw)
  To: Joey Pabalinas, zsh-workers

On Tue, Nov 6, 2018 at 3:47 PM Joey Pabalinas <joeypabalinas@gmail.com> wrote:
>
> If you think it's a bit superfluous then I don't mind removing that part and
> sending a quick v2.

No need for that.  (I would have added the parens but not done the setopt.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-11-07  6:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-06 23:34 [PATCH] select-bracketed: set nocprecedences to force native precedence ordering Joey Pabalinas
2018-11-06 23:40 ` Bart Schaefer
2018-11-06 23:47   ` Joey Pabalinas
2018-11-07  6:28     ` Bart Schaefer

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).