Function: dired-tree-lessp

dired-tree-lessp is a byte-compiled function defined in dired-aux.el.gz.

Signature

(dired-tree-lessp DIR1 DIR2)

Source Code

;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
(defun dired-tree-lessp (dir1 dir2)
  ;; Lexicographic order on file name components, like `ls -lR':
  ;; DIR1 < DIR2 if DIR1 comes *before* DIR2 in an `ls -lR' listing,
  ;;   i.e., if DIR1 is a (grand)parent dir of DIR2,
  ;;   or DIR1 and DIR2 are in the same parentdir and their last
  ;;   components are string-lessp.
  ;; Thus ("/usr/" "/usr/bin") and ("/usr/a/" "/usr/b/") are tree-lessp.
  ;; string-lessp could arguably be replaced by file-newer-than-file-p
  ;;   if dired-actual-switches contained t.
  (setq dir1 (file-name-as-directory dir1)
	dir2 (file-name-as-directory dir2))
  (let ((components-1 (split-string dir1 "/"))
	(components-2 (split-string dir2 "/")))
    (while (and components-1
		components-2
		(equal (car components-1) (car components-2)))
      (setq components-1 (cdr components-1)
	    components-2 (cdr components-2)))
    (let ((c1 (car components-1))
	  (c2 (car components-2)))

      (cond ((and c1 c2)
	     (string-lessp c1 c2))
	    ((and (null c1) (null c2))
	     nil)			; they are equal, not lessp
	    ((null c1)			; c2 is a subdir of c1: c1<c2
	     t)
	    ((null c2)			; c1 is a subdir of c2: c1>c2
	     nil)
	    (t (error "This can't happen"))))))