Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Does zsh functions have this feature?

On Sep 2,  9:41am, vinurs wrote:
}            As time goes on, my functions will be more and more. But, I
} won't all of them will be treated as shell commands.
}        In zsh, is there any feature like emacs lisp that  when I write a
} function if I want it to be call by M-x, I should add
}       (interactive)
}        in it; if not, it will only be called by lisp programs.

In general, no.  Zsh differentiates functions callable by the editor by
declaring them to be "widgets" via "zle -N" and related commands, but
it does not prevent widget functions from being called directly, any
more than emacs prevents a lisp program from invoking a function that
contains a call to (interactive).

There are various ways to cause functions to be excluded from command
correction and completion, and you can test for whether the editor is
active by e.g.

    if zle
    then zle -R "line editor is active"
    else print "line editor is not active"

The closest equivalent to (call-interactively) is to invoke the widget
by passing its name as an argument to the "zle" command.  There are lots
of examples of this in the sample widget functions.

Messages sorted by: Reverse Date, Date, Thread, Author