int find_file(const char *filename) { Buffer *bp; char *s; for (bp = head_bp; bp != NULL; bp = bp->next) if (bp->filename != NULL && !strcmp(bp->filename, filename)) { switch_to_buffer(bp); return TRUE; } s = make_buffer_name(filename); if (strlen(s) < 1) { free(s); return FALSE; } if (!is_regular_file(filename)) { minibuf_error("%s is not a regular file", filename); waitkey(WAITKEY_DEFAULT); return FALSE; } bp = create_buffer(s); free(s); bp->filename = zstrdup(filename); switch_to_buffer(bp); read_from_disk(filename); thisflag |= FLAG_NEED_RESYNC; return TRUE; }
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 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); }
char * term_minibuf_read (const char *prompt, const char *value, size_t pos, Completion * cp, History * hp) { Window *wp, *old_wp = cur_wp; char *s = NULL; astr as; if (hp) prepare_history (hp); as = do_minibuf_read (prompt, value, pos, cp, hp); if (as) { s = xstrdup (astr_cstr (as)); astr_delete (as); } if (cp != NULL && (get_completion_flags (cp) & CFLAG_POPPEDUP) && (wp = find_window ("*Completions*")) != NULL) { set_current_window (wp); if (get_completion_flags (cp) & CFLAG_CLOSE) FUNCALL (delete_window); else if (get_completion_old_bp (cp)) switch_to_buffer (get_completion_old_bp (cp)); set_current_window (old_wp); } return s; }
/* I should try it like emacs--- if prefix argument, then save all without user intervention */ int save_some_buffers (void) { Buffer *b, *tmp; int ans = 0; int err; b = CBuf; do { if ((b->flags & BUFFER_MODIFIED) && (*b->file)) { if (b->flags & AUTO_SAVE_JUST_SAVE) ans = 1; else ans = jed_vget_y_n ("Buffer %s not saved. Save it", b->name); if (ans == -1) /* warning--- bug here if user edits file at startup and forgets to save it then aborts. */ return -1; if (ans == 1) { tmp = CBuf; switch_to_buffer(b); /* It should not be necessary to do this here. Lower * level routines will do it. */ /* while (b->narrow != NULL) widen_buffer(b); */ err = jed_save_buffer_cmd (); switch_to_buffer(tmp); if (err < 0) return -1; /* b->flags &= ~BUFFER_MODIFIED; */ /* b->flags |= AUTO_SAVE_BUFFER; */ b->hits = 0; } } b = b->next; } while (b != CBuf); clear_message (); return 1; }
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 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; }
bool find_file (const char *filename) { Buffer bp; for (bp = head_bp; bp != NULL; bp = get_buffer_next (bp)) if (get_buffer_filename (bp) != NULL && STREQ (get_buffer_filename (bp), filename)) break; if (bp == NULL) { if (exist_file (filename) && !is_regular_file (filename)) { minibuf_error ("File exists but could not be read"); return false; } else { bp = buffer_new (); set_buffer_names (bp, filename); set_buffer_dir (bp, astr_new_cstr (dir_name (filename))); estr es = estr_readf (filename); if (es) set_buffer_readonly (bp, !check_writable (filename)); else es = estr_new_astr (astr_new ()); set_buffer_text (bp, es); /* Reset undo history. */ set_buffer_next_undop (bp, NULL); set_buffer_last_undop (bp, NULL); set_buffer_modified (bp, false); } } switch_to_buffer (bp); thisflag |= FLAG_NEED_RESYNC; return true; }
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_shell(EditState *e) { EditBuffer *b; char *argv[3]; char *shell_path; /* 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(e, b); do_set_mode(e, &shell_mode, NULL); put_status(e, "Press C-o to toggle between shell/edit mode"); shell_launched = 1; }