aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ponce2005-09-08 08:54:34 +0000
committerDavid Ponce2005-09-08 08:54:34 +0000
commite58af6f198545ddcab01ec29ea8206b2492311f2 (patch)
treebfb98d23d7b05697923b4c230da03f66353fadd4
parent844c6ee7498df3bea0a15942d4917c828be74d9e (diff)
downloademacs-e58af6f198545ddcab01ec29ea8206b2492311f2.tar.gz
emacs-e58af6f198545ddcab01ec29ea8206b2492311f2.zip
(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.
-rw-r--r--lisp/recentf.el78
1 files changed, 69 insertions, 9 deletions
diff --git a/lisp/recentf.el b/lisp/recentf.el
index 524d00d389d..adc4dd023bf 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -5,7 +5,6 @@
5 5
6;; Author: David Ponce <david@dponce.com> 6;; Author: David Ponce <david@dponce.com>
7;; Created: July 19 1999 7;; Created: July 19 1999
8;; Maintainer: FSF
9;; Keywords: files 8;; Keywords: files
10 9
11;; This file is part of GNU Emacs. 10;; This file is part of GNU Emacs.
@@ -259,6 +258,14 @@ If it returns nil, the filename is left unchanged."
259 :group 'recentf 258 :group 'recentf
260 :type '(choice (const :tag "None" nil) 259 :type '(choice (const :tag "None" nil)
261 function)) 260 function))
261
262(defcustom recentf-show-file-shortcuts-flag t
263 "Whether to show ``[N]'' for the Nth item up to 10.
264If non-nil, `recentf-open-files' will show labels for keys that can be
265used as shortcuts to open the Nth file."
266 :group 'recentf
267 :type 'boolean)
268
262 269
263;;; Utilities 270;;; Utilities
264;; 271;;
@@ -349,7 +356,7 @@ filenames."
349 "Convert filename NAME to absolute, and canonicalize it. 356 "Convert filename NAME to absolute, and canonicalize it.
350See also the function `expand-file-name'. 357See also the function `expand-file-name'.
351If defined, call the function `recentf-filename-handler' 358If defined, call the function `recentf-filename-handler'
352to postprocess the canonical name." 359to post process the canonical name."
353 (let* ((filename (expand-file-name name))) 360 (let* ((filename (expand-file-name name)))
354 (or (and recentf-filename-handler 361 (or (and recentf-filename-handler
355 (funcall recentf-filename-handler filename)) 362 (funcall recentf-filename-handler filename))
@@ -926,6 +933,9 @@ Go to the beginning of buffer if not found."
926 (set-keymap-parent km widget-keymap) 933 (set-keymap-parent km widget-keymap)
927 (define-key km "q" 'recentf-cancel-dialog) 934 (define-key km "q" 'recentf-cancel-dialog)
928 (define-key km [down-mouse-1] 'widget-button-click) 935 (define-key km [down-mouse-1] 'widget-button-click)
936 ;; Keys in reverse order of appearence in help.
937 (dolist (k '("0" "9" "8" "7" "6" "5" "4" "3" "2" "1"))
938 (define-key km k 'recentf-open-file-with-key))
929 km) 939 km)
930 "Keymap used in recentf dialogs.") 940 "Keymap used in recentf dialogs.")
931 941
@@ -1063,6 +1073,18 @@ IGNORE other arguments."
1063 (kill-buffer (current-buffer)) 1073 (kill-buffer (current-buffer))
1064 (funcall recentf-menu-action (widget-value widget))) 1074 (funcall recentf-menu-action (widget-value widget)))
1065 1075
1076;; List of files associated to a digit shortcut key.
1077(defvar recentf--files-with-key nil)
1078
1079(defun recentf-show-digit-shortcut-filter (l)
1080 "Filter the list of menu-elements L to show digit shortcuts."
1081 (let ((i 0))
1082 (dolist (e l)
1083 (setq i (1+ i))
1084 (recentf-set-menu-element-item
1085 e (format "[%d] %s" (% i 10) (recentf-menu-element-item e))))
1086 l))
1087
1066(defun recentf-open-files-item (menu-element) 1088(defun recentf-open-files-item (menu-element)
1067 "Return a widget to display MENU-ELEMENT in a dialog buffer." 1089 "Return a widget to display MENU-ELEMENT in a dialog buffer."
1068 (if (consp (cdr menu-element)) 1090 (if (consp (cdr menu-element))
@@ -1085,6 +1107,26 @@ IGNORE other arguments."
1085 :action recentf-open-files-action 1107 :action recentf-open-files-action
1086 ,(cdr menu-element)))) 1108 ,(cdr menu-element))))
1087 1109
1110(defun recentf-open-files-items (files)
1111 "Return a list of widgets to display FILES in a dialog buffer."
1112 (set (make-local-variable 'recentf--files-with-key)
1113 (recentf-trunc-list files 10))
1114 (mapcar 'recentf-open-files-item
1115 (append
1116 ;; When requested group the files with shortcuts together
1117 ;; at the top of the list.
1118 (when recentf-show-file-shortcuts-flag
1119 (setq files (nthcdr 10 files))
1120 (recentf-apply-menu-filter
1121 'recentf-show-digit-shortcut-filter
1122 (mapcar 'recentf-make-default-menu-element
1123 recentf--files-with-key)))
1124 ;; Then the other files.
1125 (recentf-apply-menu-filter
1126 recentf-menu-filter
1127 (mapcar 'recentf-make-default-menu-element
1128 files)))))
1129
1088(defun recentf-open-files (&optional files buffer-name) 1130(defun recentf-open-files (&optional files buffer-name)
1089 "Show a dialog to open a recent file. 1131 "Show a dialog to open a recent file.
1090If optional argument FILES is non-nil, it is a list of recently-opened 1132If optional argument FILES is non-nil, it is a list of recently-opened
@@ -1093,25 +1135,43 @@ If optional argument BUFFER-NAME is non-nil, it is a buffer name to
1093use for the dialog. It defaults to \"*`recentf-menu-title'*\"." 1135use for the dialog. It defaults to \"*`recentf-menu-title'*\"."
1094 (interactive) 1136 (interactive)
1095 (recentf-dialog (or buffer-name (format "*%s*" recentf-menu-title)) 1137 (recentf-dialog (or buffer-name (format "*%s*" recentf-menu-title))
1096 (widget-insert "Click on a file to open it. 1138 (widget-insert "Click on a file"
1097Click on Cancel or type `q' to cancel.\n" ) 1139 (if recentf-show-file-shortcuts-flag
1140 ", or type the corresponding digit key,"
1141 "")
1142 " to open it.\n"
1143 "Click on Cancel or type `q' to cancel.\n")
1098 ;; Use a L&F that looks like the recentf menu. 1144 ;; Use a L&F that looks like the recentf menu.
1099 (tree-widget-set-theme "folder") 1145 (tree-widget-set-theme "folder")
1100 (apply 'widget-create 1146 (apply 'widget-create
1101 `(group 1147 `(group
1102 :indent 2 1148 :indent 2
1103 :format "\n%v\n" 1149 :format "\n%v\n"
1104 ,@(mapcar 'recentf-open-files-item 1150 ,@(recentf-open-files-items (or files recentf-list))))
1105 (recentf-apply-menu-filter
1106 recentf-menu-filter
1107 (mapcar 'recentf-make-default-menu-element
1108 (or files recentf-list))))))
1109 (widget-create 1151 (widget-create
1110 'push-button 1152 'push-button
1111 :notify 'recentf-cancel-dialog 1153 :notify 'recentf-cancel-dialog
1112 "Cancel") 1154 "Cancel")
1113 (recentf-dialog-goto-first 'link))) 1155 (recentf-dialog-goto-first 'link)))
1114 1156
1157(defun recentf-open-file-with-key (n)
1158 "Open the recent file with the shortcut numeric key N.
1159N must be a valid digit.
1160`1' opens the first file, `2' the second file, ... `9' the ninth file.
1161`0' opens the tenth file."
1162 (interactive
1163 (list
1164 (let ((n (string-to-number (this-command-keys))))
1165 (cond
1166 ((zerop n) 10)
1167 ((and (> n 0) (< n 10)) n)
1168 ((error "Invalid digit key %d" n))))))
1169 (when recentf--files-with-key
1170 (let ((file (nth (1- n) recentf--files-with-key)))
1171 (unless file (error "Not that many recent files"))
1172 (kill-buffer (current-buffer))
1173 (funcall recentf-menu-action file))))
1174
1115(defun recentf-open-more-files () 1175(defun recentf-open-more-files ()
1116 "Show a dialog to open a recent file that is not in the menu." 1176 "Show a dialog to open a recent file that is not in the menu."
1117 (interactive) 1177 (interactive)