zsh-users
 help / color / mirror / code / Atom feed
* Few newbie questions..
@ 2001-08-17 10:55 Jukka Lehti
  2001-08-17 15:22 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Jukka Lehti @ 2001-08-17 10:55 UTC (permalink / raw)
  To: zsh-users

MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

Hi, and excuse me if these are already answered but
a quick look at TFM didn't help. Anyway,

How I can make zsh3 add slash when doing:
cd ..[TAB]? bash does this automatically and IMHO
it's really useful.

Is there a way to use own function in ~/.zshrc for man
completion instead of zsh4 builtin? Setting fpath=~/
or ~/.zshrc doesn't help.

Thanks in advance!

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/


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

* Re: Few newbie questions..
  2001-08-17 10:55 Few newbie questions Jukka Lehti
@ 2001-08-17 15:22 ` Bart Schaefer
  2001-08-17 17:39   ` Jukka Lehti
  2001-08-20 11:59   ` Jukka Lehti
  0 siblings, 2 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-17 15:22 UTC (permalink / raw)
  To: Jukka Lehti, zsh-users

On Aug 17,  3:55am, Jukka Lehti wrote:
}
} How I can make zsh3 add slash when doing:
} cd ..[TAB]? bash does this automatically and IMHO
} it's really useful.

Completion is supposed to save you keystrokes.  (Funny, it seems to be
causing me a whole lot of extra keystrokes right now.)  Tab and slash
are each one keystroke.  Hence not really useful.

However:

	compctl -g '*(/)' + -x 'S[..]' -k '(..)' -qS/ -- cd
 
} Is there a way to use own function in ~/.zshrc for man
} completion instead of zsh4 builtin? Setting fpath=~/
} or ~/.zshrc doesn't help.

I should think not.  ~/.zshrc isn't a directory or a zcompiled file, so
putting it in fpath is meaningless.  Also, fpath is an array, so setting
it with fpath=~/ is wrong; you probably mean fpath=(~ $fpath) [you don't
need the slash after the tilde].  And you only need to change fpath if
the definition of your function is in its own file and is autoloaded
(that is, you've got a command like `autoload nameofyourfunction' in your
init files somewhere).  If the function is defined in .zshrc, an fpath
search is not needed to find it.

You also haven't said whether you're using "new" completion (`compinit'
in your .zshrc somewhere), or 3.0-style compctl.  The two do mix, but
new completion will always be tried first if it is enabled.  Or you might
want to define a "completion widget," which is another thing entirely.
So it'd be better if you told us what you want zsh to do when you type
a tab after the man command, and let us tell you how to get there; or at
least give us a few more details of what you're trying to do.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: Few newbie questions..
  2001-08-17 15:22 ` Bart Schaefer
@ 2001-08-17 17:39   ` Jukka Lehti
  2001-08-18  3:25     ` Bart Schaefer
  2001-08-20 11:59   ` Jukka Lehti
  1 sibling, 1 reply; 11+ messages in thread
From: Jukka Lehti @ 2001-08-17 17:39 UTC (permalink / raw)
  To: Bart Schaefer, zsh-users

Bart Schaefer <schaefer@brasslantern.com> wrote:

Bart, hi, and thanks for quick reply.

> On Aug 17,  3:55am, Jukka Lehti wrote:
> }
> } How I can make zsh3 add slash when doing:
> } cd ..[TAB]? bash does this automatically and IMHO
> } it's really useful.
>
> Tab and slash are each one keystroke.  Hence not
> really useful.

With a Finnish keyboard you have to use Shift+7
to get /, so that's the reason for my question.

> compctl -g '*(/)' + -x 'S[..]' -k '(..)' -qS/ -- cd

Yes, this does just what I was thinking about!

> You also haven't said whether you're using "new"
> completion (`compinit'
> in your .zshrc somewhere), or 3.0-style compctl. 
> The two do mix, but
> new completion will always be tried first if it is
> enabled.  Or you might
> want to define a "completion widget," which is
> another thing entirely.
> So it'd be better if you told us what you want zsh
> to do when you type
> a tab after the man command, and let us tell you how
> to get there; or at
> least give us a few more details of what you're
> trying to do.

Ok, sorry for inadequate information. So, I have in my
~/.zshrc: [hopefully you can see this..]

