static void bufed_select(EditState *s, int temp) { BufedState *bs = s->mode_data; StringItem *item; EditBuffer *b; EditState *e; int index; index = list_get_pos(s); if (index < 0 || index >= bs->items.nb_items) return; if (temp && index == bs->last_index) return; item = bs->items.items[index]; b = eb_find(item->str); if (!b) return; e = find_window(s, KEY_RIGHT); if (temp) { if (e) { bs->last_index = index; switch_to_buffer(e, b); } return; } if (e) { /* delete dired window */ do_delete_window(s, 1); switch_to_buffer(e, b); } else { switch_to_buffer(s, b); } }
static void build_bufed_list(EditState *s) { QEmacsState *qs = s->qe_state; EditBuffer *b, *b1; BufedState *hs; int last_index = list_get_pos(s); int i, flags; hs = s->mode_data; free_strings(&hs->items); for (b = qs->first_buffer; b != NULL; b = b->next) { if (!(b->flags & BF_SYSTEM) || (hs->flags & BUFED_ALL_VISIBLE)) add_string(&hs->items, b->name); } /* build buffer */ b = s->b; flags = b->flags; b->flags &= ~BF_READONLY; eb_delete(b, 0, b->total_size); for (i = 0; i < hs->items.nb_items; i++) { eb_printf(b, " %-20s", hs->items.items[i]->str); b1 = eb_find(hs->items.items[i]->str); if (b1) { /* CG: should also display mode */ eb_printf(b, " %10d %s", b1->total_size, b1->filename); } eb_printf(b, "\n"); } b->flags = flags; s->offset = eb_goto_pos(s->b, last_index, 0); }
static void do_compile(EditState *e, const char *cmd) { const char *argv[4]; EditBuffer *b; /* if the buffer already exists, kill it */ b = eb_find("*compilation*"); if (b) { /* XXX: e should not become invalid */ b->modified = 0; do_kill_buffer(e, "*compilation*"); } error_offset = -1; last_line_num = -1; /* create new buffer */ argv[0] = "/bin/sh"; argv[1] = "-c"; argv[2] = (char *)cmd; argv[3] = NULL; b = new_shell_buffer("*compilation*", "/bin/sh", argv, 0); if (!b) return; /* XXX: try to split window if necessary */ switch_to_buffer(e, b); }
static void latex_cmd_run(void *opaque, char *cmd) { struct latex_function *func = (struct latex_function *)opaque; char *argv[4], cwd[1024]; char *wd, *p; int len; if(cmd == 0) { put_status(func->es, "aborted"); return; } argv[0] = "/bin/sh"; argv[1] = "-c"; argv[2] = cmd; argv[3] = NULL; getcwd(cwd, sizeof(cwd)); /* get the directory of the open file and change into it */ p = strrchr(func->es->b->filename, '/'); if(p == func->es->b->filename) p++; len = p - func->es->b->filename + 1; wd = (char *)malloc(len); pstrcpy(wd, len, func->es->b->filename); chdir(wd); free(wd); if(func->output_to_buffer) { /* if the buffer already exists, kill it */ EditBuffer *b = eb_find("*LaTeX output*"); if (b) { /* XXX: e should not become invalid */ b->modified = 0; do_kill_buffer(func->es, "*LaTeX output*"); } /* create new buffer */ b = new_shell_buffer("*LaTeX output*", "/bin/sh", argv, 0); if (b) /* XXX: try to split window if necessary */ switch_to_buffer(func->es, b); } else { int pid = fork(); if (pid == 0) { /* child process */ setsid(); execv("/bin/sh", (char *const*)argv); exit(1); } } chdir(cwd); }
static EditBuffer *bufed_get_buffer(EditState *s) { BufedState *bs = s->mode_data; int index; index = list_get_pos(s); if (index < 0 || index >= bs->items.nb_items) return NULL; return eb_find(bs->items.items[index]->str); }
/* rename a buffer and add characters so that the name is unique */ void set_buffer_name(EditBuffer *b, const char *name1) { char name[sizeof(b->name)]; int n, pos; pstrcpy(name, sizeof(b->name) - 10, name1); /* set the buffer name to NULL since it will be changed */ b->name[0] = '\0'; pos = strlen(name); n = 2; while (eb_find(name) != NULL) { sprintf(name + pos, "<%d>", n); n++; } pstrcpy(b->name, sizeof(b->name), name); }
static void do_shell(EditState *s, int force) { QEmacsState *qs = s->qe_state; EditState *e; EditBuffer *b; const char *argv[3]; const char *shell_path; /* CG: Should prompt for buffer name if arg: * find a syntax for optional string argument w/ prompt */ /* find shell buffer if any */ if (!force || force == NO_ARG) { b = eb_find("*shell*"); if (b) { e = edit_find(b); if (e) qs->active_window = e; else switch_to_buffer(s, b); return; } } /* find shell name */ shell_path = getenv("SHELL"); if (!shell_path) shell_path = "/bin/sh"; /* create new buffer */ argv[0] = shell_path; argv[1] = NULL; b = new_shell_buffer("*shell*", shell_path, argv, 1); if (!b) return; switch_to_buffer(s, b); do_set_mode(s, &shell_mode, NULL); put_status(s, "Press C-o to toggle between shell/edit mode"); shell_launched = 1; }
static void bufed_select(EditState *s) { BufedState *bs = s->mode_data; StringItem *item; EditBuffer *b; EditState *e; int index; index = list_get_pos(s); if (index < 0 || index >= bs->items.nb_items) return; item = bs->items.items[index]; b = eb_find(item->str); if (!b) return; e = find_window_right(s); if (!e) return; /* delete dired window */ do_delete_window(s, 1); switch_to_buffer(e, b); }
static void do_compile_error(EditState *s, int dir) { QEmacsState *qs = s->qe_state; EditState *e; EditBuffer *b; int offset, offset1, found_offset; char filename[MAX_FILENAME_SIZE], *q; int line_num, c; /* CG: should have a buffer flag for error source. * first check if current buffer is an error source. * if not, then scan for appropriate error source * in buffer least recently used order */ if ((b = eb_find("*compilation*")) == NULL && (b = eb_find("*shell*")) == NULL && (b = eb_find("*errors*")) == NULL) { put_status(s, "No compilation buffer"); return; } /* find next/prev error */ offset = error_offset; if (offset < 0) { offset = 0; goto find_error; } for (;;) { if (dir > 0) { if (offset >= b->total_size) { put_status(s, "No more errors"); return; } for (;;) { c = eb_nextc(b, offset, &offset); if (c == '\n') break; } } else { if (offset <= 0) { put_status(s, "No previous error"); return; } eb_prevc(b, offset, &offset); for (;;) { c = eb_prevc(b, offset, &offset1); if (c == '\n') break; offset = offset1; } } find_error: found_offset = offset; /* extract filename */ q = filename; for (;;) { c = eb_nextc(b, offset, &offset); if (c == '\n' || c == '\t' || c == ' ') goto next_line; if (c == ':') break; if ((q - filename) < (int)sizeof(filename) - 1) *q++ = c; } *q = '\0'; /* extract line number */ line_num = 0; for (;;) { c = eb_nextc(b, offset, &offset); if (c == ':') break; if (!isdigit(c)) goto next_line; line_num = line_num * 10 + c - '0'; } if (line_num >= 1) { if (line_num != last_line_num || strcmp(filename, last_filename) != 0) { last_line_num = line_num; pstrcpy(last_filename, sizeof(last_filename), filename); break; } } next_line: offset = found_offset; } error_offset = found_offset; /* update offsets */ for (e = qs->first_window; e != NULL; e = e->next_window) { if (e->b == b) { e->offset = error_offset; } } /* CG: Should remove popups, sidepanes, helppanes... */ /* go to the error */ do_load(s, filename); do_goto_line(s, line_num); }
static void do_compile_error(EditState *s, int dir) { QEmacsState *qs = &qe_state; EditState *e; EditBuffer *b; int offset, offset1, found_offset; char filename[1024], *q; int line_num, c; b = eb_find("*compilation*"); if (!b) { b = eb_find("*shell*"); if (!b) { put_status(s, "No compilation buffer"); return; } } /* find next/prev error */ offset = error_offset; if (offset < 0) { offset = 0; goto find_error; } for(;;) { if (dir > 0) { if (offset >= b->total_size) { put_status(s, "No more errors"); return; } for(;;) { c = eb_nextc(b, offset, &offset); if (c == '\n') break; } } else { if (offset <= 0) { put_status(s, "No previous error"); return; } eb_prevc(b, offset, &offset); for(;;) { c = eb_prevc(b, offset, &offset1); if (c == '\n') break; offset = offset1; } } find_error: found_offset = offset; /* extract filename */ q = filename; for(;;) { c = eb_nextc(b, offset, &offset); if (c == '\n' || c == '\t' || c == ' ') goto next_line; if (c == ':') break; if ((q - filename) < sizeof(filename) - 1) *q++ = c; } *q = '\0'; /* extract line number */ line_num = 0; for(;;) { c = eb_nextc(b, offset, &offset); if (c == ':') break; if (!isdigit(c)) goto next_line; line_num = line_num * 10 + c - '0'; } if (line_num >= 1) { if (line_num != last_line_num || strcmp(filename, last_filename) != 0) { last_line_num = line_num; pstrcpy(last_filename, sizeof(last_filename), filename); break; } } next_line: offset = found_offset; } error_offset = found_offset; /* update offsets */ for(e = qs->first_window; e != NULL; e = e->next_window) { if (e->b == b) { e->offset = error_offset; } } /* go to the error */ do_load(s, filename); do_goto_line(s, line_num); }