Menu

[b959bd]: / joe / poshist.c  Maximize  Restore  History

Download this file

140 lines (126 with data), 2.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Position history
* Copyright
* (C) 1992 Joseph H. Allen
*
* This file is part of JOE (Joe's Own Editor)
*/
#include "types.h"
typedef struct pos POS;
struct pos {
LINK(POS) link;
P *p;
W *w;
};
POS pos = { {&pos, &pos} };
POS frpos = { {&frpos, &frpos} };
POS *curpos = &pos;
int npos = 0;
static void markpos(W *w, P *p)
{
POS *newpos = (POS *)alitem(&frpos, SIZEOF(POS));
newpos->p = NULL;
pdupown(p, &newpos->p, "markpos");
poffline(newpos->p);
newpos->w = w;
enqueb(POS, link, &pos, newpos);
if (npos == 20) {
newpos = pos.link.next;
prm(newpos->p);
demote(POS, link, &frpos, newpos);
} else {
++npos;
}
}
void afterpos(void)
{
if (curpos != &pos) {
demote(POS, link, &pos, curpos);
curpos = &pos;
}
}
void aftermove(W *w, P *p)
{
if (pos.link.prev != &pos && pos.link.prev->w == w && pos.link.prev->p && oabs(pos.link.prev->p->line - p->line) < 3) {
poffline(pset(pos.link.prev->p, p));
} else {
markpos(w, p);
}
}
void windie(W *w)
{
POS *n;
for (n = pos.link.prev; n != &pos; n = n->link.prev) {
if (n->w == w) {
n->w = NULL;
}
}
}
int unextpos(W *w, int k)
{
BW *bw;
WIND_BW(bw, w);
lp:
if (curpos->link.next != &pos && curpos != &pos) {
curpos = curpos->link.next;
if (!curpos->p || !curpos->w) {
goto lp;
}
if (!(curpos->w->watom->what & (TYPETW|TYPEPW)))
goto lp;
bw = (BW *)curpos->w->object;
if (bw->b != curpos->p->b)
goto lp;
if (w->t->curwin == curpos->w && curpos->p->byte == ((BW *) w->t->curwin->object)->cursor->byte) {
goto lp;
}
if (w->t->curwin != curpos->w) {
w->t->curwin = curpos->w;
if (w->t->curwin->y == -1) {
wfit(w->t);
}
}
w = w->t->curwin;
bw = (BW *) w->object;
if (bw->cursor->byte != curpos->p->byte) {
pset(bw->cursor, curpos->p);
}
return 0;
} else {
return -1;
}
}
int uprevpos(W *w, int k)
{
BW *bw;
WIND_BW(bw, w);
lp:
if (curpos->link.prev != &pos) {
curpos = curpos->link.prev;
if (!curpos->p || !curpos->w) {
goto lp;
}
if (!(curpos->w->watom->what & (TYPETW|TYPEPW)))
goto lp;
bw = (BW *)curpos->w->object;
if (bw->b != curpos->p->b)
goto lp;
if (w->t->curwin == curpos->w && curpos->p->byte == ((BW *) w->t->curwin->object)->cursor->byte) {
goto lp;
}
if (w->t->curwin != curpos->w) {
w->t->curwin = curpos->w;
if (w->t->curwin->y == -1) {
wfit(w->t);
}
}
w = w->t->curwin;
bw = (BW *) w->object;
if (bw->cursor->byte != curpos->p->byte) {
pset(bw->cursor, curpos->p);
}
return 0;
} else {
return -1;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.