unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: recentf.el - digit shortcuts
@ 2005-09-05 11:27 David PONCE
  2005-09-06  8:19 ` Karl Chen
  0 siblings, 1 reply; 8+ messages in thread
From: David PONCE @ 2005-09-05 11:27 UTC (permalink / raw)
  Cc: emacs-devel

Hi,

Here is another patch (sorry) that isolates files with shortcuts in
front of the dialog list, instead of mixing them up into sub-menus.
This way it is very easy to locate files with shortcuts when
`recentf-show-file-shortcuts-flag' is non-nil.

David

2005-09-05  David Ponce  <david@dponce.com>

	* recentf.el (recentf-show-file-shortcuts-flag): New option.
	(recentf-expand-file-name): Doc fix.
	(recentf-dialog-mode-map): Define digit shortcuts.
	(recentf--files-with-key): New variable.
	(recentf-show-digit-shortcut-filter): New function.
	(recentf-open-files-items): New function.
	(recentf-open-files): Use it.
	(recentf-open-file-with-key): New command.

Index: lisp/recentf.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/recentf.el,v
retrieving revision 1.42
diff -c -r1.42 recentf.el
*** lisp/recentf.el	6 Aug 2005 22:13:43 -0000	1.42
--- lisp/recentf.el	5 Sep 2005 11:21:31 -0000
***************
*** 5,11 ****
  
  ;; Author: David Ponce <david@dponce.com>
  ;; Created: July 19 1999
- ;; Maintainer: FSF
  ;; Keywords: files
  
  ;; This file is part of GNU Emacs.
--- 5,10 ----
***************
*** 259,264 ****
--- 258,271 ----
    :group 'recentf
    :type '(choice (const :tag "None" nil)
                   function))
+ 
+ (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)
+ 
  \f
  ;;; 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))
--- 356,362 ----
    "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 ****
--- 933,941 ----
      (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.")
  
***************
*** 1063,1068 ****
--- 1073,1090 ----
    (kill-buffer (current-buffer))
    (funcall recentf-menu-action (widget-value widget)))
  
+ ;; List of files associated to a digit shortcut key.
+ (defvar recentf--files-with-key nil)
+ 
+ (defun recentf-show-digit-shortcut-filter (l)
+   "Filter the list of menu-elements L to show digit shortcuts."
+   (let ((i 0))
+     (dolist (e l)
+       (setq i (1+ i))
+       (recentf-set-menu-element-item
+        e (format "[%d] %s" (% i 10) (recentf-menu-element-item e))))
+     l))
+ 
  (defun recentf-open-files-item (menu-element)
    "Return a widget to display MENU-ELEMENT in a dialog buffer."
    (if (consp (cdr menu-element))
***************
*** 1085,1090 ****
--- 1107,1136 ----
             :action recentf-open-files-action
             ,(cdr menu-element))))
  
