unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Revisit: recentf-cleanup, file-readable-p & remote files
@ 2005-03-11 22:32 Michael Mauger
  2005-03-13 11:53 ` David Ponce
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Mauger @ 2005-03-11 22:32 UTC (permalink / raw)


Not to drag up old discussions, but I was reviewing some old patches that
I still use.

Back in Sep 2003, a request was made to exclude remote files from the
automatic cleanup process that recentf.el runs when it is enabled.  The
discussion ended forking off into a discussion of performance of Tramp
and detecting network connectivity.

I am now in a situation where about half of the files I edit are local
and the remainder are on a remote Unix server.  I appreciate the
automatic cleanup of files on the recentf list and would like to leave
that feature in place.  Unfortunately the time to connect to the badly
overloaded server and checking files there has gotten painful.  Having
the remote filenames on the recentf list is valuable (thus I don't want
to place remote files on the recentf-exclude list).  What I would like to
be able to do is just not check these remote files as part of the auto
cleanup process.

Below is a simple patch which adds a customizable flag indicating whether
remote files should be cleaned up.  This flag is then checked before
checking the status of a remote file.  The default is to check remote
files, thus behavior is unchanged.  I've been using this patch for a year
without problems.

2005-03-11  Michael R. Mauger  <mmaug@yahoo.com>

	* recentf.el (recentf-cleanup-remote): New variable.  Should
	remote files be cleaned up?
	(recentf-cleanup): Use variable to conditionally check availablity
	of remote files.

Index: emacs/lisp/recentf.el
===================================================================
RCS file: /c/cvsroot/emacs/emacs/lisp/recentf.el,v
retrieving revision 1.30
diff -u -r1.30 recentf.el
--- emacs/lisp/recentf.el       20 Apr 2004 20:54:53 -0000      1.30
+++ emacs/lisp/recentf.el       9 Jun 2004 20:38:01 -0000
@@ -255,6 +255,11 @@
 If it returns nil, the filename is left unchanged."
   :group 'recentf
   :type 'function)
+
+(defcustom recentf-cleanup-remote t
+  "*non-nil means to auto cleanup remote files."
+  :group 'recentf
+  :type  'boolean)
 ^L
 ;;; Utilities
 ;;
@@ -1168,7 +1173,10 @@
   (message "Cleaning up the recentf list...")
   (let (newlist)
     (dolist (f recentf-list)
-      (if (and (recentf-include-p f) (recentf-file-readable-p f))
+      (if (and (recentf-include-p f)
+              (or (and (file-remote-p f)
+                       (not recentf-cleanup-remote))
+                  (recentf-file-readable-p f)))
           (push f newlist)
         (message "File %s removed from the recentf list" f)))
     (setq recentf-list (nreverse newlist))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Revisit: recentf-cleanup, file-readable-p & remote files
  2005-03-11 22:32 Michael Mauger
@ 2005-03-13 11:53 ` David Ponce
  2005-03-14 17:36   ` Michael Mauger
  0 siblings, 1 reply; 4+ messages in thread
From: David Ponce @ 2005-03-13 11:53 UTC (permalink / raw)
  Cc: Emacs Devel

Hi Michael and other Emacs developers,

 > Not to drag up old discussions, but I was reviewing some old patches
 > that I still use.
 >
 > Back in Sep 2003, a request was made to exclude remote files from
 > the automatic cleanup process that recentf.el runs when it is
 > enabled.  The discussion ended forking off into a discussion of
 > performance of Tramp and detecting network connectivity.
 >
 > I am now in a situation where about half of the files I edit are
 > local and the remainder are on a remote Unix server.  I appreciate
 > the automatic cleanup of files on the recentf list and would like to
 > leave that feature in place.  Unfortunately the time to connect to
 > the badly overloaded server and checking files there has gotten
 > painful.  Having the remote filenames on the recentf list is
 > valuable (thus I don't want to place remote files on the
 > recentf-exclude list).  What I would like to be able to do is just
 > not check these remote files as part of the auto cleanup process.
 >
 > Below is a simple patch which adds a customizable flag indicating
 > whether remote files should be cleaned up.  This flag is then
 > checked before checking the status of a remote file.  The default is
 > to check remote files, thus behavior is unchanged.  I've been using
 > this patch for a year without problems.

Your patch looks good. However I would prefer a more general mechanism
to keep files in the recent list, that is which can keep remote files
of course but other ones too.

Here is a patch that implements that. It introduces a new customizable
variable `recentf-keep' which can be saw as a counterpoint of
`recentf-exclude'. It uses the same format so you can force to keep
file names in the recent list based on regexp matching or on
predicates. For compatibility, the default is to keep readable files,
that is those that verify the `file-readable-p' predicate. It is
easy to keep remote file names too by adding the `file-remote-p'
predicate in front of `recentf-keep'. To keep all file names just set
`recentf-keep' to nil.

Another advantage of that solution is that it eliminates the need of
the `recentf-keep-non-readable-files-flag' flag and simplifies the
implementation! I also removed the unnecessary `recentf-find-file'
wrapper function to directly use `find-file' to open files.

Could you please try this patch? WDYT?

