static void print_horizontal_tab_title(struct view *v, int idx) { int skip = v->tt_width - v->tt_truncated_width; const char *filename = buffer_filename(v->buffer); char buf[16]; if (skip > 0) { filename += u_skip_chars(filename, &skip); } snprintf(buf, sizeof(buf), "%c%d%s", obuf.x == 0 && idx > 0 ? '<' : ' ', idx + 1, buffer_modified(v->buffer) ? "+" : ":"); if (v == v->window->view) set_builtin_color(BC_ACTIVETAB); else set_builtin_color(BC_INACTIVETAB); buf_add_str(buf); buf_add_str(filename); if (obuf.x == obuf.width - 1 && idx < v->window->views.count - 1) buf_put_char('>'); else buf_put_char(' '); }
int fmt_motion() { struct range rng; int x[2]; if(motion_wrap(&x[0], &rng.start, &x[1], &rng.end, "", 0)) return 1; buffer_modified(buffers_current()) = 1; return range_through_pipe(&rng, "fmt -80"); }
static void print_vertical_tab_title(struct view *v, int idx, int width) { const char *orig_filename = buffer_filename(v->buffer); const char *filename = orig_filename; int max = options.tab_bar_max_components; char buf[16]; int skip; snprintf(buf, sizeof(buf), "%2d%s", idx + 1, buffer_modified(v->buffer) ? "+" : " "); if (max) { int i, count = 1; for (i = 0; filename[i]; i++) { if (filename[i] == '/') count++; } // ignore first slash because it does not separate components if (filename[0] == '/') count--; if (count > max) { // skip possible first slash for (i = 1; ; i++) { if (filename[i] == '/' && --count == max) { i++; break; } } filename += i; } } else { skip = strlen(buf) + u_str_width(filename) - width + 1; if (skip > 0) filename += u_skip_chars(filename, &skip); } if (filename != orig_filename) { // filename was shortened. add "<<" symbol long i = strlen(buf); u_set_char(buf, &i, 0xab); buf[i] = 0; } if (v == v->window->view) set_builtin_color(BC_ACTIVETAB); else set_builtin_color(BC_INACTIVETAB); buf_add_str(buf); buf_add_str(filename); buf_clear_eol(); }
void buffers_init(int argc, const char **argv, int ro) { int i, bufidx; int read_stdin = 0; if(argc > 0 && !strcmp(argv[0], "-")){ argc--; argv++; read_stdin = 1; fputs("uvi: reading from stdin\n", stderr); } count = argc; arg_ro = ro; fnames = umalloc((count + 1) * sizeof *fnames); bufidx = 0; for(i = 0; i < count; i++){ int j, found = 0; for(j = 0; j < i; j++) if(!strcmp(argv[i], argv[j])){ found = 1; break; } if(!found) fnames[bufidx++] = new_old_buf(argv[i]); } fnames[count = bufidx] = NULL; current = count > 0 ? 0 : -1; if(read_stdin){ current_buf = buffers_readfile(stdin, "-", 1); /* force noro */ buffer_modified(current_buf) = 1; input_reopen(); current = -1; }else if(count > 0){ buffers_goto(0); }else{ current_buf = buffer_new_empty(); } }
int range_through_pipe(struct range *rng, const char *cmd) { struct list *l, *to_pipe; int eno, ret = 0; to_pipe = buffer_extract_range(buffers_current(), rng); l = pipe_readwrite(cmd, to_pipe ? to_pipe : buffer_gethead(buffers_current())); if(l){ if(l->data){ if(to_pipe){ struct list *inshere; inshere = buffer_getindex(buffers_current(), rng->start); if(inshere) buffer_insertlistbefore(buffers_current(), inshere, l); else buffer_appendlist(buffers_current(), l); list_free_nodata(to_pipe); to_pipe = NULL; }else{ buffer_replace(buffers_current(), l); } buffer_modified(buffers_current()) = 1; }else{ /* FIXME? assign to_pipe to "reg? restore into buffer? */ list_free(l, free); ret = 1; } } eno = errno; if(to_pipe) list_free(to_pipe, free); errno = eno; return ret; }
void update_term_title(struct buffer *b) { static int term_type = -1; char title[1024]; if (term_type == -1) { const char *term = getenv("TERM"); term_type = 0; if (term) { if (strstr(term, "xterm") || strstr(term, "rxvt")) { term_type = 1; } else if (streq(term, "screen")) { term_type = 2; } } } // FIXME: title must not contain control characters snprintf(title, sizeof(title), "%s %c %s", buffer_filename(b), buffer_modified(b) ? '+' : '-', program); switch (term_type) { case 1: // xterm or compatible buf_escape("\033]2;"); buf_escape(title); buf_escape("\007"); break; case 2: // tmux or screen // NOTE: screen might need to be configured to get it working buf_escape("\033_"); buf_escape(title); buf_escape("\033\\"); break; } }
void tilde(unsigned int rep) { char *data = (char *)buffer_getindex(buffers_current(), gui_y())->data; char *pos = data + gui_x(); if(!rep) rep = 1; gui_move(gui_y(), gui_x() + rep); while(rep --> 0){ if(islower(*pos)) *pos = toupper(*pos); else *pos = tolower(*pos); /* *pos ^= (1 << 5); * flip bit 100000 = 6 */ if(!*++pos) break; } buffer_modified(buffers_current()) = 1; }