From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Karl Chen Newsgroups: gmane.emacs.devel Subject: recentf.el - digit shortcuts Date: Thu, 01 Sep 2005 13:58:18 -0700 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1125609211 14377 80.91.229.2 (1 Sep 2005 21:13:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 1 Sep 2005 21:13:31 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 01 23:13:20 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EAwLr-0007Hq-4g for ged-emacs-devel@m.gmane.org; Thu, 01 Sep 2005 23:12:03 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EAwQ6-0006n8-9f for ged-emacs-devel@m.gmane.org; Thu, 01 Sep 2005 17:16:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EAwMy-0005JN-Gc for emacs-devel@gnu.org; Thu, 01 Sep 2005 17:13:12 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EAwMt-0005GP-SY for emacs-devel@gnu.org; Thu, 01 Sep 2005 17:13:09 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EAwMs-00055w-Cg for emacs-devel@gnu.org; Thu, 01 Sep 2005 17:13:06 -0400 Original-Received: from [128.32.35.215] (helo=roar.quarl.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EAwBT-000653-Ld for emacs-devel@gnu.org; Thu, 01 Sep 2005 17:01:20 -0400 Original-Received: by roar.quarl.org (Postfix, from userid 18378) id 0DD675C0B4; Thu, 1 Sep 2005 13:58:18 -0700 (PDT) Original-To: Emacs Developement List X-Quack-Archive: 1 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:42569 Archived-At: Here is a patch that adds shortcut keys and corresponding labels to recentf-dialog-mode (the mode that `recentf-open-files' uses). The variable `recentf-dialog-show-labels-p' controls whether labels are displayed, and could default to nil. I've been using this functionality for a long time and find it indispensable. However, defadvice is brittle and I had to rewrite it every time recentf changed. I hope this feature is suitable for installing. 2005-09-01 Karl Chen * recentf.el (recentf-dialog-choose): Open the Nth item. (recentf-dialog-show-labels-p): New variable. (recentf-dialog-mode-map): Define keys 0-9 as recentf-dialog-choose. (recentf-dialog-files, recentf--number): New variables. (recentf-open-files-item): Display label (via recentf--number) if recentf-dialog-show-labels-p. (recentf-open-files): Reflect new variables and help text. --- /usr/share/emacs/22.0.50/lisp/recentf.el 2005-08-06 15:13:43.000000000 -0700 +++ recentf.el 2005-09-01 13:42:22.000000000 -0700 @@ -259,6 +259,15 @@ :group 'recentf :type '(choice (const :tag "None" nil) function)) + +(defcustom recentf-dialog-show-labels-p t + "Whether to show ``[N]'' for the Nth item up to 10. + +If set, `recentf-open-files' will show labels for keys that +can be used as shortcuts to open the Nth file." + :group 'recentf + :type 'boolean) + ;;; Utilities ;; @@ -926,6 +935,19 @@ (set-keymap-parent km widget-keymap) (define-key km "q" 'recentf-cancel-dialog) (define-key km [down-mouse-1] 'widget-button-click) + + ;; define in reverse order of how we want the keys to appear in help + (define-key km "0" 'recentf-dialog-choose) + (define-key km "9" 'recentf-dialog-choose) + (define-key km "8" 'recentf-dialog-choose) + (define-key km "7" 'recentf-dialog-choose) + (define-key km "6" 'recentf-dialog-choose) + (define-key km "5" 'recentf-dialog-choose) + (define-key km "4" 'recentf-dialog-choose) + (define-key km "3" 'recentf-dialog-choose) + (define-key km "2" 'recentf-dialog-choose) + (define-key km "1" 'recentf-dialog-choose) + km) "Keymap used in recentf dialogs.") @@ -1063,6 +1085,9 @@ (kill-buffer (current-buffer)) (funcall recentf-menu-action (widget-value widget))) +;; The current item number while building recentf-open-files buffer +(defvar recentf--number nil) + (defun recentf-open-files-item (menu-element) "Return a widget to display MENU-ELEMENT in a dialog buffer." (if (consp (cdr menu-element)) @@ -1076,8 +1101,12 @@ ,@(mapcar 'recentf-open-files-item (cdr menu-element))) ;; Represent a single file with a link widget + (setq recentf--number (+ 1 recentf--number)) `(link :tag ,(car menu-element) - :button-prefix "" + :button-prefix ,(if recentf-dialog-show-labels-p + (if (<= recentf--number 10) + (format "[%d] " (% recentf--number 10)) " ") + "") :button-suffix "" :button-face default :format "%[%t%]\n" @@ -1085,6 +1114,9 @@ :action recentf-open-files-action ,(cdr menu-element)))) +;; Current files listed +(defvar recentf-dialog-files nil) + (defun recentf-open-files (&optional files buffer-name) "Show a dialog to open a recent file. If optional argument FILES is non-nil, it is a list of recently-opened @@ -1092,8 +1124,9 @@ 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)) - (widget-insert "Click on a file to open it. + (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") @@ -1101,17 +1134,38 @@ `(group :indent 2 :format "\n%v\n" - ,@(mapcar 'recentf-open-files-item - (recentf-apply-menu-filter - recentf-menu-filter - (mapcar 'recentf-make-default-menu-element - (or files recentf-list)))))) + ,@(let ((recentf--number 0)) + (mapcar 'recentf-open-files-item + (recentf-apply-menu-filter + recentf-menu-filter + (mapcar 'recentf-make-default-menu-element files)))))) (widget-create 'push-button :notify 'recentf-cancel-dialog "Cancel") + (set (make-local-variable 'recentf-dialog-files) files) (recentf-dialog-goto-first 'link))) +(defun recentf-dialog-choose (n) + "Open the Nth file. + +When called interactively via a numeric key N, open the Nth file. +I.e., `1' opens the first file, `2' the second file, ... `9' the +ninth file. `0' opens the tenth file." + + (interactive + (list (let ((char (string-to-char (this-command-keys)))) + (cond ((= char ?0) 10) + ((and (>= char ?1) (<= char ?9)) (- char ?0)) + (t (error "Invalid key bound to `recentf-dialog-numkey'.")))))) + + (setq n (- n 1)) + (if (<= (length recentf-dialog-files) n) + (error "Not that many recent files")) + (let ((file (nth n recentf-dialog-files))) + (kill-buffer (current-buffer)) + (funcall recentf-menu-action file))) + (defun recentf-open-more-files () "Show a dialog to open a recent file that is not in the menu." (interactive) -- Karl 2005-09-01 13:39