If there is no objection, can I commit it?

Thanks!
David

2005-03-13  David Ponce  <david@dponce.com>

	* recentf.el: (recentf-keep): New option.
	(recentf-menu-action): Default to `find-file'.
	(recentf-keep-non-readable-files-flag)
	(recentf-keep-non-readable-files-p)
	(recentf-file-readable-p, recentf-find-file): Remove.
	(recentf-include-p): More robust.
	(recentf-keep-p): New function.
	(recentf-remove-if-non-kept): Rename from
	`recentf-remove-if-non-readable'. Use `recentf-keep-p'. All
	callers updated.
	(recentf-menu-items-for-commands): Fix help string.
	(recentf-track-closed-file): Update. Doc fix.
	(recentf-cleanup): Update. Count removed files. Doc fix.


*** ./recentf.el~	2005-02-09 18:57:11.000000000 +0100
--- ./recentf.el	2005-03-13 12:43:55.367540400 +0100
***************
*** 1,6 ****
   ;;; recentf.el --- setup a menu of recently opened files

! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003
   ;;   Free Software Foundation, Inc.

   ;; Author: David Ponce <david@dponce.com>
--- 1,6 ----
   ;;; recentf.el --- setup a menu of recently opened files

! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005
   ;;   Free Software Foundation, Inc.

   ;; Author: David Ponce <david@dponce.com>
***************
*** 84,89 ****
--- 84,102 ----
     :group 'recentf
     :type '(repeat (choice regexp function)))

+ (defcustom recentf-keep
+   '(file-readable-p)
+   "*List of regexps and predicates for filenames kept in the recent list.
+ Regexps and predicates are tried in the specified order.
+ When nil all filenames are kept in the recent list.
+ When a filename matches any of the regexps or satisfies any of the
+ predicates it is kept in the recent list.
+ A predicate is a function that is passed a filename to check and that
+ must return non-nil to keep it.
+ The default is to keep readable files."
+   :group 'recentf
+   :type '(repeat (choice regexp function)))
+
   (defun recentf-menu-customization-changed (variable value)
     "Function called when the recentf menu customization has changed.
   Set VARIABLE with VALUE, and force a rebuild of the recentf menu."
***************
*** 114,122 ****
                    (const :tag "Last" nil))
     :set 'recentf-menu-customization-changed)

! (defcustom recentf-menu-action 'recentf-find-file
     "*Function to invoke with a filename item of the recentf menu.
! The default is to call `recentf-find-file' to edit the selected file."
     :group 'recentf
     :type 'function
     :set 'recentf-menu-customization-changed)
--- 127,135 ----
                    (const :tag "Last" nil))
     :set 'recentf-menu-customization-changed)

! (defcustom recentf-menu-action 'find-file
     "*Function to invoke with a filename item of the recentf menu.
! The default is to call `find-file' to edit the selected file."
     :group 'recentf
     :type 'function
     :set 'recentf-menu-customization-changed)
***************
*** 194,210 ****
                           'recentf-menu-append-commands-flag
                           "22.1")

- (defcustom recentf-keep-non-readable-files-flag nil
-   "*non-nil means to keep non readable files in the recent list."
-   :group 'recentf
-   :type 'boolean)
-
- (defvaralias 'recentf-keep-non-readable-files-p
-   'recentf-keep-non-readable-files-flag)
- (make-obsolete-variable 'recentf-keep-non-readable-files-p
-                         'recentf-keep-non-readable-files-flag
-                         "22.1")
-
   (defcustom recentf-auto-cleanup 'mode
     "*Define when to automatically cleanup the recent list.
   The following values can be set:
--- 207,212 ----
***************
*** 351,378 ****
                (funcall recentf-filename-handler filename))
           filename)))

- (defsubst recentf-file-readable-p (filename)
-   "Return t if file FILENAME exists and you can read it.
- Like the function `file-readable-p' but return nil on error."
-   (condition-case nil
-       (file-readable-p filename)
-     (error nil)))
-
   (defun recentf-include-p (filename)
     "Return non-nil if FILENAME should be included in the recent list.
   That is, if it doesn't match any of the `recentf-exclude' checks."
     (let ((case-fold-search recentf-case-fold-search)
           (checks recentf-exclude)
!         (keepit t)
!         check)
       (while (and checks keepit)
!       (setq check  (car checks)
!             checks (cdr checks)
!             keepit (not (if (stringp check)
                               ;; A regexp
!                             (string-match check filename)
                             ;; A predicate
!                           (funcall check filename)))))
       keepit))

   (defsubst recentf-add-file (filename)
--- 353,390 ----
                (funcall recentf-filename-handler filename))
           filename)))

   (defun recentf-include-p (filename)
     "Return non-nil if FILENAME should be included in the recent list.
   That is, if it doesn't match any of the `recentf-exclude' checks."
     (let ((case-fold-search recentf-case-fold-search)
           (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))
!             checks (cdr checks)))
!     keepit))
!
! (defun recentf-keep-p (filename)
!   "Return non-nil if FILENAME should be kept in the recent list.
! That is, if it matches any of the `recentf-keep' checks."
!   (let* ((case-fold-search recentf-case-fold-search)
!          (checks recentf-keep)
!          (keepit (null checks)))
!     (while (and checks (not keepit))
!       (setq keepit (condition-case nil
!                        (if (stringp (car checks))
!                            ;; A regexp
!                            (string-match (car checks) filename)
!                          ;; A predicate
!                          (funcall (car checks) filename))
!                      (error nil))
!             checks (cdr checks)))
       keepit))

   (defsubst recentf-add-file (filename)
***************
*** 383,406 ****
     (when (recentf-include-p filename)
       (recentf-push filename)))

! (defsubst recentf-remove-if-non-readable (filename)
!   "Remove FILENAME from the recent list, if file is not readable.
   Return non-nil if FILENAME has been removed."
!   (unless (recentf-file-readable-p filename)
       (let ((m (recentf-string-member
                 (recentf-expand-file-name filename) recentf-list)))
         (and m (setq recentf-list (delq (car m) recentf-list))))))

- (defun recentf-find-file (filename)
-   "Edit file FILENAME using `find-file'.
- If the file does not exist or is non readable, and
- `recentf-keep-non-readable-files-flag' is nil, it is not edited and
- its name is removed from the recent list."
-   (if (and (not recentf-keep-non-readable-files-flag)
-            (recentf-remove-if-non-readable filename))
-       (message "File `%s' not found" filename)
-     (find-file filename)))
-
   (defsubst recentf-directory-compare (f1 f2)
     "Compare absolute filenames F1 and F2.
   First compare directories, then filenames sans directory.
--- 395,408 ----
     (when (recentf-include-p filename)
       (recentf-push filename)))

