basic: changed API for popup windows

- pass current window to show_popup()
- remove show_ptr argument from new_help_buffer()
- call show_popup() unconditionally
- add int eb_vprintf(EditBuffer *b, const char *fmt, va_list ap);
This commit is contained in:
Charlie Gordon 2017-03-26 15:57:24 +00:00
commit d06fdbfd14
8 changed files with 53 additions and 63 deletions

View file

@ -286,7 +286,7 @@ static void do_list_buffers(EditState *s, int argval)
if (!b)
return;
e = show_popup(b);
e = show_popup(s, b);
if (!e)
return;

View file

@ -2213,20 +2213,19 @@ int eb_puts(EditBuffer *b, const char *s)
return eb_insert_utf8_buf(b, b->total_size, s, strlen(s));
}
int eb_printf(EditBuffer *b, const char *fmt, ...)
int eb_vprintf(EditBuffer *b, const char *fmt, va_list ap)
{
char buf0[1024];
char *buf;
int len, size, written;
va_list ap;
va_list ap2;
va_start(ap, fmt);
va_copy(ap2, ap);
size = sizeof(buf0);
buf = buf0;
len = vsnprintf(buf, size, fmt, ap);
va_end(ap);
len = vsnprintf(buf, size, fmt, ap2);
va_end(ap2);
if (len >= size) {
va_start(ap, fmt);
size = len + 1;
#ifdef CONFIG_WIN32
buf = qe_malloc_bytes(size);
@ -2234,7 +2233,6 @@ int eb_printf(EditBuffer *b, const char *fmt, ...)
buf = alloca(size);
#endif
vsnprintf(buf, size, fmt, ap);
va_end(ap);
}
/* CG: insert buf encoding according to b->charset and b->eol_type.
* buf may contain \0 characters via the %c modifer.
@ -2248,6 +2246,17 @@ int eb_printf(EditBuffer *b, const char *fmt, ...)
return written;
}
int eb_printf(EditBuffer *b, const char *fmt, ...)
{
va_list ap;
int written;
va_start(ap, fmt);
written = eb_vprintf(b, fmt, ap);
va_end(ap);
return written;
}
#if 0
/* pad current line with spaces so that it reaches column n */
void eb_line_pad(EditBuffer *b, int n)

View file

@ -1162,7 +1162,7 @@ static void do_c_list_conditionals(EditState *s)
}
}
if (b->total_size > 0) {
show_popup(b);
show_popup(s, b);
} else {
eb_free(&b);
put_status(s, "Not in a #if conditional");

View file

@ -912,9 +912,8 @@ static void print_bindings(EditBuffer *b, const char *title,
void do_describe_bindings(EditState *s)
{
EditBuffer *b;
int show;
b = new_help_buffer(&show);
b = new_help_buffer();
if (!b)
return;
@ -922,9 +921,7 @@ void do_describe_bindings(EditState *s)
print_bindings(b, "\nGlobal bindings", 0, NULL);
b->flags |= BF_READONLY;
if (show) {
show_popup(b);
}
show_popup(s, b);
}
void do_apropos(EditState *s, const char *str)
@ -934,11 +931,12 @@ void do_apropos(EditState *s, const char *str)
EditBuffer *b;
CmdDef *d;
VarDef *vp;
int found, show;
int found;
b = new_help_buffer(&show);
b = new_help_buffer();
if (!b)
return;
eb_printf(b, "apropos '%s':\n\n", str);
found = 0;
@ -973,12 +971,9 @@ void do_apropos(EditState *s, const char *str)
}
if (found) {
b->flags |= BF_READONLY;
if (show) {
show_popup(b);
}
show_popup(s, b);
} else {
if (show)
eb_free(&b);
eb_free(&b);
put_status(s, "No apropos matches for `%s'", str);
}
}
@ -1035,7 +1030,7 @@ static void do_about_qemacs(EditState *s)
b->flags |= BF_READONLY;
/* Should show window caption "About QEmacs" */
show_popup(b);
show_popup(s, b);
}
static void do_set_region_color(EditState *s, const char *str)
@ -1107,9 +1102,8 @@ static void do_describe_buffer(EditState *s, int argval)
buf_t descbuf, *desc;
EditBuffer *b = s->b;
EditBuffer *b1;
int show;
b1 = new_help_buffer(&show);
b1 = new_help_buffer();
if (!b1)
return;
@ -1299,18 +1293,15 @@ static void do_describe_buffer(EditState *s, int argval)
}
b1->flags |= BF_READONLY;
if (show) {
show_popup(b1);
}
show_popup(s, b1);
}
static void do_describe_window(EditState *s, int argval)
{
EditBuffer *b1;
int show;
int w;
b1 = new_help_buffer(&show);
b1 = new_help_buffer();
if (!b1)
return;
@ -1369,19 +1360,16 @@ static void do_describe_window(EditState *s, int argval)
eb_printf(b1, "\n");
b1->flags |= BF_READONLY;
if (show) {
show_popup(b1);
}
show_popup(s, b1);
}
static void do_describe_screen(EditState *e, int argval)
{
QEditScreen *s = e->screen;
EditBuffer *b1;
int show;
int w;
b1 = new_help_buffer(&show);
b1 = new_help_buffer();
if (!b1)
return;
@ -1400,9 +1388,7 @@ static void do_describe_screen(EditState *e, int argval)
}
b1->flags |= BF_READONLY;
if (show) {
show_popup(b1);
}
show_popup(e, b1);
}
/*---------------- buffer contents sorting ----------------*/

