Bug 7011 - [patch] Improvements to ls to help Emacs users; patch included
Summary: [patch] Improvements to ls to help Emacs users; patch included
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 3.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: hoek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1998-06-21 22:10 UTC by Joel Ray Holveck
Modified: 1998-07-29 01:53 UTC (History)
0 users

See Also:


Attachments
file.diff (3.07 KB, patch)
1998-06-21 22:10 UTC, Joel Ray Holveck
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joel Ray Holveck 1998-06-21 22:10:01 UTC
Emacs's editing mode, dired, will ls individual files when it creates
changes.  However, our current implementation of ls may use different
column widths for different sets of files being ls'd.  This means that
if a single dired directory listing includes data from multiple
invocations of ls, the columns may not align properly.

This problem should also exist under any other directory utility which
directly displays the output of ls, and will display data obtained
from multiple invocations with different filesets at the same time.

Fix: I propose a change to ls which will allow minimum column widths to be
set in the environment.  A runtime environment variable, LS_COLWIDTHS
is added.  This is a colon-delimited list of minimum column widths for
each variable-width column, in order of display by 'ls -lois'.  For
example, by default, 'ls -l' may display:

total 321
-rw-r--r--  1 joelh  bin    7435 Jun 21 13:45 cmp.o
-rwxr-xr-x  1 joelh  bin  238385 Jun 21 14:42 ls
-rw-r--r--  1 joelh  bin    4352 Jun 21 14:42 ls.1.gz
-rw-r--r--  1 joelh  bin   21182 Jun 21 14:42 ls.o
-rw-r--r--  1 joelh  bin   16457 Jun 21 13:45 print.o
-rw-r--r--  1 joelh  bin    9814 Jun 21 13:45 stat_flags.o
-rw-r--r--  1 joelh  bin   11508 Jun 21 13:45 util.o

However, with LS_COLWIDTHS set to 6:4:2:8:8:1:7:0 (the affected fields
for a simple -l listing are block count, user, group, and size),
'ls -l' in the same directory will display:

total 321
-rw-r--r--   1 joelh     bin          7435 Jun 21 13:45 cmp.o
-rwxr-xr-x   1 joelh     bin        238385 Jun 21 14:42 ls
-rw-r--r--   1 joelh     bin          4352 Jun 21 14:42 ls.1.gz
-rw-r--r--   1 joelh     bin         21182 Jun 21 14:42 ls.o
-rw-r--r--   1 joelh     bin         16457 Jun 21 13:45 print.o
-rw-r--r--   1 joelh     bin          9814 Jun 21 13:45 stat_flags.o
-rw-r--r--   1 joelh     bin         11508 Jun 21 13:45 util.o

By setting LS_COLWIDTHS to a reasonable value, all invocations of ls
will use the same column widths, thereby effectively allowing a
repeatable output format under normal conditions.  (The problem will
still manifest as before if the column widths specified in
LS_COLWIDTHS are insufficient to display the requested listing, since
the columns output will still expand to meet the needs of the
listing.)

If additional output columns are added in the future, it is
recommended to append column width specifiers to LS_COLWIDTHS rather
than adding them in display order, to maintain backward compatibility.

Attached are the diffs to ls.c and ls.1 to implement the recommended
change.

Happy hacking,
joelh
How-To-Repeat: 
Launch Emacs.  Press: C-x C-f ~ RET

Dired will launch and displays a directory listing of the home
directory.  A portion of a sample follows:

  -rwxr-xr-x   1 joelh  joelh     3863 May 11 23:20 .bashrc
  -rw-r--r--   1 joelh  joelh    32126 Jun 21 14:10 .emacs
  -rw-r--r--   1 joelh  joelh      209 Jan  8 12:34 .emacs.bmk
  -rw-r--r--   1 joelh  joelh        0 Mar  4 02:45 .emacs_args
  -rw-------   1 joelh  joelh     4217 Jun 17 00:24 .fetchmailrc

Using C-n and C-p, navigate to an item that uses less than the maximum
width of any column (eg, has a size an order of magnitude smaller than
another).  (I am using .emacs.bmk as an example.)  Press M
(dired-do-chmod).  Press u+r (which is probably a nop in chmod, but
will cause the file selected to refresh by itself).  The directory
will now have skewed columns:

  -rwxr-xr-x   1 joelh  joelh     3863 May 11 23:20 .bashrc
  -rw-r--r--   1 joelh  joelh    32126 Jun 21 14:10 .emacs
  -rw-r--r--  1 joelh  joelh  209 Jan  8 12:34 .emacs.bmk
  -rw-r--r--   1 joelh  joelh        0 Mar  4 02:45 .emacs_args
  -rw-------   1 joelh  joelh     4217 Jun 17 00:24 .fetchmailrc
Comment 1 Poul-Henning Kamp freebsd_committer freebsd_triage 1998-06-27 10:46:37 UTC
State Changed
From-To: open->suspended

awaiting committer 
Comment 2 hoek freebsd_committer freebsd_triage 1998-07-29 00:04:53 UTC
Responsible Changed
From-To: freebsd-bugs->hoek

I'll do this as soon Babylon 5 is over.  And maybe Buff/Vampire-Slayer, too. 
Comment 3 hoek freebsd_committer freebsd_triage 1998-07-29 01:50:33 UTC
State Changed
From-To: suspended->closed

Modified patches applied.  Thanks! 

"Ordered lists shall remain ordered!"  - bde, on -hackers, date unknown. ;-)