bug-coreutils
[Top][All Lists]
Advanced

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

coreutils ls.c proposed change for Emacs dired fixed-width columns


From: Paul Eggert
Subject: coreutils ls.c proposed change for Emacs dired fixed-width columns
Date: Fri, 24 Sep 2004 23:17:46 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Here's a proposed patch to implement RMS's request to support Emacs
dired fixed-width columns.  It's a bit of a quick hack, and is
therefore undocumented.  A better long-term approach is to allow
arbitrary formats, but that'd take more work (notably in the
documentation) and this is simpler.

This patch uses "diff -w" to avoid indentation-only changes, so it's
not suitable for applying as-is.  Also, it'd need a changelog entry of
course.  Just wanted to get it out for comments before installing it.

--- ls.c.~1.361.~       2004-09-22 12:45:44 -0700
+++ ls.c        2004-09-24 23:05:12 -0700
@@ -344,6 +344,10 @@ static int major_device_number_width;
 static int minor_device_number_width;
 static int file_size_width;
 
+/* If true, use fixed width columns, with traditional widths.
+   Otherwise, calculate widths from the data.  */
+static bool fixed_width_columns;
+
 /* Option flags */
 
 /* long_format for lots of info, one per line.
@@ -680,6 +684,7 @@ enum
   BLOCK_SIZE_OPTION,
   COLOR_OPTION,
   DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION,
+  FIXED_WIDTH_COLUMNS_OPTION,
   FORMAT_OPTION,
   FULL_TIME_OPTION,
   INDICATOR_STYLE_OPTION,
@@ -697,6 +702,10 @@ static struct option const long_options[
   {"escape", no_argument, 0, 'b'},
   {"directory", no_argument, 0, 'd'},
   {"dired", no_argument, 0, 'D'},
+
+  /* This undocumented option is for Emacs dired incremental redisplay.  */
+  {"fixed-width-columns", no_argument, 0, FIXED_WIDTH_COLUMNS_OPTION},
+
   {"full-time", no_argument, 0, FULL_TIME_OPTION},
   {"human-readable", no_argument, 0, 'h'},
   {"inode", no_argument, 0, 'i'},
@@ -1338,6 +1347,7 @@ decode_switches (int argc, char **argv)
       abort ();
     }
 
+  fixed_width_columns = false;
   time_type = time_mtime;
   sort_type = sort_name;
   sort_reverse = false;
@@ -1646,6 +1656,10 @@ decode_switches (int argc, char **argv)
          format = XARGMATCH ("--format", optarg, format_args, format_types);
          break;
 
+       case FIXED_WIDTH_COLUMNS_OPTION:
+         fixed_width_columns = true;
+         break;
+
        case FULL_TIME_OPTION:
          format = long_format;
          time_style_option = "full-iso";
@@ -2374,16 +2388,26 @@ clear_files (void)
     }
 
   files_index = 0;
+
+  if (fixed_width_columns)
+    {
+      inode_number_width = 7;
+      block_size_width = 4;
+      nlink_width = 3;
+      owner_width = group_width = author_width = 8;
+      major_device_number_width = minor_device_number_width = 3;
+      file_size_width = 8;
+    }
+  else
+    {
   inode_number_width = 0;
   block_size_width = 0;
   nlink_width = 0;
-  owner_width = 0;
-  group_width = 0;
-  author_width = 0;
-  major_device_number_width = 0;
-  minor_device_number_width = 0;
+      owner_width = group_width = author_width = 0;
+      major_device_number_width = minor_device_number_width = 0;
   file_size_width = 0;
 }
+}
 
 /* Add a file to the current table of files.
    Verify that the file exists, and print an error message if it does not.
@@ -2535,6 +2559,10 @@ gobble_file (const char *name, enum file
       else
        f->filetype = normal;
 
+      blocks = ST_NBLOCKS (f->stat);
+
+      if (!fixed_width_columns)
+       {
       {
        char buf[INT_BUFSIZE_BOUND (uintmax_t)];
        int len = strlen (umaxtostr (f->stat.st_ino, buf));
@@ -2542,11 +2570,11 @@ gobble_file (const char *name, enum file
          inode_number_width = len;
       }
 
-      blocks = ST_NBLOCKS (f->stat);
       {
        char buf[LONGEST_HUMAN_READABLE + 1];
        int len = strlen (human_readable (blocks, buf, human_output_opts,
-                                         ST_NBLOCKSIZE, output_block_size));
+                                             ST_NBLOCKSIZE,
+                                             output_block_size));
        if (block_size_width < len)
          block_size_width = len;
       }
@@ -2602,6 +2630,7 @@ gobble_file (const char *name, enum file
            file_size_width = len;
        }
     }
+    }
   else
     {
       f->filetype = type;




reply via email to

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