zsh-users
 help / color / mirror / code / Atom feed
* Problem writing ri completion function
@ 2005-10-06 16:41 Tobias Gruetzmacher
  2005-10-07  9:08 ` Alexey Tourbin
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Gruetzmacher @ 2005-10-06 16:41 UTC (permalink / raw)
  To: zsh-users


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

Hi,

I was writing a new completion for ri, the ruby documentation viewing
tool, when I came upon a small problem: ri takes as argument the full
name of a class, module or method.

It can generate a list of all documented functions, which I use to fill
the completion list. This list is very long, so I tried to use
_multi_parts to get a better overview. The problem is: ri uses
different separators to differentiate between class method and instance
methods. For example I have these alternatives:

File (class or module)
File::basename (class method)
File.path (instance method)
File::Stat (another class)
File::Stat::new (another class method)

I currently only use _multi_parts with "." as separator - I don't know
enough zsh scripting to build something to use multiple separators. Any
ideas?

Greetings Tobi

-- 
GPG-Key 0xE2BEA341 - signed/encrypted mail preferred
My, oh so small, homepage: http://portfolio16.de/
http://www.fli4l.de/ - ISDN- & DSL-Router on one disk!
Registered FLI4L-User #00000003

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

#compdef ri
#
# zsh completion for the ri ruby documentation tool
# from http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/128677
# + some changes

_ri () {
  _arguments -C -s \
    '(-h --help)'{-h,--help}'[print help message]' \
    '(-c --classes)'{-c,--classes}'[Display the names of classes and modules we know about]' \
    '(-d --doc-dir)'{-d+,--doc-dir+}'[A directory to search for documentation]:directory:_files -/' \
    '(-f --format)'{-f,--format}'[Format to use when displaying output]:format:(ansi bs html plain simple)' \
    '(-l --list-names)'{-l,--list-names}'[List all the names known to RDoc, one per line]' \
    '(-T --no-pager)'{-T,--no-pager}'[Send output directly to stdout]' \
    '(-w --width)'{-w+,--width+}'[output width]:width: ' \
    '(-v --version)'{-v,--version}'[Display the version of ri]' \
    "*:help topics:_ri_names"
}

_ri_names () {
  if ( [[ ${+_ri_list_names} -eq 0 ]] || _cache_invalid ri_names ) &&
    ! _retrieve_cache ri_names; then
    _ri_list_names=( ${$(_call_program ri--list-names RI= ri -l -T 2>/dev/null)//\#/.} )
    _store_cache ri_names _ri_list_names
  fi
  _multi_parts -i "." _ri_list_names
}

_ri "$@"

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

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

* Re: Problem writing ri completion function
  2005-10-06 16:41 Problem writing ri completion function Tobias Gruetzmacher
@ 2005-10-07  9:08 ` Alexey Tourbin
  0 siblings, 0 replies; 2+ messages in thread
From: Alexey Tourbin @ 2005-10-07  9:08 UTC (permalink / raw)
  To: zsh-users


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

On Thu, Oct 06, 2005 at 06:41:12PM +0200, Tobias Gruetzmacher wrote:
> Hi,

Hello,

> I was writing a new completion for ri, the ruby documentation viewing

BTW, I've got another _ri completion that was recently written by Sir Raorn.
https://bugzilla.altlinux.org/show_bug.cgi?id=7593

Please take a look (I believe it is available under the same terms as zsh).

[-- Attachment #1.2: zsh-4.3.0-alt-comp-ri.patch --]
[-- Type: text/plain, Size: 1258 bytes --]

--- zsh-4.3.0-20050926/Completion/Unix/Command/_ri-	2005-09-25 22:18:51 +0000
+++ zsh-4.3.0-20050926/Completion/Unix/Command/_ri	2005-09-25 22:22:25 +0000
@@ -0,0 +1,24 @@
+#compdef ri
+
+local curcontext="$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]' \
+  '(-T --no-pager)'{-T,--no-pager}'[send output directly to stdout]' \
+  '(-w --width)'{-w,--width}'[set the width of the output]:output width:' \
+  '*:ri name:->ri-name' && ret=0
+
+if [[ "$state" = ri-name ]]; then
+    local ri_names 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
+fi
+
+return $ret

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

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

end of thread, other threads:[~2005-10-07  9:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-06 16:41 Problem writing ri completion function Tobias Gruetzmacher
2005-10-07  9:08 ` Alexey Tourbin

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