[hackers] [sbase] ed: place newly joined lines correctly || Thomas Mannay

From: <git_AT_suckless.org>
Date: Tue, 27 Dec 2016 15:04:01 +0100 (CET)

commit 2304df908c2f0741fb72c6d03e1f45fffdf69649
Author: Thomas Mannay <audiobarrier_AT_openmailbox.org>
AuthorDate: Sun Oct 9 23:12:46 2016 +0000
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Dec 27 12:50:20 2016 +0100

    ed: place newly joined lines correctly

diff --git a/ed.c b/ed.c
index ff619d8..a9aacf1 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -299,13 +299,17 @@ undo(void)
 }
 
 static void
-inject(char *s)
+inject(char *s, int j)
 {
         int off, k, begin, end;
 
- begin = getindex(curln);
- end = getindex(nextln(curln));
-
+ if (j) {
+ begin = getindex(curln-1);
+ end = getindex(nextln(curln-1));
+ } else {
+ begin = getindex(curln);
+ end = getindex(nextln(curln));
+ }
         while (*s) {
                 k = makeline(s, &off);
                 s += off;
_AT_@ -636,7 +640,7 @@ doread(char *fname)
                         s[n-1] = '\n';
                         s[n] = '\0';
                 }
- inject(s);
+ inject(s, 0);
         }
         if (optdiag)
                 printf("%zu\n", cnt);
_AT_@ -753,7 +757,7 @@ append(int num)
         while (getline(&s, &len, stdin) > 0) {
                 if (*s == '.' && s[1] == '\n')
                         break;
- inject(s);
+ inject(s, 0);
         }
         free(s);
 }
_AT_@ -818,7 +822,7 @@ join(void)
         s = addchar('\n', s, &cap, &len);
         s = addchar('\0', s, &cap, &len);
         delete(line1, line2);
- inject(s);
+ inject(s, 1);
         free(s);
 }
 
_AT_@ -845,7 +849,7 @@ copy(int where)
         curln = where;
 
         for (i = line1; i <= line2; ++i)
- inject(gettxt(i));
+ inject(gettxt(i), 0);
 }
 
 static void
_AT_@ -1020,7 +1024,7 @@ subline(int num, int nth)
         addpost(&s, &cap, &siz);
         delete(num, num);
         curln = prevln(num);
- inject(s);
+ inject(s, 0);
 }
 
 static void
Received on Tue Dec 27 2016 - 15:04:01 CET

This archive was generated by hypermail 2.3.0 : Tue Dec 27 2016 - 15:12:52 CET