zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: Suggested tilde-keeping in expansions
Date: Wed, 07 Jun 2000 17:00:09 +0100	[thread overview]
Message-ID: <0FVS00JH4KG9R0@la-la.cambridgesiliconradio.com> (raw)

How about something like this?  The style keep-tilde defaults to on and
makes _expand restore the ~/ or ~foo/ part of an expression after globbing.
It doesn't need to default to on.  It could probably usefully take a third
value indicating you would like the ~ expanded if there were no other
changes --- that might be a good default.

I won't commit this because I'm sure someone will have suggestions for
expansions, deletions, changes, or complete rewrites.  For example, you
could restore initial parameter expressions such as ${HOME}/ in a similar
way if the glob succeeded (or subst-globs-only is true).  But we could do
with something or other along these lines.

It's a different question, but maybe we could set nonomatch for the
duration of the function to handle failed matches more gracefully.  Or
maybe people who don't set nonomatch (i.e. do set no nonomatch) like it the
way it is.

Index: Completion/Core/_expand
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_expand,v
retrieving revision 1.14
diff -u -r1.14 _expand
--- Completion/Core/_expand	2000/06/06 13:04:10	1.14
+++ Completion/Core/_expand	2000/06/07 15:49:15
@@ -12,6 +12,7 @@
 [[ _matcher_num -gt 1 ]] && return 1
 
 local exp word sort expr expl subd suf=" " force opt
+local tilde untilde match mbegin mend
 
 (( $# )) &&
     while getopts gsco opt; do
@@ -60,11 +61,22 @@
 
 # Now try globbing.
 
-[[ "$force" = *g* ]] ||
+if [[ "$force" = *g* ]] ||
   { { zstyle -s ":completion:${curcontext}:" glob expr ||
       { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
-        [[ "${(e):-\$[$expr]}" -eq 1 ]] } &&
+        [[ "${(e):-\$[$expr]}" -eq 1 ]] }; then
+    if zstyle -T ":completion:${curcontext}:" keep-tilde &&
+      [[ $exp = (#b)(\~[^/]#)/* ]]; then
+      # Attempt to keep a ~dir initial segment intact:  remember
+      # its expansion so as to replace that back with the original.
+      tilde=$match[1]
+      untilde=(${~tilde})
+    fi
     exp=( ${~exp} )
+    if [[ -n $expr ]]; then
+      exp=( ${exp/(#s)$untilde/$tilde} )
+    fi
+fi
 
 # If we don't have any expansions or only one and that is the same
 # as the original string, we let other completers run.
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.59
diff -u -r1.59 compsys.yo
--- Doc/Zsh/compsys.yo	2000/05/29 14:48:38	1.59
+++ Doc/Zsh/compsys.yo	2000/06/07 15:49:16
@@ -1283,6 +1283,13 @@
 tt(approximate-)var(num), where var(num) is the number of errors that
 were accepted.
 )
+kindex(keep-tilde, completion style)
+item(tt(keep-tilde))(
+Used by the tt(_expand) completer.  By default, expansions of expressions
+beginning with a named directory, i.e. tt(~/) or tt(~)var(name)tt(/),
+will keep that part unchanged.  If this style is set to one of the false
+values, a full expansion will be performed instead.
+)
 kindex(last-prompt, completion style)
 item(tt(last-prompt))(
 This is used to determine if the completion code should try to put the

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


                 reply	other threads:[~2000-06-07 16:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=0FVS00JH4KG9R0@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).