Back to index

texmacs  1.0.7.15
Functions | Variables
new_buffer.cpp File Reference
#include "tm_data.hpp"
#include "convert.hpp"
#include "file.hpp"
#include "web_files.hpp"
#include "tm_link.hpp"
#include "message.hpp"
#include "dictionary.hpp"
#include "new_document.hpp"

Go to the source code of this file.

Functions

url get_all_buffers ()
int nr_bufs ()
bool no_bufs ()
int find_buffer (tm_buffer buf)
int find_buffer (path p)
int find_buffer (url name)
string new_menu_name (url u)
url get_this_buffer ()
url get_name_buffer ()
url get_name_buffer (path p)
void set_name_buffer (url name)
string get_abbr_buffer (url name)
void set_abbr_buffer (url name, string abbr)
bool buffer_in_menu (url name)
bool is_aux_buffer (url name)
double last_visited (url name)
bool buffer_modified (url name)
void set_buffer_tree (url name, tree doc)
tree get_buffer_tree (url name)
tm_buffer create_buffer (url name)
tm_buffer create_buffer (url name, tree doc)
url create_buffer ()
void revert_buffer (url name, tree doc)
void revert_buffer ()
void delete_buffer (tm_buffer buf)
void kill_buffer ()
void switch_to_buffer (int nr)
bool switch_to_buffer (path p)
void switch_to_buffer (url name)
void switch_to_active_buffer (url name)
void set_aux (string aux, url name)
void set_aux_buffer (string aux, url name, tree doc)
static string get_doc_title (tree t)
string get_help_title (url name, tree t)
void set_help_buffer (url name, tree doc)

Variables

array< tm_bufferbufs

Function Documentation

bool buffer_in_menu ( url  name)

