[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs archive.c latex-mode.c qe.h shell.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs archive.c latex-mode.c qe.h shell.c |
Date: |
Sat, 20 May 2017 16:43:15 -0400 (EDT) |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 17/05/20 16:43:15
Modified files:
. : archive.c latex-mode.c qe.h shell.c
Log message:
shell: start process in directory of current window
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/archive.c?cvsroot=qemacs&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.266&r2=1.267
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.135&r2=1.136
Patches:
Index: archive.c
===================================================================
RCS file: /sources/qemacs/qemacs/archive.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- archive.c 15 May 2017 09:58:02 -0000 1.33
+++ archive.c 20 May 2017 20:43:14 -0000 1.34
@@ -144,7 +144,7 @@
eb_printf(b, " Directory of %s archive %s\n",
atp->name, b->filename);
qe_shell_subst(cmd, sizeof(cmd), atp->list_cmd, b->filename, NULL);
- new_shell_buffer(b, NULL, get_basename(b->filename), NULL, cmd,
+ new_shell_buffer(b, NULL, get_basename(b->filename), NULL, NULL, cmd,
atp->sf_flags | SF_INFINITE | SF_BUFED_MODE);
/* XXX: should check for archiver error */
@@ -287,7 +287,7 @@
b->data_type_name = ctp->name;
eb_clear(b);
qe_shell_subst(cmd, sizeof(cmd), ctp->load_cmd, b->filename, NULL);
- new_shell_buffer(b, NULL, get_basename(b->filename), NULL, cmd,
+ new_shell_buffer(b, NULL, get_basename(b->filename), NULL, NULL, cmd,
ctp->sf_flags | SF_INFINITE | SF_AUTO_CODING |
SF_AUTO_MODE);
/* XXX: should check for archiver error */
/* XXX: should delay BF_SAVELOG until buffer is fully loaded */
@@ -375,7 +375,7 @@
eb_clear(b);
qe_shell_subst(cmd, sizeof(cmd), "wget -q -O - $1", b->filename, NULL);
- new_shell_buffer(b, NULL, get_basename(b->filename), NULL, cmd,
+ new_shell_buffer(b, NULL, get_basename(b->filename), NULL, NULL, cmd,
SF_INFINITE | SF_AUTO_CODING | SF_AUTO_MODE);
/* XXX: should refilter by content type */
/* XXX: should have a way to keep http headers --save-headers */
@@ -465,7 +465,7 @@
eb_clear(b);
qe_shell_subst(cmd, sizeof(cmd), "man $1", b->filename, NULL);
- new_shell_buffer(b, NULL, get_basename(b->filename), NULL, cmd,
+ new_shell_buffer(b, NULL, get_basename(b->filename), NULL, NULL, cmd,
SF_COLOR | SF_INFINITE);
/* XXX: should check for man error */
/* XXX: should delay BF_SAVELOG until buffer is fully loaded */
Index: latex-mode.c
===================================================================
RCS file: /sources/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- latex-mode.c 21 Apr 2017 14:44:14 -0000 1.57
+++ latex-mode.c 20 May 2017 20:43:14 -0000 1.58
@@ -235,26 +235,19 @@
static void latex_cmd_run(void *opaque, char *cmd)
{
struct latex_function *func = (struct latex_function *)opaque;
- char cwd[MAX_FILENAME_SIZE];
char dir[MAX_FILENAME_SIZE];
- char *p;
- int len;
+ const char *path = NULL;
if (cmd == NULL) {
put_status(func->es, "Aborted");
return;
}
- 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;
- pstrncpy(dir, sizeof(dir), func->es->b->filename, len);
- chdir(dir);
+ /* get the directory of the open file and change into it */
+ if (func->es->b) {
+ path = get_default_path(func->es->b, func->es->b->total_size,
+ dir, sizeof dir);
+ }
if (func->output_to_buffer) {
/* if the buffer already exists, kill it */
@@ -265,7 +258,7 @@
}
/* create new buffer */
- b = new_shell_buffer(NULL, NULL, "*LaTeX output*", NULL, cmd,
+ b = new_shell_buffer(NULL, NULL, "*LaTeX output*", NULL, path, cmd,
SF_COLOR | SF_INFINITE);
if (b) {
/* XXX: try to split window if necessary */
@@ -276,6 +269,8 @@
if (pid == 0) {
const char *argv[4];
+ if (path) chdir(path);
+
/* child process */
setsid();
@@ -288,7 +283,6 @@
exit(1);
}
}
- chdir(cwd);
}
static void do_latex(EditState *e, const char *cmd)
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.266
retrieving revision 1.267
diff -u -b -r1.266 -r1.267
--- qe.h 15 May 2017 07:57:12 -0000 1.266
+++ qe.h 20 May 2017 20:43:14 -0000 1.267
@@ -2354,6 +2354,7 @@
#define SF_BUFED_MODE 0x20
EditBuffer *new_shell_buffer(EditBuffer *b0, EditState *e,
const char *bufname, const char *caption,
+ const char *path,
const char *cmd, int shell_flags);
#define QASSERT(e) do { if (!(e)) fprintf(stderr, "%s:%d: assertion
failed: %s\n", __FILE__, __LINE__, #e); } while (0)
Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -b -r1.135 -r1.136
--- shell.c 10 May 2017 15:46:17 -0000 1.135
+++ shell.c 20 May 2017 20:43:14 -0000 1.136
@@ -182,7 +182,8 @@
#define QE_TERM_YSIZE_INFINITE 10000
static int run_process(const char *cmd, int *fd_ptr, int *pid_ptr,
- int cols, int rows, int shell_flags)
+ int cols, int rows, const char *path,
+ int shell_flags)
{
int pty_fd, pid, i, nb_fds;
char tty_name[MAX_FILENAME_SIZE];
@@ -258,6 +259,8 @@
unsetenv("PAGER");
//setenv("QELEVEL", "1", 1);
+ if (path) chdir(path);
+
execv(argv[0], (char * const*)argv);
exit(1);
}
@@ -2044,6 +2047,7 @@
EditBuffer *new_shell_buffer(EditBuffer *b0, EditState *e,
const char *bufname, const char *caption,
+ const char *path,
const char *cmd, int shell_flags)
{
QEmacsState *qs = &qe_state;
@@ -2105,7 +2109,7 @@
s->cols = cols;
s->rows = rows;
- if (run_process(cmd, &s->pty_fd, &s->pid, cols, rows, shell_flags) < 0) {
+ if (run_process(cmd, &s->pty_fd, &s->pid, cols, rows, path, shell_flags) <
0) {
if (!b0)
eb_free(&b);
return NULL;
@@ -2140,11 +2144,15 @@
static void do_shell(EditState *e, int force)
{
+ char curpath[MAX_FILENAME_SIZE];
EditBuffer *b = NULL;
if (e->flags & (WF_POPUP | WF_MINIBUF))
return;
+ /* Start the shell in the default directory of the current window */
+ get_default_path(e->b, e->offset, curpath, sizeof curpath);
+
/* avoid messing with the dired pane */
e = qe_find_target_window(e, 1);
@@ -2175,11 +2183,13 @@
}
/* otherwise, restart the process here */
e->offset = b->total_size;
+ /* restart the shell in the same directory */
+ get_default_path(e->b, e->offset, curpath, sizeof curpath);
}
}
/* create new shell buffer or restart shell in current buffer */
- b = new_shell_buffer(b, e, "*shell*", "Shell process", NULL,
+ b = new_shell_buffer(b, e, "*shell*", "Shell process", curpath, NULL,
SF_COLOR | SF_INTERACTIVE);
if (!b)
return;
@@ -2215,7 +2225,8 @@
return;
/* create new buffer */
- b = new_shell_buffer(NULL, s, bufname, NULL, cmd, SF_COLOR | SF_INFINITE);
+ b = new_shell_buffer(NULL, s, bufname, NULL, NULL, cmd,
+ SF_COLOR | SF_INFINITE);
if (!b)
return;
@@ -2245,7 +2256,7 @@
snprintf(bufname, sizeof(bufname), "*ssh-%s*", arg);
/* create new buffer */
- b = new_shell_buffer(NULL, s, bufname, "ssh", cmd,
+ b = new_shell_buffer(NULL, s, bufname, "ssh", NULL, cmd,
SF_COLOR | SF_INTERACTIVE);
if (!b)
return;
@@ -2775,8 +2786,11 @@
static void do_shell_command(EditState *e, const char *cmd)
{
+ char curpath[MAX_FILENAME_SIZE];
EditBuffer *b;
+ get_default_path(e->b, e->offset, curpath, sizeof curpath);
+
/* if the buffer already exists, kill it */
b = eb_find("*shell command output*");
if (b) {
@@ -2784,7 +2798,7 @@
}
/* create new buffer */
- b = new_shell_buffer(NULL, e, "*shell command output*", NULL, cmd,
+ b = new_shell_buffer(NULL, e, "*shell command output*", NULL, curpath, cmd,
SF_COLOR | SF_INFINITE);
if (!b)
return;
@@ -2796,11 +2810,14 @@
static void do_compile(EditState *s, const char *cmd)
{
+ char curpath[MAX_FILENAME_SIZE];
EditBuffer *b;
if (s->flags & (WF_POPUP | WF_MINIBUF))
return;
+ get_default_path(s->b, s->offset, curpath, sizeof curpath);
+
if (s->flags & WF_POPLEFT) {
/* avoid messing with the dired pane */
s = find_window(s, KEY_RIGHT, s);
@@ -2817,7 +2834,7 @@
cmd = "make";
/* create new buffer */
- b = new_shell_buffer(NULL, s, "*compilation*", "Compilation", cmd,
+ b = new_shell_buffer(NULL, s, "*compilation*", "Compilation", curpath, cmd,
SF_COLOR | SF_INFINITE);
if (!b)
return;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs archive.c latex-mode.c qe.h shell.c,
Charlie Gordon <=