zsh-workers
 help / color / mirror / code / Atom feed
* Updated _acroread completer
@ 2005-04-14 13:47 Haakon Riiser
  2005-04-15 11:11 ` Haakon Riiser
  0 siblings, 1 reply; 9+ messages in thread
From: Haakon Riiser @ 2005-04-14 13:47 UTC (permalink / raw)
  To: zsh-workers

I just wrote an updated version of _acroread that works for both
acroread 5 and 7.  Unfortunately, determining the version number
involves running acroread -help, which is a bit slow.  I was
thinking about caching the version number, but I'm not sure what's
the recommended way of doing that.  Is it OK if I just set a non-
local variable _acroread_version?

Anyway, here's what I got so far:

#------------------------------------------------------------------------------#
#compdef acroread

local curcontext="$curcontext" state line

# The output of acroread -version cannot be piped to stdout for some reason, so
# the version number must be read from ACROREAD-PREFIX/Reader/AcroVersion.
# Since acroread might have been started via a wrapper script, the only
# failsafe way of determining ACROREAD-PREFIX is to look at the output of
# acroread -help.  TODO: running acroread -help is slow - can version be cached
# for a single shell session?
local acropath=${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}
local version=$(< ${acropath%/*}/../Reader/AcroVersion)

if [[ $version == 7.* ]]; then
    _arguments -C \
      '--display=:X display:_x_display' \
      '--screen=:X screen (overrides the screen part of DISPLAY)' \
      --sync \
      '-geometry:[<width>x<height>][{+|-}<x offset>{+|-}<y offset>]' \
      -help \
      -iconic \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      -openInNewWindow \
      -version \
      '-visual:X visual:_x_visual' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      -annotsOff \
      '(-level3)-level2' \
      '(-level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      -expand \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
else
    _x_arguments -C \
      -help \
      -helpall \
      \*-iconic \
      \*+iconic \
      '-name:application name:_x_name' \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      '(+useFrontEndProgram)-useFrontEndProgram' \
      '(-useFrontEndProgram)+useFrontEndProgram' \
      '-visual:X visual:_x_visual' \
      '-xrm:X resource specification:_x_resource' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      '(-level2 -level3)-level1' \
      '(-level1 -level3)-level2' \
      '(-level1 -level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
fi

return 1
#------------------------------------------------------------------------------#

-- 
 Haakon


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

* Re: Updated _acroread completer
  2005-04-14 13:47 Updated _acroread completer Haakon Riiser
@ 2005-04-15 11:11 ` Haakon Riiser
  2005-04-25  7:43   ` Oliver Kiddle
  0 siblings, 1 reply; 9+ messages in thread
From: Haakon Riiser @ 2005-04-15 11:11 UTC (permalink / raw)
  To: zsh-workers

> Unfortunately, determining the version number involves
> running acroread -help, which is a bit slow.  I was thinking
> about caching the version number, but I'm not sure what's the
> recommended way of doing that.  Is it OK if I just set a non-
> local variable _acroread_version?

I have now tried the non-local variable trick, and it works just
like I expected.  I also noticed that the zsh completion system
has a set of caching functions (_store_cache, _retrieve_cache and
_cache_invalid).  These functions apparently store data on disk,
so that the cache will outlive the zsh session.  In my case,
that's problably not good, since running the expensive acroread
-help command is the only way to determine if the cache is invalid,
and thus I will save nothing when using these cache functions.

The version of _acroread that uses a non-local variable is included
below.  I would appreciate it someone could tell me who I should
sent it to so that it can be included with the next version of zsh.
(Or better, if that person reads this message, and tells me that
the updated _acroread is now included. :-)


#------------------------------------------------------------------------------#
#compdef acroread

local curcontext="$curcontext" state line

# The output of acroread -version cannot be piped to stdout for some reason, so
# the version number must be read from ACROREAD-PREFIX/Reader/AcroVersion.
# Since acroread might have been started via a wrapper script, the only
# failsafe way of determining ACROREAD-PREFIX is to look at the output of
# acroread -help.
if [[ -z $_acroread_version ]]; then
    local acropath=${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}
    local version_file=${acropath%/*}/../Reader/AcroVersion
    [[ -r $version_file ]] && _acroread_version=$(< $version_file)
fi

if [[ $_acroread_version == 7.* ]]; then
    _arguments -C \
      '--display=:X display:_x_display' \
      '--screen=:X screen (overrides the screen part of DISPLAY)' \
      --sync \
      '-geometry:[<width>x<height>][{+|-}<x offset>{+|-}<y offset>]' \
      -help \
      -iconic \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      -openInNewWindow \
      -version \
      '-visual:X visual:_x_visual' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      -annotsOff \
      '(-level3)-level2' \
      '(-level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      -expand \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
else
    _x_arguments -C \
      -help \
      -helpall \
      \*-iconic \
      \*+iconic \
      '-name:application name:_x_name' \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      '(+useFrontEndProgram)-useFrontEndProgram' \
      '(-useFrontEndProgram)+useFrontEndProgram' \
      '-visual:X visual:_x_visual' \
      '-xrm:X resource specification:_x_resource' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      '(-level2 -level3)-level1' \
      '(-level1 -level3)-level2' \
      '(-level1 -level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
fi

return 1
#------------------------------------------------------------------------------#

-- 
 Haakon


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

* Re: Updated _acroread completer
  2005-04-15 11:11 ` Haakon Riiser
