diff options
| author | Russ Cox <rsc@swtch.com> | 2017-11-02 11:58:07 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@swtch.com> | 2017-11-02 12:01:14 -0400 |
| commit | 3d6e5cb56a6249e7f3001091fe81c171cd501319 (patch) | |
| tree | a59c7110ff800a3c83694928e4a16f089d19aa38 /src/cmd/acme/addr.c | |
| parent | 805d91d359d67676a89edc9789ee8267bb7da6e1 (diff) | |
| download | plan9port-3d6e5cb56a6249e7f3001091fe81c171cd501319.tar.gz plan9port-3d6e5cb56a6249e7f3001091fe81c171cd501319.zip | |
acme: preserve window position and selection during Get
Before, executing Get in a file rewound the window offset and
selection to the start of the file.
After this CL, Get preserves the window offset and selection,
where preserve is defined as "the same line number and rune
offset within the line". So if the window started at line 10
before and the selection was line 13 chars 5-7, then that
will still be true after Get, provided the new content is large
enough.
This should help the common situation of plumbing a
compiler error, realizing the window is out of date,
clicking Get, and then losing the positioning from the
plumb operation.
Diffstat (limited to 'src/cmd/acme/addr.c')
| -rw-r--r-- | src/cmd/acme/addr.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/cmd/acme/addr.c b/src/cmd/acme/addr.c index 861e5e01..2ccae960 100644 --- a/src/cmd/acme/addr.c +++ b/src/cmd/acme/addr.c @@ -49,6 +49,27 @@ isregexc(int r) return FALSE; } +// nlcounttopos starts at q0 and advances nl lines, +// being careful not to walk past the end of the text, +// and then nr chars, being careful not to walk past +// the end of the current line. +// It returns the final position. +long +nlcounttopos(Text *t, long q0, long nl, long nr) +{ + while(nl > 0 && q0 < t->file->b.nc) { + if(textreadc(t, q0++) == '\n') + nl--; + } + if(nl > 0) + return q0; + while(nr > 0 && q0 < t->file->b.nc && textreadc(t, q0) != '\n') { + q0++; + nr--; + } + return q0; +} + Range number(uint showerr, Text *t, Range r, int line, int dir, int size, int *evalp) { |
