From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David PONCE Newsgroups: gmane.emacs.devel Subject: Re: Revisit: recentf-cleanup, file-readable-p & remote files Date: Mon, 21 Mar 2005 12:21:57 +0100 (CET) Message-ID: <2450455.1111404117592.JavaMail.www@wwinf1202> Reply-To: david.ponce@wanadoo.fr NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1111408562 2979 80.91.229.2 (21 Mar 2005 12:36:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 21 Mar 2005 12:36:02 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 21 13:36:02 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DDM7y-0005Om-NI for ged-emacs-devel@m.gmane.org; Mon, 21 Mar 2005 13:35:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DDMP4-0007QU-5V for ged-emacs-devel@m.gmane.org; Mon, 21 Mar 2005 07:53:06 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DDLuG-0002Yq-6Z for emacs-devel@gnu.org; Mon, 21 Mar 2005 07:21:17 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DDLWn-0000Nt-7O for emacs-devel@gnu.org; Mon, 21 Mar 2005 06:57:03 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DDLQW-0008UH-Vs for emacs-devel@gnu.org; Mon, 21 Mar 2005 06:50:34 -0500 Original-Received: from [193.252.22.20] (helo=smtp12.wanadoo.fr) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DDKyt-0001p6-Q1 for emacs-devel@gnu.org; Mon, 21 Mar 2005 06:22:00 -0500 Original-Received: from me-wanadoo.net (unknown [127.0.0.1]) by mwinf1204.wanadoo.fr (SMTP Server) with ESMTP id A3B081C00090; Mon, 21 Mar 2005 12:21:57 +0100 (CET) Original-Received: from wwinf1202 (wwinf1202 [172.22.143.29]) by mwinf1204.wanadoo.fr (SMTP Server) with ESMTP id 944851C00092; Mon, 21 Mar 2005 12:21:57 +0100 (CET) X-ME-UUID: 20050321112157607.944851C00092@mwinf1204.wanadoo.fr Original-To: mmaug@yahoo.com X-Originating-IP: [205.167.7.18] X-WUM-FROM: |~| X-WUM-TO: |~| X-WUM-CC: |~| X-WUM-REPLYTO: |~| X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: news.gmane.org gmane.emacs.devel:34878 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34878 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 objecti= on 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 =09* NEWS: Mention recentf-keep. 2005-03-21 David Ponce =09* recentf.el: (recentf-keep): New option. =09(recentf-menu-action): Default to `find-file'. =09(recentf-keep-non-readable-files-flag) =09(recentf-keep-non-readable-files-p) =09(recentf-file-readable-p, recentf-find-file) =09(recentf-cleanup-remote): Remove. =09(recentf-include-p): More robust. =09(recentf-keep-p): New function. =09(recentf-remove-if-non-kept): Rename from =09`recentf-remove-if-non-readable'. Use `recentf-keep-p'. All =09callers updated. =09(recentf-menu-items-for-commands): Fix help string. =09(recentf-track-closed-file): Update. Doc fix. =09(recentf-cleanup): Update. Count removed files. Doc fix. Index: etc/NEWS =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/etc/NEWS,v retrieving revision 1.1128 diff -c -r1.1128 NEWS *** etc/NEWS=0917 Mar 2005 23:54:50 -0000=091.1128 --- etc/NEWS=0921 Mar 2005 11:15:21 -0000 *************** *** 876,891 **** enabled. The new option `recentf-auto-cleanup' controls when to do automatic cleanup. =20 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. =20 ! 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. =20 ** 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. =20 + 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. +=20 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. =20 ! 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. =20 ** The default for the paper size (variable ps-paper-type) is taken from the locale. Index: lisp/recentf.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/recentf.el,v retrieving revision 1.34 diff -c -r1.34 recentf.el *** lisp/recentf.el=0919 Mar 2005 14:09:29 -0000=091.34 --- lisp/recentf.el=0921 Mar 2005 11:15:24 -0000 *************** *** 1,6 **** ;;; recentf.el --- setup a menu of recently opened files =20 ! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003 ;; Free Software Foundation, Inc. =20 ;; Author: David Ponce --- 1,6 ---- ;;; recentf.el --- setup a menu of recently opened files =20 ! ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005 ;; Free Software Foundation, Inc. =20 ;; Author: David Ponce *************** *** 84,89 **** --- 84,105 ---- :group 'recentf :type '(repeat (choice regexp function))) =20 + (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))) +=20 (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) =20 ! (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) =20 ! (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") =20 - (defcustom recentf-keep-non-readable-files-flag nil - "*non-nil means to keep non readable files in the recent list." - :group 'recentf - :type 'boolean) -=20 - (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") -=20 (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) -=20 - (defcustom recentf-cleanup-remote t - "*non-nil means to auto cleanup remote files." - :group 'recentf - :type 'boolean) =0C ;;; Utilities ;; --- 260,265 ---- *************** *** 356,411 **** (funcall recentf-filename-handler filename)) filename))) =20 - (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))) -=20 (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)) =20 (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 o= r ! predicates." (setq filename (recentf-expand-file-name filename)) (when (recentf-include-p filename) (recentf-push filename))) =20 ! (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)))))) =20 - (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))) -=20 (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))) =20 (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)) !=20 ! (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)) =20 (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))) =20 ! (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)))))) =20 (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 recen= t 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 li= st" :active t] ["Edit list..." recentf-edit-list *************** *** 938,948 **** =20 (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))) =20 (defun recentf-update-menu () "Update the recentf menu from the current recent list." --- 938,946 ---- =20 (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))) =20 (defun recentf-update-menu () "Update the recentf menu from the current recent list." *************** *** 1169,1187 **** recentf-list)))))) =20 (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) ! =09 (or (and (file-remote-p f) ! =09=09=09(not recentf-cleanup-remote)) ! =09=09 (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"))) =20 ;;;###autoload (define-minor-mode recentf-mode --- 1167,1184 ---- recentf-list)))))) =20 (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)))) =20 ;;;###autoload (define-minor-mode recentf-mode