mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-04 06:14:50 +01:00
Initial revision
This commit is contained in:
parent
520116ec68
commit
65392c396b
8 changed files with 1826 additions and 0 deletions
26
Completion/Base/_job
Normal file
26
Completion/Base/_job
Normal file
|
@ -0,0 +1,26 @@
|
|||
#autoload
|
||||
|
||||
local expl disp jobs job jids
|
||||
|
||||
if [[ "$1" = -r ]]; then
|
||||
jids=( "${(@k)jobstates[(R)running*]}" )
|
||||
shift
|
||||
_description expl 'running job'
|
||||
elif [[ "$1" = -s ]]; then
|
||||
jids=( "${(@k)jobstates[(R)running*]}" )
|
||||
shift
|
||||
_description expl 'suspended job'
|
||||
else
|
||||
[[ "$1" = - ]] && shift
|
||||
jids=( "${(@k)jobtexts}" )
|
||||
_description expl job
|
||||
fi
|
||||
|
||||
disp=()
|
||||
jobs=()
|
||||
for job in "$jids[@]"; do
|
||||
disp=( "$disp[@]" "[${(l:2:: :)job}] ${jobtexts[$job]}" )
|
||||
jobs=( "$jobs[@]" "$job" )
|
||||
done
|
||||
|
||||
compadd "$@" "$expl[@]" -ld disp - "$jobs[@]"
|
7
Doc/Zsh/mod_complete.yo
Normal file
7
Doc/Zsh/mod_complete.yo
Normal file
|
@ -0,0 +1,7 @@
|
|||
texinode(The complete Module)(The compctl Module)(The clone Module)(Zsh Modules)
|
||||
sect(The complete Module)
|
||||
The tt(compctl) module makes available several builtin commands which
|
||||
can be used in user-defined completion widgets, see
|
||||
ifzman(zmanref(zshcompwid))\
|
||||
ifnzman(noderef(Completion Widgets))\
|
||||
.
|
28
Doc/Zsh/mod_zleparameter.yo
Normal file
28
Doc/Zsh/mod_zleparameter.yo
Normal file
|
@ -0,0 +1,28 @@
|
|||
texinode(The zleparameter Module)()(The zle Module)(Zsh Modules)
|
||||
sect(The zleparameter Module)
|
||||
cindex(parameters, special)
|
||||
The tt(zleparameter) module defines two special parameters that can be
|
||||
used to access internal information of the Zsh Line Editor (see
|
||||
ifzman(zmanref(zshzle))\
|
||||
ifnzman(noderef(Zsh Line Editor))\
|
||||
).
|
||||
|
||||
startitem()
|
||||
vindex(zlekeymaps)
|
||||
item(tt(zlekeymaps))(
|
||||
This array contains the names of the keymaps currently defined.
|
||||
)
|
||||
vindex(zlewidgets)
|
||||
item(tt(zlewidgets))(
|
||||
This associative array contains one entry per widget defined. The name
|
||||
of the widget is the key and the value gives information about the
|
||||
widget. It is either the string `tt(builtin)' for builtin widgets, a
|
||||
string of the form `tt(user:)var(name)' for user-defined widgets,
|
||||
where var(name) is the name of the shell function implementing the
|
||||
widget, or it is a string of the form
|
||||
`tt(completion:)var(type)tt(:)var(name)', for completion widgets. In
|
||||
the last case var(type) is the name of the builtin widgets the
|
||||
completion widget imitates in its behavior and var(name) is the name
|
||||
of the shell function implementing the completion widget.
|
||||
)
|
||||
enditem()
|
160
Src/Zle/compctl.h
Normal file
160
Src/Zle/compctl.h
Normal file
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* comp.h - header file for completion
|
||||
*
|
||||
* This file is part of zsh, the Z shell.
|
||||
*
|
||||
* Copyright (c) 1992-1997 Paul Falstad
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and to distribute modified versions of this software for any
|
||||
* purpose, provided that the above copyright notice and the following
|
||||
* two paragraphs appear in all copies of this software.
|
||||
*
|
||||
* In no event shall Paul Falstad or the Zsh Development Group be liable
|
||||
* to any party for direct, indirect, special, incidental, or consequential
|
||||
* damages arising out of the use of this software and its documentation,
|
||||
* even if Paul Falstad and the Zsh Development Group have been advised of
|
||||
* the possibility of such damage.
|
||||
*
|
||||
* Paul Falstad and the Zsh Development Group specifically disclaim any
|
||||
* warranties, including, but not limited to, the implied warranties of
|
||||
* merchantability and fitness for a particular purpose. The software
|
||||
* provided hereunder is on an "as is" basis, and Paul Falstad and the
|
||||
* Zsh Development Group have no obligation to provide maintenance,
|
||||
* support, updates, enhancements, or modifications.
|
||||
*
|
||||
*/
|
||||
|
||||
#undef compctlread
|
||||
|
||||
typedef struct compctlp *Compctlp;
|
||||
typedef struct compctl *Compctl;
|
||||
typedef struct compcond *Compcond;
|
||||
typedef struct patcomp *Patcomp;
|
||||
|
||||
/* node for compctl hash table (compctltab) */
|
||||
|
||||
struct compctlp {
|
||||
HashNode next; /* next in hash chain */
|
||||
char *nam; /* command name */
|
||||
int flags; /* CURRENTLY UNUSED */
|
||||
Compctl cc; /* pointer to the compctl desc. */
|
||||
};
|
||||
|
||||
/* for the list of pattern compctls */
|
||||
|
||||
struct patcomp {
|
||||
Patcomp next;
|
||||
char *pat;
|
||||
Compctl cc;
|
||||
};
|
||||
|
||||
/* compctl -x condition */
|
||||
|
||||
struct compcond {
|
||||
Compcond and, or; /* the next or'ed/and'ed conditions */
|
||||
int type; /* the type (CCT_*) */
|
||||
int n; /* the array length */
|
||||
union { /* these structs hold the data used to */
|
||||
struct { /* test this condition */
|
||||
int *a, *b; /* CCT_POS, CCT_NUMWORDS */
|
||||
}
|
||||
r;
|
||||
struct { /* CCT_CURSTR, CCT_CURPAT,... */
|
||||
int *p;
|
||||
char **s;
|
||||
}
|
||||
s;
|
||||
struct { /* CCT_RANGESTR,... */
|
||||
char **a, **b;
|
||||
}
|
||||
l;
|
||||
}
|
||||
u;
|
||||
};
|
||||
|
||||
#define CCT_UNUSED 0
|
||||
#define CCT_POS 1
|
||||
#define CCT_CURSTR 2
|
||||
#define CCT_CURPAT 3
|
||||
#define CCT_WORDSTR 4
|
||||
#define CCT_WORDPAT 5
|
||||
#define CCT_CURSUF 6
|
||||
#define CCT_CURPRE 7
|
||||
#define CCT_CURSUB 8
|
||||
#define CCT_CURSUBC 9
|
||||
#define CCT_NUMWORDS 10
|
||||
#define CCT_RANGESTR 11
|
||||
#define CCT_RANGEPAT 12
|
||||
#define CCT_QUOTE 13
|
||||
|
||||
/* Contains the real description for compctls */
|
||||
|
||||
struct compctl {
|
||||
int refc; /* reference count */
|
||||
Compctl next; /* next compctl for -x */
|
||||
unsigned long mask, mask2; /* masks of things to complete (CC_*) */
|
||||
char *keyvar; /* for -k (variable) */
|
||||
char *glob; /* for -g (globbing) */
|
||||
char *str; /* for -s (expansion) */
|
||||
char *func; /* for -K (function) */
|
||||
char *explain; /* for -X (explanation) */
|
||||
char *ylist; /* for -y (user-defined desc. for listing) */
|
||||
char *prefix, *suffix; /* for -P and -S (prefix, suffix) */
|
||||
char *subcmd; /* for -l (command name to use) */
|
||||
char *substr; /* for -1 (command name to use) */
|
||||
char *withd; /* for -w (with directory */
|
||||
char *hpat; /* for -H (history pattern) */
|
||||
int hnum; /* for -H (number of events to search) */
|
||||
char *gname; /* for -J and -V (group name) */
|
||||
Compctl ext; /* for -x (first of the compctls after -x) */
|
||||
Compcond cond; /* for -x (condition for this compctl) */
|
||||
Compctl xor; /* for + (next of the xor'ed compctls) */
|
||||
Cmatcher matcher; /* matcher control (-M) */
|
||||
char *mstr; /* matcher string */
|
||||
};
|
||||
|
||||
/* objects to complete (mask) */
|
||||
#define CC_FILES (1<<0)
|
||||
#define CC_COMMPATH (1<<1)
|
||||
#define CC_REMOVE (1<<2)
|
||||
#define CC_OPTIONS (1<<3)
|
||||
#define CC_VARS (1<<4)
|
||||
#define CC_BINDINGS (1<<5)
|
||||
#define CC_ARRAYS (1<<6)
|
||||
#define CC_INTVARS (1<<7)
|
||||
#define CC_SHFUNCS (1<<8)
|
||||
#define CC_PARAMS (1<<9)
|
||||
#define CC_ENVVARS (1<<10)
|
||||
#define CC_JOBS (1<<11)
|
||||
#define CC_RUNNING (1<<12)
|
||||
#define CC_STOPPED (1<<13)
|
||||
#define CC_BUILTINS (1<<14)
|
||||
#define CC_ALREG (1<<15)
|
||||
#define CC_ALGLOB (1<<16)
|
||||
#define CC_USERS (1<<17)
|
||||
#define CC_DISCMDS (1<<18)
|
||||
#define CC_EXCMDS (1<<19)
|
||||
#define CC_SCALARS (1<<20)
|
||||
#define CC_READONLYS (1<<21)
|
||||
#define CC_SPECIALS (1<<22)
|
||||
#define CC_DELETE (1<<23)
|
||||
#define CC_NAMED (1<<24)
|
||||
#define CC_QUOTEFLAG (1<<25)
|
||||
#define CC_EXTCMDS (1<<26)
|
||||
#define CC_RESWDS (1<<27)
|
||||
#define CC_DIRS (1<<28)
|
||||
|
||||
#define CC_EXPANDEXPL (1<<30)
|
||||
#define CC_RESERVED (1<<31)
|
||||
|
||||
/* objects to complete (mask2) */
|
||||
#define CC_NOSORT (1<<0)
|
||||
#define CC_XORCONT (1<<1)
|
||||
#define CC_CCCONT (1<<2)
|
||||
#define CC_PATCONT (1<<3)
|
||||
#define CC_DEFCONT (1<<4)
|
||||
#define CC_UNIQCON (1<<5)
|
||||
#define CC_UNIQALL (1<<6)
|
1332
Src/Zle/complete.c
Normal file
1332
Src/Zle/complete.c
Normal file
File diff suppressed because it is too large
Load diff
11
Src/Zle/complete.mdd
Normal file
11
Src/Zle/complete.mdd
Normal file
|
@ -0,0 +1,11 @@
|
|||
hasexport=1
|
||||
|
||||
moddeps="zle"
|
||||
|
||||
autobins="compgen compadd compset"
|
||||
|
||||
autoprefixconds="prefix suffix between after"
|
||||
|
||||
autoparams="compmatchers"
|
||||
|
||||
objects="complete.o"
|
257
Src/Zle/zleparameter.c
Normal file
257
Src/Zle/zleparameter.c
Normal file
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* zleparameter.c - parameter interface to zle internals
|
||||
*
|
||||
* This file is part of zsh, the Z shell.
|
||||
*
|
||||
* Copyright (c) 1999 Sven Wischnowsky
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and to distribute modified versions of this software for any
|
||||
* purpose, provided that the above copyright notice and the following
|
||||
* two paragraphs appear in all copies of this software.
|
||||
*
|
||||
* In no event shall Sven Wischnowsky or the Zsh Development Group be liable
|
||||
* to any party for direct, indirect, special, incidental, or consequential
|
||||
* damages arising out of the use of this software and its documentation,
|
||||
* even if Sven Wischnowsky and the Zsh Development Group have been advised of
|
||||
* the possibility of such damage.
|
||||
*
|
||||
* Sven Wischnowsky and the Zsh Development Group specifically disclaim any
|
||||
* warranties, including, but not limited to, the implied warranties of
|
||||
* merchantability and fitness for a particular purpose. The software
|
||||
* provided hereunder is on an "as is" basis, and Sven Wischnowsky and the
|
||||
* Zsh Development Group have no obligation to provide maintenance,
|
||||
* support, updates, enhancements, or modifications.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zleparameter.mdh"
|
||||
#include "zleparameter.pro"
|
||||
|
||||
/* Empty dummy function for special hash parameters. */
|
||||
|
||||
/**/
|
||||
static void
|
||||
shempty(void)
|
||||
{
|
||||
}
|
||||
|
||||
/* Create a simple special hash parameter. */
|
||||
|
||||
/**/
|
||||
static Param
|
||||
createspecialhash(char *name, GetNodeFunc get, ScanTabFunc scan)
|
||||
{
|
||||
Param pm;
|
||||
HashTable ht;
|
||||
|
||||
if (!(pm = createparam(name, PM_SPECIAL|PM_HIDE|PM_REMOVABLE|PM_HASHED)))
|
||||
return NULL;
|
||||
|
||||
pm->level = pm->old ? locallevel : 0;
|
||||
pm->gets.hfn = hashgetfn;
|
||||
pm->sets.hfn = hashsetfn;
|
||||
pm->unsetfn = stdunsetfn;
|
||||
pm->u.hash = ht = newhashtable(7, name, NULL);
|
||||
|
||||
ht->hash = hasher;
|
||||
ht->emptytable = (TableFunc) shempty;
|
||||
ht->filltable = NULL;
|
||||
ht->addnode = (AddNodeFunc) shempty;
|
||||
ht->getnode = ht->getnode2 = get;
|
||||
ht->removenode = (RemoveNodeFunc) shempty;
|
||||
ht->disablenode = NULL;
|
||||
ht->enablenode = NULL;
|
||||
ht->freenode = (FreeNodeFunc) shempty;
|
||||
ht->printnode = printparamnode;
|
||||
ht->scantab = scan;
|
||||
|
||||
return pm;
|
||||
}
|
||||
|
||||
/* Functions for the zlewidgets special parameter. */
|
||||
|
||||
/**/
|
||||
static char *
|
||||
widgetstr(Widget w)
|
||||
{
|
||||
if (w->flags & WIDGET_INT)
|
||||
return dupstring("builtin");
|
||||
if (w->flags & WIDGET_NCOMP) {
|
||||
char *t = (char *) zhalloc(13 + strlen(w->u.comp.wid) +
|
||||
strlen(w->u.comp.func));
|
||||
|
||||
strcpy(t, "completion:");
|
||||
strcat(t, w->u.comp.wid);
|
||||
strcat(t, ":");
|
||||
strcat(t, w->u.comp.func);
|
||||
|
||||
return t;
|
||||
}
|
||||
return dyncat("user:", w->u.fnnam);
|
||||
}
|
||||
|
||||
/**/
|
||||
static HashNode
|
||||
getpmwidgets(HashTable ht, char *name)
|
||||
{
|
||||
Param pm = NULL;
|
||||
Thingy th;
|
||||
|
||||
HEAPALLOC {
|
||||
pm = (Param) zhalloc(sizeof(struct param));
|
||||
pm->nam = dupstring(name);
|
||||
pm->flags = PM_SCALAR | PM_READONLY;
|
||||
pm->sets.cfn = NULL;
|
||||
pm->gets.cfn = strgetfn;
|
||||
pm->unsetfn = NULL;
|
||||
pm->ct = 0;
|
||||
pm->env = NULL;
|
||||
pm->ename = NULL;
|
||||
pm->old = NULL;
|
||||
pm->level = 0;
|
||||
if ((th = (Thingy) thingytab->getnode(thingytab, name)) &&
|
||||
!(th->flags & DISABLED))
|
||||
pm->u.str = widgetstr(th->widget);
|
||||
else {
|
||||
pm->u.str = dupstring("");
|
||||
pm->flags |= PM_UNSET;
|
||||
}
|
||||
} LASTALLOC;
|
||||
|
||||
return (HashNode) pm;
|
||||
}
|
||||
|
||||
/**/
|
||||
static void
|
||||
scanpmwidgets(HashTable ht, ScanFunc func, int flags)
|
||||
{
|
||||
struct param pm;
|
||||
int i;
|
||||
HashNode hn;
|
||||
|
||||
pm.flags = PM_SCALAR | PM_READONLY;
|
||||
pm.sets.cfn = NULL;
|
||||
pm.gets.cfn = strgetfn;
|
||||
pm.unsetfn = NULL;
|
||||
pm.ct = 0;
|
||||
pm.env = NULL;
|
||||
pm.ename = NULL;
|
||||
pm.old = NULL;
|
||||
pm.level = 0;
|
||||
|
||||
for (i = 0; i < thingytab->hsize; i++)
|
||||
for (hn = thingytab->nodes[i]; hn; hn = hn->next) {
|
||||
pm.nam = hn->nam;
|
||||
if (func != scancountparams)
|
||||
pm.u.str = widgetstr(((Thingy) hn)->widget);
|
||||
func((HashNode) &pm, flags);
|
||||
}
|
||||
}
|
||||
|
||||
/* Functions for the zlekeymaps special parameter. */
|
||||
|
||||
static char **
|
||||
keymapsgetfn(Param pm)
|
||||
{
|
||||
int i;
|
||||
HashNode hn;
|
||||
char **ret, **p;
|
||||
|
||||
p = ret = (char **) zhalloc((keymapnamtab->ct + 1) * sizeof(char *));
|
||||
|
||||
for (i = 0; i < keymapnamtab->hsize; i++)
|
||||
for (hn = keymapnamtab->nodes[i]; hn; hn = hn->next)
|
||||
*p++ = dupstring(hn->nam);
|
||||
*p = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Table for defined parameters. */
|
||||
|
||||
struct pardef {
|
||||
char *name;
|
||||
int flags;
|
||||
GetNodeFunc getnfn;
|
||||
ScanTabFunc scantfn;
|
||||
void (*hsetfn) _((Param, HashTable));
|
||||
void (*setfn) _((Param, char **));
|
||||
char **(*getfn) _((Param));
|
||||
void (*unsetfn) _((Param, int));
|
||||
Param pm;
|
||||
};
|
||||
|
||||
static struct pardef partab[] = {
|
||||
{ "zlewidgets", PM_READONLY,
|
||||
getpmwidgets, scanpmwidgets, hashsetfn,
|
||||
NULL, NULL, stdunsetfn, NULL },
|
||||
{ "zlekeymaps", PM_ARRAY|PM_HIDE|PM_SPECIAL|PM_READONLY,
|
||||
NULL, NULL, NULL,
|
||||
arrsetfn, keymapsgetfn, stdunsetfn, NULL },
|
||||
{ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
/**/
|
||||
int
|
||||
setup_zleparameter(Module m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**/
|
||||
int
|
||||
boot_zleparameter(Module m)
|
||||
{
|
||||
struct pardef *def;
|
||||
|
||||
for (def = partab; def->name; def++) {
|
||||
unsetparam(def->name);
|
||||
|
||||
if (def->getnfn) {
|
||||
if (!(def->pm = createspecialhash(def->name, def->getnfn,
|
||||
def->scantfn)))
|
||||
return 1;
|
||||
def->pm->flags |= def->flags;
|
||||
if (def->hsetfn)
|
||||
def->pm->sets.hfn = def->hsetfn;
|
||||
} else {
|
||||
if (!(def->pm = createparam(def->name, def->flags)))
|
||||
return 1;
|
||||
def->pm->sets.afn = def->setfn;
|
||||
def->pm->gets.afn = def->getfn;
|
||||
def->pm->unsetfn = def->unsetfn;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MODULE
|
||||
|
||||
/**/
|
||||
int
|
||||
cleanup_zleparameter(Module m)
|
||||
{
|
||||
Param pm;
|
||||
struct pardef *def;
|
||||
|
||||
for (def = partab; def->name; def++) {
|
||||
if ((pm = (Param) paramtab->getnode(paramtab, def->name)) &&
|
||||
pm == def->pm) {
|
||||
pm->flags &= ~PM_READONLY;
|
||||
unsetparam_pm(pm, 0, 1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**/
|
||||
int
|
||||
finish_zleparameter(Module m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
5
Src/Zle/zleparameter.mdd
Normal file
5
Src/Zle/zleparameter.mdd
Normal file
|
@ -0,0 +1,5 @@
|
|||
moddeps="zle"
|
||||
|
||||
autoparams="zlewidgets zlekeymaps"
|
||||
|
||||
objects="zleparameter.o"
|
Loading…
Reference in a new issue