# man page completion
man_glob () {
	local a
	read -cA a
	if [[ $a[2] = -s ]]	# Or [[ $a[2] = [0-9]* ]] for BSD
	then
		reply=( ${^$(man -w | sed 's/:/
/g')}/man$a[3]/$1*$2(N:t:r) )
	else
		reply=( ${^$(man -w | sed 's/:/
/g')}/man*/$1*$2(N:t:r) )
	fi
}
compctl -K man_glob -f -x 'C[-1,-P]' -m - \
	'R[-*l*,;]' -g '*.(man|[0-9nlpo](|[a-z]))' + -g
'*(-/)' -- man

When I type for example 'man local' and hit tab
I can choose from:

locale.1 locale.3 locale.7

I prefer the man completion to show me the section
numbers (although I have remove the number before
pressing enter since man can't find e.g. locale.1).
With zsh4 'man local[TAB]' doesn't list the
alternatives, so that's why I don't like.

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/


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

* Re: Few newbie questions..
  2001-08-17 17:39   ` Jukka Lehti
@ 2001-08-18  3:25     ` Bart Schaefer
  2001-08-18  8:04       ` Jukka Lehti
  2001-08-20 22:34       ` Vincent Lefevre
  0 siblings, 2 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-18  3:25 UTC (permalink / raw)
  To: Jukka Lehti, zsh-users

On Aug 17, 10:39am, Jukka Lehti wrote:
}
} When I type for example 'man local' and hit tab
} I can choose from:
} 
} locale.1 locale.3 locale.7
} 
} I prefer the man completion to show me the section
} numbers (although I have remove the number before
} pressing enter since man can't find e.g. locale.1).

Aha.

Before I go any further, I'll mention that with `compinit' zsh 4 is able
to complete only those pages that are available in a particular section,
so you can do e.g.

    zsh% man 7 lo<TAB>

and see only the pages that are in section 7.  I realize this is sort of
the inverse of what you were asking, but maybe it's of interest.

OK, moving on.  You must be using `compinit' or the compctl that you
described would still be working.  So you need to change the way that
the existing completion function adds matches.  Assuming that you have
4.0.2 (it changed since 4.0.1) the following should fix you up.

First, make a copy of the _man function definition:

    mkdir ~/zshfuncs
    cp $^fpath/_man(|)(N) ~/zshfuncs

The (|)(N) silliness is just to ignore the directories in $fpath where
there is no _man file.  Look up "glob qualifiers" in the manual.

Edit ~/zshfuncs/_man to change the _man_pages helper function (which is
also defined in the _man file) as shown below:

    _man_pages() {
	local matcher pages dummy
	zparseopts -E M+:=matcher
	if (( $#matcher ))
	then
	    matcher=(${matcher:#-M}) 
	    matcher="$matcher" 
	else
	    matcher= 
	fi
	pages=($dirs) 
	compfiles -p pages '' '' "$matcher" '' dummy '*'
	pages=($~pages(:t)) 				# CHANGED
	(($#mrd)) && pages[$#pages+1]=($(awk $awk $mrd)) 
	compadd "$@" -a pages				# CHANGED
    }

That fixes _man_pages so as to keep the file suffixes when adding the
completions.  It'll have to be updated if _man changes again in another
zsh release, but it's the best that can be done in the circumstances.

Then, in your .zshrc somewhere -after- you call `compinit', add:

    fpath=(~/zshfuncs $fpath)