Definition at line 179 of file new_buffer.cpp.

                          {
  int nr= find_buffer (name);
  if (nr == -1) return false;
  else return bufs[nr]->buf->in_menu;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool buffer_modified ( url  name)

Definition at line 200 of file new_buffer.cpp.

                           {
  int nr= find_buffer (name);
  if (nr == -1) return false;
  return bufs[nr]->needs_to_be_saved ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 228 of file new_buffer.cpp.

                         {
  int nr= find_buffer (name);
  if (nr != -1) return bufs[nr];
  tm_buffer buf= tm_new<tm_buffer_rep> (name);
  buf->buf->abbr= new_menu_name (name);
  bufs << buf;
  return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tm_buffer create_buffer ( url  name,
tree  doc 
)

Definition at line 238 of file new_buffer.cpp.

                                   {
  int nr= find_buffer (name);
  if (nr != -1) return bufs[nr];
  tm_buffer buf= create_buffer (name);
  tree body= detach_data (doc, buf->data);
  set_document (buf->rp, body);
  if (buf->data->project != "") {
    url prj_name= head (name) * as_string (buf->data->project);
    buf->prj= load_passive_buffer (prj_name);
  }
  return buf;
}

Here is the call graph for this function:

Definition at line 252 of file new_buffer.cpp.

                 {
  int i=1;
  while (true) {
    url name= url_scratch ("no_name_", ".tm", i);
    int nr= find_buffer (name);
    if (nr == -1) {
      new_buffer_in_this_window (name, tree (DOCUMENT));
      return name;
    }
    else i++;
  }
}

Here is the call graph for this function:

void delete_buffer ( tm_buffer  buf)

Definition at line 290 of file new_buffer.cpp.

                              {
  int nr= find_buffer (buf), n= N(bufs);
  if (nr >= 0) {
    for (int i=nr; i<(n-1); i++) bufs[i]= bufs[i+1];
    bufs->resize (n-1);
  }
  for (int i=0; i<N(buf->vws); i++)
    delete_view (buf->vws[i]);
  tm_delete (buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int find_buffer ( tm_buffer  buf)

Definition at line 68 of file new_buffer.cpp.

                            {
  int i;
  for (i=0; i<N(bufs); i++)
    if (bufs[i] == buf)
      return i;
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int find_buffer ( path  p)

Definition at line 77 of file new_buffer.cpp.

                     {
  int i;
  for (i=0; i<N(bufs); i++)
    if (bufs[i]->rp <= p)
      return i;
  return -1;
}

Here is the call graph for this function:

int find_buffer ( url  name)

Definition at line 86 of file new_buffer.cpp.

                       {
  int i;
  for (i=0; i<N(bufs); i++)
    if (bufs[i]->buf->name == name)
      return i;
  return -1;
}

Here is the call graph for this function:

Definition at line 155 of file new_buffer.cpp.

                           {
  int nr= find_buffer (name);
  if (nr == -1) return "";
  else return bufs[nr]->buf->abbr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 50 of file new_buffer.cpp.

                   {
  url u= url_none ();
  for (int i=N(bufs)-1; i>=0; i--)
    u= bufs[i]->buf->name | u;
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 216 of file new_buffer.cpp.

                           {
  int nr= find_buffer (name);
  if (nr == -1) return "";
  tm_buffer buf= bufs[nr];
  return subtree (the_et, buf->rp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string get_doc_title ( tree  t) [static]

Definition at line 420 of file new_buffer.cpp.

                       {
  if (is_atomic (t)) return "";
  if (is_compound (t, "doc-title") ||
      is_compound (t, "tmdoc-title") ||
      is_compound (t, "tmdoc-title*") ||
      is_compound (t, "tmweb-title"))
    return tree_to_verbatim (t[0]);
  else {
    for (int i=0; i<N(t); i++) {
      string r= get_doc_title (t[i]);
      if (r != "") return r;
    }
    return "";
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string get_help_title ( url  name,
tree  t 
)

Definition at line 437 of file new_buffer.cpp.

                                  {
  string s= get_doc_title (t);
  if (s == "") return "Help - " * as_string (tail (name));
  else return "Help - " * s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 133 of file new_buffer.cpp.

                   {
  tm_buffer buf= get_buffer ();
  if (!is_none (buf->buf->extra)) return buf->buf->extra;
  return buf->buf->name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 140 of file new_buffer.cpp.

                         {
  int nr= find_buffer (p);
  if (nr == -1) return url_none ();
  return bufs[nr]->buf->name;
}

Here is the call graph for this function:

Definition at line 127 of file new_buffer.cpp.

                   {
  tm_buffer buf= get_buffer ();
  return buf->buf->name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_aux_buffer ( url  name)

Definition at line 186 of file new_buffer.cpp.

                         {
  int nr= find_buffer (name);
  if (nr == -1) return false;
  else return !is_none (bufs[nr]->buf->extra);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void kill_buffer ( )

Definition at line 302 of file new_buffer.cpp.

               {
  int i, nr;
  if (N(bufs) <= 1) get_server () -> quit();
  tm_buffer buf= get_buffer();
  for (nr=0; nr<N(bufs); nr++) if (buf == bufs[nr]) break;
  ASSERT (nr != N(bufs), "buffer not found");
  for (nr=0; nr<N(bufs); nr++) if (buf != bufs[nr]) break;
  ASSERT (nr != N(bufs), "no suitable new buffer");
  tm_buffer new_buf = bufs[nr];

  for (i=0; i<N(buf->vws); i++) {
    tm_view old_vw= buf->vws[i];
    if (old_vw->win != NULL) {
      tm_window win = old_vw->win;
      tm_view new_vw= get_passive_view (new_buf);
      detach_view (old_vw);
      attach_view (win, new_vw);
      if (get_view () == old_vw) set_view (new_vw);
    }
  }
  delete_buffer (buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double last_visited ( url  name)

Definition at line 193 of file new_buffer.cpp.

                        {
  int nr= find_buffer (name);
  if (nr == -1) return (double) texmacs_time ();
  else return (double) bufs[nr]->buf->last_visit;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 99 of file new_buffer.cpp.

                      {
  string name= as_string (tail (u));
  if (starts (name, "no_name_") && ends (name, ".tm")) {
    string no_name= translate ("No name");
    for (int i=0; i<N(no_name); i++)
      if (((unsigned char) (no_name[i])) >= (unsigned char) 128)
       { no_name= "No name"; break; }
    name= no_name * " [" * name (8, N(name) - 3) * "]";
  }
  if ((name == "") || (name == "."))
    name= as_string (tail (u * url_parent ()));
  if ((name == "") || (name == "."))
    name= as_string (u);
  if (is_rooted_tmfs (u))
    name= as_string (call ("tmfs-name", as_string (u)));

  int i, j;
  for (j=1; true; j++) {
    bool flag= true;
    string ret (name);
    if (j>1) ret= name * " (" * as_string (j) * ")";
    for (i=0; i<N(bufs); i++)
      if (bufs[i]->buf->abbr == ret) flag= false;
    if (flag) return ret;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool no_bufs ( )

Definition at line 63 of file new_buffer.cpp.

           {
  return N(bufs) == 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nr_bufs ( )

Definition at line 58 of file new_buffer.cpp.

           {
  return N(bufs);
}

Here is the call graph for this function:

void revert_buffer ( url  name,
tree  doc 
)

Definition at line 266 of file new_buffer.cpp.

                                   {
  int i, nr= find_buffer (name);
  if (nr == -1) return;
  tm_buffer buf= bufs[nr];
  tree body= detach_data (doc, buf->data);
  if (N(buf->vws)==0) set_document (buf->rp, body);
  else for (i=0; i<N(buf->vws); i++) {
    tm_view vw= buf->vws[i];
    if (i==0) assign (vw->ed->rp, body);
    vw->ed->set_data (buf->data);
    vw->ed->notify_save ();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void revert_buffer ( )

Definition at line 281 of file new_buffer.cpp.

                 {
  tm_buffer buf= get_buffer ();
  web_cache_invalidate (buf->buf->name);
  tree doc= load_tree (buf->buf->name, buf->buf->fm);
  if (doc == "error") set_message ("Error: file not found", "revert buffer");
  else revert_buffer (buf->buf->name, doc);
}

Here is the call graph for this function:

void set_abbr_buffer ( url  name,
string  abbr 
)

Definition at line 162 of file new_buffer.cpp.

                                        {
  int nr= find_buffer (name);
  if (nr == -1) return;
  tm_buffer buf= bufs[nr];
  if (buf->buf->abbr == abbr) return;
  buf->buf->abbr= abbr;
  for (int i=0; i<N(buf->vws); i++) {
    tm_view vw2= buf->vws[i];
    if (vw2->win != NULL) {
      vw2->win->set_window_name (buf->buf->abbr);
      vw2->win->set_window_url (is_none (buf->buf->extra)?
                                buf->buf->name: buf->buf->extra);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_aux ( string  aux,
url  name 
)

Definition at line 391 of file new_buffer.cpp.

                               {
  int i, nr= find_buffer (aux);
  if (nr != -1) {
    tm_buffer buf= bufs[nr];
    buf->buf->extra= name;
    if (starts (aux, "Help - ")) {
      buf->buf->fm= "help";
      buf->buf->read_only= true;
    }
    for (i=0; i<N(buf->vws); i++) {
      tm_view vw= buf->vws[i];
      vw->ed->set_base_name (name);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_aux_buffer ( string  aux,
url  name,
tree  doc 
)

Definition at line 408 of file new_buffer.cpp.

                                                {
  int nr= find_buffer (aux);
  if (nr == -1) create_buffer (aux, doc);
  else revert_buffer (aux, doc);
  nr= find_buffer (aux);
  if (nr != -1) {
    set_aux (aux, name);
    switch_to_buffer (nr);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_buffer_tree ( url  name,
tree  doc 
)

Definition at line 207 of file new_buffer.cpp.

                                     {
  int nr= find_buffer (name);
  if (nr == -1) create_buffer (name, tree (DOCUMENT, ""));
  nr= find_buffer (name);
  tm_buffer buf= bufs[nr];
  assign (buf->rp, doc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_help_buffer ( url  name,
tree  doc 
)

Definition at line 444 of file new_buffer.cpp.

                                     {
  set_aux_buffer (get_help_title (name, doc), name, doc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_name_buffer ( url  name)

Definition at line 147 of file new_buffer.cpp.

                           {
  tm_buffer buf= get_buffer ();
  if (buf->buf->name == name) return;
  buf->buf->name= name;
  set_abbr_buffer (name, new_menu_name (name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void switch_to_active_buffer ( url  name)

Definition at line 363 of file new_buffer.cpp.

                                   {
  // This function is a temporary hack for coq
  // Switching to buffers in other windows should be completely rewritten

  int nr= find_buffer (name);
  if (nr == -1) {
    load_passive_buffer (name);
    nr= find_buffer (name);
  }
  if (nr != -1) {
    int i;
    tm_buffer buf= bufs[nr];
    for (i=0; i<N(buf->vws); i++) // search active view
      if (buf->vws[i]->win != NULL) {
        tm_view vw= buf->vws[i];
        set_view (vw);
        buf->buf->last_visit= texmacs_time ();
        return;
      }
  }
  switch_to_buffer (name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void switch_to_buffer ( int  nr)

Definition at line 330 of file new_buffer.cpp.

                          {
  // cout << "Switching to buffer " << nr << "\n";
  tm_window win    = get_window ();
  tm_buffer buf    = bufs[nr];
  tm_view   old_vw = get_view ();
  tm_view   new_vw = get_passive_view (buf);
  detach_view (old_vw);
  attach_view (win, new_vw);
  set_view (new_vw);
  buf->buf->last_visit= texmacs_time ();
  tm_window nwin= new_vw->win;
  nwin->set_shrinking_factor (nwin->get_shrinking_factor ());
  // cout << "Switched to buffer " << nr << "\n";
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool switch_to_buffer ( path  p)

Definition at line 346 of file new_buffer.cpp.

                          {
  int nr= find_buffer (p);
  if (nr != -1) switch_to_buffer (nr);
  return nr != -1;
}

Here is the call graph for this function:

void switch_to_buffer ( url  name)

Definition at line 353 of file new_buffer.cpp.

                            {
  int nr= find_buffer (name);
  if (nr == -1) {
    load_passive_buffer (name);
    nr= find_buffer (name);
  }
  if (nr != -1) switch_to_buffer (nr);
}

Here is the call graph for this function:


Variable Documentation

Definition at line 21 of file new_buffer.cpp.