View file

@ -419,7 +419,7 @@ void do_save_session(EditState *s, int popup)
b->flags |= BF_READONLY;
/* Should show window caption "qemacs session" */
show_popup(b);
show_popup(s, b);
} else {
eb_write_buffer(b, 0, b->total_size, ".qesession");
eb_free(&b);

32
qe.c
View file

@ -6159,10 +6159,10 @@ void do_popup_exit(EditState *s)
}
/* show a popup on a readonly buffer */
EditState *show_popup(EditBuffer *b)
EditState *show_popup(EditState *s, EditBuffer *b)
{
QEmacsState *qs = &qe_state;
EditState *s = qs->active_window;
EditState *e;
int w, h, w1, h1;
/* Prevent recursion */
@ -6175,14 +6175,14 @@ EditState *show_popup(EditBuffer *b)
w = (w1 * 4) / 5;
h = (h1 * 3) / 4;
s = edit_new(b, (w1 - w) / 2, (h1 - h) / 2, w, h, WF_POPUP);
edit_set_mode(s, &popup_mode);
s->wrap = WRAP_TRUNCATE;
e = edit_new(b, (w1 - w) / 2, (h1 - h) / 2, w, h, WF_POPUP);
edit_set_mode(e, &popup_mode);
e->wrap = WRAP_TRUNCATE;
popup_saved_active = qs->active_window;
qs->active_window = s;
do_refresh(s);
return s;
qs->active_window = e;
do_refresh(e);
return e;
}
static void popup_init(void)
@ -7526,29 +7526,27 @@ void do_describe_key_briefly(EditState *s)
key_ctx.describe_key = 1;
}
EditBuffer *new_help_buffer(int *show_ptr)
EditBuffer *new_help_buffer(void)
{
EditBuffer *b;
*show_ptr = 0;
b = eb_find("*Help*");
if (b) {
eb_clear(b);
} else {
b = eb_new("*Help*", BF_UTF8);
*show_ptr = 1;
}
return b;
}
void do_help_for_help(qe__unused__ EditState *s)
void do_help_for_help(EditState *s)
{
EditBuffer *b;
int show;
b = new_help_buffer(&show);
b = new_help_buffer();
if (!b)
return;
eb_printf(b,
"QEmacs help for help - Press q to quit:\n"
"\n"
@ -7557,9 +7555,7 @@ void do_help_for_help(qe__unused__ EditState *s)
"C-h c Describe key briefly\n"
);
b->flags |= BF_READONLY;
if (show) {
show_popup(b);
}
show_popup(s, b);
}
#ifdef CONFIG_WIN32
@ -8623,7 +8619,7 @@ static void qe_init(void *opaque)
b = eb_find("*errors*");
if (b != NULL) {
show_popup(b);
show_popup(s, b);
edit_display(qs);
dpy_flush(&global_screen);
}

5
qe.h
View file

@ -1061,6 +1061,7 @@ int eb_insert_str(EditBuffer *b, int offset, const char *str);
int eb_match_uchar(EditBuffer *b, int offset, int c, int *offsetp);
int eb_match_str(EditBuffer *b, int offset, const char *str, int *offsetp);
int eb_match_istr(EditBuffer *b, int offset, const char *str, int *offsetp);
int eb_vprintf(EditBuffer *b, const char *fmt, va_list ap) qe__attr_printf(2,0);
int eb_printf(EditBuffer *b, const char *fmt, ...) qe__attr_printf(2,3);
int eb_puts(EditBuffer *b, const char *s);
int eb_putc(EditBuffer *b, int c);
@ -1842,7 +1843,7 @@ void do_load_qerc(EditState *e, const char *file);
void do_add_resource_path(EditState *s, const char *path);
/* popup / low level window handling */
EditState *show_popup(EditBuffer *b);
EditState *show_popup(EditState *s, EditBuffer *b);
int check_read_only(EditState *s);
EditState *insert_window_left(EditBuffer *b, int width, int flags);
EditState *find_window(EditState *s, int key, EditState *def);
@ -2069,7 +2070,7 @@ void do_delete_hidden_windows(EditState *s);
void do_describe_key_briefly(EditState *s);
void do_show_bindings(EditState *s, const char *cmd_name);
void do_apropos(EditState *s, const char *str);
EditBuffer *new_help_buffer(int *show_ptr);
EditBuffer *new_help_buffer(void);
void do_describe_bindings(EditState *s);
void do_help_for_help(EditState *s);
void qe_event_init(void);

8
x11.c
View file

@ -1878,10 +1878,10 @@ static void x11_list_fonts(EditState *s, int argval)
{
char buf[80];
EditBuffer *b;
int show, i, count;
int i, count;
char **list;
b = new_help_buffer(&show);
b = new_help_buffer();
if (!b)
return;
@ -1900,9 +1900,7 @@ static void x11_list_fonts(EditState *s, int argval)
XFreeFontNames(list);
b->flags |= BF_READONLY;
if (show) {
show_popup(b);
}
show_popup(s, b);
}
static CmdDef x11_commands[] = {