zsh-users
 help / color / mirror / code / Atom feed
* 'print -s' in a function
@ 1996-05-26 12:19 Huy Le
  1996-05-26 18:44 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Huy Le @ 1996-05-26 12:19 UTC (permalink / raw)
  To: zsh-users

VERSION: zsh2.6beta13

So, I'm trying the following:

function fed() {
  # Allows for the editing of functions in memory

  if [[$# -ne 1]]; then
    echo "usage: $0 function"
    return 1
  fi

  local i

  if autoload | grep " $1 " >/dev/null 2>&1; then
    for i in "$fpath[@]"; do
      if [[-f $fpath[1]/$1]]; then
        eval "`echo \"function $1() {\"; <$fpath[1]/$1;
               echo \}`"
        break
      fi
    done
  fi

  builtin print -s "function `which $1`"

  fc
  # Replace the previous line with the next line to see what's intended
  #builtin print -z fc
}


If you try running this, such as running:
      fed fed
you'll notice that what shows up in your editor
is "fed fed" instead of the contents of fed.

The problem is that the history doesn't get updated right
away after the 'print -s' line.  Why?  Could this be a bug?

- Huy



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

* Re: 'print -s' in a function
  1996-05-26 12:19 'print -s' in a function Huy Le
@ 1996-05-26 18:44 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1996-05-26 18:44 UTC (permalink / raw)
  To: Huy Le, zsh-users

On May 26,  5:19am, Huy Le wrote:
} Subject: 'print -s' in a function
}
} VERSION: zsh2.6beta13
} 
} So, I'm trying the following:
} 
} function fed() {
}   # Allows for the editing of functions in memory
} 
[snip]
} 
}   builtin print -s "function `which $1`"
} 
}   fc
} }
} 
} If you try running this, such as running:
}       fed fed
} you'll notice that what shows up in your editor
} is "fed fed" instead of the contents of fed.
} 
} The problem is that the history doesn't get updated right
} away after the 'print -s' line.  Why?  Could this be a bug?

The history does get updated right away; replace "fc" with "history 1"
and you'll see that the `print -s' output is there.

What doesn't get updated seems to be the history position from which
"fc" starts looking backwards for commands to edit.  Even if you use

	n=$(print -P %\!)
	((n++))
	fc $n

You just get "fc: bad history number" even though an event with that
number shows up in the "history 1" output.

This may be intentional behavior of fc for some other reason -- you
don't normally want a command to edit itself.  Stick a SECOND command
into the history:

	builtin print -s "function `which $1`"
	builtin print -s "echo Dummy command for fed"
	fc

and then it works as you wanted -- and the dummy command never shows
up in the history list, it gets replaced by the result of "fc".

BTW, there's a history quoting bug (beta19).  Try:

zsh% function broken () {
> n=$(print -P %\!)
> }
zsh %
      ^
Type C-p here to edit the last command; note that the ! in %! is not
quoted; you get:

zsh% function broken () {
	n=$(print -P %!)
}

This produces a history-not-found error when you press return.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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

end of thread, other threads:[~1996-05-26 19:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-26 12:19 'print -s' in a function Huy Le
1996-05-26 18:44 ` 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).