示例#1
0
array<T>::operator tree () {
  int i, n=rep->n;
  tree t (TUPLE, n);
  for (i=0; i<n; i++)
    t[i]= as_tree(rep->a[i]);
  return t;
}
示例#2
0
tree
edit_typeset_rep::exec_html (tree t, path p) {
  t= convert_OTS1_symbols_to_universal_encoding (t);
  if (p == (rp * 0)) typeset_preamble ();
  typeset_exec_until (p);
  hashmap<string,tree> H= copy (cur[p]);
  tree patch= as_tree (eval ("(stree->tree (tmhtml-env-patch))"));
  hashmap<string,tree> P (UNINIT, patch);
  H->join (P);
  tree w (WITH);
  if (H->contains ("html-title"))
    w << string ("html-title") << H["html-title"];
  if (H->contains ("html-css"))
    w << string ("html-css") << H["html-css"];
  if (H->contains ("html-head-javascript"))
    w << string ("html-head-javascript") << H["html-head-javascript"];
  if (H->contains ("html-head-javascript-src"))
    w << string ("html-head-javascript-src") << H["html-head-javascript-src"];
  if (N(w) == 0) return exec (t, H);
  else {
    w << t;
    return exec (w, H);
  }
  //tree r= exec (t, H);
  //cout << "In: " << t << "\n";
  //cout << "Out: " << r << "\n";
  //return r;
}
示例#3
0
void
edit_select_rep::selection_cut (string key) {
  if (inside_active_graphics ()) {
    if (key != "none") {
      tree t= as_tree (eval ("(graphics-cut)"));
      selection_set (key, t);
    }
  }
  else if (selection_active_any ()) {
    path p1, p2;
    if (selection_active_table ()) {
      p1= start_p; p2= end_p;
      if(key != "none") {
        tree sel= selection_get ();
        selection_set (key, sel);
      }
    }
    else {
      selection_get (p1, p2);
      go_to (p2);
      if (p2 == p1) return;
      if (key != "none") {
        tree sel= selection_compute (et, p1, p2);
        selection_set (key, simplify_correct (sel));
      }
    }
    cut (p1, p2);
  }
}
示例#4
0
tree
edit_typeset_rep::exec_latex (tree t, path p) {
  t= convert_OTS1_symbols_to_universal_encoding (t);
  bool expand_unknown_macros= "on" == as_string (
      call ("get-preference", "texmacs->latex:expand-macros"));
  bool expand_user_macro= "on" == as_string (
      call ("get-preference", "texmacs->latex:expand-user-macros"));
  if (!expand_unknown_macros && !expand_user_macro)
    return t;
  if (p == (rp * 0)) typeset_preamble ();
  typeset_exec_until (p);
  hashmap<string,tree> H= copy (cur[p]);
  object l= null_object ();
  iterator<string> it= iterate (H);
  while (it->busy ()) l= cons (object (it->next ()), l);
  tree patch= as_tree (call ("stree->tree", call ("tmtex-env-patch", t, l)));
  hashmap<string,tree> P (UNINIT, patch);
  H->join (P);

  if (!expand_user_macro &&
      is_document (t) && is_compound (t[0], "hide-preamble")) {
    tree r= copy (t);
    r[0]= "";
    r= exec (value_to_compound (r, P), H, false);
    r[0]= exec (t[0], H, false);
    return r;
  }
  else {
    tree r= exec (value_to_compound (t, P), H, false);
    return r;
  }
}
示例#5
0
tree
div (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) / as_double (t2));
  if (t1 == "0") return "0";
  if (t2 == "1") return t1;
  return tree (OVER, t1, t2);
}
示例#6
0
tree
sub (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) - as_double (t2));
  if (t1 == "0") return tree (MINUS, t2);
  if (t2 == "0") return t1;
  return tree (MINUS, t1, t2);
}
示例#7
0
tree
add (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) + as_double (t2));
  if (t1 == "0") return t2;
  if (t2 == "0") return t1;
  return tree (PLUS, t1, t2);
}
示例#8
0
tree
mul (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) * as_double (t2));
  if (t1 == "0" || t2 == "0") return "0";
  if (t1 == "1") return t2;
  if (t2 == "1") return t1;
  return tree (TIMES, t1, t2);
}
示例#9
0
tree
pow (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (pow (as_double (t1), as_double (t2)));
  if (t1 == "0" || t1 == "1") return t1;
  if (t2 == "0") return "1";
  if (t2 == "1") return t1;
  return tree (POW, t1, t2);
}
示例#10
0
static void
rewrite_symbolic_arguments (tree macro, tree& env) {
  if (!is_func (env, ATTR)) return;
  for (int i=1; i<N(env); i+=2)
    if (is_func (env[i], ARG, 1)) {
      for (int j=0; j+1<N(macro); j++)
	if (macro[j] == env[i][0])
	  env[i]= tree (ARG, as_tree (j));
    }
}
示例#11
0
tree
edit_graphics_rep::graphical_select (
  double x1, double y1, double x2, double y2)
{ 
  frame f= find_frame ();
  if (is_nil (f)) return tuple ();
  gr_selections sels;
  point p1 = f (point (x1, y1)), p2= f (point (x2, y2));
  sels= eb->graphical_select ((SI)p1[0], (SI)p1[1], (SI)p2[0], (SI)p2[1]);
  return as_tree (sels);
}
示例#12
0
tree
edit_graphics_rep::graphical_select (double x, double y) { 
  frame f= find_frame ();
  if (is_nil (f)) return tuple ();
  gr_selections sels;
  point p0 = point (x, y);
  point p = f (p0);
  sels= eb->graphical_select ((SI)p[0], (SI)p[1], 10*get_pixel_size ());
  gs= sels;
  pts= array<point> (0);
  ci= array<point> (0);
  cgi= array<point> (0);
  gr0= empty_grid ();
  grid g= find_grid ();
  frame f2= find_frame (true);
  if (!is_nil (g) && !is_nil (f2)) {
    gr0= g;
    p = f2 (point (x, y));
    int i, j, n= N(sels);
    for (i=0; i<n; i++) {
      array<point> pts2= sels[i]->pts;
      if (N(pts2)>0 && norm (pts2[0] - p) <= 10*get_pixel_size ())
	pts= pts << pts2[0];
      if (N(pts2)>1 && norm (pts2[1] - p) <= 10*get_pixel_size ())
	pts= pts << pts2[1];
    }
    double eps= get_pixel_size () / 10.0;
    for (i=0; i<n; i++) {
      for (j=0; j<n; j++)
        if (i<j) {
	  curve c1= sels[i]->c;
	  curve c2= sels[j]->c;
	  if (!is_nil (c1) && !is_nil (c2))
	    ci= ci << intersection (c1, c2, p, eps);
        }
    }
    array<grid_curve> gc= g->get_curves_around (p0, 10*get_pixel_size (), f);
    //FIXME: Too slow
    for (i=0; i<N(gc); i++) {
      curve c= f2 (gc[i]->c);
      for (j=0; j<n; j++)
	if (!is_nil (sels[j]->c))
	  cgi= cgi << intersection (c, sels[j]->c, p, eps);
    }
  }
  return as_tree (sels);
}
示例#13
0
static tree
from_verbatim (string s, bool wrap= true) {
  string r;
  int i, n=N(s);
  for (i=0; i<n; i++) {
    if (s[i] == '<') r << "<less>";
    else if (s[i] == '>') r << "<gtr>";
    else if (s[i] < ' ' || s[i] > '~') break;
    else r << s[i];
  }
  if (i == n) return as_tree (r);

  tree t= verbatim_to_tree (s, wrap, "SourceCode");
  if (is_document (t) && N(t) == 1)
    return t[0];
  return t;
}
示例#14
0
void
edit_select_rep::selection_copy (string key) {
  if (inside_active_graphics ()) {
    tree t= as_tree (eval ("(graphics-copy)"));
    selection_set (key, t);
    return;
  }
  if (selection_active_any ()) {
    path old_tp= tp;
    selection sel; selection_get (sel);
    go_to (sel->end);
    tree t= selection_get ();
    go_to (sel->start);
    selection_set (key, t);
    go_to (old_tp);
  }
}
示例#15
0
tree
edit_graphics_rep::graphical_select (double x, double y) { 
  frame f= find_frame ();
  if (is_nil (f)) return tuple ();
  gr_selections pre_sels, sels;
  point p0 = point (x, y);
  point p = f (p0);
  pre_sels= eb->graphical_select ((SI)p[0], (SI)p[1], snap_distance);
  for (int i=0; i<N(pre_sels); i++)
    if (admissible_selection (pre_sels[i]))
      sels << pre_sels[i];
  //for (int i=0; i<N(sels); i++)
  //  cout << i << ":\t" << sels[i] << "\n";
  gs= sels;
  gr0= empty_grid ();
  grid g= find_grid ();
  frame f2= find_frame (true);
  if (!is_nil (g) && !is_nil (f2)) {
    gr0= g;
    p_x= x;
    p_y= y;
  }
  return as_tree (sels);
}
示例#16
0
void
tm_frame_rep::set_int_window_property (string what, int val) {
  concrete_window () -> set_property (what, as_tree (val));
}
示例#17
0
void
edit_interface_rep::set_left_footer () {
  tree s= concat ();
  double base_sz= get_env_int (FONT_BASE_SIZE);
  double sz= get_env_double (FONT_SIZE);
  /*
  tree the_style= get_style ();
  for (int i=0; i<arity (the_style); i++)
    s << " " << as_string (the_style[i]);
  */
  string mode= get_env_string (MODE);
  string lan = get_env_string (MODE_LANGUAGE (mode));
  if (mode == "prog") s << "program";
  else if (as_string (get_init_value (MODE_LANGUAGE (mode))) != lan)
    s << " " << lan;
  else s << " " << mode;
  if ((mode == "text") || (mode == "src")) {
    s << " " << get_env_string (FONT);
    append_left_footer (s, FONT_FAMILY);
    s << " " << as_string ((int) ((base_sz+0.5)*sz));
    append_left_footer (s, FONT_SERIES);
    append_left_footer (s, FONT_SHAPE);
  }
  else if (mode == "math") {
    s << " " << get_env_string (MATH_FONT);
    append_left_footer (s, MATH_FONT_FAMILY);
    s << " " << as_string ((int) ((base_sz+0.5)*sz));
    append_left_footer (s, MATH_FONT_SERIES);
    append_left_footer (s, MATH_FONT_SHAPE);
  }
  else if (mode == "prog") {
    string session_name= get_env_string (PROG_SESSION);
    if (session_name != "default") s << "-" << session_name;
    s << " " << get_env_string (PROG_FONT);
    append_left_footer (s, PROG_FONT_FAMILY);
    s << " " << as_string ((int) ((base_sz+0.5)*sz));
    append_left_footer (s, PROG_FONT_SERIES);
    append_left_footer (s, PROG_FONT_SHAPE);
  }
  string r= get_env_string (COLOR);
  if (r != "black") s << " " << r;
  if (N(s) > 0 && s[0] == " ") s= s (1, N(s));
  if (inside ("session") && (lan != "scheme")) {
    string lan    = get_env_string (PROG_LANGUAGE);
    string session= get_env_string (PROG_SESSION);
    switch (connection_status (lan, session)) {
    case CONNECTION_DEAD:
      s= s << " [dead]";
      break;
    case CONNECTION_DYING:
    case WAITING_FOR_OUTPUT:
      s= s << " [busy]";
      break;
    case WAITING_FOR_INPUT:
      s= s << " [idle]";
      break;
    }
  }
  s= as_tree (call ("footer-hook", object (s)));
  set_left_footer (s);
}
示例#18
0
inline bool operator != (grid g1, grid g2) {
  return as_tree (g1) != as_tree(g2); }
