329 |
|
|
330 |
void do_global_set_key(EditState *s, const char *keystr, const char *cmd_name) |
void do_global_set_key(EditState *s, const char *keystr, const char *cmd_name) |
331 |
{ |
{ |
332 |
int key, nb_keys; |
int nb_keys; |
333 |
unsigned int keys[MAX_KEYS]; |
unsigned int keys[MAX_KEYS]; |
|
const char *p; |
|
334 |
CmdDef *d; |
CmdDef *d; |
335 |
|
|
336 |
p = keystr; |
nb_keys = strtokeys(keystr, keys, MAX_KEYS); |
337 |
nb_keys = 0; |
if (!nb_keys) |
338 |
for(;;) { |
return; |
339 |
skip_spaces(&p); |
|
|
if (*p == '\0') |
|
|
break; |
|
|
key = strtokey(&p); |
|
|
keys[nb_keys++] = key; |
|
|
if (nb_keys >= MAX_KEYS) |
|
|
break; |
|
|
} |
|
340 |
d = qe_find_cmd(cmd_name); |
d = qe_find_cmd(cmd_name); |
341 |
if (!d) |
if (!d) |
342 |
return; |
return; |
1673 |
void do_save(EditState *s, int save_as); |
void do_save(EditState *s, int save_as); |
1674 |
void do_isearch(EditState *s, int dir); |
void do_isearch(EditState *s, int dir); |
1675 |
void do_refresh(EditState *s); |
void do_refresh(EditState *s); |
1676 |
|
void do_refresh_complete(EditState *s); |
1677 |
|
|
1678 |
/* compute string for the first part of the mode line (flags, |
/* compute string for the first part of the mode line (flags, |
1679 |
filename, modename) */ |
filename, modename) */ |
1760 |
} |
} |
1761 |
} |
} |
1762 |
|
|
1763 |
|
void display_window_borders(EditState *e) |
1764 |
|
{ |
1765 |
|
QEmacsState *qs = e->qe_state; |
1766 |
|
|
1767 |
|
if (e->borders_invalid) { |
1768 |
|
if (e->flags & (WF_POPUP | WF_RSEPARATOR)) { |
1769 |
|
CSSRect rect; |
1770 |
|
QEColor color; |
1771 |
|
|
1772 |
|
rect.x1 = 0; |
1773 |
|
rect.y1 = 0; |
1774 |
|
rect.x2 = qs->width; |
1775 |
|
rect.y2 = qs->height; |
1776 |
|
set_clip_rectangle(qs->screen, &rect); |
1777 |
|
color = qe_styles[QE_STYLE_WINDOW_BORDER].bg_color; |
1778 |
|
if (e->flags & WF_POPUP) { |
1779 |
|
fill_rectangle(qs->screen, |
1780 |
|
e->x1, e->y1, |
1781 |
|
qs->border_width, e->y2 - e->y1, color); |
1782 |
|
fill_rectangle(qs->screen, |
1783 |
|
e->x2 - qs->border_width, e->y1, |
1784 |
|
qs->border_width, e->y2 - e->y1, color); |
1785 |
|
fill_rectangle(qs->screen, |
1786 |
|
e->x1, e->y1, |
1787 |
|
e->x2 - e->x1, qs->border_width, color); |
1788 |
|
fill_rectangle(qs->screen, |
1789 |
|
e->x1, e->y2 - qs->border_width, |
1790 |
|
e->x2 - e->x1, qs->border_width, color); |
1791 |
|
} |
1792 |
|
if (e->flags & WF_RSEPARATOR) { |
1793 |
|
fill_rectangle(qs->screen, |
1794 |
|
e->x2 - qs->separator_width, e->y1, |
1795 |
|
qs->separator_width, e->y2 - e->y1, color); |
1796 |
|
} |
1797 |
|
} |
1798 |
|
e->borders_invalid = 0; |
1799 |
|
} |
1800 |
|
} |
1801 |
|
|
1802 |
/* compute style */ |
/* compute style */ |
1803 |
static void apply_style(QEStyleDef *style, int style_index) |
static void apply_style(QEStyleDef *style, int style_index) |
1804 |
{ |
{ |
3352 |
s->mode->display(s); |
s->mode->display(s); |
3353 |
|
|
3354 |
display_mode_line(s); |
display_mode_line(s); |
3355 |
|
display_window_borders(s); |
3356 |
} |
} |
3357 |
|
|
3358 |
/* display all windows */ |
/* display all windows */ |
3368 |
s->mode->display_hook(s); |
s->mode->display_hook(s); |
3369 |
} |
} |
3370 |
|
|
3371 |
/* first display popups and minibuf */ |
/* count popups */ |
3372 |
|
/* CG: maybe a separate list for popups? */ |
3373 |
has_popups = 0; |
has_popups = 0; |
3374 |
for (s = qs->first_window; s != NULL; s = s->next_window) { |
for (s = qs->first_window; s != NULL; s = s->next_window) { |
3375 |
if (s->flags & WF_POPUP) { |
if (s->flags & WF_POPUP) { |
|
window_display(s); |
|
3376 |
has_popups = 1; |
has_popups = 1; |
|
} else if (s->minibuf) { |
|
|
window_display(s); |
|
3377 |
} |
} |
3378 |
} |
} |
3379 |
|
|
3380 |
if (!has_popups) { |
/* refresh normal windows and minibuf with popup kludge */ |
3381 |
for(s = qs->first_window; s != NULL; s = s->next_window) { |
for (s = qs->first_window; s != NULL; s = s->next_window) { |
3382 |
if (!s->minibuf) |
if (!(s->flags & WF_POPUP) && |
3383 |
window_display(s); |
(s->minibuf || !has_popups || qs->complete_refresh)) { |
3384 |
} |
window_display(s); |
3385 |
|
} |
3386 |
|
} |
3387 |
|
/* refresh popups if any */ |
3388 |
|
if (has_popups) { |
3389 |
|
for (s = qs->first_window; s != NULL; s = s->next_window) { |
3390 |
|
if (s->flags & WF_POPUP) { |
3391 |
|
if (qs->complete_refresh) |
3392 |
|
/* refresh frame */; |
3393 |
|
window_display(s); |
3394 |
|
} |
3395 |
|
} |
3396 |
} |
} |
3397 |
|
|
3398 |
|
qs->complete_refresh = 0; |
3399 |
} |
} |
3400 |
|
|
3401 |
void do_universal_argument(EditState *s) |
void do_universal_argument(EditState *s) |
3486 |
} |
} |
3487 |
} |
} |
3488 |
|
|
3489 |
|
void do_execute_macro_keys(EditState *s, const char *keys) |
3490 |
|
{ |
3491 |
|
int key; |
3492 |
|
const char *p; |
3493 |
|
|
3494 |
|
p = keys; |
3495 |
|
for (;;) { |
3496 |
|
skip_spaces(&p); |
3497 |
|
if (*p == '\0') |
3498 |
|
break; |
3499 |
|
key = strtokey(&p); |
3500 |
|
qe_key_process(key); |
3501 |
|
} |
3502 |
|
} |
3503 |
|
|
3504 |
|
void do_define_kbd_macro(EditState *s, const char *name, const char *keys, |
3505 |
|
const char *keystr) |
3506 |
|
{ |
3507 |
|
CmdDef *def; |
3508 |
|
int size; |
3509 |
|
char *macro_name, *p; |
3510 |
|
|
3511 |
|
size = strlen(name) + 1; |
3512 |
|
macro_name = malloc(size + 2); |
3513 |
|
memcpy(macro_name, name, size); |
3514 |
|
p = macro_name + size; |
3515 |
|
*p++ = 'S'; |
3516 |
|
*p++ = '\0'; |
3517 |
|
|
3518 |
|
def = malloc(2 * sizeof(CmdDef)); |
3519 |
|
memset(def, 0, sizeof(CmdDef) * 2); |
3520 |
|
def->key = def->alt_key = KEY_NONE; |
3521 |
|
def->name = macro_name; |
3522 |
|
def->action.func = do_execute_macro_keys; |
3523 |
|
def->val = strdup(keystr); |
3524 |
|
|
3525 |
|
qe_register_cmd_table(def, NULL); |
3526 |
|
do_global_set_key(s, keystr, name); |
3527 |
|
} |
3528 |
|
|
3529 |
#define MACRO_KEY_INCR 64 |
#define MACRO_KEY_INCR 64 |
3530 |
|
|
3531 |
static void macro_add_key(int key) |
static void macro_add_key(int key) |
3602 |
EditState *s; |
EditState *s; |
3603 |
KeyDef *kd; |
KeyDef *kd; |
3604 |
CmdDef *d; |
CmdDef *d; |
3605 |
char buf1[32]; |
char buf1[128]; |
3606 |
int len; |
int len; |
3607 |
|
|
3608 |
if (qs->defining_macro) { |
if (qs->defining_macro) { |
3628 |
|
|
3629 |
/* special case for escape : we transform it as meta so |
/* special case for escape : we transform it as meta so |
3630 |
that unix users are happy ! */ |
that unix users are happy ! */ |
3631 |
|
/* CG: should allow for other key compositions, such as |
3632 |
|
* diacritics, and compositions of more than 2 keys |
3633 |
|
*/ |
3634 |
if (key == KEY_ESC) { |
if (key == KEY_ESC) { |
3635 |
c->is_escape = 1; |
c->is_escape = 1; |
3636 |
goto next; |
goto next; |
3637 |
} else if (c->is_escape) { |
} else if (c->is_escape) { |
3638 |
if (c->nb_keys >= 2) { |
compose_keys(c->keys, &c->nb_keys); |
|
c->nb_keys--; |
|
|
c->keys[c->nb_keys - 1] = KEY_META(key); |
|
|
} |
|
3639 |
c->is_escape = 0; |
c->is_escape = 0; |
3640 |
} |
} |
3641 |
|
|
3679 |
} |
} |
3680 |
} |
} |
3681 |
} |
} |
3682 |
qe_key_init(); |
if (!c->describe_key) |
3683 |
|
/* CG: should beep */; |
3684 |
|
|
3685 |
|
put_status(s, "No command on %s", |
3686 |
|
keys_to_str(buf1, sizeof(buf1), c->keys, c->nb_keys)); |
3687 |
c->describe_key = 0; |
c->describe_key = 0; |
3688 |
|
qe_key_init(); |
3689 |
|
dpy_flush(&global_screen); |
3690 |
|
return; |
3691 |
} else if (c->nb_keys == kd->nb_keys) { |
} else if (c->nb_keys == kd->nb_keys) { |
3692 |
exec_cmd: |
exec_cmd: |
3693 |
d = kd->cmd; |
d = kd->cmd; |
3706 |
} |
} |
3707 |
} |
} |
3708 |
if (c->describe_key) { |
if (c->describe_key) { |
|
char buf1[128]; |
|
3709 |
put_status(s, "%s runs the command %s", |
put_status(s, "%s runs the command %s", |
3710 |
keys_to_str(buf1, sizeof(buf1), c->keys, c->nb_keys), |
keys_to_str(buf1, sizeof(buf1), c->keys, c->nb_keys), |
3711 |
d->name); |
d->name); |
3722 |
next: |
next: |
3723 |
/* display key pressed */ |
/* display key pressed */ |
3724 |
if (!s->minibuf) { |
if (!s->minibuf) { |
3725 |
|
/* Should print argument if any in a more readable way */ |
3726 |
keytostr(buf1, sizeof(buf1), key); |
keytostr(buf1, sizeof(buf1), key); |
3727 |
len = strlen(c->buf); |
len = strlen(c->buf); |
3728 |
if (len >= 1) |
if (len >= 1) |
3897 |
EditState *edit_new(EditBuffer *b, |
EditState *edit_new(EditBuffer *b, |
3898 |
int x1, int y1, int width, int height, int flags) |
int x1, int y1, int width, int height, int flags) |
3899 |
{ |
{ |
3900 |
|
/* b may be NULL ??? */ |
3901 |
EditState *s; |
EditState *s; |
3902 |
QEmacsState *qs = &qe_state; |
QEmacsState *qs = &qe_state; |
3903 |
|
|
3921 |
return s; |
return s; |
3922 |
} |
} |
3923 |
|
|
3924 |
|
/* detach the window from the window tree. */ |
3925 |
|
void edit_detach(EditState *s) |
3926 |
|
{ |
3927 |
|
QEmacsState *qs = s->qe_state; |
3928 |
|
EditState **ep; |
3929 |
|
|
3930 |
|
for (ep = &qs->first_window; *ep; ep = &(*ep)->next_window) { |
3931 |
|
if (*ep == s) { |
3932 |
|
*ep = s->next_window; |
3933 |
|
s->next_window = NULL; |
3934 |
|
break; |
3935 |
|
} |
3936 |
|
} |
3937 |
|
if (qs->active_window == s) |
3938 |
|
qs->active_window = qs->first_window; |
3939 |
|
} |
3940 |
|
|
3941 |
|
/* attach the window to the window list. */ |
3942 |
|
void edit_attach(EditState *s, EditState **ep) |
3943 |
|
{ |
3944 |
|
s->next_window = *ep; |
3945 |
|
*ep = s; |
3946 |
|
} |
3947 |
|
|
3948 |
/* close the edit window. If it is active, find another active |
/* close the edit window. If it is active, find another active |
3949 |
window. If the buffer is only referenced by this window, then save |
window. If the buffer is only referenced by this window, then save |
3950 |
in the buffer all the window state so that it can be recovered. */ |
in the buffer all the window state so that it can be recovered. */ |
4338 |
|
|
4339 |
s = edit_new(b, 0, qs->screen->height - qs->status_height, |
s = edit_new(b, 0, qs->screen->height - qs->status_height, |
4340 |
qs->screen->width, qs->status_height, 0); |
qs->screen->width, qs->status_height, 0); |
4341 |
|
/* Should insert at end of window list */ |
4342 |
do_set_mode(s, &minibuffer_mode, NULL); |
do_set_mode(s, &minibuffer_mode, NULL); |
4343 |
s->prompt = strdup(prompt); |
s->prompt = strdup(prompt); |
4344 |
s->minibuf = 1; |
s->minibuf = 1; |
4391 |
QEmacsState *qs = s->qe_state; |
QEmacsState *qs = s->qe_state; |
4392 |
EditBuffer *b; |
EditBuffer *b; |
4393 |
|
|
4394 |
|
/* CG: should verify that popup_saved_active still exists */ |
4395 |
qs->active_window = popup_saved_active; |
qs->active_window = popup_saved_active; |
4396 |
b = s->b; |
b = s->b; |
4397 |
edit_close(s); |
edit_close(s); |
5183 |
int i, j; |
int i, j; |
5184 |
|
|
5185 |
switch (ch) { |
switch (ch) { |
5186 |
case KEY_BACKSPACE: |
case KEY_DEL: |
5187 |
|
case KEY_BS: /* Should test actual binding of KEY_BS */ |
5188 |
if (is->pos > 0) |
if (is->pos > 0) |
5189 |
is->pos--; |
is->pos--; |
5190 |
break; |
break; |
5425 |
|
|
5426 |
void do_doctor(EditState *s) |
void do_doctor(EditState *s) |
5427 |
{ |
{ |
5428 |
|
/* Should show keys? */ |
5429 |
put_status(s, "Hello, how are you ?"); |
put_status(s, "Hello, how are you ?"); |
5430 |
} |
} |
5431 |
|
|
5454 |
int new_status_height, new_mode_line_height, content_height; |
int new_status_height, new_mode_line_height, content_height; |
5455 |
int width, height; |
int width, height; |
5456 |
|
|
5457 |
|
if (qs->complete_refresh) { |
5458 |
|
if (qs->screen->dpy.dpy_invalidate) |
5459 |
|
qs->screen->dpy.dpy_invalidate(); |
5460 |
|
} |
5461 |
|
|
5462 |
/* recompute various dimensions */ |
/* recompute various dimensions */ |
5463 |
if (qs->screen->media & CSS_MEDIA_TTY) { |
if (qs->screen->media & CSS_MEDIA_TTY) { |
5464 |
qs->separator_width = 1; |
qs->separator_width = 1; |
5521 |
/* invalidate all the edit windows and draw borders */ |
/* invalidate all the edit windows and draw borders */ |
5522 |
for(e = qs->first_window; e != NULL; e = e->next_window) { |
for(e = qs->first_window; e != NULL; e = e->next_window) { |
5523 |
edit_invalidate(e); |
edit_invalidate(e); |
5524 |
if (e->flags & (WF_POPUP | WF_RSEPARATOR)) { |
e->borders_invalid = 1; |
|
CSSRect rect; |
|
|
QEColor color; |
|
|
rect.x1 = 0; |
|
|
rect.y1 = 0; |
|
|
rect.x2 = qs->width; |
|
|
rect.y2 = qs->height; |
|
|
set_clip_rectangle(qs->screen, &rect); |
|
|
color = qe_styles[QE_STYLE_WINDOW_BORDER].bg_color; |
|
|
if (e->flags & WF_POPUP) { |
|
|
fill_rectangle(qs->screen, |
|
|
e->x1, e->y1, |
|
|
qs->border_width, e->y2 - e->y1, color); |
|
|
fill_rectangle(qs->screen, |
|
|
e->x2 - qs->border_width, e->y1, |
|
|
qs->border_width, e->y2 - e->y1, color); |
|
|
fill_rectangle(qs->screen, |
|
|
e->x1, e->y1, |
|
|
e->x2 - e->x1, qs->border_width, color); |
|
|
fill_rectangle(qs->screen, |
|
|
e->x1, e->y2 - qs->border_width, |
|
|
e->x2 - e->x1, qs->border_width, color); |
|
|
} |
|
|
if (e->flags & WF_RSEPARATOR) { |
|
|
fill_rectangle(qs->screen, |
|
|
e->x2 - qs->separator_width, e->y1, |
|
|
qs->separator_width, e->y2 - e->y1, color); |
|
|
} |
|
|
} |
|
5525 |
} |
} |
5526 |
/* invalidate status line */ |
/* invalidate status line */ |
5527 |
qs->status_shadow[0] = '\0'; |
qs->status_shadow[0] = '\0'; |
5528 |
put_status(NULL, " "); |
put_status(NULL, " "); |
5529 |
} |
} |
5530 |
|
|
5531 |
|
void do_refresh_complete(EditState *s) |
5532 |
|
{ |
5533 |
|
QEmacsState *qs = s->qe_state; |
5534 |
|
|
5535 |
|
qs->complete_refresh = 1; |
5536 |
|
do_refresh(s); |
5537 |
|
} |
5538 |
|
|
5539 |
void do_other_window(EditState *s) |
void do_other_window(EditState *s) |
5540 |
{ |
{ |
5541 |
QEmacsState *qs = s->qe_state; |
QEmacsState *qs = s->qe_state; |
5615 |
if (e) |
if (e) |
5616 |
compute_client_area(e); |
compute_client_area(e); |
5617 |
} |
} |
5618 |
|
if (qs->active_window == s) |
5619 |
|
qs->active_window = e ? e : qs->first_window; |
5620 |
edit_close(s); |
edit_close(s); |
5621 |
if (qs->first_window) |
if (qs->first_window) |
5622 |
do_refresh(qs->first_window); |
do_refresh(qs->first_window); |
5646 |
/* XXX: add minimum size test and refuse to split if reached */ |
/* XXX: add minimum size test and refuse to split if reached */ |
5647 |
void do_split_window(EditState *s, int horiz) |
void do_split_window(EditState *s, int horiz) |
5648 |
{ |
{ |
5649 |
|
QEmacsState *qs = s->qe_state; |
5650 |
EditState *e; |
EditState *e; |
5651 |
int x, y; |
int x, y; |
5652 |
|
|
5672 |
return; |
return; |
5673 |
s->y2 = y; |
s->y2 = y; |
5674 |
} |
} |
5675 |
|
/* insert in the window list after current window */ |
5676 |
|
edit_detach(e); |
5677 |
|
edit_attach(e, &s->next_window); |
5678 |
|
|
5679 |
|
if (qs->flag_split_window_change_focus) |
5680 |
|
qs->active_window = e; |
5681 |
|
|
5682 |
compute_client_area(s); |
compute_client_area(s); |
5683 |
do_refresh(s); |
do_refresh(s); |
5684 |
} |
} |
5753 |
b->flags |= BF_READONLY; |
b->flags |= BF_READONLY; |
5754 |
if (show) { |
if (show) { |
5755 |
show_popup(b); |
show_popup(b); |
5756 |
eb_free(b); |
//eb_free(b); |
5757 |
} |
} |
5758 |
} |
} |
5759 |
|
|