zsh-users
 help / color / mirror / code / Atom feed
* Equivalent of Vim's has("feature")?
@ 2010-11-22 17:12 Benjamin R. Haskell
  2010-11-22 17:32 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin R. Haskell @ 2010-11-22 17:12 UTC (permalink / raw)
  To: Zsh Users

Vim has a function 'has()' that lets you test for features compiled in 
to the running version of Vim.  So, e.g.:

if has('perl')
 	" do something using the Perl interface for Vim
endif

I suspect there is similar functionality for Zsh, but I'm not quite sure 
where to look.  I'd rather use something like 'has()' than something 
involving ZSH_VERSION or similar.

For commands and widgets I've found the following to work well:

(( $+commands[screen] )) && # do something with screen

(( $+widgets[history-incremental-pattern-search-backward] )) \
&& bindkey "^R" history-incremental-pattern-search-backward

But, 1) I can't seem to rediscover the documentation for those arrays, 
and 2) Is there such an array for things that are more inbuilt?  In 
particular, I'm looking for a test that the ':A' history modifier 
exists.

-- 
Best,
Ben


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

* Re: Equivalent of Vim's has("feature")?
  2010-11-22 17:12 Equivalent of Vim's has("feature")? Benjamin R. Haskell
@ 2010-11-22 17:32 ` Peter Stephenson
  2010-11-22 19:02   ` Benjamin R. Haskell
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2010-11-22 17:32 UTC (permalink / raw)
  To: Zsh Users

On Mon, 22 Nov 2010 12:12:51 -0500 (EST)
"Benjamin R. Haskell" <zsh@benizi.com> wrote:
> For commands and widgets I've found the following to work well:
> 
> (( $+commands[screen] )) && # do something with screen
> 
> (( $+widgets[history-incremental-pattern-search-backward] )) \
> && bindkey "^R" history-incremental-pattern-search-backward
> 
> But, 1) I can't seem to rediscover the documentation for those
> arrays, 

Look at the documentation for the zsh/parameter module in zshmodules.

> and 2) Is there such an array for things that are more
> inbuilt?  In particular, I'm looking for a test that the ':A' history
> modifier exists.

If you haven't recorded the version when it first appeared so you can
use the is-at-least function, which is the usual way (as long as you do
it as soon as the feature appears it's painless), you have to attempt to
make use of the feature and record the result.

integer history_A
( : ${PATH:A} ) 2>/dev/null  &&  history_A=1

-- 
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] 4+ messages in thread

* Re: Equivalent of Vim's has("feature")?
  2010-11-22 17:32 ` Peter Stephenson
@ 2010-11-22 19:02   ` Benjamin R. Haskell
  2010-11-23  7:17     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin R. Haskell @ 2010-11-22 19:02 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users

On Mon, 22 Nov 2010, Peter Stephenson wrote:

> On Mon, 22 Nov 2010 12:12:51 -0500 (EST) "Benjamin R. Haskell" wrote:
>> For commands and widgets I've found the following to work well:
>>
>> (( $+commands[screen] )) && # do something with screen
>>
>> (( $+widgets[history-incremental-pattern-search-backward] )) \
>> && bindkey "^R" history-incremental-pattern-search-backward
>>
>> But, 1) I can't seem to rediscover the documentation for those 
>> arrays,
>
> Look at the documentation for the zsh/parameter module in zshmodules.

Thanks.  Didn't realize these weren't standard (for some value of 
"standard").


>> and 2) Is there such an array for things that are more inbuilt?  In 
>> particular, I'm looking for a test that the ':A' history modifier 
>> exists.
>
> If you haven't recorded the version when it first appeared so you can 
> use the is-at-least function, which is the usual way (as long as you 
> do it as soon as the feature appears it's painless),

Is there any support for ZSH_PATCHLEVEL in is-at-least?  :a and :A were 
added in ZSH_VERSION=4.3.10(-dev-1?) ZSH_PATCHLEVEL=1.4618.


> you have to attempt to make use of the feature and record the result.
>
> integer history_A
> ( : ${PATH:A} ) 2>/dev/null  &&  history_A=1

Both of these seem slippery-slopy.  (Easy for one feature, but 
increasingly annoying as more tests are needed.  Also, if a given 
feature takes non-trivial time to test.).  Nonetheless, I guess I don't 
have some easy-peasy way to add the feature detection to the case 
statement in Src/hist.c and a new parameter in Src/Modules/parameter.c 
(<-- note to self in the unlikely even I get back to this), so I'll 
retreat with:

( : ${${:-/}:A} ) 2>/dev/null && has_A=true
...
(( $+has_A )) && # use it

which works fine for this case.

-- 
Thanks,
Ben


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

* Re: Equivalent of Vim's has("feature")?
  2010-11-22 19:02   ` Benjamin R. Haskell
@ 2010-11-23  7:17     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2010-11-23  7:17 UTC (permalink / raw)
  To: Zsh Users

On Nov 22,  2:02pm, Benjamin R. Haskell wrote:
}
} Is there any support for ZSH_PATCHLEVEL in is-at-least?  :a and :A were 
} added in ZSH_VERSION=4.3.10(-dev-1?) ZSH_PATCHLEVEL=1.4618.

is-at-least 1.4618 $ZSH_PATCHLEVEL

However, that fails on versions of zsh where ZSH_PATCHLEVEL itself is
not yet defined.

} > you have to attempt to make use of the feature and record the result.
} 
} Both of these seem slippery-slopy.  (Easy for one feature, but 
} increasingly annoying as more tests are needed.

I don't see any way to avoid "more tests" as features are added, no
matter what form the tests take.

Furthermore, there's a chicken-and-egg problem -- how do you test for
the feature that provides the test for other features?

For example, PWS didn't mention that features derived from modules
(such as the existence of the "widgets" parameter itself) can be
checked by running "zmodload -lF modulename featurespec" as in

    zmodload -lF zsh/zleparameter p:widgets

However, this is the egg of the zmodload chicken, because the feature
of modules providing named lists of their features is also relatively
recent.

} Also, if a given feature takes non-trivial time to test.)

At some point one has to recognize that it's not practical (nor in
actual practice necessary) to test for the existence of every possible
feature every time the shell starts up.  Run "make check" in the zsh
build tree for an idea of how long it takes to test a large number of
features even when each of them takes trivial time to test.

} Nonetheless, I guess I don't have some easy-peasy way to add the      
} feature detection to the case statement in Src/hist.c and a new       
} parameter in Src/Modules/parameter.c                                  

I think you're holding zsh to a rather more detailed standard than
vim if you think zsh ought to provide a compiled-in self-test for
every syntactic nit. :-)  However, no-prize to you if you can even
come up with a naming convention that would cover everything that
might need to be tested.

-- 


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

end of thread, other threads:[~2010-11-23  7:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-22 17:12 Equivalent of Vim's has("feature")? Benjamin R. Haskell
2010-11-22 17:32 ` Peter Stephenson
2010-11-22 19:02   ` Benjamin R. Haskell
2010-11-23  7:17     ` Bart Schaefer

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