zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: PATCH: $PREDISPLAY/$POSTDISPLAY
Date: Thu, 04 Jul 2002 10:57:11 +0100	[thread overview]
Message-ID: <10302.1025776631@csr.com> (raw)
In-Reply-To: "Sven Wischnowsky"'s message of "Thu, 04 Jul 2002 09:57:09 +0200." <15651.65493.979771.882185@wischnow.berkom.de>

Sven Wischnowsky wrote:
> Peter Stephenson wrote:
> > Note the way these parameters survive across invocations of zle.  This
> > was simply because it was the most natural way of writing it.  We can
> > make zleread() reinitialise them if it seems preferable.
> 
> I can see that it's more powerful, but it's really rather irritating,
> isn't it? Especially since you can't make them go away from the
> (normal) command line. Although with well-behaved widgets...

Yes, I came to that conclusion, too.

> It could also be nice if we could restrict
> the allowed movement-range in recursive edits (kind of like
> narrow-to-region in emacs).

You can already do this bit, with the same limitation as the Emacs
function, i.e. the editable region is always the bit in the middle.

narrow-to-region() {
  # Restrict the start of the editable line to the position
  # between MARK and CURSOR

  local lbuffer rbuffer
  integer start=$MARK end=$CURSOR swap

  if (( start == end )); then
    return 1
  elif (( start > end )); then
    swap=start
    start=end
    end=swap
  fi

  (( end++ ))

  PREDISPLAY=${BUFFER[1,start]}
  lbuffer=$PREDISPLAY
  POSTDISPLAY=${BUFFER[end,-1]}
  rbuffer=$POSTDISPLAY
  BUFFER=${BUFFER[start+1,end-1]}
  if (( swap )); then 
    CURSOR=0 
    MARK=${#BUFFER}
  else
    MARK=0
    CURSOR=${#BUFFER}
  fi

  zle recursive-edit

  PREDISPLAY=
  POSTDISPLAY=
  LBUFFER="$lbuffer$LBUFFER"
  RBUFFER="$RBUFFER$rbuffer"
}

Obviously, you can easily modify this to make the text outside the
region display as "...", and so on.  You might want to make accept-line
a dummy during this and define a widget `widen' which calls
.accept-line, or make the normal accept-line set a flag that
restrict-start will propagate the accept-line upwards, or something.

To be consistent, it would be better not to assume PREDISPLAY and
POSTDISPLAY are empty, i.e. we should really set predisplay=$PREDISPLAY,
PREDISPLAY+=... before and PREDISPLAY=$predisplay after, but I got bored
at that point.

There could be lurking off-by-one errors, but it seemed to do roughly
what I expected.

Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.24
diff -u -r1.24 zle.yo
--- Doc/Zsh/zle.yo	1 Jul 2002 16:50:43 -0000	1.24
+++ Doc/Zsh/zle.yo	4 Jul 2002 09:28:36 -0000
@@ -666,17 +666,15 @@
 item(tt(PREDISPLAY) (scalar))(
 Text to be displayed before the start of the editable text buffer.  This
 does not have to be a complete line; to display a complete line, a newline
-must be appended explicitly.  Note that the text survives between calls to zle
-and hence must be removed explicitly by assigning an empty value to the
-parameter.
+must be appended explicitly.    The text is reset on each new invocation
+(but not recursive invocation) of zle.
 )
 vindex(POSTDISPLAY)
 item(tt(POSTDISPLAY) (scalar))(
 Text to be displayed after the end of the editable text buffer.  This
 does not have to be a complete line; to display a complete line, a newline
-must be prepended explicitly.  Note that the text survives between calls to
-zle and hence must be removed explicitly by assigning an empty value to the
-parameter.
+must be prepended explicitly.  The text is reset on each new invocation
+(but not recursive invocation) of zle.
 )
 vindex(RBUFFER)
 item(tt(RBUFFER) (scalar))(
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.25
diff -u -r1.25 zle_main.c
--- Src/Zle/zle_main.c	1 Jul 2002 09:54:48 -0000	1.25
+++ Src/Zle/zle_main.c	4 Jul 2002 09:28:36 -0000
@@ -752,6 +752,7 @@
     pmpt_attr = txtchange;
     rpromptbuf = promptexpand(rp, 1, NULL, NULL);
     rpmpt_attr = txtchange;
+    free_prepostdisplay();
 
     zlereadflags = flags;
     histline = curhist;
Index: Src/Zle/zle_params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v
retrieving revision 1.5
diff -u -r1.5 zle_params.c
--- Src/Zle/zle_params.c	1 Jul 2002 16:50:43 -0000	1.5
+++ Src/Zle/zle_params.c	4 Jul 2002 09:28:36 -0000
@@ -516,3 +516,13 @@
 {
     return get_prepost(postdisplay, postdisplaylen);
 }
+
+/**/
+void
+free_prepostdisplay(void)
+{
+    if (predisplaylen)
+	set_prepost(&predisplay, &predisplaylen, NULL);
+    if (postdisplaylen)
+	set_prepost(&postdisplay, &postdisplaylen, NULL);
+}

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


      reply	other threads:[~2002-07-04 10:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-30 20:53 PATCH: zle recursive editing Peter Stephenson
2002-06-30 21:19 ` Bart Schaefer
2002-07-01  9:52   ` Peter Stephenson
2002-07-01 11:23     ` PATCH: $PREDISPLAY/$POSTDISPLAY Peter Stephenson
2002-07-04  7:57       ` Sven Wischnowsky
2002-07-04  9:57         ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10302.1025776631@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).