[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs dired.c extras.c qe.c qe.h shell.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs dired.c extras.c qe.c qe.h shell.c |
Date: |
Sat, 26 Nov 2016 11:30:29 +0000 (UTC) |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 16/11/26 11:30:29
Modified files:
. : dired.c extras.c qe.c qe.h shell.c
Log message:
improve current directory handling for shell mode
- get_default_path() takes buffer and offset instead of window
- mode specific handler returns NULL is current directory cannot be
determined
- set EditBuffer->default_mode upon creating buffer_mode_data
- add ShellState->curpath to hold shell buffer current directory
- add shell_get_curpath to parse shell output for current directory
in shell prompt, check if dir actually exists.
- update shell directory upon enter key.
should instead keep a list with validity ranges
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.68&r2=1.69
http://cvs.savannah.gnu.org/viewcvs/qemacs/extras.c?cvsroot=qemacs&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.229&r2=1.230
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.222&r2=1.223
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.111&r2=1.112
Patches:
Index: dired.c
===================================================================
RCS file: /sources/qemacs/qemacs/dired.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -b -r1.68 -r1.69
--- dired.c 26 Jun 2016 08:35:25 -0000 1.68
+++ dired.c 26 Nov 2016 11:30:29 -0000 1.69
@@ -1185,14 +1185,18 @@
}
}
-static char *dired_get_default_path(EditState *s, char *buf, int buf_size)
+static char *dired_get_default_path(EditBuffer *b, int offset,
+ char *buf, int buf_size)
{
- if (is_directory(s->b->filename)) {
- return makepath(buf, buf_size, s->b->filename, "");
- } else {
- get_dirname(buf, buf_size, s->b->filename);
+ if (is_directory(b->filename)) {
+ return makepath(buf, buf_size, b->filename, "");
+ } else
+ if (b->filename[0]) {
+ get_dirname(buf, buf_size, b->filename);
append_slash(buf, buf_size);
return buf;
+ } else {
+ return NULL;
}
}
Index: extras.c
===================================================================
RCS file: /sources/qemacs/qemacs/extras.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- extras.c 13 Jun 2016 17:12:35 -0000 1.42
+++ extras.c 26 Nov 2016 11:30:29 -0000 1.43
@@ -140,7 +140,7 @@
const char *tail;
pathlen = get_basename_offset(filename);
- get_default_path(s, dir, sizeof(dir));
+ get_default_path(s->b, s->offset, dir, sizeof(dir));
if (strstart(filename, dir, &tail)) {
snprintf(buf, sizeof(buf), "%s../%s", dir, tail);
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.229
retrieving revision 1.230
diff -u -b -r1.229 -r1.230
--- qe.c 29 Jul 2016 11:20:08 -0000 1.229
+++ qe.c 26 Nov 2016 11:30:29 -0000 1.230
@@ -1968,6 +1968,9 @@
md->next = b->mode_data_list;
b->mode_data_list = md;
}
+ if (!b->default_mode) {
+ b->default_mode = m;
+ }
}
return md;
}
@@ -4407,7 +4410,7 @@
def_input[0] = '\0';
es->default_input[0] = '\0';
if (strequal(completion_name, "file")) {
- get_default_path(s, def_input, sizeof(def_input));
+ get_default_path(s->b, s->offset, def_input,
sizeof(def_input));
} else
if (strequal(completion_name, "buffer")) {
EditBuffer *b;
@@ -6191,6 +6194,11 @@
/* canonicalize the path for a given window and make it absolute */
void canonicalize_absolute_path(EditState *s, char *buf, int buf_size, const
char *path1)
{
+ return canonicalize_absolute_buffer_path(s ? s->b : NULL, s ? s->offset :
0, buf, buf_size, path1);
+}
+
+void canonicalize_absolute_buffer_path(EditBuffer *b, int offset, char *buf,
int buf_size, const char *path1)
+{
char cwd[MAX_FILENAME_SIZE];
char path[MAX_FILENAME_SIZE];
char *homedir;
@@ -6220,10 +6228,7 @@
}
} else {
/* CG: not sufficient for windows drives */
- /* CG: should test result */
- if (s) {
- get_default_path(s, cwd, sizeof(cwd));
- } else {
+ if (!b || !get_default_path(b, offset, cwd, sizeof(cwd))) {
getcwd(cwd, sizeof(cwd));
#ifdef CONFIG_WIN32
path_win_to_unix(cwd);
@@ -6237,15 +6242,16 @@
}
/* compute default path for find/save buffer */
-char *get_default_path(EditState *s, char *buf, int buf_size)
+char *get_default_path(EditBuffer *b, int offset, char *buf, int buf_size)
{
- EditBuffer *b = s->b;
char buf1[MAX_FILENAME_SIZE];
const char *filename;
/* dispatch to mode specific handler if any */
- if (s->mode->get_default_path) {
- return s->mode->get_default_path(s, buf, buf_size);
+ if (b->default_mode
+ && b->default_mode->get_default_path
+ && b->default_mode->get_default_path(b, offset, buf, buf_size)) {
+ return buf;
}
if ((b->flags & BF_SYSTEM)
@@ -6253,7 +6259,7 @@
|| b->filename[0] == '\0') {
filename = "a";
} else {
- filename = s->b->filename;
+ filename = b->filename;
}
/* XXX: should just retrieve the current directory */
canonicalize_absolute_path(NULL, buf1, sizeof(buf1), filename);
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.222
retrieving revision 1.223
diff -u -b -r1.222 -r1.223
--- qe.h 29 Jul 2016 11:20:08 -0000 1.222
+++ qe.h 26 Nov 2016 11:30:29 -0000 1.223
@@ -215,6 +215,9 @@
int is_filepattern(const char *filespec);
void canonicalize_path(char *buf, int buf_size, const char *path);
void canonicalize_absolute_path(EditState *s, char *buf, int buf_size, const
char *path1);
+void canonicalize_absolute_buffer_path(EditBuffer *b, int offset,
+ char *buf, int buf_size,
+ const char *path1);
char *make_user_path(char *buf, int buf_size, const char *path);
char *reduce_filename(char *dest, int size, const char *filename);
int match_extension(const char *filename, const char *extlist);
@@ -1312,7 +1315,9 @@
EditBufferDataType *data_type; /* native buffer data type (NULL = raw) */
void (*get_mode_line)(EditState *s, buf_t *out);
void (*indent_func)(EditState *s, int offset);
- char *(*get_default_path)(EditState *s, char *buf, int buf_size);
+ /* Get the current directory for the window, return NULL if none */
+ char *(*get_default_path)(EditBuffer *s, int offset,
+ char *buf, int buf_size);
/* mode specific key bindings */
struct KeyDef *first_key;
@@ -1821,7 +1826,7 @@
/* loading files */
void do_exit_qemacs(EditState *s, int argval);
-char *get_default_path(EditState *s, char *buf, int buf_size);
+char *get_default_path(EditBuffer *b, int offset, char *buf, int buf_size);
void do_find_file(EditState *s, const char *filename, int bflags);
void do_load_from_path(EditState *s, const char *filename, int bflags);
void do_find_file_other_window(EditState *s, const char *filename, int bflags);
Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -b -r1.111 -r1.112
--- shell.c 26 Jun 2016 08:35:26 -0000 1.111
+++ shell.c 26 Nov 2016 11:30:29 -0000 1.112
@@ -84,7 +84,7 @@
const char *caption; /* process caption for exit message */
int shell_flags;
int last_char; /* last char sent to the process */
-
+ char curpath[MAX_FILENAME_SIZE]; /* should keep a list with validity
ranges */
} ShellState;
/* CG: these variables should be encapsulated in a global structure */
@@ -93,6 +93,9 @@
static int error_line_num = -1;
static char error_filename[MAX_FILENAME_SIZE];
+static char *shell_get_curpath(EditBuffer *b, int offset,
+ char *buf, int buf_size);
+
static void set_error_offset(EditBuffer *b, int offset)
{
pstrcpy(error_buffer, sizeof(error_buffer), b ? b->name : "");
@@ -177,7 +180,7 @@
int cols, int rows, int shell_flags)
{
int pty_fd, pid, i, nb_fds;
- char tty_name[1024];
+ char tty_name[MAX_FILENAME_SIZE];
struct winsize ws;
pty_fd = get_pty(tty_name, sizeof(tty_name));
@@ -1327,6 +1330,7 @@
*/
s->b->mark = s->cur_prompt = s->cur_offset;
}
+ shell_get_curpath(s->b, s->cur_offset, s->curpath, sizeof(s->curpath));
/* now we do some refresh */
edit_display(qs);
@@ -1825,6 +1829,11 @@
struct timespec ts;
if (e->interactive) {
+ ShellState *s = shell_get_state(e, 1);
+
+ if (s) {
+ shell_get_curpath(e->b, e->offset, s->curpath, sizeof(s->curpath));
+ }
shell_write_char(e, '\r');
/* give the process a chance to handle the input */
ts.tv_sec = 0;
@@ -2012,17 +2021,21 @@
/* get current directory from prompt on current line */
/* XXX: should extend behavior to handle more subtile cases */
-static char *shell_get_default_path(EditState *s, char *buf, int buf_size)
+static char *shell_get_curpath(EditBuffer *b, int offset,
+ char *buf, int buf_size)
{
char line[1024];
- int offset = eb_goto_bol(s->b, s->offset);
+ char curpath[MAX_FILENAME_SIZE];
int start, first_blank, last_blank, stop, i;
- eb_get_strline(s->b, line, sizeof(line), &offset);
+ offset = eb_goto_bol(b, offset);
+ eb_get_strline(b, line, sizeof(line), &offset);
first_blank = last_blank = 0;
- for (i = 0; line[i] != '\0'; i++) {
+ for (i = 0;; i++) {
int c = line[i];
+ if (c == '\0')
+ return NULL;
if (c == '$' || c == '>')
break;
if (c == ' ') {
@@ -2041,10 +2054,26 @@
line[stop] = '\0';
+ if (start == stop)
+ return NULL;
+
/* XXX: should use a lower level function to avoid potential recursion */
- canonicalize_absolute_path(NULL, buf, buf_size, line + start);
- append_slash(buf, buf_size);
- return buf;
+ canonicalize_absolute_path(NULL, curpath, sizeof curpath, line + start);
+ if (!is_directory(curpath))
+ return NULL;
+ append_slash(curpath, sizeof curpath);
+ return pstrcpy(buf, buf_size, curpath);
+}
+
+static char *shell_get_default_path(EditBuffer *b, int offset,
+ char *buf, int buf_size)
+{
+ ShellState *s = qe_get_buffer_mode_data(b, &shell_mode, NULL);
+
+ if (s && (s->curpath[0] || shell_get_curpath(b, offset, s->curpath,
sizeof(s->curpath)))) {
+ return pstrcpy(buf, buf_size, s->curpath);
+ }
+ return shell_get_curpath(b, offset, buf, buf_size);
}
static void do_shell_command(EditState *e, const char *cmd)
@@ -2155,8 +2184,8 @@
buf_putc_utf8(fname, c);
}
- /* XXX: default directory should depend on current position in `s` */
- canonicalize_absolute_path(s, fullpath, sizeof(fullpath), filename);
+ canonicalize_absolute_buffer_path(b, found_offset,
+ fullpath, sizeof(fullpath),
filename);
/* extract line number */
for (line_num = col_num = 0;;) {
@@ -2204,6 +2233,7 @@
/* CG: Should remove popups, sidepanes, helppanes... */
/* go to the error */
+ /* XXX: should check for file existence */
do_find_file(s, fullpath, 0);
do_goto_line(qs->active_window, line_num, col_num);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs dired.c extras.c qe.c qe.h shell.c,
Charlie Gordon <=