Thus your _man file will be found before the installed one, and you'll
see the file suffixes.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: Few newbie questions..
  2001-08-18  3:25     ` Bart Schaefer
@ 2001-08-18  8:04       ` Jukka Lehti
  2001-08-20 22:34       ` Vincent Lefevre
  1 sibling, 0 replies; 11+ messages in thread
From: Jukka Lehti @ 2001-08-18  8:04 UTC (permalink / raw)
  To: Bart Schaefer, zsh-users

Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Thus your _man file will be found before the
> installed one, and you'll
> see the file suffixes.

It worked! Thanks for your interest!


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/


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

* Re: Few newbie questions..
  2001-08-17 15:22 ` Bart Schaefer
  2001-08-17 17:39   ` Jukka Lehti
@ 2001-08-20 11:59   ` Jukka Lehti
  2001-08-20 12:19     ` Sven Wischnowsky
  1 sibling, 1 reply; 11+ messages in thread
From: Jukka Lehti @ 2001-08-20 11:59 UTC (permalink / raw)
  To: Bart Schaefer, zsh-users

Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Aug 17,  3:55am, Jukka Lehti wrote:
> }
> } How I can make zsh3 add slash when doing:
> } cd ..[TAB]? bash does this automatically and IMHO
> } it's really useful.
> compctl -g '*(/)' + -x 'S[..]' -k '(..)' -qS/ -- cd

Hmm, it seems that cd ../..<TAB> doesn't work. I can't
figure out why?

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/


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

* Re: Few newbie questions..
  2001-08-20 11:59   ` Jukka Lehti
@ 2001-08-20 12:19     ` Sven Wischnowsky
  0 siblings, 0 replies; 11+ messages in thread
From: Sven Wischnowsky @ 2001-08-20 12:19 UTC (permalink / raw)
  To: zsh-users


Jukka Lehti wrote:

> Bart Schaefer <schaefer@brasslantern.com> wrote:
> > On Aug 17,  3:55am, Jukka Lehti wrote:
> > }
> > } How I can make zsh3 add slash when doing:
> > } cd ..[TAB]? bash does this automatically and IMHO
> > } it's really useful.
> > compctl -g '*(/)' + -x 'S[..]' -k '(..)' -qS/ -- cd
> 
> Hmm, it seems that cd ../..<TAB> doesn't work. I can't
> figure out why?

Replace the above with:

  compctl -g "*(-/) .." cd

or start using the new completion system and look at the
`special-dirs' style.


Bye
  Sven

-- 
Sven Wischnowsky                    wischnow@informatik.hu-berlin.de


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

* Re: Few newbie questions..
  2001-08-18  3:25     ` Bart Schaefer
  2001-08-18  8:04       ` Jukka Lehti
@ 2001-08-20 22:34       ` Vincent Lefevre
  2001-08-21  2:55         ` Bart Schaefer
  1 sibling, 1 reply; 11+ messages in thread
From: Vincent Lefevre @ 2001-08-20 22:34 UTC (permalink / raw)
  To: zsh-users

On Sat, Aug 18, 2001 at 03:25:13 +0000, Bart Schaefer wrote:
> Before I go any further, I'll mention that with `compinit' zsh 4 is able
> to complete only those pages that are available in a particular section,
> so you can do e.g.
> 
>     zsh% man 7 lo<TAB>

But this doesn't work under Solaris, where you need the -s option.

  man 5 lo<TAB>

gives

  man 5 locale

but I get the error: No manual entry for 5.

  man -s 5 lo<TAB>

gives many possibilities, but many of them aren't in Section 5.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100%
validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des
Jeux Mathématiques et Logiques, TETRHEX, etc.
Work: CR INRIA - computer arithmetic / SPACES project at LORIA


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

* Re: Few newbie questions..
  2001-08-20 22:34       ` Vincent Lefevre
@ 2001-08-21  2:55         ` Bart Schaefer
  2001-08-21  6:27           ` Borsenkow Andrej
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2001-08-21  2:55 UTC (permalink / raw)
  To: Vincent Lefevre, zsh-users

On Aug 21, 12:34am, Vincent Lefevre wrote:
} Subject: Re: Few newbie questions..
}
} On Sat, Aug 18, 2001 at 03:25:13 +0000, Bart Schaefer wrote:
} > 
} >     zsh% man 7 lo<TAB>
} 
} But this doesn't work under Solaris, where you need the -s option.

Try this patch.  It handles -s, -S, and $MANSECT.  However, I don't
know what it does with the awk stuff in _man_pages -- it's possible
that the assignment to $awk needs to be adjusted as well.


Index: Completion/Unix/Command/_man
===================================================================
--- Completion/Unix/Command/_man	2001/07/10 09:05:14	1.3
+++ Completion/Unix/Command/_man	2001/08/21 02:48:25
@@ -22,9 +22,18 @@
 
   mrd=(${^manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N))
 
-  if [[ $words[2] = (<->*|1M|l|n) ]]; then
-    dirs=( $^manpath/(sman|man|cat)${words[2]}/ )
-    awk="\$2 == \"$words[2]\" {print \$1}"
+  local sect
+  if [[ $OSTYPE = solaris* ]]; then
+    sect=$words[$words[(i)-s]+1]
+  elif [[ -n ${sect:=$words[$words[(i)-S]+1]} || -n ${sect:=$MANSECT} ]]; then
+    if [[ $sect != ${sect::="${sect//:/|}"} ]]; then
+      sect="($sect)"
+    fi
+  fi
+
+  if [[ $sect = (<->*|1M|l|n) || $sect = \((*\|*)\) ]]; then
+    dirs=( $^manpath/(sman|man|cat)${~sect}/ )
+    awk="\$2 == \"$sect\" {print \$1}"
   else
     dirs=( $^manpath/(sman|man|cat)*/ )
     awk='{print $1}'


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* RE: Few newbie questions..
  2001-08-21  2:55         ` Bart Schaefer
