[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs qe.h qe.c shell.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs qe.h qe.c shell.c |
Date: |
Mon, 8 May 2017 06:26:57 -0400 (EDT) |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 17/05/08 06:26:56
Modified files:
. : qe.h qe.c shell.c
Log message:
shell: simplify do_shell
- publish qe_find_target_window() to bypass dired pane
- simplify do_shell, restart process in last shell buffer
used and switch to interactive mode
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.262&r2=1.263
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.282&r2=1.283
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.132&r2=1.133
Patches:
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.262
retrieving revision 1.263
diff -u -b -r1.262 -r1.263
--- qe.h 7 May 2017 20:32:30 -0000 1.262
+++ qe.h 8 May 2017 10:26:56 -0000 1.263
@@ -2035,6 +2035,7 @@
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);
+EditState *qe_find_target_window(EditState *s, int activate);
void do_find_window(EditState *s, int key);
/* window handling */
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.282
retrieving revision 1.283
diff -u -b -r1.282 -r1.283
--- qe.c 7 May 2017 20:32:30 -0000 1.282
+++ qe.c 8 May 2017 10:26:56 -0000 1.283
@@ -6872,7 +6872,7 @@
return found_modes;
}
-static EditState *qe_find_target_window(EditState *s, int activate) {
+EditState *qe_find_target_window(EditState *s, int activate) {
QEmacsState *qs = s->qe_state;
EditState *e;
Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -b -r1.132 -r1.133
--- shell.c 7 May 2017 20:32:30 -0000 1.132
+++ shell.c 8 May 2017 10:26:56 -0000 1.133
@@ -1973,10 +1973,10 @@
else
status = -1;
if (status == 0) {
- snprintf(buf, sizeof(buf), "\n%s finished at %s",
+ snprintf(buf, sizeof(buf), "\n%s finished at %s\n",
s->caption, time_str);
} else {
- snprintf(buf, sizeof(buf), "\n%s exited abnormally with code %d at
%s",
+ snprintf(buf, sizeof(buf), "\n%s exited abnormally with code %d at
%s\n",
s->caption, status, time_str);
}
}
@@ -2097,85 +2097,79 @@
return b;
}
-static EditBuffer *try_show_buffer(EditState *s, const char *bufname)
+/* If a window is attached to buffer b, activate it,
+ otherwise attach window s to buffer b.
+ */
+static EditBuffer *try_show_buffer(EditState **sp, const char *bufname)
{
+ EditState *e, *s = *sp;
QEmacsState *qs = s->qe_state;
- EditState *e;
EditBuffer *b;
b = eb_find(bufname);
- if (b) {
+ if (b && s->b != b) {
e = eb_find_window(b, NULL);
- if (e)
- qs->active_window = e;
- else
+ if (e) {
+ qs->active_window = *sp = e;
+ } else {
switch_to_buffer(s, b);
}
+ }
return b;
}
-static void do_shell(EditState *s, int force)
+static void do_shell(EditState *e, int force)
{
- ShellState *shs;
EditBuffer *b = NULL;
- if (s->flags & (WF_POPUP | WF_MINIBUF))
+ if (e->flags & (WF_POPUP | WF_MINIBUF))
return;
- if (s->flags & WF_POPLEFT) {
/* avoid messing with the dired pane */
- s = find_window(s, KEY_RIGHT, s);
- s->qe_state->active_window = s;
- }
+ e = qe_find_target_window(e, 1);
- /* 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) {
- /* XXX: if current buffer is a shell buffer without a process,
- * restart shell process in it.
- */
- b = s->b;
- shs = shell_get_state(s, 0);
- if (shs && strstart(b->name, "*shell", NULL)) {
- /* move to end of buffer (start interactive mode) */
- s->offset = b->total_size;
- if (shs->pid >= 0)
- return;
- } else {
- /* Find the last used shell buffer */
- const char *bname = "*shell*";
-
- if ((b = eb_find(error_buffer)) != NULL
- && qe_get_buffer_mode_data(b, &shell_mode, NULL) != NULL) {
- bname = error_buffer;
+ if (strstart(e->b->name, "*shell", NULL)) {
+ /* If the current buffer is a shell buffer, use it */
+ b = e->b;
+ } else {
+ /* Find the last used shell buffer, if any */
+ if (strstart(error_buffer, "*shell", NULL)) {
+ b = try_show_buffer(&e, error_buffer);
}
- b = try_show_buffer(s, bname);
- if (b) {
- shs = qe_get_buffer_mode_data(b, &shell_mode, NULL);
- if (shs && shs->pid >= 0)
- return;
+ if (b == NULL) {
+ b = try_show_buffer(&e, "*shell*");
}
}
if (b) {
- /* restart shell in *shell* buffer */
- s->offset = b->total_size;
+ /* If the process is active, switch to interactive mode */
+ ShellState *s = shell_get_state(e, 0);
+ if (s && s->pid >= 0) {
+ e->offset = b->total_size;
+ if ((s->shell_flags & SF_INTERACTIVE) && !s->grab_keys) {
+ e->offset = s->cur_offset;
+ e->interactive = 1;
+ }
+ return;
+ }
+ /* otherwise, restart the process here */
+ e->offset = b->total_size;
}
}
- /* create new buffer */
- b = new_shell_buffer(b, s, "*shell*", "Shell process", NULL,
+ /* create new shell buffer or restart shell in current buffer */
+ b = new_shell_buffer(b, e, "*shell*", "Shell process", NULL,
SF_COLOR | SF_INTERACTIVE);
if (!b)
return;
b->default_mode = &shell_mode;
- switch_to_buffer(s, b);
- /* set next error reference point, also used for do_shell to determine
- * the last process buffer used */
+ switch_to_buffer(e, b);
+ /* force interactive mode if restarting */
+ shell_mode.mode_init(e, b, 0);
set_error_offset(b, 0);
- put_status(s, "Press C-o to toggle between shell/edit mode");
+ put_status(e, "Press C-o to toggle between shell/edit mode");
}
static void do_man(EditState *s, const char *arg)
@@ -2197,7 +2191,7 @@
snprintf(cmd, sizeof(cmd), "man %s", arg);
snprintf(bufname, sizeof(bufname), "*Man %s*", arg);
- if (try_show_buffer(s, bufname))
+ if (try_show_buffer(&s, bufname))
return;
/* create new buffer */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs qe.h qe.c shell.c,
Charlie Gordon <=