zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Zsh users mailing list <zsh-users@math.gatech.edu>, borsenkow.msk@sni.de
Subject: Re: Question about completeion.
Date: Thu, 25 Jul 1996 09:49:06 -0700	[thread overview]
Message-ID: <960725094906.ZM13529@candle.brasslantern.com> (raw)
In-Reply-To: Andrej Borsenkow <borsenkow.msk@sni.de> "Question about completeion." (Jul 25,  3:47pm)

On Jul 25,  3:47pm, Andrej Borsenkow wrote:
} Subject: Question about completeion.
}
} Now I would like to write small wrapper around cd, so that
} 
} % cd /u/l/l/t<RETURN>
} 
} would change dir into /usr/local/lib/texmf iff the match is unique;
} otherweise expand argument and leave me in MENU mode. 

This is not currently possible in zsh.

Zsh lacks two features necessary for this to work:

First, although zsh has `print -z', any characters inserted into the
input by this method are implicitly quoted; so you can't (for example)
use "print -Pz '\eA'" to cause zsh to execute accept-and-hold.  Instead
you get a escape character and an `A' inserted into the zle buffer.

(An alternative, which I would love to have, would be a way to shove a
zle command onto the input BY NAME, even when it is not bound to any
keystroke; e.g. `print -Zz accept-line'.)

Second, there's no way to cause a `bindkey -s' sequence to abort in the
middle.  E.g. in vi, if a `map' macro contains an impossible motion or
any other failed action, the entire macro aborts at the point of failure.
In zsh, the keystrokes keep right on going as if nothing was wrong, so
you have to be very careful with `bindkey -s' to avoid doing anything
destructive after a sequence that might not always succeed.

Either of these alone would make what you want possible, but zsh has
neither.

} I am not so skillfull in zsh programming; also, I am not sure if I can
} call completion from inside of shell function.

No, you cannot.

The approach would have to be to rebind RETURN to do expand-or-complete
followed by accept-line, e.g. bindkey -s '^M' '\t^J'.  However, there's
no way to stop the accept-line from happening when the expand-or-complete
doesn't find a unique match.

I suppose you could reverse the procedure ...

	bindkey -s '^M' '^J\t'
	cd () {
	    local d=()
	    eval d=( "*${1:gs@/@*/*@}*" )	# Crude stand-in for multicomp;
						# you should use the real thing
						# (modified to avoid "read -c")
	    [[ $#d -eq 1 ]] && builtin cd $d
	    [[ $#d -ne 1 ]] && print -z cd $1
	}
	alias cd="noglob cd"			# Let globbing happen inside

Then when you hit return, your cd wrapper would execute.  If it finds a
directory to switch to, it switches there, otherwise it shoves the original
command back and then the \t from the bindkey completes it.

However, this leaves you with a leading tab on the next command line for
every command other than an unsuccessful cd, which is probably annoying.

So the closest you could get to what you want is to use a cd wrapper like
the one above (with print -z on failure) and DO NOT rebind RETURN.  Then
when your cd fails you get the command line back and you can manually type
TAB to begin menu completion.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"


      reply	other threads:[~1996-07-25 16:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-25 11:47 Andrej Borsenkow
1996-07-25 16:49 ` Bart Schaefer [this message]

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=960725094906.ZM13529@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=borsenkow.msk@sni.de \
    --cc=schaefer@nbn.com \
    --cc=zsh-users@math.gatech.edu \
    /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).