示例#19
0
tree
sqrt (tree t) {
  if (is_double (t)) return as_tree (sqrt (as_double (t)));
  return tree (MATH_SQRT, t);
}
示例#20
0
tree
exp (tree t) {
  if (is_double (t)) return as_tree (exp (as_double (t)));
  return tree (EXP, t);
}
示例#21
0
void
edit_process_rep::generate_bibliography (
  string bib, string style, string fname)
{
  system_wait ("Generating bibliography, ", "please wait");
  if (DEBUG_AUTO)
    debug_automatic << "Generating bibliography"
                    << " [" << bib << ", " << style << ", " << fname << "]\n";
  tree bib_t= buf->data->aux[bib];
  if (buf->prj != NULL) bib_t= buf->prj->data->aux[bib];
  tree t;
  url bib_file= find_bib_file (buf->buf->name, fname);
  //cout << fname << " -> " << concretize (bib_file) << "\n";
  if (is_none (bib_file)) {
    url bbl_file= find_bib_file (buf->buf->name, fname, ".bbl");
    if (is_none (bbl_file)) {
      if (supports_db ()) {
        t= as_tree (call (string ("bib-compile"), bib, style, bib_t));
        call (string ("bib-attach"), bib, bib_t);
      }
      else {
	std_error << "Could not load BibTeX file " << fname;
        set_message ("Could not find bibliography file",
                     "compile bibliography");
        return;
      }
    }
    else t= bibtex_load_bbl (bib, bbl_file);
  }
  else {
    if (!bibtex_present () && !starts (style, "tm-")) {
      if (style == "abbrv") style= "tm-abbrv";
      else if (style == "acm") style= "tm-acm";
      else if (style == "alpha") style= "tm-alpha";
      else if (style == "elsart-num") style= "tm-elsart-num";
      else if (style == "ieeetr") style= "tm-ieeetr";
      else if (style == "siam") style= "tm-siam";
      else if (style == "unsrt") style= "tm-unsrt";
      else style= "tm-plain";
    }
    if (supports_db () && !is_rooted (bib_file))
      bib_file= find_bib_file (buf->buf->name, fname, ".bib", true);
    if (supports_db ()) {
      //(void) call (string ("bib-import-bibtex"), bib_file);
      t= as_tree (call (string ("bib-compile"), bib, style, bib_t, bib_file));
    }
    else if (starts (style, "tm-")) {
      string sbib;
      if (load_string (bib_file, sbib, false))
	std_error << "Could not load BibTeX file " << fname;
      tree te= bib_entries (parse_bib (sbib), bib_t);
      object ot= tree_to_stree (te);
      eval ("(use-modules (bibtex " * style (3, N(style)) * "))");
      t= stree_to_tree (call (string ("bib-process"),
                              bib, style (3, N(style)), ot));
    }
    else
      t= bibtex_run (bib, style, bib_file, bib_t);
    if (supports_db ())
      (void) call (string ("bib-attach"), bib, bib_t, bib_file);
  }
  if (is_atomic (t) && starts (t->label, "Error:"))
    set_message (t->label, "compile bibliography");
  else if (is_compound (t) && N(t) > 0) insert_tree (t);
}
示例#22
0
tree
neg (tree t) {
  if (is_double (t)) return as_tree (-as_double (t));
  return tree (MINUS, t);
}
示例#23
0
void
edit_main_rep::set_int_property (string what, int val) {
  props (what)= as_tree (val);
}
示例#24
0
tree
cos (tree t) {
  if (is_double (t)) return as_tree (cos (as_double (t)));
  return tree (COS, t);
}
示例#25
0
tree
log (tree t) {
  if (is_double (t)) return as_tree (log (as_double (t)));
  return tree (LOG, t);
}
示例#26
0
tree
sin (tree t) {
  if (is_double (t)) return as_tree (sin (as_double (t)));
  return tree (SIN, t);
}
示例#27
0
tree
tan (tree t) {
  if (is_double (t)) return as_tree (tan (as_double (t)));
  return tree (TAN, t);
}