From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3587 invoked by alias); 30 Nov 2009 17:19:18 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27441 Received: (qmail 26032 invoked from network); 30 Nov 2009 17:19:15 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.5 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@zsh.org (Zsh hackers list) Subject: PATCH: completion list highlighting for suffix aliases X-Mailer: MH-E 8.0.3; nmh 1.3; GNU Emacs 22.1.1 Date: Mon, 30 Nov 2009 17:18:59 +0000 Message-ID: <2521.1259601539@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 30 Nov 2009 17:19:02.0901 (UTC) FILETIME=[3679C250:01CA71E1] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-09-22-03 (www.mailcontrol.com) on 10.68.0.159 This adds the ability to highlight all files that have an associated suffix alias. Not that useful, since when you can actually use a suffix alias they are highlighted by grouping, but it's a way of highlighting a lot of "interesting" files in one go (without needing to specify highlighting for individual suffixes). Hence if you use zsh-mime-setup you get a definition of "interesting" files for free. Call me weird, but I also decided "filename" was a better variable name for a filename than "n". Index: Doc/Zsh/mod_complist.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_complist.yo,v retrieving revision 1.28 diff -u -r1.28 mod_complist.yo --- Doc/Zsh/mod_complist.yo 1 Jul 2009 17:09:38 -0000 1.28 +++ Doc/Zsh/mod_complist.yo 30 Nov 2009 17:13:28 -0000 @@ -72,6 +72,10 @@ item(tt(ow 34;43))( for world writable directories without sticky bit set ) +item(tt(sa) var(none))( +for files with an associated suffix alias; this is only tested +after specific suffixes, as described below +) item(tt(st 37;44))( for directories with sticky bit set but not world writable ) Index: Src/Zle/complist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v retrieving revision 1.121 diff -u -r1.121 complist.c --- Src/Zle/complist.c 1 Jul 2009 17:09:38 -0000 1.121 +++ Src/Zle/complist.c 30 Nov 2009 17:13:28 -0000 @@ -187,15 +187,16 @@ #define COL_MA 21 #define COL_HI 22 #define COL_DU 23 +#define COL_SA 24 -#define NUM_COLS 24 +#define NUM_COLS 25 /* Names of the terminal strings. */ static char *colnames[] = { "no", "fi", "di", "ln", "pi", "so", "bd", "cd", "or", "mi", "su", "sg", "tw", "ow", "st", "ex", - "lc", "rc", "ec", "tc", "sp", "ma", "hi", "du", NULL + "lc", "rc", "ec", "tc", "sp", "ma", "hi", "du", "sa", NULL }; /* Default values. */ @@ -203,7 +204,7 @@ static char *defcols[] = { "0", "0", "1;31", "1;36", "33", "1;35", "1;33", "1;33", NULL, NULL, "37;41", "30;43", "30;42", "34;42", "37;44", "1;32", - "\033[", "m", NULL, "0", "0", "7", NULL, NULL + "\033[", "m", NULL, "0", "0", "7", NULL, NULL, "0" }; /* This describes a terminal string for a file type. */ @@ -872,17 +873,18 @@ * file modes. */ static int -putfilecol(char *group, char *n, mode_t m, int special) +putfilecol(char *group, char *filename, mode_t m, int special) { int colour = -1; Extcol ec; Patcol pc; + int len; nrefs = MAX_POS - 1; for (pc = mcolors.pats; pc; pc = pc->next) if ((!pc->prog || !group || pattry(pc->prog, group)) && - pattryrefs(pc->pat, n, -1, -1, 0, &nrefs, begpos, endpos)) { + pattryrefs(pc->pat, filename, -1, -1, 0, &nrefs, begpos, endpos)) { if (pc->cols[1]) { patcols = pc->cols; @@ -928,13 +930,29 @@ } for (ec = mcolors.exts; ec; ec = ec->next) - if (strsfx(ec->ext, n) && + if (strsfx(ec->ext, filename) && (!ec->prog || !group || pattry(ec->prog, group))) { zlrputs(ec->col); return 0; } + /* Check for suffix alias */ + len = strlen(filename); + /* shortest valid suffix format is a.b */ + if (len > 2) { + char *suf = filename + len - 1; + while (suf > filename+1) { + if (suf[-1] == '.') { + if (sufaliastab->getnode(sufaliastab, suf)) { + zcputs(group, COL_SA); + return 0; + } + break; + } + suf--; + } + } zcputs(group, COL_FI); return 0; -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom