Spelling fixes.
[bpt/emacs.git] / lisp / recentf.el
index d172396..2dac870 100644 (file)
@@ -1,7 +1,6 @@
 ;;; recentf.el --- setup a menu of recently opened files
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
 
 ;; Author: David Ponce <david@dponce.com>
 ;; Created: July 19 1999
@@ -9,10 +8,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published
-;; by the Free Software Foundation; either version 3, or (at your
-;; option) any later version.
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;; This package maintains a menu for visiting files that were operated
 ;; on recently.  When enabled a new "Open Recent" sub menu is
-;; displayed in the "Files" menu.  The recent files list is
+;; displayed in the "File" menu.  The recent files list is
 ;; automatically saved across Emacs sessions.  You can customize the
 ;; number of recent files displayed, the location of the menu and
 ;; others options (see the source code for details).
 
+;; To enable this package, add the following to your .emacs:
+;; (recentf-mode 1)
+
 ;;; History:
 ;;
 
@@ -69,7 +69,7 @@ See the command `recentf-save-list'."
   :group 'recentf
   :type 'integer)
 
-(defcustom recentf-save-file "~/.recentf"
+(defcustom recentf-save-file (convert-standard-filename "~/.recentf")
   "File to save the recent list into."
   :group 'recentf
   :type 'file
@@ -227,15 +227,15 @@ This item will replace the \"More...\" item."
   :group 'recentf
   :type 'boolean)
 
+(define-obsolete-variable-alias 'recentf-menu-append-commands-p
+                                'recentf-menu-append-commands-flag
+                                "22.1")
+
 (defcustom recentf-menu-append-commands-flag t
   "Non-nil means to append command items to the menu."
   :group 'recentf
   :type 'boolean)
 
-(define-obsolete-variable-alias 'recentf-menu-append-commands-p
-                                'recentf-menu-append-commands-flag
-                                "22.1")
-
 (defcustom recentf-auto-cleanup 'mode
   "Define when to automatically cleanup the recent list.
 The following values can be set:
@@ -302,7 +302,7 @@ used as shortcuts to open the Nth file."
 ;;; Utilities
 ;;
 (defconst recentf-case-fold-search
-  (memq system-type '(vax-vms windows-nt cygwin))
+  (memq system-type '(windows-nt cygwin))
   "Non-nil if recentf searches and matches should ignore case.")
 
 (defsubst recentf-string-equal (s1 s2)
@@ -411,13 +411,14 @@ That is, if it doesn't match any of the `recentf-exclude' checks."
         (checks recentf-exclude)
         (keepit t))
     (while (and checks keepit)
-      (setq keepit (condition-case nil
-                       (not (if (stringp (car checks))
-                                ;; A regexp
-                                (string-match (car checks) filename)
-                              ;; A predicate
-                              (funcall (car checks) filename)))
-                     (error nil))
+      ;; If there was an error in a predicate, err on the side of
+      ;; keeping the file.  (Bug#5843)
+      (setq keepit (not (ignore-errors
+                          (if (stringp (car checks))
+                              ;; A regexp
+                              (string-match (car checks) filename)
+                            ;; A predicate
+                            (funcall (car checks) filename))))
             checks (cdr checks)))
     keepit))
 
