qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs TODO.org extras.c qe.h dired.c qe.c util.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs TODO.org extras.c qe.h dired.c qe.c util.c
Date: Mon, 13 Jun 2016 17:12:35 +0000 (UTC)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        16/06/13 17:12:35

Modified files:
        .              : TODO.org extras.c qe.h dired.c qe.c util.c 

Log message:
        dired: support file patterns, improve current directory support
        
        - add `is_filepattern` utility function to check for wildcards
        - add `get_default_path` public function to retrieve the context 
specific 
          current directory associated with a window.
        - explore directories and file patterns in dired window
        - compare-files determines parent file from current directory
        - accept file patterns for dired listing

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/TODO.org?cvsroot=qemacs&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/qemacs/extras.c?cvsroot=qemacs&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.218&r2=1.219
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.66&r2=1.67
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.225&r2=1.226
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.71&r2=1.72

Patches:
Index: TODO.org
===================================================================
RCS file: /sources/qemacs/qemacs/TODO.org,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- TODO.org    9 Jun 2016 16:24:10 -0000       1.13
+++ TODO.org    13 Jun 2016 17:12:35 -0000      1.14
@@ -102,8 +102,9 @@
 ** charset: handle chinese encodings
 ** charset: handle euc-kr
 ** charset: autodetect sjis, euc-jp...
-** c-mode: fix c indentation inside comments
-** c-mode: fix c indentation inside struct, array and enum initializers
+** clang: align multi line comments leading * one space to the right
+** clang: fix c indentation inside comments
+** clang: fix c indentation inside struct, array and enum initializers
 ** dired: keep dired current file upon: RET C-x C-k RET
 ** dired: fork for directory scan, background inode tracking, dir size scan
 ** hex: extend hex mode to support 16,32,64 bit words as little and big endian
@@ -122,6 +123,7 @@
    <><>(define-macro "last-kbd-macro" "\<>\<>")
 ** modes: header-line format
 ** modes: mode-line format
+** modes: display filename relative to current directory instead of buffer 
name on mode-line
 ** modes: major and minor modes
 ** modes: split modes into colorizers, interaction, io, charset, eoltype
 ** script: expression evaluator

Index: extras.c
===================================================================
RCS file: /sources/qemacs/qemacs/extras.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- extras.c    9 Jun 2016 16:24:10 -0000       1.41
+++ extras.c    13 Jun 2016 17:12:35 -0000      1.42
@@ -135,9 +135,16 @@
 void do_compare_files(EditState *s, const char *filename, int bflags)
 {
     char buf[MAX_FILENAME_SIZE];
+    char dir[MAX_FILENAME_SIZE];
     int pathlen, parent_pathlen;
+    const char *tail;
 
     pathlen = get_basename_offset(filename);
+    get_default_path(s, dir, sizeof(dir));
+
+    if (strstart(filename, dir, &tail)) {
+        snprintf(buf, sizeof(buf), "%s../%s", dir, tail);
+    } else
     if (pathlen == 0) {
         snprintf(buf, sizeof(buf), "../%s", filename);
     } else

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -b -r1.218 -r1.219
--- qe.h        7 Jun 2016 08:56:40 -0000       1.218
+++ qe.h        13 Jun 2016 17:12:35 -0000      1.219
@@ -212,6 +212,7 @@
 int find_file_next(FindFileState *s, char *filename, int filename_size_max);
 void find_file_close(FindFileState **sp);
 int is_directory(const char *path);
+int is_filepattern(const char *filespec);
 void canonicalize_path(char *buf, int buf_size, const char *path);
 void canonicalize_absolute_path(char *buf, int buf_size, const char *path1);
 char *make_user_path(char *buf, int buf_size, const char *path);
@@ -1820,6 +1821,7 @@
 
 /* loading files */
 void do_exit_qemacs(EditState *s, int argval);
+char *get_default_path(EditState *s, 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: dired.c
===================================================================
RCS file: /sources/qemacs/qemacs/dired.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -b -r1.66 -r1.67
--- dired.c     9 Jun 2016 16:24:10 -0000       1.66
+++ dired.c     13 Jun 2016 17:12:35 -0000      1.67
@@ -170,7 +170,13 @@
 
     /* build filename */
     /* CG: Should canonicalize path */
+    if (is_directory(ds->path)) {
     return makepath(buf, buf_size, ds->path, dip->name);
+    } else {
+        get_dirname(buf, buf_size, ds->path);
+        append_slash(buf, buf_size);
+        return pstrcat(buf, buf_size, dip->name);
+    }
 }
 
 static int dired_find_target(DiredState *ds, const char *target)
@@ -922,8 +928,10 @@
 {
     FindFileState *ffst;
     char filename[MAX_FILENAME_SIZE];
+    char dir[MAX_FILENAME_SIZE];
     char line[1024];
     const char *p;
+    const char *pattern;
     struct stat st;
     StringItem *item;
 
@@ -940,9 +948,24 @@
 
     eb_clear(b);
 
-    ffst = find_file_open(ds->path, "*");
+    pstrcpy(dir, sizeof(dir), ds->path);
+    pattern = "*";
+
+    if (!is_directory(dir)) {
+        get_dirname(dir, sizeof(dir), ds->path);
+        pattern = get_basename(ds->path);
+    }
+
+    /* XXX: should scan directory for subdirectories and filter with
+     * pattern only for regular files.
+     * XXX: should handle generalized file patterns.
+     * XXX: should use a separate thread to make the scan asynchronous.
+     * XXX: should compute recursive size data.
+     * XXX: should track file creation, deletion and modifications.
+     */
+    ffst = find_file_open(dir, pattern);
     /* Should scan directory/filespec before computing lines to adjust
-     * filename gutter width
+     * filename gutter width.
      */
     while (!find_file_next(ffst, filename, sizeof(filename))) {
         if (lstat(filename, &st) < 0)
@@ -1164,7 +1187,13 @@
 
 static char *dired_get_default_path(EditState *s, 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);
+        append_slash(buf, buf_size);
+        return buf;
+    }
 }
 
 static int dired_mode_init(EditState *s, EditBuffer *b, int flags)
@@ -1194,7 +1223,7 @@
     dired_free(ds);
 }
 