+ (defun recentf-open-files-items (files)
+   "Return a list of widgets to display FILES in a dialog buffer."
+   (set (make-local-variable 'recentf--files-with-key)
+        (recentf-trunc-list files 10))
+   (mapcar 'recentf-open-files-item
+           (if recentf-show-file-shortcuts-flag
+               (append
+                (recentf-apply-menu-filter
+                 'recentf-show-digit-shortcut-filter
+ ;;                 (recentf-apply-menu-filter
+ ;;                  'recentf-relative-filter
+                  (mapcar 'recentf-make-default-menu-element
+                          recentf--files-with-key)
+ ;;                  )
+                 )
+                (recentf-apply-menu-filter
+                 recentf-menu-filter
+                 (mapcar 'recentf-make-default-menu-element
+                         (nthcdr 10 files))))
+             (recentf-apply-menu-filter
+              recentf-menu-filter
+              (mapcar 'recentf-make-default-menu-element
+                      files)))))
+ 
  (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
***************
*** 1093,1099 ****
  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")
--- 1139,1146 ----
  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 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,1116 ****
             `(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))))))
      (widget-create
       'push-button
       :notify 'recentf-cancel-dialog
       "Cancel")
      (recentf-dialog-goto-first 'link)))
  
  (defun recentf-open-more-files ()
    "Show a dialog to open a recent file that is not in the menu."
--- 1148,1177 ----
             `(group
               :indent 2
               :format "\n%v\n"
!              ,@(recentf-open-files-items (or files recentf-list))))
      (widget-create
       'push-button
       :notify 'recentf-cancel-dialog
       "Cancel")
      (recentf-dialog-goto-first 'link)))
+ 
+ (defun recentf-open-file-with-key (n)
+   "Open the recent file with the shortcut numeric key N.
+ N must be a valid digit.
+ `1' opens the first file, `2' the second file, ... `9' the ninth file.
+ `0' opens the tenth file."
+   (interactive
+    (list
+     (let ((n (string-to-number (this-command-keys))))
+       (cond
+        ((zerop n) 10)
+        ((and (> n 0) (< n 10)) n)
+        ((error "Invalid digit key %d" n))))))
+   (when recentf--files-with-key
+     (let ((file (nth (1- n) recentf--files-with-key)))
+       (unless file (error "Not that many recent 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."

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: recentf.el - digit shortcuts
@ 2005-09-07 12:44 David PONCE
  2005-09-07 17:26 ` Karl Chen
  0 siblings, 1 reply; 8+ messages in thread
From: David PONCE @ 2005-09-07 12:44 UTC (permalink / raw)
  Cc: emacs-devel

> The files with shortcuts are now unaligned with files without
> shortcuts.  Is that intentional?  Otherwise it seems fine.

Yes it is, because items with extra alignment spaces doesn't look good
(IMO) when they are grouped into sub-lists. As items with shortcuts
are now grouped together at the top of the list, the extra alignment
spaces seem no more necessary IMO. Also that simplifies the code a
little ;-)

I will commit the changes as soon as my free time will permit.

Thanks!

David

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: recentf.el - digit shortcuts
@ 2005-09-05  7:21 David PONCE
  0 siblings, 0 replies; 8+ messages in thread
From: David PONCE @ 2005-09-05  7:21 UTC (permalink / raw)
  Cc: emacs-devel

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  <david@dponce.com>

	* recentf.el Require 'cl at compilation time.
	(recentf-show-file-shortcuts-flag): New option.
	(recentf-expand-file-name): Doc fix.
	(recentf-dialog-mode-map): Define digit shortcuts.
	(recentf--files-with-key): New variable.
	(recentf-open-files-item): Show digit shortcuts.
	(recentf-open-files): Associate files with digit shortcuts.
	(recentf-open-file-with-key): New command.

Index: lisp/recentf.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/recentf.el,v
retrieving revision 1.42
diff -c -r1.42 recentf.el
*** lisp/recentf.el	6 Aug 2005 22:13:43 -0000	1.42
--- lisp/recentf.el	5 Sep 2005 07:04:23 -0000
***************
*** 5,11 ****
  
  ;; Author: David Ponce <david@dponce.com>
  ;; Created: July 19 1999
- ;; Maintainer: FSF
  ;; Keywords: files
  
  ;; 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))
  
  ;;; Internal data
  ;;
***************
*** 259,264 ****
--- 259,272 ----
    :group 'recentf
    :type '(choice (const :tag "None" nil)
                   function))
+ 
+ (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)
+ 
  \f
  ;;; 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.")
  
***************
*** 1063,1068 ****
--- 1074,1082 ----
    (kill-buffer (current-buffer))
    (funcall recentf-menu-action (widget-value widget)))
  
+ ;; List of files associated to a digit shortcut key.
+ (defvar recentf--files-with-key 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,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))))
  
  (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)))))
  
  (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)))
  
  (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)))
+ 
+ (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))))
  
  (defun recentf-open-more-files ()
    "Show a dialog to open a recent file that is not in the menu."

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: recentf.el - digit shortcuts
@ 2005-09-02  8:19 David PONCE
  2005-09-03  9:24 ` Karl Chen
  0 siblings, 1 reply; 8+ messages in thread
From: David PONCE @ 2005-09-02  8:19 UTC (permalink / raw)
  Cc: emacs-devel

Hi Karl,

> 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.

This is a good idea!  However your implementation fails when items are
grouped into sub-menus in the `recentf-open-files' dialog. Attached is
a reworked patch which fixes that bug, plus some minor cleanups. Could
you try it please. If it works as you expect I could commit it if
there is no objection from the other developers.

Thanks!

David

Index: lisp/recentf.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/recentf.el,v
retrieving revision 1.42
diff -c -r1.42 recentf.el
*** lisp/recentf.el	6 Aug 2005 22:13:43 -0000	1.42
--- lisp/recentf.el	2 Sep 2005 08:16:10 -0000
***************
*** 259,264 ****
--- 259,272 ----
    :group 'recentf
    :type '(choice (const :tag "None" nil)
                   function))
