// Clear execution positions - after a `run', for instance. // Keep commands only. void UndoBuffer::clear_exec_pos() { if (locked) return; UndoBufferArray new_history(history.size()); int old_history_position = history_position; for (int i = 0; i < history.size(); i++) { const UndoBufferEntry& entry = history[i]; if (entry.has(UB_COMMAND)) { UndoBufferEntry new_entry; new_entry[UB_COMMAND] = entry[UB_COMMAND]; if (entry.has(UB_SOURCE)) new_entry[UB_SOURCE] = entry[UB_SOURCE]; new_history += new_entry; } else { // Ignore this entry if (i < old_history_position) history_position--; } } history = new_history; done(); }
void HwcmScorer::extractHeadWordChain(TreePointer tree, vector<string> & history, vector<map<string, int> > & hwc) { if (tree->GetLength() > 0) { string head = getHead(tree); if (head.empty()) { for (std::vector<TreePointer>::const_iterator it = tree->GetChildren().begin(); it != tree->GetChildren().end(); ++it) { extractHeadWordChain(*it, history, hwc); } } else { vector<string> new_history(kHwcmOrder); new_history[0] = head; hwc[0][head]++; for (size_t hist_idx = 0; hist_idx < kHwcmOrder-1; hist_idx++) { if (!history[hist_idx].empty()) { string chain = history[hist_idx] + " " + head; hwc[hist_idx+1][chain]++; if (hist_idx+2 < kHwcmOrder) { new_history[hist_idx+1] = chain; } } } for (std::vector<TreePointer>::const_iterator it = tree->GetChildren().begin(); it != tree->GetChildren().end(); ++it) { extractHeadWordChain(*it, new_history, hwc); } } } }
// Remove all entries with no effect; // also truncate history such that it fits into limits void UndoBuffer::cleanup() { if (max_history_depth == 0 || max_history_size == 0) { clear(); return; } int end = 0; // Copy entries greater than END if (max_history_depth >= 0) { // Truncate according to MAX_HISTORY_DEPTH end = max(0, history.size() - max_history_depth); } if (max_history_size >= 0) { // Truncate according to MAX_HISTORY_SIZE int size = 0; for (int i = history.size() - 1; i >= end; i--) { UndoBufferEntry& entry = history[i]; if (!has_effect(entry)) continue; int alloc = entry.allocation(); if (size + alloc > max_history_size) { end = i; break; } size += alloc; } } UndoBufferArray new_history(history.size() - end); int old_history_position = history_position; for (int i = 0; i < history.size(); i++) { UndoBufferEntry& entry = history[i]; if (i >= end && has_effect(entry)) { new_history += entry; } else { // Ignore this entry if (i < old_history_position) history_position--; } } history = new_history; }
struct logtop *new_logtop(size_t history_size) { struct logtop *this; this = malloc(sizeof(*this)); if (this == NULL) return NULL; this->history_start = 0; this->history_size = history_size; this->strings = NULL; this->history = new_history(this); this->top = new_avl(this); return this; }
static historyp make_variable_history(void) { alist al; historyp hp; hpair *pair; al = htable_list(var_table); hp = new_history(FALSE); for (pair = alist_first(al); pair != NULL; pair = alist_next(al)) alist_append(hp->completions, zstrdup(pair->key)); alist_delete(al); return hp; }
// Remove all later entries, except for exec positions void UndoBuffer::clear_after_position() { UndoBufferArray new_history(history.size()); for (int i = 0; i < history.size(); i++) { if (i < history_position || (!history[i].has_command() && !history[i].has_pos())) { UndoBufferEntry entry = history[i]; if (i >= history_position) { entry.remove(UB_POS); entry.remove(UB_ADDRESS); entry.remove(UB_COMMAND); entry.remove(UB_EXEC_COMMAND); } new_history += entry; } } history = new_history; }
void command_paste(doc *d, char **args, int nargs) { cursor precursor = d->c; doc n; int change = 0; int i, j, nlines, ii, jj; if (nargs != 1) return paste_usage(); n = to_doc(args[0]); lock(d); if (n.size != 1) goto error; nlines = d->l[d->c.line].n; /* take into account subline of cursor to paste */ for (i = 0, ii = 0; i < n.l[0].size; i++, ii++) { item *s = &n.l[0].i[i], *dst; new_item(&d->l[d->c.line], d->c.item+ii); dst = &d->l[d->c.line].i[d->c.item+ii]; for (j = 0, jj = 0; j < s->size; j++, jj++) { switch (s->i[j].t) { case CLEF: if (s->i[j].clef.s + d->c.subline >= nlines) {jj--;continue;} new_vertical_item(dst, jj, CLEF, s->i[j].clef.t, s->i[j].clef.s + d->c.subline, s->i[j].clef.p); break; case ARMATURE:if(s->i[j].armature.s+d->c.subline>=nlines){jj--;continue;} new_vertical_item(dst, jj, ARMATURE, s->i[j].armature.t, s->i[j].armature.s + d->c.subline, s->i[j].armature.p); break; case NOTE: if (s->i[j].note.s + d->c.subline >= nlines){jj--;continue;} new_vertical_item(dst, jj, NOTE, s->i[j].note.duration, s->i[j].note.dots, s->i[j].note.alteration, s->i[j].note.s + d->c.subline, s->i[j].note.p, s->i[j].note.st, s->i[j].note.l, s->i[j].note.m, s->i[j].note.o); break; case SILENCE: if(s->i[j].silence.s+d->c.subline>=nlines){jj--;continue;} new_vertical_item(dst, jj, SILENCE, s->i[j].silence.duration, s->i[j].silence.dots, s->i[j].silence.s + d->c.subline, s->i[j].silence.p); break; case BAR: /* always works */ new_vertical_item(dst, jj, BAR); break; } } if (dst->size == 0) { delete_item(&d->l[d->c.line], d->c.item+ii); ii--; continue; } for (j = 0; j < s->tsize; j++) new_text(dst, s->t[j].t, s->t[j].dx, s->t[j].dy); change = 1; } if (change == 0) goto error; d->dirty = 1; unlock(d); resize(d); new_history(d, precursor); delete_doc(&n); return; error: unlock(d); printf("cannot paste '%s'\n", args[0]); delete_doc(&n); }