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: recentf.el - digit shortcuts Date: Mon, 5 Sep 2005 09:21:48 +0200 (CEST) Message-ID: <18147181.1125904908247.JavaMail.www@wwinf1617> Reply-To: david.ponce@wanadoo.fr NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1125905093 6983 80.91.229.2 (5 Sep 2005 07:24:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 5 Sep 2005 07:24:53 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 05 09:24:45 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ECBLH-0002np-U2 for ged-emacs-devel@m.gmane.org; Mon, 05 Sep 2005 09:24:36 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ECBPi-00039Z-Hi for ged-emacs-devel@m.gmane.org; Mon, 05 Sep 2005 03:29:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ECBNs-0002iA-Fh for emacs-devel@gnu.org; Mon, 05 Sep 2005 03:27:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ECBNp-0002hI-Dv for emacs-devel@gnu.org; Mon, 05 Sep 2005 03:27:14 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ECBNo-0002h4-Vi for emacs-devel@gnu.org; Mon, 05 Sep 2005 03:27:13 -0400 Original-Received: from [193.252.23.89] (helo=smtp16.wanadoo.fr) by monty-python.gnu.org with esmtp (Exim 4.34) id 1ECBMI-0007eE-Vg for emacs-devel@gnu.org; Mon, 05 Sep 2005 03:25:39 -0400 Original-Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf1601.wanadoo.fr (SMTP Server) with ESMTP id 41443700008B for ; Mon, 5 Sep 2005 09:21:48 +0200 (CEST) Original-Received: from wwinf1617 (wwinf1617 [172.22.147.61]) by mwinf1601.wanadoo.fr (SMTP Server) with ESMTP id 3EE507000085; Mon, 5 Sep 2005 09:21:48 +0200 (CEST) X-ME-UUID: 20050905072148257.3EE507000085@mwinf1601.wanadoo.fr Original-To: quarl@cs.berkeley.edu X-Originating-IP: [205.167.7.18] X-Wum-Nature: EMAIL-NATURE 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 Xref: news.gmane.org gmane.emacs.devel:42618 Archived-At: Hi, Here is a new patch for digit shortcuts in the selection dialog of recentf.el. Compared to the previous one it assigns digit shortcuts to the ten most recent files, independently of their location in sub-menus. IMO this is a more intuitive approach. The implementation is a little simpler too ;-) Could you try it please and tell me what you think? If no objection I will commit the changes in a few days. Thanks! David 2005-09-05 David Ponce =09* recentf.el Require 'cl at compilation time. =09(recentf-show-file-shortcuts-flag): New option. =09(recentf-expand-file-name): Doc fix. =09(recentf-dialog-mode-map): Define digit shortcuts. =09(recentf--files-with-key): New variable. =09(recentf-open-files-item): Show digit shortcuts. =09(recentf-open-files): Associate files with digit shortcuts. =09(recentf-open-file-with-key): New command. 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.42 diff -c -r1.42 recentf.el *** lisp/recentf.el=096 Aug 2005 22:13:43 -0000=091.42 --- lisp/recentf.el=095 Sep 2005 07:04:23 -0000 *************** *** 5,11 **** =20 ;; Author: David Ponce ;; Created: July 19 1999 - ;; Maintainer: FSF ;; Keywords: files =20 ;; This file is part of GNU Emacs. --- 5,10 ---- *************** *** 41,46 **** --- 40,46 ---- (require 'easymenu) (require 'tree-widget) (require 'timer) + (eval-when-compile (require 'cl)) =20 ;;; Internal data ;; *************** *** 259,264 **** --- 259,272 ---- :group 'recentf :type '(choice (const :tag "None" nil) function)) +=20 + (defcustom recentf-show-file-shortcuts-flag t + "Whether to show ``[N]'' for the Nth item up to 10. + If non-nil, `recentf-open-files' will show labels for keys that can be + used as shortcuts to open the Nth file." + :group 'recentf + :type 'boolean) +=20 =0C ;;; Utilities ;; *************** *** 349,355 **** "Convert filename NAME to absolute, and canonicalize it. See also the function `expand-file-name'. If defined, call the function `recentf-filename-handler' ! to postprocess the canonical name." (let* ((filename (expand-file-name name))) (or (and recentf-filename-handler (funcall recentf-filename-handler filename)) --- 357,363 ---- "Convert filename NAME to absolute, and canonicalize it. See also the function `expand-file-name'. If defined, call the function `recentf-filename-handler' ! to post process the canonical name." (let* ((filename (expand-file-name name))) (or (and recentf-filename-handler (funcall recentf-filename-handler filename)) *************** *** 926,931 **** --- 934,942 ---- (set-keymap-parent km widget-keymap) (define-key km "q" 'recentf-cancel-dialog) (define-key km [down-mouse-1] 'widget-button-click) + ;; Keys in reverse order of appearence in help. + (dolist (k '("0" "9" "8" "7" "6" "5" "4" "3" "2" "1")) + (define-key km k 'recentf-open-file-with-key)) km) "Keymap used in recentf dialogs.") =20 *************** *** 1063,1068 **** --- 1074,1082 ---- (kill-buffer (current-buffer)) (funcall recentf-menu-action (widget-value widget))) =20 + ;; List of files associated to a digit shortcut key. + (defvar recentf--files-with-key nil) +=20 (defun recentf-open-files-item (menu-element) "Return a widget to display MENU-ELEMENT in a dialog buffer." (if (consp (cdr menu-element)) *************** *** 1076,1089 **** ,@(mapcar 'recentf-open-files-item (cdr menu-element))) ;; Represent a single file with a link widget ! `(link :tag ,(car menu-element) ! :button-prefix "" ! :button-suffix "" ! :button-face default ! :format "%[%t%]\n" ! :help-echo ,(concat "Open " (cdr menu-element)) ! :action recentf-open-files-action ! ,(cdr menu-element)))) =20 (defun recentf-open-files (&optional files buffer-name) "Show a dialog to open a recent file. --- 1090,1108 ---- ,@(mapcar 'recentf-open-files-item (cdr menu-element))) ;; Represent a single file with a link widget ! ;; Show digit shortcuts for the ten most recent files. ! (let ((label "") key) ! (and recentf-show-file-shortcuts-flag ! (setq key (assoc (cdr menu-element) recentf--files-with-key)) ! (setq label (format "[%d] " (cdr key)))) ! `(link :tag ,(car menu-element) ! :button-prefix ,label ! :button-suffix "" ! :button-face default ! :format "%[%t%]\n" ! :help-echo ,(concat "Open " (cdr menu-element)) ! :action recentf-open-files-action ! ,(cdr menu-element))))) =20 (defun recentf-open-files (&optional files buffer-name) "Show a dialog to open a recent file. *************** *** 1092,1099 **** If optional argument BUFFER-NAME is non-nil, it is a buffer name to use for the dialog. It defaults to \"*`recentf-menu-title'*\"." (interactive) (recentf-dialog (or buffer-name (format "*%s*" recentf-menu-title)) ! (widget-insert "Click on a file to open it. Click on Cancel or type `q' to cancel.\n" ) ;; Use a L&F that looks like the recentf menu. (tree-widget-set-theme "folder") --- 1111,1128 ---- If optional argument BUFFER-NAME is non-nil, it is a buffer name to use for the dialog. It defaults to \"*`recentf-menu-title'*\"." (interactive) + (or files (setq files recentf-list)) (recentf-dialog (or buffer-name (format "*%s*" recentf-menu-title)) ! (let ((i 0) l) ! (dolist (f files) ! (setq i (1+ i)) ! (if (> i 10) ! (return) ! (push (cons f (% i 10)) l))) ! (set (make-local-variable 'recentf--files-with-key) ! (nreverse l))) ! (widget-insert ! "Click on a file or type the corresponding digit key to open it. Click on Cancel or type `q' to cancel.\n" ) ;; Use a L&F that looks like the recentf menu. (tree-widget-set-theme "folder") *************** *** 1105,1116 **** (recentf-apply-menu-filter recentf-menu-filter (mapcar 'recentf-make-default-menu-element ! (or files recentf-list)))))) (widget-create 'push-button :notify 'recentf-cancel-dialog "Cancel") (recentf-dialog-goto-first 'link))) =20 (defun recentf-open-more-files () "Show a dialog to open a recent file that is not in the menu." --- 1134,1156 ---- (recentf-apply-menu-filter recentf-menu-filter (mapcar 'recentf-make-default-menu-element ! files))))) (widget-create 'push-button :notify 'recentf-cancel-dialog "Cancel") (recentf-dialog-goto-first 'link))) +=20 + (defun recentf-open-file-with-key (n) + "Open the recent file with the shortcut numeric key N. + `1' opens the first file, `2' the second file, ... `9' the ninth file. + `0' opens the tenth file." + (interactive (list (string-to-number (this-command-keys)))) + (when recentf--files-with-key + (let ((file (car (rassq n recentf--files-with-key)))) + (unless file (error "Not that many recent files")) + (kill-buffer (current-buffer)) + (funcall recentf-menu-action file)))) =20 (defun recentf-open-more-files () "Show a dialog to open a recent file that is not in the menu."