@ 2005-04-25  7:43   ` Oliver Kiddle
  2005-04-25  8:41     ` Haakon Riiser
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Kiddle @ 2005-04-25  7:43 UTC (permalink / raw)
  To: zsh-workers; +Cc: Haakon Riiser

On 15 Apr, Haakon Riiser wrote:
> I have now tried the non-local variable trick, and it works just
> like I expected.  I also noticed that the zsh completion system
> has a set of caching functions (_store_cache, _retrieve_cache and
> _cache_invalid).  These functions apparently store data on disk,

I never use those and don't really like them. I prefer completion to be
slow the first time I complete something than for it to be out-of-date.

> # The output of acroread -version cannot be piped to stdout for some reason, so
> # the version number must be read from ACROREAD-PREFIX/Reader/AcroVersion.
> # Since acroread might have been started via a wrapper script, the only
> # failsafe way of determining ACROREAD-PREFIX is to look at the output of
> # acroread -help.

Unfortunately, this doesn't work on the system I tried it on, using
Adobe's rpm. /usr/bin/acroread is a symbolic like to
/usr/local/Adobe/Acrobat7.0/bin/acroread. Handling that involves using ls
to get the symlink destination.

Is acroread always a script? The following works well (and very quickly)
on any system I have access to:
  grep '^ver=' =acroread

>From a completion function, we can use $commands[$words[1]] instead
of =acroread.

Oliver


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

* Re: Updated _acroread completer
  2005-04-25  7:43   ` Oliver Kiddle
@ 2005-04-25  8:41     ` Haakon Riiser
  2005-04-25  8:54       ` Oliver Kiddle
  2005-04-25  9:39       ` Peter Stephenson
  0 siblings, 2 replies; 9+ messages in thread
From: Haakon Riiser @ 2005-04-25  8:41 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

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

[Oliver Kiddle]

>> The output of acroread -version cannot be piped to stdout for
>> some reason, so the version number must be read from
>> ACROREAD-PREFIX/Reader/AcroVersion.  Since acroread might have
>> been started via a wrapper script, the only failsafe way of
>> determining ACROREAD-PREFIX is to look at the output of acroread
>> -help.
> 
> Unfortunately, this doesn't work on the system I tried it on, using
> Adobe's rpm. /usr/bin/acroread is a symbolic like to
> /usr/local/Adobe/Acrobat7.0/bin/acroread. Handling that involves using ls
> to get the symlink destination.
> 
> Is acroread always a script? The following works well (and very quickly)
> on any system I have access to:
>   grep '^ver=' =acroread
> 
> From a completion function, we can use $commands[$words[1]] instead
> of =acroread.

