zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: widget called when zle starts.
@ 2003-12-12 22:53 Peter Stephenson
  2003-12-13 19:34 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2003-12-12 22:53 UTC (permalink / raw)
  To: Zsh hackers list

If it's really this simple, it's definitely worth having.

Comment on the name, if you like.  The idea is that there could
conceivably be other zle-<something-else>-<init-or-exit-or-change>
special widgets in future.

An extra chunk simply shuts up a long-standing warning from gcc.

Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.37
diff -u -r1.37 zle_main.c
--- Src/Zle/zle_main.c	3 Nov 2003 13:57:53 -0000	1.37
+++ Src/Zle/zle_main.c	12 Dec 2003 22:42:21 -0000
@@ -348,7 +348,8 @@
 {
     long exp100ths;
     int ret;
-#ifdef HAS_TIO
+#if defined(HAS_TIO) && \
+  (defined(sun) || (!defined(HAVE_POLL) && !defined(HAVE_SELECT)))
     struct ttyinfo ti;
 #endif
 #ifndef HAVE_POLL
@@ -739,6 +740,7 @@
     unsigned char *s;
     int old_errno = errno;
     int tmout = getiparam("TMOUT");
+    Thingy initthingy;
 
 #if defined(HAVE_POLL) || defined(HAVE_SELECT)
     baud = getiparam("BAUD");
@@ -820,6 +822,14 @@
     lastcol = -1;
     initmodifier(&zmod);
     prefixflag = 0;
+
+    if ((initthingy = rthingy_nocreate("zle-line-init"))) {
+	char *args[2];
+	args[0] = initthingy->nam;
+	args[1] = NULL;
+	execzlefunc(initthingy, args);
+	unrefthingy(initthingy);
+    }
 
     zlecore();
 
Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.11
diff -u -r1.11 zle_thingy.c
--- Src/Zle/zle_thingy.c	29 Oct 2003 19:17:48 -0000	1.11
+++ Src/Zle/zle_thingy.c	12 Dec 2003 22:42:22 -0000
@@ -164,6 +164,17 @@
     return refthingy(t);
 }
 
+/**/
+Thingy
+rthingy_nocreate(char *nam)
+{
+    Thingy t = (Thingy) thingytab->getnode2(thingytab, nam);
+
+    if(!t)
+	return NULL;
+    return refthingy(t);
+}
+
 /***********/
 /* widgets */
 /***********/
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.30
diff -u -r1.30 zle.yo
--- Doc/Zsh/zle.yo	22 May 2003 09:48:28 -0000	1.30
+++ Doc/Zsh/zle.yo	12 Dec 2003 22:42:28 -0000
@@ -695,6 +695,26 @@
 The name of the widget currently being executed; read-only.
 )
 enditem()
+
+subsect(Special Widget)
+
+There is one user-defined widget which is special to the shell.
+If it does not exist, no special action is taken.  The environment
+provided is identical to that for any other editing widget.
+
+startitem()
+tindex(zle-line-init)
+item(tt(zle-line-init))(
+Executed every time the line editor is started to read a new line
+of input.  The following example puts the line editor into vi command
+mode when it starts up.
+
+example(zle-line-init() { zle -K vicmd; }
+zle -N zle-line-init)
+
+)
+enditem()
+
 sect(Standard Widgets)
 cindex(widgets, standard)
 The following is a list of all the standard widgets,

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


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

* Re: PATCH: widget called when zle starts.
  2003-12-12 22:53 PATCH: widget called when zle starts Peter Stephenson
@ 2003-12-13 19:34 ` Bart Schaefer
  2003-12-15 10:57   ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2003-12-13 19:34 UTC (permalink / raw)
  To: Zsh hackers list

On Dec 12, 10:53pm, Peter Stephenson wrote:
}
} If it's really this simple, it's definitely worth having.

I'm a bit concerned that this is going to be called at unexpected times,
such as every pass around a "select" loop, or right before printing the
to PS2 prompt, etc.  Normally I'd think one only wants it called before
the first PS1 prompt, at approximately the same time as precmd.

A comment on the example:

} +example(zle-line-init() { zle -K vicmd; }

It might be worth mentioning that this is the same as 

    zle-line-init() { zle vi-cmd-mode }

(The trailing ';' isn't necessary, is it?)


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

* Re: PATCH: widget called when zle starts.
  2003-12-13 19:34 ` Bart Schaefer
