From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org (Zsh hackers list)
Subject: Re: PATCH: update region highlighting as line changes
Date: Thu, 10 Mar 2011 21:08:20 +0000 [thread overview]
Message-ID: <20110310210820.3da0ce95@pws-pc.ntlworld.com> (raw)
In-Reply-To: <8161.1298064044@pws-pc.ntlworld.com>
On Fri, 18 Feb 2011 21:20:44 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> This makes an attempt to keep the highlighted regions set by the zle
> special parameter $region_highlight in sync as the line changes.
This is a rather dull update to fix things up in the case where you use
the "P" prefix to include $PREDISPLAY in the character count.
Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.59
diff -p -u -r1.59 zle_utils.c
--- Src/Zle/zle_utils.c 18 Feb 2011 22:08:46 -0000 1.59
+++ Src/Zle/zle_utils.c 10 Mar 2011 21:06:28 -0000
@@ -191,7 +191,7 @@ mod_export char *
zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outllp,
int *outcsp, int useheap)
{
- int outcs, outll;
+ int outcs, outll, sub;
struct region_highlight *rhp;
#ifdef MULTIBYTE_SUPPORT
@@ -212,11 +212,15 @@ zlelineasstring(ZLE_STRING_T instr, int
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (rhp->start == 0)
- rhp->start_meta = mb_len;
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (rhp->start - sub == 0)
+ rhp->start_meta = sub + mb_len;
rhp->start--;
- if (rhp->end == 0)
- rhp->end_meta = mb_len;
+ if (rhp->end - sub == 0)
+ rhp->end_meta = sub + mb_len;
rhp->end--;
}
}
@@ -242,10 +246,14 @@ zlelineasstring(ZLE_STRING_T instr, int
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (rhp->start == 0)
- rhp->start_meta = mb_len;
- if (rhp->end == 0)
- rhp->end_meta = mb_len;
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (rhp->start - sub == 0)
+ rhp->start_meta = sub + mb_len;
+ if (rhp->end - sub == 0)
+ rhp->end_meta = sub + mb_len;
}
}
s[mb_len] = '\0';
@@ -296,10 +304,14 @@ zlelineasstring(ZLE_STRING_T instr, int
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (strp < startp + rhp->start) {
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (strp < startp + rhp->start - sub) {
rhp->start_meta++;
}
- if (strp < startp + rhp->end) {
+ if (strp < startp + rhp->end - sub) {
rhp->end_meta++;
}
}
@@ -362,7 +374,7 @@ mod_export ZLE_STRING_T
stringaszleline(char *instr, int incs, int *outll, int *outsz, int *outcs)
{
ZLE_STRING_T outstr;
- int ll, sz;
+ int ll, sz, sub;
struct region_highlight *rhp;
#ifdef MULTIBYTE_SUPPORT
mbstate_t mbs;
@@ -393,10 +405,14 @@ stringaszleline(char *instr, int incs, i
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (inptr - instr < rhp->start) {
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (inptr - instr < rhp->start - sub) {
rhp->start_meta--;
}
- if (inptr - instr < rhp->end) {
+ if (inptr - instr < rhp->end - sub) {
rhp->end_meta--;
}
}
@@ -471,13 +487,17 @@ stringaszleline(char *instr, int incs, i
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (offs <= rhp->start_meta &&
- rhp->start_meta < offs + (int)cnt) {
- rhp->start = outptr - outstr;
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (offs <= rhp->start_meta - sub &&
+ rhp->start_meta - sub < offs + (int)cnt) {
+ rhp->start = outptr - outstr + sub;
}
- if (offs <= rhp->end_meta &&
- rhp->end_meta < offs + (int)cnt) {
- rhp->end = outptr - outstr;
+ if (offs <= rhp->end_meta - sub &&
+ rhp->end_meta - sub < offs + (int)cnt) {
+ rhp->end = outptr - outstr + sub;
}
}
}
@@ -705,7 +725,7 @@ zle_restore_positions(void)
mod_export void
spaceinline(int ct)
{
- int i;
+ int i, sub;
struct region_highlight *rhp;
if (zlemetaline) {
@@ -722,10 +742,14 @@ spaceinline(int ct)
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (rhp->start_meta >= zlemetacs) {
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (rhp->start_meta - sub >= zlemetacs) {
rhp->start_meta += ct;
}
- if (rhp->end_meta >= zlemetacs) {
+ if (rhp->end_meta - sub >= zlemetacs) {
rhp->end_meta += ct;
}
}
@@ -744,10 +768,14 @@ spaceinline(int ct)
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (rhp->start >= zlecs) {
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (rhp->start - sub >= zlecs) {
rhp->start += ct;
}
- if (rhp->end >= zlecs) {
+ if (rhp->end - sub >= zlecs) {
rhp->end += ct;
}
}
@@ -765,6 +793,7 @@ void
shiftchars(int to, int cnt)
{
struct region_highlight *rhp;
+ int sub;
if (mark >= to + cnt)
mark -= cnt;
@@ -777,14 +806,18 @@ shiftchars(int to, int cnt)
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (rhp->start_meta > to) {
- if (rhp->start_meta > to + cnt)
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (rhp->start_meta - sub > to) {
+ if (rhp->start_meta - sub > to + cnt)
rhp->start_meta -= cnt;
else
rhp->start_meta = to;
}
- if (rhp->end_meta > to) {
- if (rhp->end_meta > to + cnt)
+ if (rhp->end_meta - sub > to) {
+ if (rhp->end_meta - sub > to + cnt)
rhp->end_meta -= cnt;
else
rhp->end_meta = to;
@@ -803,14 +836,18 @@ shiftchars(int to, int cnt)
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
rhp < region_highlights + n_region_highlights;
rhp++) {
- if (rhp->start > to) {
- if (rhp->start > to + cnt)
+ if (rhp->flags & ZRH_PREDISPLAY)
+ sub = predisplaylen;
+ else
+ sub = 0;
+ if (rhp->start - sub > to) {
+ if (rhp->start - sub > to + cnt)
rhp->start -= cnt;
else
rhp->start = to;
}
- if (rhp->end > to) {
- if (rhp->end > to + cnt)
+ if (rhp->end - sub > to) {
+ if (rhp->end - sub > to + cnt)
rhp->end -= cnt;
else
rhp->end = to;
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
prev parent reply other threads:[~2011-03-10 21:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-18 21:20 Peter Stephenson
2011-03-10 21:08 ` 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=20110310210820.3da0ce95@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/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).