+ 
+ (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)
+ 
  \f
  ;;; 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 '("O" "9" "8" "7" "6" "5" "4" "3" "2" "1"))
+       (define-key km k 'recentf-open-file-with-key))
      km)
    "Keymap used in recentf dialogs.")
  
***************
*** 1063,1068 ****
--- 1074,1084 ----
    (kill-buffer (current-buffer))
    (funcall recentf-menu-action (widget-value widget)))
  
+ ;; File counter while building the `recentf-open-files' dialog.
+ (defvar recentf--file-count nil)
+ ;; List of files associated to a digit shortcut key.
+ (defvar recentf--files-with-key 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,1083 ****
          ,@(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"
--- 1092,1108 ----
          ,@(mapcar 'recentf-open-files-item
                    (cdr menu-element)))
      ;; Represent a single file with a link widget
+     ;; Use digit shortcuts for the first ten files.
+     (setq recentf--file-count (+ 1 recentf--file-count))
+     (unless (> recentf--file-count 10)
+       (push (cdr menu-element) recentf--files-with-key))
      `(link :tag ,(car menu-element)
!            :button-prefix ,(if recentf-show-file-shortcuts-flag
!                                (if (> recentf--file-count 10)
!                                    "    "
!                                  (format "[%d] "
!                                          (% recentf--file-count 10)))
!                              "")
             :button-suffix ""
             :button-face default
             :format "%[%t%]\n"
***************
*** 1093,1116 ****
  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")
      (apply 'widget-create
             `(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))))))
      (widget-create
       'push-button
       :notify 'recentf-cancel-dialog
       "Cancel")
      (recentf-dialog-goto-first 'link)))
  
  (defun recentf-open-more-files ()
    "Show a dialog to open a recent file that is not in the menu."
--- 1118,1162 ----
  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 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")
+     (make-local-variable 'recentf--files-with-key)
      (apply 'widget-create
             `(group
               :indent 2
               :format "\n%v\n"
!              ,@(let ((recentf--file-count 0))
!                  (mapcar 'recentf-open-files-item
!                          (recentf-apply-menu-filter
!                           recentf-menu-filter
!                           (mapcar 'recentf-make-default-menu-element
!                                   (or files recentf-list)))))))
!     (setq recentf--files-with-key
!           (nreverse recentf--files-with-key))
      (widget-create
       'push-button
       :notify 'recentf-cancel-dialog
       "Cancel")
      (recentf-dialog-goto-first 'link)))
+ 
+ (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
+     (let ((char (string-to-char (this-command-keys))))
+       (cond
+        ((= char ?0) 10)
+        ((and (>= char ?1) (<= char ?9)) (- char ?0))
+        (t (error "Invalid digit key"))))))
+   (let ((file (nth (- n 1) recentf--files-with-key)))
+     (unless file (error "Not that many recent 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."

^ permalink raw reply	[flat|nested] 8+ messages in thread
* recentf.el - digit shortcuts
@ 2005-09-01 20:58 Karl Chen
  0 siblings, 0 replies; 8+ messages in thread
From: Karl Chen @ 2005-09-01 20:58 UTC (permalink / raw)



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  <quarl@cs.berkeley.edu>

	* 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)
+
 \f
 ;;; 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

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

end of thread, other threads:[~2005-09-07 17:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-05 11:27 recentf.el - digit shortcuts David PONCE
2005-09-06  8:19 ` Karl Chen
  -- strict thread matches above, loose matches on Subject: below --
2005-09-07 12:44 David PONCE
2005-09-07 17:26 ` Karl Chen
2005-09-05  7:21 David PONCE
2005-09-02  8:19 David PONCE
2005-09-03  9:24 ` Karl Chen
2005-09-01 20:58 Karl Chen

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).