zsh-workers
 help / color / mirror / code / Atom feed
From: "Alexey I. Froloff" <raorn@altlinux.org>
To: Zsh list <zsh-workers@sunsite.dk>
Subject: Completion for ri (Ruby API reference frontend)
Date: Fri, 2 Oct 2009 03:24:58 +0400	[thread overview]
Message-ID: <20091001232458.GG22325@altlinux.org> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 89 bytes --]

Will complete classes, class methods and instance methods.

-- 
Regards,
Sir Raorn.

[-- Attachment #1.2: _ri --]
[-- Type: text/plain, Size: 3088 bytes --]

#compdef ri

local context="$curcontext" state line ret=1
typeset -A opt_args

_arguments \
  '(- *)'{-h,--help}'[print help information and exit]' \
  '(- *)'{-v,--version}'[display the version of ri]' \
  '*'{-d,--doc-dir}'[directory to search for documentation]:ri doc directory:_files -/' \
  '(-f --fmt --format)'{-f,--fmt,--format}'[format to use when displaying output]:output format:(ansi bs html plain simple)' \
  '(-T --no-pager)'{-T,--no-pager}'[send output directly to stdout]' \
  '(-i, --interactive)'{-i,--interactive}'[interactive mode]' \
  '--list-doc-dirs[list the directories from which ri will source documentation]' \
  '(-w --width)'{-w,--width}'[set the width of the output]:output width:' \
  '--no-standard-docs[do not include documentation from the Ruby standard library, site_lib, installed gems, or ~/.rdoc]' \
  '(--no-use-cache --use-cache)--'{no-,}'use-cache[whether or not to use ri'\''s cache]' \
  '(--no-system --system)--'{no-,}'system[include documentation from Ruby'\''s standard library]' \
  '(--no-site --site)--'{no-,}'site[include documentation from libraries installed in site_lib]' \
  '(--no-gems --gems)--'{no-,}'gems[include documentation from RubyGems]' \
  '(--no-home --home)--'{no-,}'home[include documentation stored in ~/.rdoc]' \
  '*:ri name:->ri-name' && ret=0

if [[ "$state" = ri-name ]]; then
  local -a ri_dirs ri_names ri_wants ri_names
  local class_dir esc_name dir curtag tag descr expl

  ret=1

  ri_dirs=( ${(f)"$(_call_program ri-names "$words[1]" ${(kv)opt_args[(I)-d|--doc-dir|--((no-|)(system|site|gems|home)|standard-docs)]} --list-doc-dirs -f plain -T)"} )

  if compset -P '?*(::|\#|.)'; then
    class_dir=${IPREFIX//(::|\#|.)/\/}
    #else
    #	:
  fi
  esc_name=${${(Q)PREFIX}//(#b)([^A-Za-z0-9_])/$(printf %%%x ${(qq)match[1]})}

  case "$IPREFIX" in
    (*::) ri_wants=( 'classes:class names' 'class-methods:class methods' );;
    (*\#) ri_wants=( 'instance-methods:instance methods' );;
    (*.) ri_wants=( 'class-methods:class methods' 'instance-methods:instance methods' );;
    (*) ri_wants=( 'classes:class names' )
  esac

  for curtag in $ri_wants; do
    tag=${curtag%%:*}
    descr=${curtag#*:}

    _tags "$tag"
    while _tags; do
      while _next_label "$tag" expl "$descr"; do
        ri_wants=()
        case "$tag" in
          (classes)
          for dir in $ri_dirs[@]; do
            ri_wants+=( $dir/$class_dir*(-/:t) )
          done
          ;;
          (class-methods)
          for dir in $ri_dirs[@]; do
            fnames=( $dir/$class_dir*-c.yaml(-.:t) )
            ri_wants+=( ${${fnames%-c.yaml}//(#b)%(??)/$(print "\\x$match[1]")} )
          done
          ;;
          (instance-methods)
          for dir in $ri_dirs[@]; do
            fnames=( $dir/$class_dir*-i.yaml(-.:t) )
            ri_wants+=( ${${fnames%-i.yaml}//(#b)%(??)/$(print "\\x$match[1]")} )
          done
          ;;
        esac
        ri_names=( ${(Q)ri_wants} )
        compadd -S '' -d ri_names -a "$expl[@]" ri_wants && ret=0
      done
      (( ret )) || break
    done
  done
fi

return ret

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

             reply	other threads:[~2009-10-01 23:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-01 23:24 Alexey I. Froloff [this message]
2009-10-02  8:42 ` Peter Stephenson
2009-10-02 15:27   ` Alexey I. Froloff
2009-10-03  6:44     ` Doug Kearns
2009-11-08 15:08   ` [PATCH] Rewrite of RI (Ruby documentation browser) completion Alexey I. Froloff
2009-11-11 14:27     ` Alexey I. Froloff
2009-11-11 16:21       ` Bart Schaefer
2009-11-11 21:24         ` Alexey I. Froloff

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=20091001232458.GG22325@altlinux.org \
    --to=raorn@altlinux.org \
    --cc=zsh-workers@sunsite.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).