zsh-workers
 help / color / mirror / code / Atom feed
* Completion for ri (Ruby API reference frontend)
@ 2009-10-01 23:24 Alexey I. Froloff
  2009-10-02  8:42 ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey I. Froloff @ 2009-10-01 23:24 UTC (permalink / raw)
  To: Zsh list


[-- 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 --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion for ri (Ruby API reference frontend)
  2009-10-01 23:24 Completion for ri (Ruby API reference frontend) Alexey I. Froloff
@ 2009-10-02  8:42 ` Peter Stephenson
  2009-10-02 15:27   ` Alexey I. Froloff
  2009-11-08 15:08   ` [PATCH] Rewrite of RI (Ruby documentation browser) completion Alexey I. Froloff
  0 siblings, 2 replies; 8+ messages in thread
From: Peter Stephenson @ 2009-10-02  8:42 UTC (permalink / raw)
  To: Zsh list

"Alexey I. Froloff" wrote:
> Will complete classes, class methods and instance methods.

There already is an _ri in Completion/Unix/Command, please provide a
diff against that if anything is missing.

Thanks.

-- 
Peter Stephenson <pws@csr.com>            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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion for ri (Ruby API reference frontend)
  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
  1 sibling, 1 reply; 8+ messages in thread
From: Alexey I. Froloff @ 2009-10-02 15:27 UTC (permalink / raw)
  To: Zsh list

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

On Fri, Oct 02, 2009 at 09:42:52AM +0100, Peter Stephenson wrote:
> > Will complete classes, class methods and instance methods.
> There already is an _ri in Completion/Unix/Command, please provide a
> diff against that if anything is missing.
Can anyone check first whether this completion still works with
ri from Ruby 1.8.x?

-- 
Regards,
Sir Raorn.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Completion for ri (Ruby API reference frontend)
  2009-10-02 15:27   ` Alexey I. Froloff
@ 2009-10-03  6:44     ` Doug Kearns
  0 siblings, 0 replies; 8+ messages in thread
From: Doug Kearns @ 2009-10-03  6:44 UTC (permalink / raw)
  To: zsh-workers

On Sat, Oct 3, 2009 at 1:27 AM, Alexey I. Froloff <raorn@altlinux.org> wrote:
> On Fri, Oct 02, 2009 at 09:42:52AM +0100, Peter Stephenson wrote:
>> > Will complete classes, class methods and instance methods.
>> There already is an _ri in Completion/Unix/Command, please provide a
>> diff against that if anything is missing.
> Can anyone check first whether this completion still works with
> ri from Ruby 1.8.x?

% ruby --version
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
% ri
unrecognized option `--list-doc-dirs'

For help on options, try 'ri --help'

  ri
No matches for: `ri name' or `class names'

Doug


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] Rewrite of RI (Ruby documentation browser) completion
  2009-10-02  8:42 ` Peter Stephenson
  2009-10-02 15:27   ` Alexey I. Froloff
@ 2009-11-08 15:08   ` Alexey I. Froloff
  2009-11-11 14:27     ` Alexey I. Froloff
  1 sibling, 1 reply; 8+ messages in thread
From: Alexey I. Froloff @ 2009-11-08 15:08 UTC (permalink / raw)
  To: Zsh list; +Cc: Alexey I. Froloff

Since Ruby 1.9 RI is no longer have option to dump all known classes
and methods.  Instead, we try to look into documentation search paths
to offer available classes and class and instance methods.

This code is tested on Ruby 1.8.7 and 1.9.1.

Signed-off-by: Alexey I. Froloff <raorn@altlinux.org>
---
 Completion/Unix/Command/_ri |   80 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 71 insertions(+), 9 deletions(-)

diff --git a/Completion/Unix/Command/_ri b/Completion/Unix/Command/_ri
index e26b918..fe2a277 100644
--- a/Completion/Unix/Command/_ri
+++ b/Completion/Unix/Command/_ri
@@ -1,24 +1,86 @@
 #compdef ri
 
