void close_gap(editor_t *ed) { int len = text_length(ed); move_gap(ed, len, 1); ed->start[len] = 0; }
void replace(editor_t *ed, int pos, int len, char *buf, int bufsize, int doundo) { char *p; undo_t *undo; // Store undo information if (doundo) { reset_undo(ed); undo = ed->undotail; if (undo && len == 0 && bufsize == 1 && undo->erased == 0 && pos == undo->pos + undo->inserted) { // Insert character at end of current redo buffer undo->redobuf = neutron_realloc(undo->redobuf, undo->inserted + 1); undo->redobuf[undo->inserted] = *buf; undo->inserted++; } else if (undo && len == 1 && bufsize == 0 && undo->inserted == 0 && pos == undo->pos) { // Erase character at end of current undo buffer undo->undobuf = neutron_realloc(undo->undobuf, undo->erased + 1); undo->undobuf[undo->erased] = get(ed, pos); undo->erased++; } else if (undo && len == 1 && bufsize == 0 && undo->inserted == 0 && pos == undo->pos - 1) { // Erase character at beginning of current undo buffer undo->pos--; undo->undobuf = neutron_realloc(undo->undobuf, undo->erased + 1); memmove(undo->undobuf + 1, undo->undobuf, undo->erased); undo->undobuf[0] = get(ed, pos); undo->erased++; } else { // Create new undo buffer undo = (undo_t *) neutron_malloc(sizeof (struct _undo_t)); if (ed->undotail) ed->undotail->next = undo; undo->prev = ed->undotail; undo->next = 0; ed->undotail = ed->undo = undo; if (!ed->undohead) ed->undohead = undo; undo->pos = pos; undo->erased = len; undo->inserted = bufsize; undo->undobuf = undo->redobuf = 0; if (len > 0) { undo->undobuf = neutron_malloc(len); copy(ed, undo->undobuf, pos, len); } if (bufsize > 0) { undo->redobuf = neutron_malloc(bufsize); memcpy(undo->redobuf, buf, bufsize); } } } p = ed->start + pos; if (bufsize == 0 && p <= ed->gap && p + len >= ed->gap) { // Handle deletions at the edges of the gap ed->rest += len - (ed->gap - p); ed->gap = p; } else { // Move the gap move_gap(ed, pos + len, bufsize - len); // Replace contents memcpy(ed->start + pos, buf, bufsize); ed->gap = ed->start + pos + bufsize; } // Mark buffer as dirty ed->dirty = 1; }
static Lisp_Object parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int htmlp) { xmlDoc *doc; Lisp_Object result = Qnil; const char *burl = ""; EMACS_INT bytes; EMACS_INT istart, iend; LIBXML_TEST_VERSION; validate_region (&start, &end); istart = XINT (start); iend = XINT (end); if (istart < GPT && GPT < iend) move_gap (iend); if (! NILP (base_url)) { CHECK_STRING (base_url); burl = SSDATA (base_url); } bytes = CHAR_TO_BYTE (iend) - CHAR_TO_BYTE (istart); if (htmlp) doc = htmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), bytes, burl, "utf-8", HTML_PARSE_RECOVER|HTML_PARSE_NONET| HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| HTML_PARSE_NOBLANKS); else doc = xmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), bytes, burl, "utf-8", XML_PARSE_NONET|XML_PARSE_NOWARNING| XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); if (doc != NULL) { xmlNode *n = doc->children->next; Lisp_Object r = Qnil; while (n) { if (!NILP (r)) result = Fcons (r, result); r = make_dom (n); n = n->next; } if (NILP (result)) result = r; else result = Fcons (intern ("top"), Fcons (Qnil, Fnreverse (Fcons (r, result)))); xmlFreeDoc (doc); xmlCleanupParser (); } return result; }