* PATCH: dynamic directory name completion
@ 2010-06-11 22:18 Peter Stephenson
2010-06-11 22:30 ` Mikael Magnusson
0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2010-06-11 22:18 UTC (permalink / raw)
To: Zsh hackers list
I've been playing around with dynamic directory names for referring to
recently used directories and in the process realised that rather than
having to overload _dynamic_directory_name in order to complete dynamic
directory names it would be much more natural to call the original
function, zsh_directory_name, with a new code letter. You don't lose
anything at all by this---you can still overload _dynamic_directory_name
if you prefer.
Here's the change with a tested (but rather less useful than the code
I'm aiming at) example.
Index: Completion/Zsh/Context/_dynamic_directory_name
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/_dynamic_directory_name,v
retrieving revision 1.1
diff -p -u -r1.1 _dynamic_directory_name
--- Completion/Zsh/Context/_dynamic_directory_name 29 Sep 2008 17:40:55 -0000 1.1
+++ Completion/Zsh/Context/_dynamic_directory_name 11 Jun 2010 22:12:36 -0000
@@ -1,7 +1,7 @@
#autoload
-# The core libraries don't check for dynamic directory name expansion;
-# this gets called from _subscript. This is a placeholder for
-# people to overload.
-
-_message 'dynamic directory name: redefine _dynamic_directory_name to use'
+if [[ -n $functions[zsh_directory_name] ]]; then
+ zsh_directory_name c
+else
+ _message 'dynamic directory name: implemented as zsh_directory_name c'
+fi
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.115
diff -p -u -r1.115 expn.yo
--- Doc/Zsh/expn.yo 11 Jun 2010 20:08:02 -0000 1.115
+++ Doc/Zsh/expn.yo 11 Jun 2010 22:12:37 -0000
@@ -1451,6 +1451,12 @@ parts of the directory path, as describe
length matched (16 in the example) is longer than that matched by any
static name.
+The completion system calls `tt(zsh_directory_name c)' in order to
+completion dynamic names for directories. The code for this should be
+as for any other completion function as described in
+ifnzman(noderef(Completion System))\
+ifzman(zmanref(zshcompsys)).
+
As a working example, here is a function that expands any dynamic names
beginning with the string tt(p:) to directories below
tt(/home/pws/perforce). In this simple case a static name for the
@@ -1461,16 +1467,28 @@ example(zsh_directory_name+LPAR()RPAR()
setopt extendedglob
local -a match mbegin mend
if [[ $1 = d ]]; then
+ # turn the directory into a name
if [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then
typeset -ga reply
reply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) )
else
return 1
fi
- else
+ elif [[ $1 = n ]]; then
+ # turn the name into a directory
[[ $2 != (#b)p:(?*) ]] && return 1
typeset -ga reply
reply=(/home/pws/perforce/$match[1])
+ elif [[ $1 = c ]]; then
+ # complete names
+ local expl
+ local -a dirs
+ dirs=(/home/pws/perforce/*(/:t))
+ dirs=(p:${^dirs})
+ _wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs
+ return
+ else
+ return 1
fi
return 0
})
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: dynamic directory name completion
2010-06-11 22:18 PATCH: dynamic directory name completion Peter Stephenson
@ 2010-06-11 22:30 ` Mikael Magnusson
0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2010-06-11 22:30 UTC (permalink / raw)
To: Zsh hackers list
On 12 June 2010 00:18, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> I've been playing around with dynamic directory names for referring to
> recently used directories and in the process realised that rather than
> having to overload _dynamic_directory_name in order to complete dynamic
> directory names it would be much more natural to call the original
> function, zsh_directory_name, with a new code letter. You don't lose
> anything at all by this---you can still overload _dynamic_directory_name
> if you prefer.
>
> Here's the change with a tested (but rather less useful than the code
> I'm aiming at) example.
>
> Index: Doc/Zsh/expn.yo
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
> retrieving revision 1.115
> diff -p -u -r1.115 expn.yo
> --- Doc/Zsh/expn.yo 11 Jun 2010 20:08:02 -0000 1.115
> +++ Doc/Zsh/expn.yo 11 Jun 2010 22:12:37 -0000
> @@ -1451,6 +1451,12 @@ parts of the directory path, as describe
> length matched (16 in the example) is longer than that matched by any
> static name.
>
> +The completion system calls `tt(zsh_directory_name c)' in order to
> +completion dynamic names for directories. The code for this should be
completion -> complete
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-11 22:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-11 22:18 PATCH: dynamic directory name completion Peter Stephenson
2010-06-11 22:30 ` Mikael Magnusson
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).