Skip to content

Commit

Permalink
vi: create istempbuf()
Browse files Browse the repository at this point in the history
  • Loading branch information
kyx0r committed Aug 21, 2023
1 parent d808ef8 commit 0a44ce4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void bufs_switch(int idx)
{
if (ex_buf != &bufs[idx]) {
exbuf_save(ex_buf)
if (ex_buf - bufs >= xbufcur || ex_buf - bufs < 0)
if (istempbuf(ex_buf))
ex_pbuf = &bufs[idx] == ex_pbuf ? ex_tpbuf : ex_pbuf;
else
ex_pbuf = ex_buf;
Expand Down Expand Up @@ -129,7 +129,7 @@ void temp_switch(int i)
ex_buf = ex_pbuf;
ex_pbuf = ex_tpbuf;
} else {
if (ex_buf - bufs < xbufcur && ex_buf - bufs >= 0) {
if (!istempbuf(ex_buf)) {
ex_tpbuf = ex_pbuf;
ex_pbuf = ex_buf;
}
Expand Down Expand Up @@ -395,7 +395,7 @@ static int ec_edit(char *loc, char *cmd, char *arg)
} else if (arg[0] || !xbufcur || !strchr(cmd, '!'))
bufs_switch(bufs_open(arg+cd));
readfile(rd =)
if (ex_buf - bufs < xbufcur && ex_buf - bufs >= 0) {
if (!istempbuf(ex_buf)) {
ex_bufpostfix(ex_buf - bufs, arg[0]);
syn_setft(ex_ft);
snprintf(msg, sizeof(msg), "\"%s\" %d lines [r]",
Expand Down
7 changes: 3 additions & 4 deletions vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,9 @@ static int vi_motion(int *row, int *off)
ex_krsset(cs, +1);
free(cs);
}
preserve(struct buf*, ex_buf, ex_buf)
struct buf* tmpex_buf = istempbuf(ex_buf) ? ex_pbuf : ex_buf;
if (mv == TK_CTL(']')) {
if (lkwdcnt != xkwdcnt)
if (vi_arg1 || lkwdcnt != xkwdcnt)
term_exec("qq", 4, /*nop*/, /*nop*/)
lkwdcnt = xkwdcnt;
fspos += fsdir < 0 ? 1 : 0;
Expand Down Expand Up @@ -1581,8 +1581,7 @@ void vi(int init)
vc_status();
break;
case TK_CTL('^'):
if (ex_pbuf - bufs < xbufcur && ex_pbuf - bufs >= 0)
bufs_switchwft(ex_pbuf - bufs)
bufs_switchwft(ex_pbuf - bufs)
vc_status();
vi_mod = 1;
break;
Expand Down
1 change: 1 addition & 0 deletions vi.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ extern struct buf *ex_buf;
extern struct buf *ex_pbuf;
extern struct buf *bufs;
extern struct buf tempbufs[2];
#define istempbuf(buf) (buf - bufs < 0 || buf - bufs >= xbufcur)
#define EXLEN 512 /* ex line length */
#define ex_path ex_buf->path
#define ex_ft ex_buf->ft
Expand Down

0 comments on commit 0a44ce4

Please sign in to comment.