! (defsubst recentf-remove-if-non-kept (filename)
!   "Remove FILENAME from the recent list, if file is not kept.
   Return non-nil if FILENAME has been removed."
!   (unless (recentf-keep-p filename)
       (let ((m (recentf-string-member
                 (recentf-expand-file-name filename) recentf-list)))
         (and m (setq recentf-list (delq (car m) recentf-list))))))

   (defsubst recentf-directory-compare (f1 f2)
     "Compare absolute filenames F1 and F2.
   First compare directories, then filenames sans directory.
***************
*** 417,423 ****
   (defvar recentf-menu-items-for-commands
     (list ["Cleanup list"
            recentf-cleanup
!          :help "Remove all non-readable and excluded files from the recent list"
            :active t]
           ["Edit list..."
            recentf-edit-list
--- 419,425 ----
   (defvar recentf-menu-items-for-commands
     (list ["Cleanup list"
            recentf-cleanup
!          :help "Remove all excluded and non-kept files from the recent list"
            :active t]
           ["Edit list..."
            recentf-edit-list
***************
*** 933,943 ****

   (defun recentf-track-closed-file ()
     "Update the recent list when a buffer is killed.
! That is, remove a non readable file from the recent list, if
! `recentf-keep-non-readable-files-flag' is nil."
     (and buffer-file-name
!        (not recentf-keep-non-readable-files-flag)
!        (recentf-remove-if-non-readable buffer-file-name)))

   (defun recentf-update-menu ()
     "Update the recentf menu from the current recent list."
--- 935,943 ----

   (defun recentf-track-closed-file ()
     "Update the recent list when a buffer is killed.
! That is, remove a non kept file from the recent list."
     (and buffer-file-name
!        (recentf-remove-if-non-kept buffer-file-name)))

   (defun recentf-update-menu ()
     "Update the recentf menu from the current recent list."
***************
*** 1164,1179 ****
                                              recentf-list))))))

   (defun recentf-cleanup ()
!   "Remove all excluded or non-readable files from the recent list."
     (interactive)
     (message "Cleaning up the recentf list...")
!   (let (newlist)
       (dolist (f recentf-list)
!       (if (and (recentf-include-p f) (recentf-file-readable-p f))
             (push f newlist)
           (message "File %s removed from the recentf list" f)))
!     (setq recentf-list (nreverse newlist))
!     (message "Cleaning up the recentf list...done")))

   ;;;###autoload
   (define-minor-mode recentf-mode
--- 1164,1181 ----
                                              recentf-list))))))

   (defun recentf-cleanup ()
!   "Remove all non-kept and excluded files from the recent list."
     (interactive)
     (message "Cleaning up the recentf list...")
!   (let ((n 0) newlist)
       (dolist (f recentf-list)
!       (if (and (recentf-include-p f)
!                (recentf-keep-p f))
             (push f newlist)
+         (setq n (1+ n))
           (message "File %s removed from the recentf list" f)))
!     (message "Cleaning up the recentf list...done (%d removed)" n)
!     (setq recentf-list (nreverse newlist))))

   ;;;###autoload
   (define-minor-mode recentf-mode

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Revisit: recentf-cleanup, file-readable-p & remote files
  2005-03-13 11:53 ` David Ponce
@ 2005-03-14 17:36   ` Michael Mauger
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Mauger @ 2005-03-14 17:36 UTC (permalink / raw)
  Cc: Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 2115 bytes --]


--- David Ponce <david.ponce@wanadoo.fr> wrote:

> Hi Michael and other Emacs developers,
> 
>  > I am now in a situation where about half of the files I edit are
>  > local and the remainder are on a remote Unix server.  I appreciate
>  > the automatic cleanup of files on the recentf list and would like to
>  > leave that feature in place.  Unfortunately the time to connect to
>  > the badly overloaded server and checking files there has gotten
>  > painful.  Having the remote filenames on the recentf list is
>  > valuable (thus I don't want to place remote files on the
>  > recentf-exclude list).  What I would like to be able to do is just
>  > not check these remote files as part of the auto cleanup process.
>  >
> 
> Your patch looks good. However I would prefer a more general mechanism
> to keep files in the recent list, that is which can keep remote files
> of course but other ones too.
> 
> Here is a patch that implements that. It introduces a new customizable
> variable `recentf-keep' which can be saw as a counterpoint of
> `recentf-exclude'. It uses the same format so you can force to keep
> file names in the recent list based on regexp matching or on
> predicates. For compatibility, the default is to keep readable files,
> that is those that verify the `file-readable-p' predicate. It is
> easy to keep remote file names too by adding the `file-remote-p'
> predicate in front of `recentf-keep'. To keep all file names just set
> `recentf-keep' to nil.
> 
> Another advantage of that solution is that it eliminates the need of
> the `recentf-keep-non-readable-files-flag' flag and simplifies the
> implementation! I also removed the unnecessary `recentf-find-file'
> wrapper function to directly use `find-file' to open files.
> 
> Could you please try this patch? WDYT?
> 
> If there is no objection, can I commit it?
> 
> Thanks!
> David
> 

I had problems with the patch but was able to manually recreate the
results.  It works great.  I'll run it for a couple of days and I'll let
you and the list know if I encounter any problems.

Attached is my re-created version of the patch.

[-- Attachment #2: recentf.diff --]
[-- Type: application/octet-stream, Size: 10144 bytes --]

Index: emacs/lisp/recentf.el
===================================================================
RCS file: /c/cvsroot/emacs/emacs/lisp/recentf.el,v
retrieving revision 1.33
diff -c -r1.33 recentf.el
*** emacs/lisp/recentf.el	9 Feb 2005 15:50:41 -0000	1.33
--- emacs/lisp/recentf.el	14 Mar 2005 17:20:09 -0000
***************
*** 1,6 ****
  ;;; recentf.el --- setup a menu of recently opened files
  
! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003
  ;;   Free Software Foundation, Inc.
  
  ;; Author: David Ponce <david@dponce.com>
--- 1,6 ----
  ;;; recentf.el --- setup a menu of recently opened files
  
! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005
  ;;   Free Software Foundation, Inc.
  
  ;; Author: David Ponce <david@dponce.com>
***************
*** 84,89 ****
--- 84,102 ----
    :group 'recentf
    :type '(repeat (choice regexp function)))
  
+ (defcustom recentf-keep
+   '(file-readable-p)
+   "*List of regexps and predicates for filenames kept in the recent list.
+ Regexps and predicates are tried in the specified order.
+ When nil all filenames are kept in the recent list.
+ When a filename matches any of the regexps or satisfies any of the
+ predicates it is kept in the recent list.
+ A predicate is a function that is passed a filename to check and that
+ must return non-nil to keep it.
+ The default is to keep readable files."
+   :group 'recentf
+   :type '(repeat (choice regexp function)))
+ 
  (defun recentf-menu-customization-changed (variable value)
    "Function called when the recentf menu customization has changed.
  Set VARIABLE with VALUE, and force a rebuild of the recentf menu."
***************
*** 114,122 ****
                   (const :tag "Last" nil))
    :set 'recentf-menu-customization-changed)
  
! (defcustom recentf-menu-action 'recentf-find-file
    "*Function to invoke with a filename item of the recentf menu.
! The default is to call `recentf-find-file' to edit the selected file."
    :group 'recentf
    :type 'function
    :set 'recentf-menu-customization-changed)
--- 127,135 ----
                   (const :tag "Last" nil))
    :set 'recentf-menu-customization-changed)
  
! (defcustom recentf-menu-action 'find-file
    "*Function to invoke with a filename item of the recentf menu.
! The default is to call `find-file' to edit the selected file."
    :group 'recentf
    :type 'function
    :set 'recentf-menu-customization-changed)
***************
*** 194,210 ****
                          'recentf-menu-append-commands-flag
                          "22.1")
  
- (defcustom recentf-keep-non-readable-files-flag nil
-   "*non-nil means to keep non readable files in the recent list."
-   :group 'recentf
-   :type 'boolean)
- 
- (defvaralias 'recentf-keep-non-readable-files-p
-   'recentf-keep-non-readable-files-flag)
- (make-obsolete-variable 'recentf-keep-non-readable-files-p
-                         'recentf-keep-non-readable-files-flag
-                         "22.1")
- 
  (defcustom recentf-auto-cleanup 'mode
    "*Define when to automatically cleanup the recent list.
  The following values can be set:
--- 207,212 ----
***************
*** 351,378 ****
               (funcall recentf-filename-handler filename))
          filename)))
  
- (defsubst recentf-file-readable-p (filename)
-   "Return t if file FILENAME exists and you can read it.
- Like the function `file-readable-p' but return nil on error."
-   (condition-case nil
-       (file-readable-p filename)
-     (error nil)))
- 
  (defun recentf-include-p (filename)
    "Return non-nil if FILENAME should be included in the recent list.
  That is, if it doesn't match any of the `recentf-exclude' checks."
    (let ((case-fold-search recentf-case-fold-search)
          (checks recentf-exclude)
!         (keepit t)
!         check)
      (while (and checks keepit)
!       (setq check  (car checks)
!             checks (cdr checks)
!             keepit (not (if (stringp check)
!                             ;; A regexp
!                             (string-match check filename)
!                           ;; A predicate
!                           (funcall check filename)))))
      keepit))
  
  (defsubst recentf-add-file (filename)
--- 353,390 ----
               (funcall recentf-filename-handler filename))
          filename)))
  
  (defun recentf-include-p (filename)
    "Return non-nil if FILENAME should be included in the recent list.
  That is, if it doesn't match any of the `recentf-exclude' checks."
    (let ((case-fold-search recentf-case-fold-search)
          (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))
! 	    checks (cdr checks)))
!     keepit))
! 
! (defun recentf-keep-p (filename)
!   "Return non-nil if FILENAME should be kept in the recent list.
! That is, if it matches any of the `recentf-keep' checks."
!   (let* ((case-fold-search recentf-case-fold-search)
! 	 (checks recentf-keep)
! 	 (keepit (null checks)))
!     (while (and checks (not keepit))
!       (setq keepit (condition-case nil
! 		       (if (stringp (car checks))
! 			   ;; A regexp
! 			   (string-match (car checks) filename)
! 			 ;; A predicate
! 			 (funcall (car checks) filename))
! 		     (error nil))
! 	    checks (cdr checks)))
      keepit))
  
  (defsubst recentf-add-file (filename)
***************
*** 383,406 ****
    (when (recentf-include-p filename)
      (recentf-push filename)))
  
! (defsubst recentf-remove-if-non-readable (filename)
!   "Remove FILENAME from the recent list, if file is not readable.
  Return non-nil if FILENAME has been removed."
!   (unless (recentf-file-readable-p filename)
      (let ((m (recentf-string-member
!               (recentf-expand-file-name filename) recentf-list)))
        (and m (setq recentf-list (delq (car m) recentf-list))))))
  
- (defun recentf-find-file (filename)
-   "Edit file FILENAME using `find-file'.
- If the file does not exist or is non readable, and
- `recentf-keep-non-readable-files-flag' is nil, it is not edited and
- its name is removed from the recent list."
-   (if (and (not recentf-keep-non-readable-files-flag)
-            (recentf-remove-if-non-readable filename))
-       (message "File `%s' not found" filename)
-     (find-file filename)))
- 
  (defsubst recentf-directory-compare (f1 f2)
    "Compare absolute filenames F1 and F2.
  First compare directories, then filenames sans directory.
--- 395,408 ----
    (when (recentf-include-p filename)
      (recentf-push filename)))
  
! (defsubst recentf-remove-if-non-kept (filename)
!   "Remove FILENAME from the recent list, if file is not kept.
  Return non-nil if FILENAME has been removed."
!   (unless (recentf-keep-p filename)
      (let ((m (recentf-string-member
! 	      (recentf-expand-file-name filename) recentf-list)))
        (and m (setq recentf-list (delq (car m) recentf-list))))))
  
  (defsubst recentf-directory-compare (f1 f2)
    "Compare absolute filenames F1 and F2.
  First compare directories, then filenames sans directory.
***************
*** 417,423 ****
  (defvar recentf-menu-items-for-commands
    (list ["Cleanup list"
           recentf-cleanup
!          :help "Remove all non-readable and excluded files from the recent list"
           :active t]
          ["Edit list..."
           recentf-edit-list
--- 419,425 ----
  (defvar recentf-menu-items-for-commands
    (list ["Cleanup list"
           recentf-cleanup
!          :help "Remove all excluded and non-kept files from the recent list"
           :active t]
          ["Edit list..."
           recentf-edit-list
***************
*** 933,943 ****
  
  (defun recentf-track-closed-file ()
    "Update the recent list when a buffer is killed.
! That is, remove a non readable file from the recent list, if
! `recentf-keep-non-readable-files-flag' is nil."
    (and buffer-file-name
!        (not recentf-keep-non-readable-files-flag)
!        (recentf-remove-if-non-readable buffer-file-name)))
  
  (defun recentf-update-menu ()
    "Update the recentf menu from the current recent list."
--- 935,943 ----
  
  (defun recentf-track-closed-file ()
    "Update the recent list when a buffer is killed.
! That is, remove a non kept file from the recent list."
    (and buffer-file-name
!        (recentf-remove-if-non-kept buffer-file-name)))
  
  (defun recentf-update-menu ()
    "Update the recentf menu from the current recent list."
***************
*** 1164,1179 ****
                                             recentf-list))))))
  
  (defun recentf-cleanup ()
!   "Remove all excluded or non-readable files from the recent list."
    (interactive)
    (message "Cleaning up the recentf list...")
!   (let (newlist)
      (dolist (f recentf-list)
!       (if (and (recentf-include-p f) (recentf-file-readable-p f))
!           (push f newlist)
!         (message "File %s removed from the recentf list" f)))
!     (setq recentf-list (nreverse newlist))
!     (message "Cleaning up the recentf list...done")))
  
  ;;;###autoload
  (define-minor-mode recentf-mode
--- 1164,1181 ----
                                             recentf-list))))))
  
  (defun recentf-cleanup ()
!   "Remove all non-kept and excluded files from the recent list."
    (interactive)
    (message "Cleaning up the recentf list...")
!   (let ((n 0) newlist)
      (dolist (f recentf-list)
!       (if (and (recentf-include-p f)
! 	       (recentf-keep-p f))
! 	  (push f newlist)
! 	(setq n (1+ n))
! 	(message "File %s removed from the recentf list" f)))
!     (message "Cleaning up the recentf list...done (%d removed)" n)
!     (setq recentf-list (nreverse newlist))))
  
  ;;;###autoload
  (define-minor-mode recentf-mode

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Revisit: recentf-cleanup, file-readable-p & remote files
@ 2005-03-21 11:21 David PONCE
  0 siblings, 0 replies; 4+ messages in thread
From: David PONCE @ 2005-03-21 11:21 UTC (permalink / raw)
  Cc: emacs-devel

Hi All,

>>Your patch looks good. However I would prefer a more general
>>mechanism to keep files in the recent list, that is which can keep
>>remote files of course but other ones too.
>>
>>Here is a patch that implements that.
[...]
>>Could you please try this patch? WDYT?
[...]
> I had problems with the patch but was able to manually recreate the
> results.  It works great.  I'll run it for a couple of days and I'll
> let you and the list know if I encounter any problems.

Thanks for testing Michael! As I didn't received any bug report nor objection
I plan to commit my patch and to update the NEWS accordingly.  Even if
it looks that someone already committed your patch!

Below is the final patch I am going to commit in the next two days.

Sincerely,
David

2005-03-21  David Ponce  <david@dponce.com>

	* NEWS: Mention recentf-keep.

2005-03-21  David Ponce  <david@dponce.com>

	* recentf.el: (recentf-keep): New option.
	(recentf-menu-action): Default to `find-file'.
	(recentf-keep-non-readable-files-flag)
	(recentf-keep-non-readable-files-p)
	(recentf-file-readable-p, recentf-find-file)
	(recentf-cleanup-remote): Remove.
	(recentf-include-p): More robust.
	(recentf-keep-p): New function.
	(recentf-remove-if-non-kept): Rename from
	`recentf-remove-if-non-readable'. Use `recentf-keep-p'. All
	callers updated.
	(recentf-menu-items-for-commands): Fix help string.
	(recentf-track-closed-file): Update. Doc fix.
	(recentf-cleanup): Update. Count removed files. Doc fix.

Index: etc/NEWS
===================================================================
RCS file: /cvsroot/emacs/emacs/etc/NEWS,v
retrieving revision 1.1128
diff -c -r1.1128 NEWS
*** etc/NEWS	17 Mar 2005 23:54:50 -0000	1.1128
--- etc/NEWS	21 Mar 2005 11:15:21 -0000
***************
*** 876,891 ****
  enabled.  The new option `recentf-auto-cleanup' controls when to do
  automatic cleanup.
  
  With the more advanced option: `recentf-filename-handler', you can
  specify a function that transforms filenames handled by recentf.  For
  example, if set to `file-truename', the same file will not be in the
  recent list with different symbolic links.
  
! To follow naming convention, `recentf-keep-non-readable-files-flag'
! and `recentf-menu-append-commands-flag' respectively replace the
! misnamed options `recentf-keep-non-readable-files-p' and
! `recentf-menu-append-commands-p'.  The old names remain available as
! aliases, but have been marked obsolete.
  
  ** The default for the paper size (variable ps-paper-type) is taken
  from the locale.
--- 876,893 ----
  enabled.  The new option `recentf-auto-cleanup' controls when to do
  automatic cleanup.
  
+ The `recentf-keep' option replaces `recentf-keep-non-readable-files-p'
+ and provides a more general mechanism to customize which file names to
+ keep in the recent list.
+ 
  With the more advanced option: `recentf-filename-handler', you can
  specify a function that transforms filenames handled by recentf.  For
  example, if set to `file-truename', the same file will not be in the
  recent list with different symbolic links.
  
! To follow naming convention, `recentf-menu-append-commands-flag'
! replaces the misnamed option `recentf-menu-append-commands-p'.  The
! old name remains available as alias, but has been marked obsolete.
  
  ** The default for the paper size (variable ps-paper-type) is taken
  from the locale.
Index: lisp/recentf.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/recentf.el,v
retrieving revision 1.34
diff -c -r1.34 recentf.el
*** lisp/recentf.el	19 Mar 2005 14:09:29 -0000	1.34
--- lisp/recentf.el	21 Mar 2005 11:15:24 -0000
***************
*** 1,6 ****
  ;;; recentf.el --- setup a menu of recently opened files
  
! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003
  ;;   Free Software Foundation, Inc.
  
  ;; Author: David Ponce <david@dponce.com>
--- 1,6 ----
  ;;; recentf.el --- setup a menu of recently opened files
  
! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005
  ;;   Free Software Foundation, Inc.
  
  ;; Author: David Ponce <david@dponce.com>
***************
*** 84,89 ****
--- 84,105 ----
    :group 'recentf
    :type '(repeat (choice regexp function)))
  
+ (defcustom recentf-keep
+   '(file-readable-p)
+   "*List of regexps and predicates for filenames kept in the recent list.
+ Regexps and predicates are tried in the specified order.
+ When nil all filenames are kept in the recent list.
+ When a filename matches any of the regexps or satisfies any of the
+ predicates it is kept in the recent list.
+ The default is to keep readable files.
+ A predicate is a function that is passed a filename to check and that
+ must return non-nil to keep it.  For example, you can add the
+ `file-remote-p' predicate in front of this list to keep remote file
+ names in the recent list without checking their readability through a
+ remote access."
+   :group 'recentf
+   :type '(repeat (choice regexp function)))
+ 
  (defun recentf-menu-customization-changed (variable value)
    "Function called when the recentf menu customization has changed.
  Set VARIABLE with VALUE, and force a rebuild of the recentf menu."
***************
*** 114,122 ****
                   (const :tag "Last" nil))
    :set 'recentf-menu-customization-changed)
  
! (defcustom recentf-menu-action 'recentf-find-file
    "*Function to invoke with a filename item of the recentf menu.
! The default is to call `recentf-find-file' to edit the selected file."
    :group 'recentf
    :type 'function
    :set 'recentf-menu-customization-changed)
--- 130,138 ----
                   (const :tag "Last" nil))
    :set 'recentf-menu-customization-changed)
  
! (defcustom recentf-menu-action 'find-file
    "*Function to invoke with a filename item of the recentf menu.
! The default is to call `find-file' to edit the selected file."
    :group 'recentf
    :type 'function
    :set 'recentf-menu-customization-changed)
***************
*** 194,210 ****
                          'recentf-menu-append-commands-flag
                          "22.1")
  
- (defcustom recentf-keep-non-readable-files-flag nil
-   "*non-nil means to keep non readable files in the recent list."
-   :group 'recentf
-   :type 'boolean)
- 
- (defvaralias 'recentf-keep-non-readable-files-p
-   'recentf-keep-non-readable-files-flag)
- (make-obsolete-variable 'recentf-keep-non-readable-files-p
-                         'recentf-keep-non-readable-files-flag
-                         "22.1")
- 
  (defcustom recentf-auto-cleanup 'mode
    "*Define when to automatically cleanup the recent list.
  The following values can be set:
--- 210,215 ----
***************
*** 255,265 ****
  If it returns nil, the filename is left unchanged."
    :group 'recentf
    :type 'function)
- 
- (defcustom recentf-cleanup-remote t
-   "*non-nil means to auto cleanup remote files."
-   :group 'recentf
-   :type  'boolean)
  \f
  ;;; Utilities
  ;;
--- 260,265 ----
***************
*** 356,411 ****
               (funcall recentf-filename-handler filename))
          filename)))
  
- (defsubst recentf-file-readable-p (filename)
-   "Return t if file FILENAME exists and you can read it.
- Like the function `file-readable-p' but return nil on error."
-   (condition-case nil
-       (file-readable-p filename)
-     (error nil)))
- 
  (defun recentf-include-p (filename)
    "Return non-nil if FILENAME should be included in the recent list.
  That is, if it doesn't match any of the `recentf-exclude' checks."
    (let ((case-fold-search recentf-case-fold-search)
          (checks recentf-exclude)
!         (keepit t)
!         check)
      (while (and checks keepit)
!       (setq check  (car checks)
!             checks (cdr checks)
!             keepit (not (if (stringp check)
!                             ;; A regexp
!                             (string-match check filename)
!                           ;; A predicate
!                           (funcall check filename)))))
      keepit))
  
  (defsubst recentf-add-file (filename)
    "Add or move FILENAME at the beginning of the recent list.
! Does nothing if the name satisfies any of the `recentf-exclude' regexps or
! predicates."
    (setq filename (recentf-expand-file-name filename))
    (when (recentf-include-p filename)
      (recentf-push filename)))
  
! (defsubst recentf-remove-if-non-readable (filename)
!   "Remove FILENAME from the recent list, if file is not readable.
  Return non-nil if FILENAME has been removed."
!   (unless (recentf-file-readable-p filename)
      (let ((m (recentf-string-member
                (recentf-expand-file-name filename) recentf-list)))
        (and m (setq recentf-list (delq (car m) recentf-list))))))
  
- (defun recentf-find-file (filename)
-   "Edit file FILENAME using `find-file'.
- If the file does not exist or is non readable, and
- `recentf-keep-non-readable-files-flag' is nil, it is not edited and
- its name is removed from the recent list."
-   (if (and (not recentf-keep-non-readable-files-flag)
-            (recentf-remove-if-non-readable filename))
-       (message "File `%s' not found" filename)
-     (find-file filename)))
- 
  (defsubst recentf-directory-compare (f1 f2)
    "Compare absolute filenames F1 and F2.
  First compare directories, then filenames sans directory.
--- 356,411 ----
               (funcall recentf-filename-handler filename))
          filename)))
  
  (defun recentf-include-p (filename)
    "Return non-nil if FILENAME should be included in the recent list.
  That is, if it doesn't match any of the `recentf-exclude' checks."
    (let ((case-fold-search recentf-case-fold-search)
          (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))
!             checks (cdr checks)))
!     keepit))
! 
! (defun recentf-keep-p (filename)
!   "Return non-nil if FILENAME should be kept in the recent list.
! That is, if it matches any of the `recentf-keep' checks."
!   (let* ((case-fold-search recentf-case-fold-search)
!          (checks recentf-keep)
!          (keepit (null checks)))
!     (while (and checks (not keepit))
!       (setq keepit (condition-case nil
!                        (if (stringp (car checks))
!                            ;; A regexp
!                            (string-match (car checks) filename)
!                          ;; A predicate
!                          (funcall (car checks) filename))
!                      (error nil))
!             checks (cdr checks)))
      keepit))
  
  (defsubst recentf-add-file (filename)
    "Add or move FILENAME at the beginning of the recent list.
! Does nothing if the name satisfies any of the `recentf-exclude'
! regexps or predicates."
    (setq filename (recentf-expand-file-name filename))
    (when (recentf-include-p filename)
      (recentf-push filename)))
  
! (defsubst recentf-remove-if-non-kept (filename)
!   "Remove FILENAME from the recent list, if file is not kept.
  Return non-nil if FILENAME has been removed."
!   (unless (recentf-keep-p filename)
      (let ((m (recentf-string-member
                (recentf-expand-file-name filename) recentf-list)))
        (and m (setq recentf-list (delq (car m) recentf-list))))))
  
  (defsubst recentf-directory-compare (f1 f2)
    "Compare absolute filenames F1 and F2.
  First compare directories, then filenames sans directory.
***************
*** 422,428 ****
  (defvar recentf-menu-items-for-commands
    (list ["Cleanup list"
           recentf-cleanup
!          :help "Remove all non-readable and excluded files from the recent list"
           :active t]
          ["Edit list..."
           recentf-edit-list
--- 422,428 ----
  (defvar recentf-menu-items-for-commands
    (list ["Cleanup list"
           recentf-cleanup
!          :help "Remove all excluded and non-kept files from the recent list"
           :active t]
          ["Edit list..."
           recentf-edit-list
***************
*** 938,948 ****
  
  (defun recentf-track-closed-file ()
    "Update the recent list when a buffer is killed.
! That is, remove a non readable file from the recent list, if
! `recentf-keep-non-readable-files-flag' is nil."
    (and buffer-file-name
!        (not recentf-keep-non-readable-files-flag)
!        (recentf-remove-if-non-readable buffer-file-name)))
  
  (defun recentf-update-menu ()
    "Update the recentf menu from the current recent list."
--- 938,946 ----
  
  (defun recentf-track-closed-file ()
    "Update the recent list when a buffer is killed.
! That is, remove a non kept file from the recent list."
    (and buffer-file-name
!        (recentf-remove-if-non-kept buffer-file-name)))
  
  (defun recentf-update-menu ()
    "Update the recentf menu from the current recent list."
***************
*** 1169,1187 ****
                                             recentf-list))))))
  
  (defun recentf-cleanup ()
!   "Remove all excluded or non-readable files from the recent list."
    (interactive)
    (message "Cleaning up the recentf list...")
!   (let (newlist)
      (dolist (f recentf-list)
        (if (and (recentf-include-p f)
! 	       (or (and (file-remote-p f)
! 			(not recentf-cleanup-remote))
! 		   (recentf-file-readable-p f)))
            (push f newlist)
          (message "File %s removed from the recentf list" f)))
!     (setq recentf-list (nreverse newlist))
!     (message "Cleaning up the recentf list...done")))
  
  ;;;###autoload
  (define-minor-mode recentf-mode
--- 1167,1184 ----
                                             recentf-list))))))
  
  (defun recentf-cleanup ()
!   "Remove all non-kept and excluded files from the recent list."
    (interactive)
    (message "Cleaning up the recentf list...")
!   (let ((n 0) newlist)
      (dolist (f recentf-list)
        (if (and (recentf-include-p f)
!                (recentf-keep-p f))
            (push f newlist)
+         (setq n (1+ n))
          (message "File %s removed from the recentf list" f)))
!     (message "Cleaning up the recentf list...done (%d removed)" n)
!     (setq recentf-list (nreverse newlist))))
  
  ;;;###autoload
  (define-minor-mode recentf-mode

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-21 11:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-21 11:21 Revisit: recentf-cleanup, file-readable-p & remote files David PONCE
  -- strict thread matches above, loose matches on Subject: below --
2005-03-11 22:32 Michael Mauger
2005-03-13 11:53 ` David Ponce
2005-03-14 17:36   ` Michael Mauger

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).