@ 2003-12-15 10:57   ` Peter Stephenson
  2003-12-15 18:43     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2003-12-15 10:57 UTC (permalink / raw)
  To: Zsh hackers list

Bart Schaefer wrote:
> I'm a bit concerned that this is going to be called at unexpected times,
> such as every pass around a "select" loop, or right before printing the
> to PS2 prompt, etc.  Normally I'd think one only wants it called before
> the first PS1 prompt, at approximately the same time as precmd.

Well, for it to do the example given, it needs to be called every time
zle is started for whatever reason.  I think that's the only consistent
thing to do by default.

It should be possible to get more control, though.  You can already test
for context, e.g. $PREBUFFER.  Another zle variable giving more about
the context is a possibility.

> A comment on the example:
> 
> } +example(zle-line-init() { zle -K vicmd; }
> 
> It might be worth mentioning that this is the same as 
> 
>     zle-line-init() { zle vi-cmd-mode }
> 
> (The trailing ';' isn't necessary, is it?)

Not in zsh, I just tend to use it for compatibility.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, 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.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: PATCH: widget called when zle starts.
  2003-12-15 10:57   ` Peter Stephenson
@ 2003-12-15 18:43     ` Bart Schaefer
  2003-12-15 18:50       ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2003-12-15 18:43 UTC (permalink / raw)
  To: Zsh hackers list

On Dec 15, 10:57am, Peter Stephenson wrote:
}
} It should be possible to get more control, though.  You can already test
} for context, e.g. $PREBUFFER.  Another zle variable giving more about
} the context is a possibility.

I think this is almost a requirement.  Otherwise one is reduced to doing
things like this:

    precmd() { zle_use_cmd_mode=1 }
    zle-line-init() {
	((zle_use_cmd_mode)) && zle vi-cmd-mode
	zle_use_cmd_mode=0
    }


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

* Re: PATCH: widget called when zle starts.
  2003-12-15 18:43     ` Bart Schaefer
@ 2003-12-15 18:50       ` Peter Stephenson
  2003-12-15 19:21         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2003-12-15 18:50 UTC (permalink / raw)
  To: Zsh hackers list

Bart Schaefer wrote:
> I think this is almost a requirement.  Otherwise one is reduced to doing
> things like this:
> 
>     precmd() { zle_use_cmd_mode=1 }
>     zle-line-init() {
> 	((zle_use_cmd_mode)) && zle vi-cmd-mode
> 	zle_use_cmd_mode=0
>     }

I still haven't understood under what circumstances you'd be doing that.
Are you demanding that sometimes when zle is started up, such as
for a continuation line, you want to maintain the current keymap?
That's way beyond the original idea of an initialisation widget.

However, I think some sort of context is a good idea anyway.
Unfortunately zle is not the most object-oriented piece of code, but it
shouldn't be too hard.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, 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.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: PATCH: widget called when zle starts.
  2003-12-15 18:50       ` Peter Stephenson
@ 2003-12-15 19:21         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2003-12-15 19:21 UTC (permalink / raw)
  To: Zsh hackers list

On Dec 15,  6:50pm, Peter Stephenson wrote:
}
} Are you demanding that sometimes when zle is started up, such as
} for a continuation line, you want to maintain the current keymap?

Yes.  If you plow though the zsh-users thread, the request for zle to
start in command mode was really a request for zle in vi mode to "act
like vi" -- that is, start in command mode, but not leave insert mode
until you explicitly press ESC.  Pressing RETURN in vi to go on to the
next line of input does not take you back to command mode, so I presume
that the user wouldn't want the PS2 prompt in zsh to behave that way.

And anyway, it'd be extremely confusing to have "select" loops start in
command mode, because there's not normally even any history to scroll
back through in that case.


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

end of thread, other threads:[~2003-12-15 19:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-12 22:53 PATCH: widget called when zle starts Peter Stephenson
2003-12-13 19:34 ` Bart Schaefer
2003-12-15 10:57   ` Peter Stephenson
2003-12-15 18:43     ` Bart Schaefer
2003-12-15 18:50       ` Peter Stephenson
2003-12-15 19:21         ` 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).