From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: David PONCE Newsgroups: gmane.emacs.devel Subject: recentf new feature proposal Date: Fri, 6 Jun 2003 13:11:23 +0200 (CEST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <29060153.1054897883578.JavaMail.www@wwinf0402> 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: main.gmane.org 1054899053 29494 80.91.224.249 (6 Jun 2003 11:30:53 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 6 Jun 2003 11:30:53 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Jun 06 13:30:50 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19OFQo-0007fM-00 for ; Fri, 06 Jun 2003 13:30:50 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19OFjK-0006j5-00 for ; Fri, 06 Jun 2003 13:49:58 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19OFOL-0006pU-4Q for emacs-devel@quimby.gnus.org; Fri, 06 Jun 2003 07:28:17 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19OFK8-0005ir-MJ for emacs-devel@gnu.org; Fri, 06 Jun 2003 07:23:56 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19OFJz-0005eW-Oc for emacs-devel@gnu.org; Fri, 06 Jun 2003 07:23:48 -0400 Original-Received: from smtp5.wanadoo.fr ([193.252.22.27] helo=mwinf0403.wanadoo.fr) by monty-python.gnu.org with esmtp (Exim 4.20) id 19OF80-0002n8-NP for emacs-devel@gnu.org; Fri, 06 Jun 2003 07:11:24 -0400 Original-Received: from wwinf0402 (wwinf0402 [172.22.135.29]) by mwinf0403.wanadoo.fr (SMTP Server) with ESMTP id 90509500022B for ; Fri, 6 Jun 2003 13:11:23 +0200 (CEST) Original-To: emacs-devel X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:14820 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:14820 Hi, I submit you the following patch for recentf.el that introduces a new feature to restore the last visited position of recently opened files. Here is the change log: 2003-06-06 David Ponce =09* recentf.el =09Add new option to restore point when opening a recent file. =09 =09(recentf-positions): New variable. =09(recentf-restore-position-flag): New option. =09(recentf-get-position, recentf-save-position) =09(recentf-sync-positions, recentf-open-file): New functions. =09(recentf-make-menu-item): Use `recentf-open-file'. =09(recentf-track-closed-file): Save position in current buffer. =09(recentf-open-files-action): Use `recentf-open-file'. =09(recentf-save-list): Save positions of recently opened file. It would be nice if that enhancement could be included in Emacs. Sincerely, David 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.24 diff -c -r1.24 recentf.el *** lisp/recentf.el=092 May 2003 12:13:14 -0000=091.24 --- lisp/recentf.el=096 Jun 2003 10:47:39 -0000 *************** *** 49,54 **** --- 49,57 ---- (defvar recentf-list nil "List of recently opened files.") =20 + (defvar recentf-positions nil + "List of positions in recently opened files.") +=20 (defvar recentf-data-cache nil "Cache of data used to build the recentf menu. The menu is rebuilt when this data has changed.") *************** *** 236,241 **** --- 239,249 ---- ;; Unavailable until recentf has been loaded. (recentf-auto-cleanup)))) =20 + (defcustom recentf-restore-position-flag t + "*non-nil means to restore last visited position of opened files." + :group 'recentf + :type 'boolean) +=20 (defcustom recentf-load-hook nil "*Normal hook run at end of loading the `recentf' package." :group 'recentf *************** *** 351,356 **** --- 359,376 ---- (setq rl (cdr rl))) (null rl))) =20 + (defsubst recentf-get-position (file) + "Return the last visited position of FILE." + (assoc file recentf-positions)) +=20 + (defun recentf-save-position () + "Save the point in current buffer as file last visited position." + (let* ((filename (recentf-expand-file-name buffer-file-name)) + (position (recentf-get-position filename))) + (if position + (setcdr position (point)) + (push (cons filename (point)) recentf-positions)))) +=20 (defsubst recentf-add-file (filename) "Add or move FILENAME at the beginning of the recent list. Does nothing it if it matches any of the `recentf-exclude' regexps." *************** *** 366,371 **** --- 386,399 ---- (recentf-expand-file-name filename) recentf-list))) (and m (setq recentf-list (delq (car m) recentf-list)))))) =20 + (defun recentf-sync-positions () + "Synchronize recent positions with the recent list." + (let (position positions) + (dolist (f recentf-list) + (when (setq position (recentf-get-position f)) + (push position positions))) + (setq recentf-positions (nreverse positions)))) +=20 (defun recentf-find-file (filename) "Edit file FILENAME using `find-file'. If the file does not exist or is non readable, and *************** *** 386,391 **** --- 414,431 ---- (recentf-string-lessp (file-name-nondirectory f1) (file-name-nondirectory f2)) (recentf-string-lessp d1 d2)))) +=20 + (defun recentf-open-file (file) + "Open FILE and move point to the last visited position." + (let ((visited (find-buffer-visiting file)) + position) + (if visited + (switch-to-buffer visited) + (funcall recentf-menu-action file) + (when recentf-restore-position-flag + (setq position (recentf-get-position file)) + (when (number-or-marker-p (cdr position)) + (goto-char (cdr position))))))) =0C ;;; Menu building ;; *************** *** 516,522 **** (value (recentf-menu-element-value elt))) (if (recentf-sub-menu-element-p elt) (cons item (mapcar 'recentf-make-menu-item value)) ! (vector item (list recentf-menu-action value) :help (concat "Open " value) :active t)))) =20 --- 556,562 ---- (value (recentf-menu-element-value elt))) (if (recentf-sub-menu-element-p elt) (cons item (mapcar 'recentf-make-menu-item value)) ! (vector item (list 'recentf-open-file value) :help (concat "Open " value) :active t)))) =20 *************** *** 905,913 **** "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." --- 945,954 ---- "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." ! (when buffer-file-name ! (unless (and (not recentf-keep-non-readable-files-flag) ! (recentf-remove-if-non-readable buffer-file-name)) ! (recentf-save-position)))) =20 (defun recentf-update-menu () "Update the recentf menu from the current recent list." *************** *** 1019,1025 **** Used internally by `recentf-open-files'. IGNORE other arguments." (kill-buffer (current-buffer)) ! (funcall recentf-menu-action (widget-value widget))) =20 (defvar recentf-open-files-item-shift "" "Amount of space to shift right sub-menu items. --- 1060,1066 ---- Used internally by `recentf-open-files'. IGNORE other arguments." (kill-buffer (current-buffer)) ! (recentf-open-file (widget-value widget))) =20 (defvar recentf-open-files-item-shift "" "Amount of space to shift right sub-menu items. *************** *** 1106,1115 **** --- 1147,1158 ---- "Save the recent list. Write data into the file specified by `recentf-save-file'." (interactive) + (recentf-sync-positions) (with-temp-file (expand-file-name recentf-save-file) (erase-buffer) (insert (format recentf-save-file-header (current-time-string))) (recentf-dump-variable 'recentf-list recentf-max-saved-items) + (recentf-dump-variable 'recentf-positions recentf-max-saved-items) (recentf-dump-variable 'recentf-filter-changer-state) nil)) =20 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.823 diff -c -r1.823 NEWS *** etc/NEWS=095 Jun 2003 23:56:32 -0000=091.823 --- etc/NEWS=096 Jun 2003 10:47:40 -0000 *************** *** 129,134 **** --- 129,138 ---- =20 ** recentf changes. =20 + Depending on the new option `recentf-restore-position-flag', after a + recent file is opened, the point is moved to the last position it was + on. By default, last positions are restored. +=20 The recent file list is now automatically cleanup when recentf mode is enabled. The new option `recentf-auto-cleanup' controls when to do automatic cleanup.