static tree connection_retrieve (string name, string session) { // cout << "Retrieve " << name << ", " << session << "\n"; connection con= connection (name * "-" * session); if (is_nil (con)) return ""; tree doc (DOCUMENT); while (true) { con->forced_eval= true; #ifndef QTTEXMACS perform_select (); #endif con->forced_eval= false; tree next= connection_read (name, session); if (next == ""); else if (is_document (next)) doc << A (next); else doc << next; if (con->status == WAITING_FOR_INPUT) break; } if (N(doc) == 0) return ""; // cout << "Retrieved " << doc << "\n"; return doc; }
static tree parse_subcommand (string s, bool wrap= false) { int start= 0, i= 0, n= N(s); tree r= ""; while (i<n) { if (start_comment (s, i)) { append_commands (r, indent_subcommand (from_verbatim (s(start, i), wrap))); if (start_coqdoc (s, i)) append_commands (r, parse_coqdoc (s, i)); else append_commands (r, parse_comment (s, i)); start= i; } else i++; } if (start < n) append_commands (r, indent_subcommand (from_verbatim (s(start, i), wrap))); if ((is_concat (r) || is_document (r)) && N(r) == 1) r= r[0]; return r; }
static tree indent_subcommand (tree t) { if (is_document (t)) { tree r (DOCUMENT); for (int i=0; i<N(t); i++) { tree tmp= indent_subcommand (t[i]); if (is_atomic (tmp)) r << tmp; else r << A(tmp); } return r; } else if (is_atomic (t)) { string s= as_string (t); int i= parse_indent (s, 0); if (i <= 0) return t; return tree (DOCUMENT, compound ("coq-indent", as_string (i)), s(i, N(s))); } else return t; }
DomDocument DomNode::to_document() const { if (is_document()) return DomDocument(impl); return DomDocument(); }
void edit_select_rep::raw_cut (path p1, path p2) { if (p2 == p1) return; path p = common (p1, p2); tree t = subtree (et, p); int n = N(p); int i1= p1[n]; int i2= p2[n]; if (is_document (t) || is_concat (t)) { path q1= copy (p); q1 << path (i1, end (t[i1])); path q2= copy (p); q2 << path (i2, start (t[i2])); raw_cut (q2, p2); if (i2>i1+1) remove (p * (i1+1), i2-i1-1); raw_cut (p1, q1); if (is_concat (t)) correct_concat (p); else remove_return (p * i1); return; } if (is_func (t, TFORMAT) || is_func (t, TABLE) || is_func (t, ROW)) { path fp= ::table_search_format (et, p); tree st= subtree (et, fp); int row1, col1, row2, col2; table_search_coordinates (st, tail (p1, N(fp)), row1, col1); table_search_coordinates (st, tail (p2, N(fp)), row2, col2); if (row1>row2) { int tmp= row1; row1= row2; row2= tmp; } if (col1>col2) { int tmp= col1; col1= col2; col2= tmp; } int i, j; for (i=row1; i<=row2; i++) for (j=col1; j<=col2; j++) { path cp= fp * ::table_search_cell (st, i, j); if (is_func (subtree (et, cp), CELL, 1)) cp= cp * 0; assign (cp, ""); } path cp= fp * ::table_search_cell (st, row1, col1); go_to (cp * path (0, 0)); if (is_func (st, TFORMAT)) table_del_format (fp, row1+1, col1+1, row2+1, col2+1, ""); return; } if (is_compound (t) && (!is_format (t))) { assign (p, ""); return; } if ((N(p1) != (N(p)+1)) || (N(p2) != (N(p)+1))) { cerr << "t = " << t << "\n"; cerr << "p = " << p << "\n"; cerr << "p1= " << p1 << "\n"; cerr << "p2= " << p2 << "\n"; FAILED ("invalid cut"); } if (is_atomic (t)) { int pos= last_item (p1); int nr = last_item (p2)-pos; if (nr>0) remove (p1, nr); } else { if ((last_item (p1) != 0) || (last_item (p2) != 1)) { cerr << "t = " << t << "\n"; cerr << "p = " << p << "\n"; cerr << "p1= " << p1 << "\n"; cerr << "p2= " << p2 << "\n"; FAILED ("invalid object cut"); } assign (p, ""); } }
tree texmacs_invarianted_merge (tree t, string src, tree org, tree u, hashmap<tree,path> h) { if (is_atomic (t)) return t; else { if (true) { int i, n= N(t); tree r (t, n); for (i=0; i<n; i++) r[i]= texmacs_invarianted_merge (t[i], src, org, u, h); t= r; } if (is_concat (t) || is_document (t)) { int i, n= N(t); tree r (L(t)); for (i=0; i<n; i++) { if (is_document (t) && is_compound (t[i], "ilx", 1)) t[i]= compound ("ilx", texmacs_invarianted_extend (t[i][0], src)); if (N(r) > 0 && is_compound (r[N(r)-1], "ilx", 1) && is_compound (t[i], "ilx", 1)) { int b1, e1, b2, e2; bool ok = get_range (r[N(r)-1][0], b1, e1, src); ok = get_range (t[i][0], b2, e2, src) || ok; if (ok && e1 <= b2) { skip_latex_spaces (src, e1); if (e1 >= b2) { string id= as_string (b1) * ":" * as_string (e2); r[N(r)-1][0]= id; continue; } } } int j= i; while (j<n && !is_compound (t[j], "ilx", 1)) j++; if (j < n && j > i && N(r) > 0 && is_compound (r[N(r)-1], "ilx", 1)) { // NOTE: this special treatment allows for the recognition of // pieces which may be invarianted even in case of missing markers int b1, e1, b2, e2; bool ok1= get_range (r[N(r)-1][0], b1, e1, src); bool ok2= get_range (t[j][0], b2, e2, src); if (ok1 && ok2 && e1 <= b2 && i-1 < N(org)) { path p= h [org[i-1]]; if (p != path (-1)) { tree pt= subtree (u, path_up (p)); int k, k2= last_item (p); for (k=i-1; k<=j && k2<N(pt); k++, k2++) if (org[k] != pt[k2]) { //cout << " <<< " << org[k] << LF // << " >>> " << pt[k2] << LF; break; } if (k > j) { string id= as_string (b1) * ":" * as_string (e2); r[N(r)-1][0]= id; i= j; continue; } } } } r << t[i]; } if (is_concat (r) && N(r) == 1) r= r[0]; return r; } return t; } }