Skip to content

Commit

Permalink
Do not try to execute a record if there is nothing already recorded.
Browse files Browse the repository at this point in the history
All this work, is dedicated to Zoi, for thirty years a gorgeous companion and mother
of our four kids as Zoi means life here actually.

She was born a day like this, when the humans touched the moon, but a day like this,
it was also the first whole day i remember crystal clear in my life (20 July of 1974).
I remember walking with my mother coming from my beloved grand parents. My father had
to go to the army that same day, because there was a war. I remember an extraordinary
bright night sky, though the moon was new.
  • Loading branch information
agathoklisx committed Jul 20, 2020
1 parent e757392 commit 7b7bb9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/__libved.h
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,9 @@ NewProp (ed,
int repeat_mode;
int record;
int record_idx;

ssize_t record_header_len;

Vstring_t *records[NUM_RECORDS + 1];

Record_cb record_cb;
Expand Down
35 changes: 29 additions & 6 deletions src/libved.c
Original file line number Diff line number Diff line change
Expand Up @@ -15750,6 +15750,8 @@ private void ed_init_special_win (ed_t *this) {
private int ed_i_record_default (ed_t *this, Vstring_t *rec) {
char *str = Vstring.to.cstring (rec, ADD_NL);

if (bytelen (str) is (size_t) $my(record_header_len)) return NOTOK;

i_t *in = I.get.current ($my(__I__));
ifnot (in)
in = I.init_instance ($my(__I__));
Expand All @@ -15764,8 +15766,7 @@ private int ed_i_record_default (ed_t *this, Vstring_t *rec) {
} else
Msg.send_fmt (this, COLOR_MSG, "Executed record [%d]", $my(record_idx) + 1);

if (retval isnot OK or retval isnot NOTOK) retval = NOTOK;
return retval;
return (retval isnot OK ? NOTOK : OK);
}

private void ed_record_default (ed_t *this, char *bytes) {
Expand All @@ -15784,7 +15785,28 @@ private void ed_record (ed_t *this, char *fmt, ...) {
$my(record_cb) (this, bytes);
}

private char *ed_init_record_default (void) {
private char *ed_init_record_default (ed_t *);

private ssize_t __record_header_len__ (ed_t *this) {
char *buf = ed_init_record_default (this);
char *sp = buf;

size_t len = bytelen (buf);

while (*sp and (buf = Cstring.byte_in_str (sp, '\n')) isnot NULL) {
len++;
sp = buf + 1;
}

return len;
}

private char *ed_init_record_default (ed_t *this) {
if ($my(record_header_len) is -1) {
$my(record_header_len) = 0;
$my(record_header_len) = __record_header_len__ (this);
}

return
"var ed = e_get_ed_current ()\n"
"var win = ed_get_current_win (ed)\n"
Expand All @@ -15803,7 +15825,7 @@ private void ed_init_record (ed_t *this, int idx) {
else
rec = Vstring.new ();

Vstring.append_with (rec, $my(init_record_cb) ());
Vstring.append_with (rec, $my(init_record_cb) (this));

$my(records)[$my(record_idx)] = rec;

Expand Down Expand Up @@ -15878,7 +15900,7 @@ private int buf_normal_cmd (ed_t *ed, buf_t **thisp, utf8 com, int count, int re

case '.':
String.replace_with ($from(ed, records)[NUM_RECORDS]->head->data,
$from(ed, init_record_cb) ());
$from(ed, init_record_cb) (ed));
retval = ed_interpr_record (ed, NUM_RECORDS);
break;

Expand Down Expand Up @@ -16663,6 +16685,7 @@ private ed_t *ed_init (E_T *E) {
$my(repeat_mode) = 0;
$my(record) = 0;
$my(record_idx) = -1;
$my(record_header_len) = -1;
$my(record_cb) = ed_record_default;
$my(i_record_cb) = ed_i_record_default;
$my(init_record_cb) = ed_init_record_default;
Expand Down Expand Up @@ -16720,7 +16743,7 @@ private ed_t *E_init (E_T *this, EdAtInit_cb init_cb) {
$from(ed, E) = this->self;

string_replace_with ($from(ed, records)[NUM_RECORDS]->head->data,
$from(ed, init_record_cb) ());
$from(ed, init_record_cb) (ed));

return ed;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libved.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ typedef void (*EdAtInit_cb) (ed_t *);
/* in between */
typedef void (*Record_cb) (ed_t *, char *);
typedef int (*IRecord_cb) (ed_t *, Vstring_t *);
typedef char *(*InitRecord_cb) (void);
typedef char *(*InitRecord_cb) (ed_t *);

/* interpeter */
typedef void (*IPrintByte_cb) (FILE *, int);
Expand Down

0 comments on commit 7b7bb9c

Please sign in to comment.