changeset 9449:d11a719d7bde

(rmail-find-all-files): Fix several errors and make faster. Always return a single-level list of file names. (rmail-construct-io-menu): If FILES is null, turn off the menus. (rmail-disable-menu): A phony "command", always disabled in menus. (rmail-list-to-menu): Reverse the list L.
author Richard M. Stallman <rms@gnu.org>
date Tue, 11 Oct 1994 17:38:48 +0000
parents 99ec41e9cb2e
children af39d29d1386
files lisp/mail/rmail.el
diffstat 1 files changed, 28 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mail/rmail.el	Tue Oct 11 17:07:27 1994 +0000
+++ b/lisp/mail/rmail.el	Tue Oct 11 17:38:48 1994 +0000
@@ -708,19 +708,27 @@
   (interactive "FRun rmail on RMAIL file: ")
   (rmail filename))
 
+;; Return a list of file names for all files in or under START
+;; whose names match rmail-secondary-file-regexp.
+;; This includes START itself, if that name matches.
+;; But normally START is a directory.
 (defun rmail-find-all-files (start)
   (if (file-accessible-directory-p start)
-      (let ((files (directory-files start nil
-				    rmail-secondary-file-regexp))
+      ;; Don't sort here.
+      (let ((files (directory-files start t
+				    rmail-secondary-file-regexp t))
 	    (ret nil))
 	(while files
 	  (setq file (car files))
 	  (setq files (cdr files))
-	  (setq ret (cons
-		     (rmail-find-all-files (concat start "/" file))
-		     ret))) 
-	(cons (file-name-nondirectory start) ret))
-    (file-name-nondirectory start)))
+	  (setq ret (nconc
+		     (rmail-find-all-files file)
+		     ret)))
+	;; Sort here instead of in directory-files
+	;; because this list is usually much shorter.
+	(sort ret 'string<))
+    (if (string-match rmail-secondary-file-regexp start)
+	(list (file-name-nondirectory start)))))
 
 (defun rmail-list-to-menu (menu-name l action &optional full-name)
   (let ((menu (make-sparse-keymap menu-name)))
@@ -748,23 +756,31 @@
 				   rmail-secondary-file-directory))))))
 		 (define-key menu (vector (intern name))
 		   (cons name command))))
-     l)
+     (reverse l))
     menu))
  
+;; This command is always "disabled" when it appears in a menu.
+(put 'rmail-disable-menu 'menu-enable ''nil)
+
 (defun rmail-construct-io-menu ()
   (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
-    (if (listp files)
+    (if files
 	(progn
 	  (define-key rmail-mode-map [menu-bar classify input-menu]
 	    (cons "Input Rmail File" 
 		  (rmail-list-to-menu "Input Rmail File" 
-				      (cdr files) 
+				      files
 				      'rmail-input)))
 	  (define-key rmail-mode-map [menu-bar classify output-menu]
 	    (cons "Output Rmail File" 
 		  (rmail-list-to-menu "Output Rmail File" 
-				      (cdr files) 
-				      'rmail-output-to-rmail-file)))))))
+				      files
+				      'rmail-output-to-rmail-file))))
+
+      (define-key rmail-mode-map [menu-bar classify input-menu]
+	'("Input Rmail File" . rmail-disable-menu))
+      (define-key rmail-mode-map [menu-bar classify output-menu]
+	'("Output Rmail File" . rmail-disable-menu)))))
 
 
 ;;;; *** Rmail input ***