]> code.delx.au - gnu-emacs/blobdiff - lisp/recentf.el
* paths.el: Remove gnus-startup-file.
[gnu-emacs] / lisp / recentf.el
index ab063353fedd5fb359c6418277dd47f5c25f1ebe..72e026ab2dbde0a9f78eecc8cf5b3c9a2c3a7dd6 100644 (file)
@@ -1,6 +1,6 @@
-;; recentf.el --- setup a menu of recently opened files
+;;; recentf.el --- setup a menu of recently opened files
 
-;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
 
 ;; Author: David Ponce <david@dponce.com>
 ;; Created: July 19 1999
@@ -35,7 +35,7 @@
 ;; startup file:
 ;;
 ;;  (require 'recentf)
-;;  (recentf-mode 1) 
+;;  (recentf-mode 1)
 
 ;;; Code:
 
@@ -63,7 +63,7 @@
   "Function called when menu customization has changed.
 It removes the recentf menu and forces its complete redrawing."
   (when recentf-initialized-p
-    (easy-menu-remove-item nil 
+    (easy-menu-remove-item nil
                            (symbol-value 'recentf-menu-path)
                            (symbol-value 'recentf-menu-title))
     (setq recentf-update-menu-p t))
@@ -102,13 +102,13 @@ You should define the options of your own filters in this group."
 
 (defcustom recentf-menu-path '("files")
   "*Path where to add the recentf menu.
-If nil add it at top-level (see also `easy-menu-change')."
+If nil add it at top level (see also `easy-menu-change')."
   :group 'recentf
   :type '(choice (const :tag "Top Level" nil)
                  (sexp :tag "Menu Path"))
   :set 'recentf-menu-customization-changed)
 
-(defcustom recentf-menu-before "open-file"
+(defcustom recentf-menu-before "Open File..."
   "*Name of the menu before which the recentf menu will be added.
 If nil add it at end of menu (see also `easy-menu-change')."
   :group 'recentf
@@ -120,7 +120,7 @@ If nil add it at end of menu (see also `easy-menu-change')."
   "*Function to invoke with a filename item of the recentf menu.
 The default action `recentf-find-file' calls `find-file' to edit an
 existing file.  If the file does not exist or is not readable, it is
-not edited and its name is removed from `recentf-list'. You can use
+not edited and its name is removed from `recentf-list'.  You can use
 `find-file' instead to open non-existing files and keep them in the
 list of recently opened files."
   :group 'recentf
@@ -135,28 +135,43 @@ list of recently opened files."
 
 (defcustom recentf-menu-filter nil
   "*Function used to filter files displayed in the recentf menu.
-Nil means no filter.  The following functions are predefined:
-
-- `recentf-sort-ascending' to sort menu items in ascending order.
-- `recentf-sort-descending' to sort menu items in descending order.
-- `recentf-sort-basenames-ascending' to sort file names in descending order.
-- `recentf-sort-basenames-descending' to sort file names in descending order.
-- `recentf-sort-directories-ascending' to sort directories in ascending order.
-- `recentf-sort-directories-descending' to sort directories in descending order.
-- `recentf-show-basenames' to show file names (no directories) in menu items.
-- `recentf-show-basenames-ascending' to show file names in ascending order.
-- `recentf-show-basenames-descending' to show file names in descending order.
-- `recentf-relative-filter' to show file names relative to `default-directory'.
-- `recentf-arrange-by-rule' to show sub-menus following user defined rules.
-- `recentf-arrange-by-mode' to show a sub-menu for each major mode.
-- `recentf-arrange-by-dir' to show a sub-menu for each directory.
-- `recentf-filter-changer' to manage a ring of filters.
+nil means no filter.  The following functions are predefined:
+
+- `recentf-sort-ascending' to sort menu items in ascending order.
+- `recentf-sort-descending' to sort menu items in descending order.
+- `recentf-sort-basenames-ascending' to sort file names in descending order.
+- `recentf-sort-basenames-descending' to sort file names in descending order.
+- `recentf-sort-directories-ascending' to sort directories in ascending order.
+- `recentf-sort-directories-descending' to sort directories in descending order.
+- `recentf-show-basenames' to show file names (no directories) in menu items.
+- `recentf-show-basenames-ascending' to show file names in ascending order.
+- `recentf-show-basenames-descending' to show file names in descending order.
+- `recentf-relative-filter' to show file names relative to `default-directory'.
+- `recentf-arrange-by-rule' to show sub-menus following user defined rules.
+- `recentf-arrange-by-mode' to show a sub-menu for each major mode.
+- `recentf-arrange-by-dir' to show a sub-menu for each directory.
+- `recentf-filter-changer' to manage a ring of filters.
 
 The filter function is called with one argument, the list of menu elements
 used to build the menu and must return a new list of menu elements (see
 `recentf-make-menu-element' for menu element form)."
   :group 'recentf
-  :type 'function
+  :type '(radio (const nil) 
+               (function-item recentf-sort-ascending)
+               (function-item recentf-sort-descending)
+               (function-item recentf-sort-basenames-ascending)
+               (function-item recentf-sort-basenames-descending)
+               (function-item recentf-sort-directories-ascending)
+               (function-item recentf-sort-directories-descending)
+               (function-item recentf-show-basenames)
+               (function-item recentf-show-basenames-ascending)
+               (function-item recentf-show-basenames-descending)
+               (function-item recentf-relative-filter)
+               (function-item recentf-arrange-by-rule)
+               (function-item recentf-arrange-by-mode)
+               (function-item recentf-arrange-by-dir)
+               (function-item recentf-filter-changer)
+               function)
   :set 'recentf-menu-customization-changed)
 
 (defcustom recentf-menu-append-commands-p t
@@ -177,33 +192,20 @@ used to build the menu and must return a new list of menu elements (see
            (add-hook 'kill-buffer-hook 'recentf-remove-file-hook))
          (custom-set-default sym val)))
 
-(defcustom recentf-mode nil
-  "Toggle recentf mode.
-When recentf mode is enabled, it maintains a menu for visiting files that
-were operated on recently.
-Setting this variable directly does not take effect;
-use either \\[customize] or the function `recentf-mode'."
-  :set (lambda (symbol value)
-         (recentf-mode (or value 0)))
-  :initialize 'custom-initialize-default
-  :type 'boolean
-  :group 'recentf
-  :require 'recentf)
-
 (defcustom recentf-load-hook nil
    "*Normal hook run at end of loading the `recentf' package."
   :group 'recentf
   :type 'hook)
 
-;;;
-;;; Common functions
-;;;
+;;;;
+;;;; Common functions
+;;;;
 (defconst recentf-case-fold-search
   (memq system-type '(vax-vms windows-nt))
   "Non-nil if recentf searches and matches should ignore case.")
 
 (defun recentf-include-p (filename)
-  "Return t if FILENAME matches none of the `recentf-exclude' regexps."
+  "Return t if FILENAME match none of the `recentf-exclude' regexps."
   (let ((case-fold-search recentf-case-fold-search)
         (rl recentf-exclude))
     (while (and rl (not (string-match (car rl) filename)))
@@ -254,7 +256,7 @@ A menu element is a pair (MENU-ITEM . MENU-VALUE) where:
 
 - - MENU-ITEM  is the menu item string displayed.
 - - MENU-VALUE is the path used to open the file when the
-               corresponding MENU-ITEM is selected. Or it is
+               corresponding MENU-ITEM is selected.  Or it is
                a pair (SUB-MENU-TITLE . MENU-ELEMENTS) where
                SUB-MENU-TITLE is a sub-menu title and
                MENU-ELEMENTS is the list of menu elements in
@@ -282,22 +284,23 @@ A menu element is a pair (MENU-ITEM . MENU-VALUE) where:
   (consp (recentf-menu-element-value e)))
 
 (defun recentf-make-default-menu-element (file-path)
-  "Make a new default menu element (MENU-ITEM . MENU-VALUE) for the
-given recent file path FILE-PATH. MENU-ITEM and MENU-VALUE are set to
-FILE-PATH. See also `recentf-make-menu-element'."
+  "Make a new default menu element (MENU-ITEM . MENU-VALUE).
+Do so for the given recent file path FILE-PATH.  MENU-ITEM and
+MENU-VALUE are set to FILE-PATH.  See also
+`recentf-make-menu-element'."
   (recentf-make-menu-element file-path file-path))
 
 (defun recentf-menu-elements (n)
-  "Return a list of the first N default menu elements from
-`recentf-list'. See also `recentf-make-default-menu-element'."
+  "Return a list of the first N default menu elements from `recentf-list'.
+See also `recentf-make-default-menu-element'."
   (mapcar 'recentf-make-default-menu-element
           (recentf-elements n)))
 
 (defun recentf-apply-menu-filter (filter l)
-  "Convenient funtion to apply the function FILTER to the list of
-menu-elements L. It takes care of sub-menu elements in L and
-recursively apply FILTER to them. It is guarantee than FILTER receives
-only a list of single menu-elements (no sub-menu)."
+  "Apply function FILTER to the list of menu-elements L.
+It takes care of sub-menu elements in L and recursively apply FILTER
+to them.  It is guaranteed that FILTER receives only a list of single
+menu-elements (no sub-menu)."
   (if (and (functionp filter) l)
       (let ((case-fold-search recentf-case-fold-search)
             menu-element sub-menu-elements single-elements)
@@ -333,10 +336,23 @@ only a list of single menu-elements (no sub-menu)."
     l))
 
 (defvar recentf-menu-items-for-commands
-  (list ["Cleanup list" recentf-cleanup t]
-        ["Edit list..." recentf-edit-list t]
-        ["Save list now" recentf-save-list t]
-        (vector "Recentf Options..." '(customize-group "recentf") t))
+  (list ["Cleanup list"
+         recentf-cleanup
+         :help "Remove all non-readable and excluded files from the recent list"
+         :active t]
+        ["Edit list..."
+         recentf-edit-list
+         :help "Edit the files that are kept in the recent list"
+         :active t]
+        ["Save list now"
+         recentf-save-list
+         :help "Save the list of recently opened files now"
+         :active t]
+        ["Options..."
+         (customize-group "recentf")
+         :help "Customize recently opened files menu and options"
+         :active t]
+        )
   "List of menu items for recentf commands.")
 
 (defvar recentf-menu-filter-commands nil
@@ -354,9 +370,13 @@ filter function this variable is reset to nil.")
                  (recentf-apply-menu-filter
                   recentf-menu-filter
                   (recentf-menu-elements recentf-max-menu-items)))))
-    (append (or file-items (list ["No files" t nil]))
+    (append (or file-items (list ["No files" t
+                                  :help "No recent file to open"
+                                  :active nil]))
             (and (< recentf-max-menu-items (length recentf-list))
-                 (list ["More..." recentf-open-more-files t]))
+                 (list ["More..." recentf-open-more-files
+                        :help "Open files that are not in the menu"
+                        :active t]))
             (and recentf-menu-filter-commands
                  (cons "---"
                        recentf-menu-filter-commands))
@@ -365,18 +385,19 @@ filter function this variable is reset to nil.")
                        recentf-menu-items-for-commands)))))
 
 (defun recentf-make-menu-item (menu-element)
-  "Make a menu item from a menu element (see `recentf-make-menu-element')."
+  "Make a menu item from MENU-ELEMENT (see `recentf-make-menu-element')."
   (let ((menu-item  (recentf-menu-element-item  menu-element))
         (menu-value (recentf-menu-element-value menu-element)))
     (if (recentf-sub-menu-element-p menu-element)
         (cons menu-item (mapcar 'recentf-make-menu-item menu-value))
       (vector menu-item
               (list recentf-menu-action menu-value)
-              t))))
+              :help (concat "Open " menu-value)
+              :active t))))
 
-;;;
-;;; Predefined menu filter functions
-;;;
+;;;;
+;;;; Predefined menu filter functions
+;;;;
 
 (defun recentf-sort-ascending (l)
   "Sort the list of menu elements L in ascending order.
@@ -417,8 +438,8 @@ Only file names (without directories) are compared."
             (file-name-nondirectory (recentf-menu-element-value e1)))))))
 
 (defun recentf-directory-compare (p1 p2)
-  "Compare directories then filenames in pathes P1 and P2 and return
-non-nil if P1 is less than P2."
+  "Compare directories then filenames in paths P1 and P2.
+Return non-nil if P1 is less than P2."
   (let ((d1 (file-name-directory    p1))
         (f1 (file-name-nondirectory p1))
         (d2 (file-name-directory    p2))
@@ -447,7 +468,7 @@ Compares directories then filenames to order the list."
 
 (defun recentf-show-basenames (l)
   "Filter the list of menu elements L to show only file names (no directories)
-in the menu. When file names are duplicated their directory component is added."
+in the menu.  When file names are duplicated their directory component is added."
   (let ((names  (mapcar (function
                          (lambda (item)
                            (file-name-nondirectory
@@ -476,20 +497,22 @@ in the menu. When file names are duplicated their directory component is added."
     (nreverse filtered-list)))
 
 (defun recentf-show-basenames-ascending (l)
-  "Filter the list of menu elements L to show only file names in the menu,
-sorted in ascending order. This filter combines the `recentf-sort-basenames-ascending'
-and `recentf-show-basenames' filters."
+  "Filter the list of menu elements L.
+Show only file names in the menu, sorted in ascending order.  This
+filter combines the `recentf-sort-basenames-ascending' and
+`recentf-show-basenames' filters."
   (recentf-show-basenames (recentf-sort-basenames-ascending l)))
 
 (defun recentf-show-basenames-descending (l)
-  "Filter the list of menu elements L to show only file names in the menu,
-sorted in descending order. This filter combines the `recentf-sort-basenames-descending'
-and `recentf-show-basenames' filters."
+  "Filter the list of menu elements L.
+Show only file names in the menu, sorted in descending order.  This
+filter combines the `recentf-sort-basenames-descending' and
+`recentf-show-basenames' filters."
   (recentf-show-basenames (recentf-sort-basenames-descending l)))
 
 (defun recentf-relative-filter (l)
-  "Filter the list of `recentf-menu-elements' L to show filenames
-relative to `default-directory'."
+  "Filter the list of `recentf-menu-elements' L.
+Show filenames relative to `default-directory'."
   (setq recentf-update-menu-p t)        ; force menu update
   (mapcar (function
            (lambda (menu-element)
@@ -507,21 +530,21 @@ relative to `default-directory'."
     ("C/C++ files (%d)" "c\\(pp\\)?$")
     )
   "*List of rules used by `recentf-arrange-by-rule' to build sub-menus.
-A rule is a pair (SUB-MENU-TITLE . MATCHER). SUB-MENU-TITLE is the
+A rule is a pair (SUB-MENU-TITLE . MATCHER).  SUB-MENU-TITLE is the
 displayed title of the sub-menu where a '%d' `format' pattern is
-replaced by the number of items in the sub-menu. MATCHER is a regexp
-or a list of regexps. Items matching one of the regular expressions in
+replaced by the number of items in the sub-menu.  MATCHER is a regexp
+or a list of regexps.  Items matching one of the regular expressions in
 MATCHER are added to the corresponding sub-menu."
   :group 'recentf-filters
   :type '(repeat (cons string (repeat regexp)))
   :set 'recentf-menu-customization-changed)
 
 (defcustom recentf-arrange-by-rule-others "Other files (%d)"
-  "*Title of the `recentf-arrange-by-rule' sub-menu where items that
-don't match any `recentf-arrange-rules' are displayed. If nil
-these items are displayed in the main recent files menu. A '%d'
-`format' pattern in the title is replaced by the number of items in
-the sub-menu."
+  "*Title of the `recentf-arrange-by-rule' sub-menu.
+This is for the menu where items that don't match any
+`recentf-arrange-rules' are displayed.  If nil these items are
+displayed in the main recent files menu.  A '%d' `format' pattern in
+the title is replaced by the number of items in the sub-menu."
   :group 'recentf-filters
   :type '(choice (const  :tag "Main menu" nil)
                  (string :tag "Title"))
@@ -539,10 +562,10 @@ defined."
 
 (defcustom recentf-arrange-by-rule-subfilter nil
   "*Function used by `recentf-arrange-by-rule' to filter sub-menu elements.
-Nil means no filter. See also `recentf-menu-filter'. You can't use
+nil means no filter.  See also `recentf-menu-filter'.  You can't use
 `recentf-arrange-by-rule' itself here!"
   :group 'recentf-filters
-  :type 'function
+  :type '(choice (const nil) function)
   :set (lambda (sym val)
          (if (eq val 'recentf-arrange-by-rule)
              (error "Can't use `recentf-arrange-by-rule' itself here!")
@@ -559,8 +582,8 @@ See `recentf-arrange-rules' for details on MATCHER."
     matcher))
 
 (defun recentf-arrange-by-rule (l)
-  "Filter the list of menu-elements L to arrange them in sub-menus
-following rules in `recentf-arrange-rules'."
+  "Filter the list of menu-elements L.
+Arrange them in sub-menus following rules in `recentf-arrange-rules'."
   (let ((sub-menus-number (length recentf-arrange-rules)))
     (if (> sub-menus-number 0)
         (let ((sub-menus (apply 'vector
@@ -655,23 +678,21 @@ following rules in `recentf-arrange-rules'."
     (nreverse rules)))
          
 (defun recentf-arrange-by-mode (l)
-  "Filter the list of menu-elements L to build sub-menus for each
-major mode."
+  "Filter the list of menu-elements L to build sub-menus for each major mode."
   (let ((recentf-arrange-rules (recentf-build-mode-rules))
         (recentf-arrange-by-rule-others "others (%d)"))
     (recentf-arrange-by-rule l)))
 
 (defun recentf-build-dir-rules (l)
-  "Convert directories in the list of menu-elements L to rules in
-`recentf-arrange-rules' format."
+  "Convert directories in menu-elements L to rules in `recentf-arrange-rules' format."
   (let (dirs)
-    (mapcar (function
-             (lambda (e)
-               (let ((dir (file-name-directory
-                           (recentf-menu-element-value e))))
-                 (or (member dir dirs)
-                     (setq dirs (cons dir dirs))))))
-            l)
+    (mapc (function
+           (lambda (e)
+             (let ((dir (file-name-directory
+                         (recentf-menu-element-value e))))
+               (or (member dir dirs)
+                   (setq dirs (cons dir dirs))))))
+          l)
     (mapcar (function
              (lambda (d)
                (cons (concat d " (%d)")
@@ -679,9 +700,9 @@ major mode."
             (nreverse (sort dirs 'string-lessp)))))
 
 (defun recentf-file-name-nondir (l)
-  "Filter the list of menu-elements L to show only filenames. This
-simplified version of `recentf-show-basenames' do not handle
-duplicates. It is used by `recentf-arrange-by-dir' as its
+  "Filter the list of menu-elements L to show only filenames.
+This simplified version of `recentf-show-basenames' does not handle
+duplicates.  It is used by `recentf-arrange-by-dir' as its
 `recentf-arrange-by-rule-subfilter'."
   (mapcar (function
            (lambda (e)
@@ -691,8 +712,7 @@ duplicates. It is used by `recentf-arrange-by-dir' as its
           l))
 
 (defun recentf-arrange-by-dir (l)
-  "Filter the list of menu-elements L to build sub-menus for each
-directory."
+  "Filter the list of menu-elements L to build sub-menus for each directory."
   (let ((recentf-arrange-rules (recentf-build-dir-rules l))
         (recentf-arrange-by-rule-subfilter 'recentf-file-name-nondir)
         recentf-arrange-by-rule-others)
@@ -747,11 +767,12 @@ Each filter is defined by a pair (FILTER-FUN . FILTER-LBL) where:
         (car filters))))
         
 (defun recentf-filter-changer (l)
-  "Manage a ring of filters. `recentf-filter-changer-alist' defines
-the filters in the ring. Actual filtering of L is delegated to the
-current filter in the ring. A filter menu item is displayed allowing
-to dynamically activate the next filter in the ring. If the filter
-ring is empty L is left unchanged."
+  "Manage a ring of filters.
+`recentf-filter-changer-alist' defines the filters in the ring.
+Actual filtering of L is delegated to the current filter in the
+ring.  A filter menu item is displayed allowing to dynamically activate
+the next filter in the ring.  If the filter ring is empty L is left
+unchanged."
   (let ((current-filter-item (recentf-filter-changer-get-current))
         (next-filter-item    (recentf-filter-changer-get-next)))
     (when current-filter-item
@@ -760,19 +781,19 @@ ring is empty L is left unchanged."
           (setq recentf-menu-filter-commands
                 (list (vector (cdr next-filter-item)
                               '(recentf-filter-changer-goto-next)
-                              t)))))
+                              :active t)))))
     l))
 
-;;;
-;;; Dialogs stuff
-;;;
+;;;;
+;;;; Dialogs stuff
+;;;;
 
 (defun recentf-cancel-dialog (&rest ignore)
-  "Cancel the current dialog. Used by `recentf-edit-list' and
-`recentf-open-files' dialogs."
+  "Cancel the current dialog.
+Used by `recentf-edit-list' and `recentf-open-files' dialogs."
   (interactive)
   (kill-buffer (current-buffer))
-  (message "Dialog canceled."))
+  (message "Dialog canceled"))
 
 (defvar recentf-dialog-mode-map nil
   "`recentf-dialog-mode' keymap.")
@@ -787,16 +808,16 @@ ring is empty L is left unchanged."
 (defun recentf-dialog-mode ()
   "Major mode used in recentf dialogs.
 
-These are the special commands of recentf-dialog-mode mode:
+These are the special commands of `recentf-dialog-mode' mode:
     q -- cancel this dialog."
   (interactive)
   (setq major-mode 'recentf-dialog-mode)
   (setq mode-name "recentf-dialog")
   (use-local-map recentf-dialog-mode-map))
 
-;;;
-;;; Hooks and Commands
-;;;
+;;;;
+;;;; Hooks and Commands
+;;;;
 
 (defun recentf-add-file-hook ()
   "Insert the name of the file just opened or written into `recentf-list'."
@@ -821,22 +842,18 @@ These are the special commands of recentf-dialog-mode mode:
       (error nil))))
 
 (defun recentf-dump-variable (variable &optional limit)
-  "Insert a \"(setq VARIABLE value)\" in the current buffer. Optional
-argument LIMIT specifies a maximum length when VARIABLE value is a
-list (default to the full list)."
+  "Insert a \"(setq VARIABLE value)\" in the current buffer.
+Optional argument LIMIT specifies a maximum length when VARIABLE value
+is a list (default to the full list)."
   (let ((value (symbol-value variable)))
-    (insert (format "(setq %S\n      '(\n" variable))
-    (cond ((consp value)
-           (if (and (integerp limit) (> limit 0))
-               (setq value (recentf-trunc-list value limit)))
-           (mapcar (function
-                    (lambda (e)
-                      (insert (format "        %S\n" e))))
-                   value))
-          (t
-           (insert (format "        %S\n" value))))
-    (insert "        ))\n")
-    ))
+    (if (listp value)
+       (progn
+         (when (and (integerp limit) (> limit 0))
+           (setq value (recentf-trunc-list value limit)))
+         (insert (format "(setq %S '(" variable))
+         (mapc (lambda (e) (insert (format "\n%S" e))) value)
+         (insert "))\n"))
+      (insert (format "(setq %S %S)\n" variable value)))))
 
 ;;;###autoload
 (defun recentf-save-list ()
@@ -853,11 +870,11 @@ list (default to the full list)."
   nil)
 
 (defvar recentf-edit-selected-items nil
-  "Used by `recentf-edit-list' to hold the list of files to be deleted
-from `recentf-list'.")
+  "Used by `recentf-edit-list'.
+Holds list of files to be deleted from `recentf-list'.")
 
 (defun recentf-edit-list-action (widget &rest ignore)
-  "Checkbox widget action used by `recentf-edit-list' to select/unselect a file."
+  "Checkbox WIDGET action used by `recentf-edit-list' to select/unselect a file."
   (let ((value (widget-get widget ':tag)))
     ;; if value is already in the selected items
     (if (memq value recentf-edit-selected-items)
@@ -883,33 +900,33 @@ from `recentf-list'.")
       (erase-buffer))
     (let ((all (overlay-lists)))
       ;; Delete all the overlays.
-      (mapcar 'delete-overlay (car all))
-      (mapcar 'delete-overlay (cdr all)))
+      (mapc 'delete-overlay (car all))
+      (mapc 'delete-overlay (cdr all)))
     (setq recentf-edit-selected-items nil)
     ;; Insert the dialog header
     (widget-insert "Select the files to be deleted from the 'recentf-list'.\n\n")
     (widget-insert "Click on Ok to update the list. ")
     (widget-insert "Click on Cancel or type \"q\" to quit.\n")
     ;; Insert the list of files as checkboxes
-    (mapcar (function
-             (lambda (item)
-               (widget-create 'checkbox
-                              :value nil ; unselected checkbox
-                              :format "\n %[%v%]  %t"
-                              :tag item
-                              :notify 'recentf-edit-list-action)))
-            recentf-list)
+    (mapc (function
+           (lambda (item)
+             (widget-create 'checkbox
+                            :value nil  ; unselected checkbox
+                            :format "\n %[%v%]  %t"
+                            :tag item
+                            :notify 'recentf-edit-list-action)))
+          recentf-list)
     (widget-insert "\n\n")
     ;; Insert the Ok button
     (widget-create 'push-button
                    :notify (lambda (&rest ignore)
                              (if recentf-edit-selected-items
                                  (progn (kill-buffer (current-buffer))
-                                        (mapcar (function
-                                                 (lambda (item)
-                                                   (setq recentf-list
-                                                         (delq item recentf-list))))
-                                                recentf-edit-selected-items)
+                                        (mapc (function
+                                               (lambda (item)
+                                                 (setq recentf-list
+                                                       (delq item recentf-list))))
+                                              recentf-edit-selected-items)
                                         (message "%S file(s) removed from the list"
                                                  (length recentf-edit-selected-items))
                                         (setq recentf-update-menu-p t))
@@ -945,17 +962,15 @@ from `recentf-list'.")
   (setq recentf-update-menu-p t))
 
 (defun recentf-open-files-action (widget &rest ignore)
-  "Button widget action used by `recentf-open-files' to open a file."
+  "Button WIDGET action used by `recentf-open-files' to open a file."
   (kill-buffer (current-buffer))
   (funcall recentf-menu-action (widget-value widget)))
 
 (defvar recentf-open-files-item-shift ""
-  "String used by `recentf-open-files' to shift right sub-menu
-items.")
+  "String used by `recentf-open-files' to shift right sub-menu items.")
 
 (defun recentf-open-files-item (menu-element)
-  "Function called by `recentf-open-files' to insert a menu-element
-item in the current interaction buffer."
+  "Insert MENU-ELEMENT item in the current interaction buffer."
   (let ((menu-item (car menu-element))
         (file-path (cdr menu-element)))
     (if (consp file-path)               ; This is a sub-menu
@@ -965,8 +980,8 @@ item in the current interaction buffer."
                          :tag menu-item
                          :sample-face 'bold
                          :format (concat shift "%{%t%}:\n"))
-          (mapcar 'recentf-open-files-item
-                  file-path)
+          (mapc 'recentf-open-files-item
+                file-path)
           (widget-insert "\n"))
       (widget-create 'push-button
                      :button-face 'default
@@ -979,10 +994,10 @@ item in the current interaction buffer."
 
 ;;;###autoload
 (defun recentf-open-files (&optional files buffer-name)
-  "Open a buffer that allows the user to choose a file to open from
-the list of recently opened files. The optional argument FILES may be
-used to specify the list, otherwise recentf-list is used. The optional
-argument BUFFER-NAME specifies which buffer to use for the interaction."
+  "Display buffer allowing user to choose a file from recently-opened list.
+The optional argument FILES may be used to specify the list, otherwise
+`recentf-list' is used.  The optional argument BUFFER-NAME specifies
+which buffer to use for the interaction."
   (interactive)
   (if (null files)
       (setq files recentf-list))
@@ -995,17 +1010,17 @@ argument BUFFER-NAME specifies which buffer to use for the interaction."
       (erase-buffer))
     (let ((all (overlay-lists)))
       ;; Delete all the overlays.
-      (mapcar 'delete-overlay (car all))
-      (mapcar 'delete-overlay (cdr all)))
+      (mapc 'delete-overlay (car all))
+      (mapc 'delete-overlay (cdr all)))
     ;; Insert the dialog header
     (widget-insert "Click on a file to open it. ")
     (widget-insert "Click on Cancel or type \"q\" to quit.\n\n" )
     ;; Insert the list of files as buttons
     (let ((recentf-open-files-item-shift ""))
-      (mapcar 'recentf-open-files-item
-              (recentf-apply-menu-filter
-               recentf-menu-filter
-               (mapcar 'recentf-make-default-menu-element files))))
+      (mapc 'recentf-open-files-item
+            (recentf-apply-menu-filter
+             recentf-menu-filter
+             (mapcar 'recentf-make-default-menu-element files))))
     (widget-insert "\n")
     ;; Insert the Cancel button
     (widget-create 'push-button
@@ -1022,40 +1037,43 @@ argument BUFFER-NAME specifies which buffer to use for the interaction."
   (recentf-open-files (nthcdr recentf-max-menu-items recentf-list)
                      (concat "*" recentf-menu-title " - More*")))
 
+
+;;; Note this definition must be at the end of the file, because
+;;; `define-minor-mode' actually calls the mode-function if the
+;;; associated variable is non-nil, which requires that all needed
+;;; functions be already defined.  [This is arguably a bug in d-m-m]
 ;;;###autoload
-(defun recentf-mode (&optional arg)
+(define-minor-mode recentf-mode
   "Toggle recentf mode.
-With prefix ARG, turn recentf mode on if and only if ARG is positive.
-Returns the new status of recentf mode (non-nil means on).
+With prefix argument ARG, turn on if positive, otherwise off.
+Returns non-nil if the new state is enabled.
 
 When recentf mode is enabled, it maintains a menu for visiting files that
 were operated on recently."
-  (interactive "P")
-  (let ((on-p (if arg
-                  (> (prefix-numeric-value arg) 0)
-                (not recentf-mode))))
-    (if on-p
-        (unless recentf-initialized-p
-          (setq recentf-initialized-p t)
-          (if (file-readable-p recentf-save-file)
-              (load-file recentf-save-file))
-          (setq recentf-update-menu-p t)
-          (add-hook 'find-file-hooks       'recentf-add-file-hook)
-          (add-hook 'write-file-hooks      'recentf-add-file-hook)
-          (add-hook 'menu-bar-update-hook  'recentf-update-menu-hook)
-          (add-hook 'kill-emacs-hook       'recentf-save-list))
-      (when recentf-initialized-p
-        (setq recentf-initialized-p nil)
-        (recentf-save-list)
-        (easy-menu-remove-item nil recentf-menu-path recentf-menu-title)
-        (remove-hook 'find-file-hooks       'recentf-add-file-hook)
-        (remove-hook 'write-file-hooks      'recentf-add-file-hook)
-        (remove-hook 'menu-bar-update-hook  'recentf-update-menu-hook)
-        (remove-hook 'kill-emacs-hook       'recentf-save-list)))
-    (setq recentf-mode on-p)))
+  :global t
+  :group 'recentf
+  (if recentf-mode
+      (unless recentf-initialized-p
+       (setq recentf-initialized-p t)
+       (if (file-readable-p recentf-save-file)
+           (load-file recentf-save-file))
+       (setq recentf-update-menu-p t)
+       (add-hook 'find-file-hooks       'recentf-add-file-hook)
+       (add-hook 'write-file-hooks      'recentf-add-file-hook)
+       (add-hook 'menu-bar-update-hook  'recentf-update-menu-hook)
+       (add-hook 'kill-emacs-hook       'recentf-save-list))
+    (when recentf-initialized-p
+      (setq recentf-initialized-p nil)
+      (recentf-save-list)
+      (easy-menu-remove-item nil recentf-menu-path recentf-menu-title)
+      (remove-hook 'find-file-hooks       'recentf-add-file-hook)
+      (remove-hook 'write-file-hooks      'recentf-add-file-hook)
+      (remove-hook 'menu-bar-update-hook  'recentf-update-menu-hook)
+      (remove-hook 'kill-emacs-hook       'recentf-save-list))))
+
 
 (provide 'recentf)
 
 (run-hooks 'recentf-load-hook)
 
-;;; recentf.el ends here.
+;;; recentf.el ends here