-local curcontext="$curcontext" state line ret=1
+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]' \
-  '(-c --classes)'{-c,--classes}'[display the names of classes and modules we know about]' \
-  '(-d --doc-dir)'{-d,--doc-dir}'[directory to search for documentation]:ri doc directory:_files -/' \
-  '(-f --format)'{-f,--format}'[format to use when displaying output]:output format:(ansi bs html plain simple)' \
-  '(-l --list-names)'{-l,--list-names}'[list all the names known to RDoc]' \
+  '*'{-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 ri_names expl
+  local -a ri_dirs ri_names ri_wants ri_names
+  local class_dir esc_name dir curtag tag descr expl
 
-    ri_names=( ${(f)"$( _call_program ri-names "$words[1]" ${(v)opt_args[(I)(-d|--doc-dir)]:+-d "${(v)opt_args[(I)(-d|--doc-dir)]}"} -l -T )"} )
-    _wanted ri-names expl "ri name" compadd -a ri_names && ret=0
+  ret=1
+
+  if "ruby${words[1]#ri}" -rrdoc/ri/ri_options.rb -e 1 >/dev/null 2>&1; then
+    # Old-style Ruby 1.8.x RI
+    ri_dirs=( ${(f)"$(_call_program ri-names "ruby${words[1]#ri}" -rrdoc/ri/ri_options -e '"o = RI::Options.instance; o.parse(ARGV); o.path.each { |p| puts p }"' -- ${(kv)opt_args[(I)-d|--doc-dir|--(system|site|gems|home)]})"} )
+  else
+    # New-style Ruby 1.9+ RI
+    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)"} )
+  fi
+
+  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
+return ret
-- 
1.6.5.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Rewrite of RI (Ruby documentation browser) completion
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey I. Froloff @ 2009-11-11 14:27 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

On Sun, Nov 08, 2009 at 06:08:33PM +0300, Alexey I. Froloff wrote:
> Since Ruby 1.9 RI is no longer have option to dump all known classes
> and methods.  Instead, we try to look into documentation search paths
> to offer available classes and class and instance methods.
ping?

-- 
Regards,
Sir Raorn.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Rewrite of RI (Ruby documentation browser) completion
  2009-11-11 14:27     ` Alexey I. Froloff
@ 2009-11-11 16:21       ` Bart Schaefer
  2009-11-11 21:24         ` Alexey I. Froloff
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2009-11-11 16:21 UTC (permalink / raw)
  To: Alexey I. Froloff, zsh-workers

Looking at zsh-workers/27367 in the archive ...

What's up with the following hunk -- why was "cur" dropped?  Localizing
curcontext is boilerplate completion code.

-local curcontext="$curcontext" state line ret=1
+local context="$curcontext" state line ret=1


The rest looks OK, so I'll commit without that one change, but someone
else should test.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Rewrite of RI (Ruby documentation browser) completion
  2009-11-11 16:21       ` Bart Schaefer
@ 2009-11-11 21:24         ` Alexey I. Froloff
  0 siblings, 0 replies; 8+ messages in thread
From: Alexey I. Froloff @ 2009-11-11 21:24 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 546 bytes --]

On Wed, Nov 11, 2009 at 08:21:40AM -0800, Bart Schaefer wrote:
> What's up with the following hunk -- why was "cur" dropped?  Localizing
> curcontext is boilerplate completion code.
> -local curcontext="$curcontext" state line ret=1
> +local context="$curcontext" state line ret=1
I'm not sure why I did this.  I'm not even sure that I did this
consciously.  All this context stuff is like Magic for me.

> The rest looks OK, so I'll commit without that one change, but someone
> else should test.
Thanks.

-- 
Regards,
Sir Raorn.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-11-11 21:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-01 23:24 Completion for ri (Ruby API reference frontend) Alexey I. Froloff
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

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).