It doesn't work when acroread is a wrapper script, which it is
in my case.  (I used a wrapper instead of a symlink, because the
script needs to do some things before it starts acroread, such
as turning off core dumps (some versions of acroread 5.x used to
crash a _lot_).)  Even if I rename the script to something other
than 'acroread', I still couldn't use =acroread since the real
acroread executable isn't in my PATH. :-/

So I'll just have to resolve the symlink using readlink.  I assume
the most portable way to do this is perl, unless there is a way
to make zsh expand the link itself.  I have attached a version that
does this.  Should handle any level of symbolic links that point to
new symbolic links.

-- 
 Haakon

[-- Attachment #2: _acroread --]
[-- Type: text/plain, Size: 3275 bytes --]

#compdef acroread

local curcontext="$curcontext" state line

# The output of acroread -version cannot be piped to stdout for some reason, so
# the version number must be read from ACROREAD-PREFIX/Reader/AcroVersion.
# Since acroread might have been started via a wrapper script, the only
# failsafe way of determining ACROREAD-PREFIX is to look at the output of
# acroread -help.
if [[ -z $_acroread_version ]]; then
    local acropath=${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}
    while [[ -L $acropath ]]; do
        acropath=$(perl -e 'print readlink($ARGV[0])' $acropath)
    done
    local version_file=${acropath%/*}/../Reader/AcroVersion
    [[ -r $version_file ]] && _acroread_version=$(< $version_file)
fi

if [[ $_acroread_version == 7.* ]]; then
    _arguments -C \
      '--display=:X display:_x_display' \
      '--screen=:X screen (overrides the screen part of DISPLAY)' \
      --sync \
      '-geometry:[<width>x<height>][{+|-}<x offset>{+|-}<y offset>]' \
      -help \
      -iconic \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      -openInNewWindow \
      -version \
      '-visual:X visual:_x_visual' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      -annotsOff \
      '(-level3)-level2' \
      '(-level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      -expand \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
else
    _x_arguments -C \
      -help \
      -helpall \
      \*-iconic \
      \*+iconic \
      '-name:application name:_x_name' \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      '(+useFrontEndProgram)-useFrontEndProgram' \
      '(-useFrontEndProgram)+useFrontEndProgram' \
      '-visual:X visual:_x_visual' \
      '-xrm:X resource specification:_x_resource' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      '(-level2 -level3)-level1' \
      '(-level1 -level3)-level2' \
      '(-level1 -level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
fi

return 1

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

* Re: Updated _acroread completer
  2005-04-25  8:41     ` Haakon Riiser
@ 2005-04-25  8:54       ` Oliver Kiddle
  2005-04-25  8:58         ` Haakon Riiser
  2005-04-25  9:39       ` Peter Stephenson
  1 sibling, 1 reply; 9+ messages in thread
From: Oliver Kiddle @ 2005-04-25  8:54 UTC (permalink / raw)
  To: Haakon Riiser; +Cc: zsh-workers

Haakon Riiser wrote:
> 
> It doesn't work when acroread is a wrapper script, which it is
> in my case.  (I used a wrapper instead of a symlink, because the

Given that it is very fast compared to running acroread -help, it would
be worth trying it and falling back on your method if it fails.

> So I'll just have to resolve the symlink using readlink.  I assume
> the most portable way to do this is perl, unless there is a way

ls -l piped to sed is more portable than perl. There's an example in
Zsh/Type/_file_descriptors if you want to copy that.

Olive


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

* Re: Updated _acroread completer
  2005-04-25  8:54       ` Oliver Kiddle
@ 2005-04-25  8:58         ` Haakon Riiser
  0 siblings, 0 replies; 9+ messages in thread
From: Haakon Riiser @ 2005-04-25  8:58 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

[Oliver Kiddle]

> Haakon Riiser wrote:
>
>> It doesn't work when acroread is a wrapper script, which it is
>> in my case.  (I used a wrapper instead of a symlink, because the
> 
> Given that it is very fast compared to running acroread -help, it would
> be worth trying it and falling back on your method if it fails.

OK.

> ls -l piped to sed is more portable than perl. There's an example in
> Zsh/Type/_file_descriptors if you want to copy that.

Didn't know that ls' output format was standardized. :-)

-- 
 Haakon


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

* Re: Updated _acroread completer
  2005-04-25  8:41     ` Haakon Riiser
  2005-04-25  8:54       ` Oliver Kiddle
@ 2005-04-25  9:39       ` Peter Stephenson
  2005-04-25 13:00         ` Haakon Riiser
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2005-04-25  9:39 UTC (permalink / raw)
  To: Zsh hackers list

Haakon Riiser wrote:
> So I'll just have to resolve the symlink using readlink.  I assume
> the most portable way to do this is perl, unless there is a way
> to make zsh expand the link itself.  I have attached a version that
> does this.  Should handle any level of symbolic links that point to
> new symbolic links.

You can use the zsh/stat library.

  zmodload -i zsh/stat
  stat -A ln +link ~/perforce
  print $ln[1]
  /pws/perforce

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


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

* Re: Updated _acroread completer
  2005-04-25  9:39       ` Peter Stephenson
@ 2005-04-25 13:00         ` Haakon Riiser
  2005-04-25 13:36           ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Haakon Riiser @ 2005-04-25 13:00 UTC (permalink / raw)
  To: Zsh hackers list

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

[Peter Stephenson]

> Haakon Riiser wrote:
> > So I'll just have to resolve the symlink using readlink.  I assume
> > the most portable way to do this is perl, unless there is a way
> > to make zsh expand the link itself.  I have attached a version that
> > does this.  Should handle any level of symbolic links that point to
> > new symbolic links.
> 
> You can use the zsh/stat library.
> 
>   zmodload -i zsh/stat
>   stat -A ln +link ~/perforce
>   print $ln[1]
>   /pws/perforce

Thanks, but I did away with that completely.  There's really no need
to think about symblic links and the version file when the version
number actually is embedded in the ACROREAD-PREFIX/bin/acroread
script.  Attached to this mail is the latest version that only runs
acroread -help to determine the patch to the real executable when
the version number was not found directly in $command[$words[1]].

By the way, it uses "sed -n 's/^ver=//p' FILE" to extract the
version.  Is it preferable to use zsh's own string functions to
do this?  The code tends to become quite hard to read, and I usually
need to spend much more time writing it than when I use sed or awk.

-- 
 Haakon

[-- Attachment #2: _acroread --]
[-- Type: text/plain, Size: 3035 bytes --]

#compdef acroread

local curcontext="$curcontext" state line

# Try extracting the version number directly from the executable.
# (This will fail if the executable is a wrapper script for acroread.)
local ver=$(sed -n 's/^ver=//p' $commands[$words[1]] 2>/dev/null)
[[ -n $ver ]] && _acroread_version=$ver

if [[ -z $_acroread_version ]]; then
    local acropath=${${(s. .)${${(f)"$($words[1] -help 2>&1)"}[1]}}[2]}
    _acroread_version=$(sed -n 's/^ver=//p' "$acropath" 2>/dev/null)
fi

if [[ $_acroread_version == 7.* ]]; then
    _arguments -C \
      '--display=:X display:_x_display' \
      '--screen=:X screen (overrides the screen part of DISPLAY)' \
      --sync \
      '-geometry:[<width>x<height>][{+|-}<x offset>{+|-}<y offset>]' \
      -help \
      -iconic \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      -openInNewWindow \
      -version \
      '-visual:X visual:_x_visual' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      -annotsOff \
      '(-level3)-level2' \
      '(-level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      -expand \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
else
    _x_arguments -C \
      -help \
      -helpall \
      \*-iconic \
      \*+iconic \
      '-name:application name:_x_name' \
      '*-setenv:<var>=<value>' \
      -tempFile \
      '-tempFileTitle:title' \
      '(+useFrontEndProgram)-useFrontEndProgram' \
      '(-useFrontEndProgram)+useFrontEndProgram' \
      '-visual:X visual:_x_visual' \
      '-xrm:X resource specification:_x_resource' \
      '-toPostScript:*::PostScript conversion options:= ->tops' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return

    [[ -n "$state" ]] && _arguments \
      '-pairs:*:pdf_file_1 ps_file_1 ...:_files -g "*.(#i)(pdf|ps)(-.)"' \
      -binary \
      '-start:integer' \
      '-end:integer' \
      -optimizeForSpeed \
      -landscape \
      -reverse \
      '(-even)-odd' \
      '(-odd)-even' \
      -commentsOff \
      '(-level2 -level3)-level1' \
      '(-level1 -level3)-level2' \
      '(-level1 -level2)-level3' \
      -printerhalftones \
      -saveVM \
      '-scale:integer' \
      -shrink \
      '-size:page size (or custom size wxh in points):(letter tabloid ledger legal executive a3 a4 a5 b4 b5)' \
      '-transQuality:transparency flattening level:(1 2 3 4 5)' \
      '*:PDF file:_files -g "*.(#i)pdf(-.)"' && return
fi

return 1

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

* Re: Updated _acroread completer
  2005-04-25 13:00         ` Haakon Riiser
@ 2005-04-25 13:36           ` Peter Stephenson
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 2005-04-25 13:36 UTC (permalink / raw)
  To: Zsh hackers list

Haakon Riiser wrote:
> By the way, it uses "sed -n 's/^ver=//p' FILE" to extract the
> version.  Is it preferable to use zsh's own string functions to
> do this?  The code tends to become quite hard to read, and I usually
> need to spend much more time writing it than when I use sed or awk.

As you need to scan an entire file for this, sed is probably as good as
anything.  However, you'll see things as bad as the following, and even
worse, inside the completion code.

The zsh version of:

local ver=$(sed -n 's/^ver=//p' $commands[$words[1]] 2>/dev/null)

would be (with EXTENDED_GLOB set):

ver=${${${(f)"$(<$commands[$words[1]])"}:#^ver=*}##ver=}

which isn't fantastically easy to understand:

  "$(<$commands[$words[1]])"

Output the contents of the file given by $commands[$words[1]] as a
single string.

  ${(f)"$(<$commands[$words[1]])"}

Split the result into an array of lines.  (This forces array context
despite the scalar assignment.)

  ${${(f)"$(<$commands[$words[1]])"}:#^ver=*}

Remove all elements of the resulting array (lines of the file) that
match ^ver=*, i.e. all lines except those that match ver=*.

  ${${${(f)"$(<$commands[$words[1]])"}:#^ver=*}##ver=}

Remove the ver= from the head of the result.  At this point it will be
treated as a scalar for the assignment, but that's OK if there's just
the one match.

There's no equivalent of sed's p (do the substitution and output the
result if the substitution succeeded), which is why we need to match on
the ver= twice.  But there are still spare letters for flags...

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


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

end of thread, other threads:[~2005-04-25 13:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14 13:47 Updated _acroread completer Haakon Riiser
2005-04-15 11:11 ` Haakon Riiser
2005-04-25  7:43   ` Oliver Kiddle
2005-04-25  8:41     ` Haakon Riiser
2005-04-25  8:54       ` Oliver Kiddle
2005-04-25  8:58         ` Haakon Riiser
2005-04-25  9:39       ` Peter Stephenson
2005-04-25 13:00         ` Haakon Riiser
2005-04-25 13:36           ` Peter Stephenson

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