@ 2001-08-21  6:27           ` Borsenkow Andrej
  2001-08-21  6:38             ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Borsenkow Andrej @ 2001-08-21  6:27 UTC (permalink / raw)
  To: 'Bart Schaefer', 'Vincent Lefevre', zsh-users

> 
> Try this patch.  It handles -s, -S, and $MANSECT.  However, I don't
> know what it does with the awk stuff in _man_pages -- it's possible
> that the assignment to $awk needs to be adjusted as well.
> 

No, it should be O.K. I wonder, if there any way to avoid reading in
full list of manual pages every time.  OTOH we build full listing for
traditional man dirs every time as well.

-andrej


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

* Re: Few newbie questions..
  2001-08-21  6:27           ` Borsenkow Andrej
@ 2001-08-21  6:38             ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-21  6:38 UTC (permalink / raw)
  To: zsh-users

On Aug 21, 10:27am, Borsenkow Andrej wrote:
}
} > Try this patch.  It handles -s, -S, and $MANSECT.  However, I don't
} > know what it does with the awk stuff in _man_pages -- it's possible
} > that the assignment to $awk needs to be adjusted as well.
} 
} No, it should be O.K.

Except, of course, that I forgot the fallback condition.  Here's the
more correct patch (the missing bit was

+  else
+    sect=$words[2]

).

Index: Completion/Unix/Command/_man
===================================================================
--- Completion/Unix/Command/_man	2001/07/10 09:05:14	1.3
+++ Completion/Unix/Command/_man	2001/08/21 06:35:55
@@ -22,9 +22,20 @@
 
   mrd=(${^manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N))
 
-  if [[ $words[2] = (<->*|1M|l|n) ]]; then
-    dirs=( $^manpath/(sman|man|cat)${words[2]}/ )
-    awk="\$2 == \"$words[2]\" {print \$1}"
+  local sect
+  if [[ $OSTYPE = solaris* ]]; then
+    sect=$words[$words[(i)-s]+1]
+  elif [[ -n ${sect:=$words[$words[(i)-S]+1]} || -n ${sect:=$MANSECT} ]]; then
+    if [[ $sect != ${sect::="${sect//:/|}"} ]]; then
+      sect="($sect)"
+    fi
+  else
+    sect=$words[2]
+  fi
+
+  if [[ $sect = (<->*|1M|l|n) || $sect = \((*\|*)\) ]]; then
+    dirs=( $^manpath/(sman|man|cat)${~sect}/ )
+    awk="\$2 == \"$sect\" {print \$1}"
   else
     dirs=( $^manpath/(sman|man|cat)*/ )
     awk='{print $1}'


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-08-21  6:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-17 10:55 Few newbie questions Jukka Lehti
2001-08-17 15:22 ` Bart Schaefer
2001-08-17 17:39   ` Jukka Lehti
2001-08-18  3:25     ` Bart Schaefer
2001-08-18  8:04       ` Jukka Lehti
2001-08-20 22:34       ` Vincent Lefevre
2001-08-21  2:55         ` Bart Schaefer
2001-08-21  6:27           ` Borsenkow Andrej
2001-08-21  6:38             ` Bart Schaefer
2001-08-20 11:59   ` Jukka Lehti
2001-08-20 12:19     ` Sven Wischnowsky

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