Subject: Re: ls-lisp.el Modification to Ignore Case

From: Dan Schmidt <[email-masked]>
Date: 28 Mar 1997 14:20:49 -0500

"Rosinger, David S" <[email-masked]> writes:

| INTRO
| 
| I have made a (trivial) modification to "ls-lisp.el" to
| ignore case when sorting files alphabetically in dired mode.
| 
| This seems particularly appropriate on Win32.

I made a similar change to my ls-lisp.el:

 - directories are displayed before files.
 - links, UID and GID are not displayed, since they're not applicable
   on Win95.
 - file names in all caps are displayed in all lowercase (and are
   sorted that way, too).

All of these options are toggleable.

Here's a patch, if anyone is interested.  It should be obvious how to
toggle the above options from the defvar's (they're all on by
default).

Dan

*** c:/app/emacs-19.34/lisp/ls-lisp.el	Wed Aug 28 23:56:18 1996
--- z:/home/dfan/Emacs/ls-lisp.el	Tue Aug 06 17:54:08 1996
***************
*** 55,60 ****
--- 55,72 ----
  
  ;;; Code:
  
+ (defvar ls-lisp-lg-style t
+   "*Display directories in what I consider to be a nicer format.
+ All subdirectories are displayed before all files.
+ Sorting of files is done in a case-insensitive manner.")
+ 
+ (defvar ls-lisp-downcase-names t
+   "*When displaying directories, convert filenames that are all caps to
+ be all lowercase, to compensate for Windows 95.")
+ 
+ (defvar ls-lisp-succint t
+   "*Don't display links, UID and GID.")
+ 
  ;;;###autoload
  (defvar ls-lisp-support-shell-wildcards t
    "*Non-nil means file patterns are treated as shell wildcards.
***************
*** 121,127 ****
  		   (function
  		    (lambda (x)
  		      ;; file-attributes("~bogus") bombs
! 		      (cons x (file-attributes (expand-file-name x)))))
  		   ;; inserting the call to directory-files right here
  		   ;; seems to stimulate an Emacs bug
  		   ;; ILLEGAL DATATYPE (#o37777777727) or #o67
--- 133,140 ----
  		   (function
  		    (lambda (x)
  		      ;; file-attributes("~bogus") bombs
! 		      (cons (ls-lisp-canonicalize-name x)
!                             (file-attributes (expand-file-name x)))))
  		   ;; inserting the call to directory-files right here
  		   ;; seems to stimulate an Emacs bug
  		   ;; ILLEGAL DATATYPE (#o37777777727) or #o67
***************
*** 184,194 ****
  			(lambda (x y)
  			  (ls-lisp-time-lessp (nth index (cdr y))
  					      (nth index (cdr x))))))
! 		      (t		; sorted alphabetically
! 		       (function
! 			(lambda (x y)
! 			  (string-lessp (car x)
! 					(car y)))))))))
    (if (memq ?r switches)		; reverse sort order
        (setq file-alist (nreverse file-alist)))
    file-alist)
--- 197,217 ----
  			(lambda (x y)
  			  (ls-lisp-time-lessp (nth index (cdr y))
  					      (nth index (cdr x))))))
! 
!                       (t                
!                        (if ls-lisp-lg-style
!                            (function        ; sorted alphabetically, dirs first,
!                             (lambda (x y)   ; case insensitive
!                               (if (eq (car (cdr x))
!                                       (car (cdr y)))
!                                   (string-lessp (downcase (car x))
!                                                 (downcase (car y)))
!                                 (eq (car (cdr x)) t))))
!                          (function          ; sorted alphabetically
!                           (lambda (x y)
!                             (string-lessp (car x)
!                                           (car y))))))))))
! 
    (if (memq ?r switches)		; reverse sort order
        (setq file-alist (nreverse file-alist)))
    file-alist)
***************
*** 203,209 ****
  	(and (= hi0 hi1)
  	     (< lo0 lo1)))))
  
- 
  (defun ls-lisp-format (file-name file-attr &optional switches)
    (let ((file-type (nth 0 file-attr)))
      (concat (if (memq ?i switches)	; inode number
--- 226,231 ----
***************
*** 216,232 ****
  	    ;; Emacs should be able to make strings of them.
  	    ;; user-login-name and user-full-name could take an
  	    ;; optional arg.
! 	    (format " %3d %-8s %-8s %8d "
! 		    (nth 1 file-attr)	; no. of links
! 		    (if (= (user-uid) (nth 2 file-attr))
! 			(user-login-name)
! 		      (int-to-string (nth 2 file-attr)))	; uid
! 		    (if (eq system-type 'ms-dos)
! 			"root"		; everything is root on MSDOS.
! 		      (int-to-string (nth 3 file-attr)))	; gid
! 		    (nth 7 file-attr)	; size in bytes
! 		    )
! 	    (ls-lisp-format-time file-attr switches)
  	    " "
  	    file-name
  	    (if (stringp file-type)	; is a symbolic link
--- 238,257 ----
  	    ;; Emacs should be able to make strings of them.
  	    ;; user-login-name and user-full-name could take an
  	    ;; optional arg.
!             (if ls-lisp-succint
!                 (format " %8d "
!                         (nth 7 file-attr))
!                 (format " %3d %8s %8s %8d "
!                         (nth 1 file-attr) ; no. of links
!                         (if (= (user-uid) (nth 2 file-attr))
!                             (user-login-name)
!                           (int-to-string (nth 2 file-attr))) ; uid
!                         (if (eq system-type 'ms-dos)
!                             "root"      ; everything is root on MSDOS.
!                           (int-to-string (nth 3 file-attr))) ; gid
!                         (nth 7 file-attr) ; size in bytes
!                         ))
!             (ls-lisp-format-time file-attr switches)
  	    " "
  	    file-name
  	    (if (stringp file-type)	; is a symbolic link
***************
*** 266,271 ****
--- 291,305 ----
  		  year)))
      (error
       "Jan 00 00:00")))
+ 
+ (defun ls-lisp-canonicalize-name (file-name)
+   ;; If ls-lisp-downcase-names is non-nil, downcase FILE-NAME if
+   ;; it's currently all caps. Useful for dealing with Windows95, in
+   ;; which files tend to be in all caps if you didn't specify otherwise.
+   (if (and ls-lisp-downcase-names
+            (equal (upcase file-name) file-name))
+       (downcase file-name)
+     file-name))
  
  (provide 'ls-lisp)