zsh-workers
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] sort: Restore option to ignore back-slashes
Date: Thu, 2 May 2019 15:14:22 -0500	[thread overview]
Message-ID: <0B615B84-776D-4033-8108-F66C0C762E42@dana.is> (raw)

Oliver mentioned to me off-list (and earlier in workers/43842) that
workers/41242 introduced an issue with sorting completion matches, where it no
longer ignores back-slashes like it used to. (e.g., in zsh 5.3 the match
`\!foo` would be sorted ahead of `Afoo`, but now it's the other way around.)

This seems to restore that functionality. I pretty much just copied and
pasted, though, so maybe someone could double-check my thinking...

dana


diff --git a/Src/sort.c b/Src/sort.c
index 92ee1c0d4..562b89491 100644
--- a/Src/sort.c
+++ b/Src/sort.c
@@ -33,6 +33,9 @@
 /* Flag for direction of sort: 1 forwards, -1 reverse */
 static int sortdir;
 
+/* Flag that sort ignores backslashes */
+static int sortnobslash;
+
 /* Flag that sort is numeric */
 static int sortnumeric;
 
@@ -113,9 +116,24 @@ eltpcmp(const void *a, const void *b)
 	bs += (laststarta - as);
 	as += (laststarta - as);
     }
+
+   if (sortnobslash) {
+	while (*as && *bs) {
+	    if (*as == '\\')
+		as++;
+	    if (*bs == '\\')
+		bs++;
+	    if (*as != *bs || !*as)
+		break;
+	    as++;
+	    bs++;
+	}
+    }
+
 #ifdef HAVE_STRCOLL
     cmp = strcoll(as, bs);
 #endif
+
     if (sortnumeric) {
 	for (; *as == *bs && *as; as++, bs++);
 #ifndef HAVE_STRCOLL
@@ -162,7 +180,10 @@ mod_export int
 zstrcmp(const char *as, const char *bs, int sortflags)
 {
     struct sortelt ae, be, *aeptr, *beptr;
-    int oldsortdir = sortdir, oldsortnumeric = sortnumeric, ret;
+    int oldsortdir = sortdir;
+    int oldsortnobslash = sortnobslash;
+    int oldsortnumeric = sortnumeric;
+    int ret;
 
     ae.cmp = as;
     be.cmp = bs;
@@ -173,11 +194,13 @@ zstrcmp(const char *as, const char *bs, int sortflags)
     beptr = &be;
 
     sortdir = 1;
+    sortnobslash = (sortflags & SORTIT_IGNORING_BACKSLASHES) ? 1 : 0;
     sortnumeric = (sortflags & SORTIT_NUMERICALLY) ? 1 : 0;
 
     ret = eltpcmp(&aeptr, &beptr);
 
     /* Paranoia: I don't think we ever need to restore these. */
+    sortnobslash = oldsortnobslash;
     sortnumeric = oldsortnumeric;
     sortdir = oldsortdir;
 
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index b1c0e40e5..f1c981f26 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -99,6 +99,7 @@ F:regression test workers/31611
     comptesteval 'cd "A(B)/C"'
     comptest $'cd ../\t'
   } always {
+    comptesteval 'cd -' # Reset CWD
     rmdir 'A(B)/C' 'A(B)'
   }
 0:directory name is not a glob qualifier
@@ -116,6 +117,27 @@ F:regression test workers/31611
 0:allow for suffixes when moving cursor to end of match (without ignored suffix)
 >line: {tst word:/}{}
 
+# Test for regression introduced by workers/41242, raised in workers/43842
+  {
+    mkdir sortnobslash
+    touch sortnobslash/{'!foo','#foo','\foo','|foo','~foo',Afoo,bfoo}
+    comptesteval 'old_LC_ALL=$LC_ALL; LC_ALL=C'
+    comptest $': sortnobslash/\t'
+  } always {
+    comptesteval 'LC_ALL=$old_LC_ALL'
+    rm -rf sortnobslash
+  }
+0:ignore backslashes when sorting completion matches
+>line: {: sortnobslash/}{}
+>DESCRIPTION:{file}
+>FI:{\!foo}
+>FI:{\#foo}
+>FI:{Afoo}
+>FI:{\\foo}
+>FI:{bfoo}
+>FI:{\|foo}
+>FI:{\~foo}
+
 %clean
 
   zmodload -ui zsh/zpty


             reply	other threads:[~2019-05-02 20:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190502201534epcas2p454f737ce02186129b299a92cbe639939@epcas2p4.samsung.com>
2019-05-02 20:14 ` dana [this message]
2019-05-03  9:08   ` Peter Stephenson

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=0B615B84-776D-4033-8108-F66C0C762E42@dana.is \
    --to=dana@dana.is \
    --cc=zsh-workers@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).