-/* can only apply dired mode on directories */
+/* can only apply dired mode on directories and file patterns */
 static int dired_mode_probe(ModeDef *mode, ModeProbeData *p)
 {
     if (qe_get_buffer_mode_data(p->b, &dired_mode, NULL))
@@ -1203,7 +1232,7 @@
     if (S_ISDIR(p->st_mode))
         return 95;
 
-    if (strchr(p->real_filename, '*') || strchr(p->real_filename, '?'))
+    if (is_filepattern(p->real_filename))
         return 90;
 
     return 0;
@@ -1235,7 +1264,7 @@
 
     /* Set the filename to the directory of the current file */
     canonicalize_absolute_path(filename, sizeof(filename), target);
-    if (!is_directory(filename)) {
+    if (!is_directory(filename) && !is_filepattern(filename)) {
         p = strrchr(filename, '/');
         if (p)
             *p = '\0';

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.225
retrieving revision 1.226
diff -u -b -r1.225 -r1.226
--- qe.c        7 Jun 2016 08:56:40 -0000       1.225
+++ qe.c        13 Jun 2016 17:12:35 -0000      1.226
@@ -53,7 +53,6 @@
 void print_at_byte(QEditScreen *screen,
                    int x, int y, int width, int height,
                    const char *str, int style_index);
-static char *get_default_path(EditState *s, char *buf, int buf_size);
 static EditBuffer *predict_switch_to_buffer(EditState *s);
 static StringArray *get_history(const char *name);
 static void qe_key_process(int key);
@@ -6127,7 +6126,7 @@
 }
 
 /* compute default path for find/save buffer */
-static char *get_default_path(EditState *s, char *buf, int buf_size)
+char *get_default_path(EditState *s, char *buf, int buf_size)
 {
     EditBuffer *b = s->b;
     char buf1[MAX_FILENAME_SIZE];
@@ -6332,8 +6331,11 @@
     }
 
 #ifndef CONFIG_TINY
-    /* avoid messing with the dired pane */
-    if ((s->flags & WF_POPLEFT) && s->x1 == 0 && !is_directory(filename)) {
+    /* when exploring from a popleft dired buffer, load a directory or
+     * file pattern into the same pane, but load a regular file into the view 
pane
+     */
+    if ((s->flags & WF_POPLEFT) && s->x1 == 0
+    &&  !is_directory(filename) && !is_filepattern(filename)) {
         EditState *e = find_window(s, KEY_RIGHT, NULL);
         if (e) {
             if (s->qe_state->active_window == s)

Index: util.c
===================================================================
RCS file: /sources/qemacs/qemacs/util.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -b -r1.71 -r1.72
--- util.c      27 Aug 2015 23:03:40 -0000      1.71
+++ util.c      13 Jun 2016 17:12:35 -0000      1.72
@@ -2,7 +2,7 @@
  * Utilities for qemacs.
  *
  * Copyright (c) 2001 Fabrice Bellard.
- * Copyright (c) 2002-2013 Charlie Gordon.
+ * Copyright (c) 2002-2016 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -139,6 +139,13 @@
         return 0;
 }
 
+int is_filepattern(const char *filespec) 
+{
+    // XXX: should also accept character ranges and {} comprehensions
+    int pos = strcspn(filespec, "*?");
+    return filespec[pos] != '\0';
+}
+
 /* suppress redundant ".", ".." and "/" from paths */
 /* XXX: make it better */
 static void canonicalize_path1(char *buf, int buf_size, const char *path)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]