@@ -566,7 +567,7 @@ menu-elements (no sub-menu)."
   (if (and l (functionp filter))
       (let ((case-fold-search recentf-case-fold-search)
             elts others)
-        ;; split L into two sub-listes, one of sub-menus elements and
+        ;; split L into two sub-lists, one of sub-menus elements and
         ;; another of single menu elements.
         (dolist (elt l)
           (if (recentf-sub-menu-element-p elt)
@@ -589,7 +590,7 @@ menu-elements (no sub-menu)."
 ;; Count the number of assigned menu shortcuts.
 (defvar recentf-menu-shortcuts)
 
-(defun recentf-make-menu-items (&optional menu)
+(defun recentf-make-menu-items (&optional _menu)
   "Make menu items from the recent list.
 This is a menu filter function which ignores the MENU argument."
   (setq recentf-menu-filter-commands nil)
@@ -1035,7 +1036,7 @@ That is, remove a non kept file from the recent list."
 
 ;;; Common dialog stuff
 ;;
-(defun recentf-cancel-dialog (&rest ignore)
+(defun recentf-cancel-dialog (&rest _ignore)
   "Cancel the current dialog.
 IGNORE arguments."
   (interactive)
@@ -1091,7 +1092,7 @@ Go to the beginning of buffer if not found."
 ;;
 (defvar recentf-edit-list nil)
 
-(defun recentf-edit-list-select (widget &rest ignore)
+(defun recentf-edit-list-select (widget &rest _ignore)
   "Toggle a file selection based on the checkbox WIDGET state.
 IGNORE other arguments."
   (let ((value (widget-get widget :tag))
@@ -1101,7 +1102,7 @@ IGNORE other arguments."
       (setq recentf-edit-list (delq value recentf-edit-list)))
     (message "%s %sselected" value (if check "" "un"))))
 
-(defun recentf-edit-list-validate (&rest ignore)
+(defun recentf-edit-list-validate (&rest _ignore)
   "Process the recent list when the edit list dialog is committed.
 IGNORE arguments."
   (if recentf-edit-list
@@ -1145,7 +1146,7 @@ Click on Cancel or type `q' to cancel.\n")
 \f
 ;;; Open file dialog
 ;;
-(defun recentf-open-files-action (widget &rest ignore)
+(defun recentf-open-files-action (widget &rest _ignore)
   "Open the file stored in WIDGET's value when notified.
 IGNORE other arguments."
   (kill-buffer (current-buffer))
@@ -1309,13 +1310,20 @@ empty `file-name-history' with the recent list."
 That is, remove duplicates, non-kept, and excluded files."
   (interactive)
   (message "Cleaning up the recentf list...")
-  (let ((n 0) newlist)
+  (let ((n 0)
+       (ht (make-hash-table
+            :size recentf-max-saved-items
+            :test 'equal))
+       newlist key)
     (dolist (f recentf-list)
-      (setq f (recentf-expand-file-name f))
+      (setq f (recentf-expand-file-name f)
+           key (if recentf-case-fold-search (downcase f) f))
       (if (and (recentf-include-p f)
                (recentf-keep-p f)
-               (not (recentf-string-member f newlist)))
-          (push f newlist)
+               (not (gethash key ht)))
+         (progn
+           (push f newlist)
+           (puthash key t ht))
         (setq n (1+ n))
         (message "File %s removed from the recentf list" f)))
     (message "Cleaning up the recentf list...done (%d removed)" n)
@@ -1328,12 +1336,14 @@ That is, remove duplicates, non-kept, and excluded files."
 
 ;;;###autoload
 (define-minor-mode recentf-mode
-  "Toggle recentf mode.
-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."
+  "Toggle \"Open Recent\" menu (Recentf mode).
+With a prefix argument ARG, enable Recentf mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+Recentf mode if ARG is omitted or nil.
+
+When Recentf mode is enabled, a \"Open Recent\" submenu is
+displayed in the \"File\" menu, containing a list of files that
+were operated on recently."
   :global t
   :group 'recentf
   :keymap recentf-mode-map
@@ -1347,15 +1357,16 @@ that were operated on recently."
     (recentf-auto-cleanup)
     (let ((hook-setup (if recentf-mode 'add-hook 'remove-hook)))
       (dolist (hook recentf-used-hooks)
-        (apply hook-setup hook)))
-    (run-hooks 'recentf-mode-hook)
-    (when (interactive-p)
-      (message "Recentf mode %sabled" (if recentf-mode "en" "dis"))))
-  recentf-mode)
+        (apply hook-setup hook)))))
+
+(defun recentf-unload-function ()
+  "Unload the recentf library."
+  (recentf-mode -1)
+  ;; continue standard unloading
+  nil)
 
 (provide 'recentf)
 
 (run-hooks 'recentf-load-hook)
 \f
-;; arch-tag: 78f1eec9-0d16-4d19-a4eb-2e4529edb62a
 ;;; recentf.el ends here