aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ponce2005-10-07 07:52:58 +0000
committerDavid Ponce2005-10-07 07:52:58 +0000
commit4e8cb3117c9ef3b79f0bb08256b1a2e6ea78be1d (patch)
treeba25f0d5d17132975270acf4a479a67f7b3f7b30
parentc2ded1b7d5b6ced034c2291d5078416fbc58fafc (diff)
downloademacs-4e8cb3117c9ef3b79f0bb08256b1a2e6ea78be1d.tar.gz
emacs-4e8cb3117c9ef3b79f0bb08256b1a2e6ea78be1d.zip
(recentf-menu-open-all-flag): New option.
(recentf-digit-shortcut-command-name): New function. (recentf--shortcuts-keymap): New variable. (recentf-menu-shortcuts): New variable. (recentf-make-menu-items): Initialize it. Replace the "More..." menu item by "All...", if `recentf-menu-open-all-flag' is non-nil. (recentf-menu-value-shortcut): New function. (recentf-make-menu-item): Use it. No more in-lined. (recentf-dialog-mode-map): Base on `recentf--shortcuts-keymap'. (recentf-open-most-recent-file): Rename from `recentf-open-file-with-key'. Don't depend on key binding. (recentf-mode-map): New variable. (recentf-mode): Use it.
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/recentf.el133
2 files changed, 111 insertions, 38 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 922c33df8f1..2c41db93141 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12005-10-07 David Ponce <david@dponce.com>
2
3 * recentf.el (recentf-menu-open-all-flag): New option.
4 (recentf-digit-shortcut-command-name): New function.
5 (recentf--shortcuts-keymap): New variable.
6 (recentf-menu-shortcuts): New variable.
7 (recentf-make-menu-items): Initialize it. Replace the "More..."
8 menu item by "All...", if `recentf-menu-open-all-flag' is non-nil.
9 (recentf-menu-value-shortcut): New function.
10 (recentf-make-menu-item): Use it. No more in-lined.
11 (recentf-dialog-mode-map): Base on `recentf--shortcuts-keymap'.
12 (recentf-open-most-recent-file): Rename from
13 `recentf-open-file-with-key'. Don't depend on key binding.
14 (recentf-mode-map): New variable.
15 (recentf-mode): Use it.
16
12005-10-06 Bill Wohler <wohler@newt.com> 172005-10-06 Bill Wohler <wohler@newt.com>
2 18
3 * mh-e/mh-loaddefs.el: Removed. Now generated automatically. 19 * mh-e/mh-loaddefs.el: Removed. Now generated automatically.
diff --git a/lisp/recentf.el b/lisp/recentf.el
index a2392fb852c..dee7a8d438d 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -206,6 +206,13 @@ elements (see `recentf-make-menu-element' for menu element form)."
206 function) 206 function)
207 :set 'recentf-menu-customization-changed) 207 :set 'recentf-menu-customization-changed)
208 208
209(defcustom recentf-menu-open-all-flag nil
210 "*Non-nil means to show an \"All...\" item in the menu.
211This item will replace the \"More...\" item."
212 :group 'recentf
213 :type 'boolean
214 :set 'recentf-menu-customization-changed)
215
209(defcustom recentf-menu-append-commands-flag t 216(defcustom recentf-menu-append-commands-flag t
210 "*Non-nil means to append command items to the menu." 217 "*Non-nil means to append command items to the menu."
211 :group 'recentf 218 :group 'recentf
@@ -278,7 +285,6 @@ If non-nil, `recentf-open-files' will show labels for keys that can be
278used as shortcuts to open the Nth file." 285used as shortcuts to open the Nth file."
279 :group 'recentf 286 :group 'recentf
280 :type 'boolean) 287 :type 'boolean)
281
282 288
283;;; Utilities 289;;; Utilities
284;; 290;;
@@ -448,6 +454,25 @@ Return non-nil if F1 is less than F2."
448 454
449;;; Menu building 455;;; Menu building
450;; 456;;
457(defsubst recentf-digit-shortcut-command-name (n)
458 "Return a command name to open the Nth most recent file.
459See also the command `recentf-open-most-recent-file'."
460 (intern (format "recentf-open-most-recent-file-%d" n)))
461
462(defvar recentf--shortcuts-keymap
463 (let ((km (make-sparse-keymap)))
464 (dolist (k '(0 9 8 7 6 5 4 3 2 1))
465 (let ((cmd (recentf-digit-shortcut-command-name k)))
466 ;; Define a shortcut command.
467 (defalias cmd
468 `(lambda ()
469 (interactive)
470 (recentf-open-most-recent-file ,k)))
471 ;; Bind it to a digit key.
472 (define-key km (vector (+ k ?0)) cmd)))
473 km)
474 "Digit shortcuts keymap.")
475
451(defvar recentf-menu-items-for-commands 476(defvar recentf-menu-items-for-commands
452 (list 477 (list
453 ["Cleanup list" 478 ["Cleanup list"
@@ -548,21 +573,29 @@ menu-elements (no sub-menu)."
548 (nconc l others)) 573 (nconc l others))
549 l)) 574 l))
550 575
576;; Count the number of assigned menu shortcuts.
577(defvar recentf-menu-shortcuts)
578
551(defun recentf-make-menu-items () 579(defun recentf-make-menu-items ()
552 "Make menu items from the recent list." 580 "Make menu items from the recent list."
553 (setq recentf-menu-filter-commands nil) 581 (setq recentf-menu-filter-commands nil)
554 (let ((file-items 582 (let* ((recentf-menu-shortcuts 0)
555 (mapcar 'recentf-make-menu-item 583 (file-items
556 (recentf-apply-menu-filter 584 (mapcar 'recentf-make-menu-item
557 recentf-menu-filter 585 (recentf-apply-menu-filter
558 (recentf-menu-elements recentf-max-menu-items))))) 586 recentf-menu-filter
587 (recentf-menu-elements recentf-max-menu-items)))))
559 (append (or file-items (list ["No files" t 588 (append (or file-items (list ["No files" t
560 :help "No recent file to open" 589 :help "No recent file to open"
561 :active nil])) 590 :active nil]))
562 (and (< recentf-max-menu-items (length recentf-list)) 591 (if recentf-menu-open-all-flag
563 (list ["More..." recentf-open-more-files 592 (list ["All..." recentf-open-files
564 :help "Open files that are not in the menu" 593 :help "Open recent files through a dialog"
565 :active t])) 594 :active t])
595 (and (< recentf-max-menu-items (length recentf-list))
596 (list ["More..." recentf-open-more-files
597 :help "Open files not in the menu through a dialog"
598 :active t])))
566 (and recentf-menu-filter-commands 599 (and recentf-menu-filter-commands
567 (cons "---" 600 (cons "---"
568 recentf-menu-filter-commands)) 601 recentf-menu-filter-commands))
@@ -570,15 +603,37 @@ menu-elements (no sub-menu)."
570 (cons "---" 603 (cons "---"
571 recentf-menu-items-for-commands))))) 604 recentf-menu-items-for-commands)))))
572 605
573(defsubst recentf-make-menu-item (elt) 606(defun recentf-menu-value-shortcut (name)
607 "Return a shorcut digit for file NAME.
608Return nil if file NAME is not one of the ten more recent."
609 (let ((i 0) k)
610 (while (and (not k) (< i 10))
611 (if (string-equal name (nth i recentf-list))
612 (progn
613 (setq recentf-menu-shortcuts (1+ recentf-menu-shortcuts))
614 (setq k (% (1+ i) 10)))
615 (setq i (1+ i))))
616 k))
617
618(defun recentf-make-menu-item (elt)
574 "Make a menu item from menu element ELT." 619 "Make a menu item from menu element ELT."
575 (let ((item (recentf-menu-element-item elt)) 620 (let ((item (recentf-menu-element-item elt))
576 (value (recentf-menu-element-value elt))) 621 (value (recentf-menu-element-value elt)))
577 (if (recentf-sub-menu-element-p elt) 622 (if (recentf-sub-menu-element-p elt)
578 (cons item (mapcar 'recentf-make-menu-item value)) 623 (cons item (mapcar 'recentf-make-menu-item value))
579 (vector item (list recentf-menu-action value) 624 (let ((k (and (< recentf-menu-shortcuts 10)
580 :help (concat "Open " value) 625 (recentf-menu-value-shortcut value))))
581 :active t)))) 626 (vector item
627 ;; If the file name is one of the ten more recent, use
628 ;; a digit shortcut command to open it, else use an
629 ;; anonymous command.
630 (if k
631 (recentf-digit-shortcut-command-name k)
632 `(lambda ()
633 (interactive)
634 (,recentf-menu-action ,value)))
635 :help (concat "Open " value)
636 :active t)))))
582 637
583(defsubst recentf-menu-bar () 638(defsubst recentf-menu-bar ()
584 "Return the keymap of the global menu bar." 639 "Return the keymap of the global menu bar."
@@ -953,13 +1008,10 @@ Go to the beginning of buffer if not found."
953 (goto-char (point-min)))) 1008 (goto-char (point-min))))
954 1009
955(defvar recentf-dialog-mode-map 1010(defvar recentf-dialog-mode-map
956 (let ((km (make-sparse-keymap))) 1011 (let ((km (copy-keymap recentf--shortcuts-keymap)))
957 (set-keymap-parent km widget-keymap) 1012 (set-keymap-parent km widget-keymap)
958 (define-key km "q" 'recentf-cancel-dialog) 1013 (define-key km "q" 'recentf-cancel-dialog)
959 (define-key km [down-mouse-1] 'widget-button-click) 1014 (define-key km [down-mouse-1] 'widget-button-click)
960 ;; Keys in reverse order of appearence in help.
961 (dolist (k '("0" "9" "8" "7" "6" "5" "4" "3" "2" "1"))
962 (define-key km k 'recentf-open-file-with-key))
963 km) 1015 km)
964 "Keymap used in recentf dialogs.") 1016 "Keymap used in recentf dialogs.")
965 1017
@@ -1081,7 +1133,7 @@ Click on Cancel or type `q' to cancel.\n")
1081 'push-button 1133 'push-button
1082 :notify 'recentf-edit-list-validate 1134 :notify 'recentf-edit-list-validate
1083 :help-echo "Delete selected files from the recent list" 1135 :help-echo "Delete selected files from the recent list"
1084 "Ok") 1136 "Ok")
1085 (widget-insert " ") 1137 (widget-insert " ")
1086 (widget-create 1138 (widget-create
1087 'push-button 1139 'push-button
@@ -1178,30 +1230,29 @@ use for the dialog. It defaults to \"*`recentf-menu-title'*\"."
1178 "Cancel") 1230 "Cancel")
1179 (recentf-dialog-goto-first 'link))) 1231 (recentf-dialog-goto-first 'link)))
1180 1232
1181(defun recentf-open-file-with-key (n)
1182 "Open the recent file with the shortcut numeric key N.
1183N must be a valid digit.
1184`1' opens the first file, `2' the second file, ... `9' the ninth file.
1185`0' opens the tenth file."
1186 (interactive
1187 (list
1188 (let ((n (string-to-number (this-command-keys))))
1189 (cond
1190 ((zerop n) 10)
1191 ((and (> n 0) (< n 10)) n)
1192 ((error "Invalid digit key %d" n))))))
1193 (when recentf--files-with-key
1194 (let ((file (nth (1- n) recentf--files-with-key)))
1195 (unless file (error "Not that many recent files"))
1196 (kill-buffer (current-buffer))
1197 (funcall recentf-menu-action file))))
1198
1199(defun recentf-open-more-files () 1233(defun recentf-open-more-files ()
1200 "Show a dialog to open a recent file that is not in the menu." 1234 "Show a dialog to open a recent file that is not in the menu."
1201 (interactive) 1235 (interactive)
1202 (recentf-open-files (nthcdr recentf-max-menu-items recentf-list) 1236 (recentf-open-files (nthcdr recentf-max-menu-items recentf-list)
1203 (format "*%s - More*" recentf-menu-title))) 1237 (format "*%s - More*" recentf-menu-title)))
1204 1238
1239(defun recentf-open-most-recent-file (&optional n)
1240 "Open the Nth most recent file.
1241Optional argument N must be a valid digit number. It defaults to 1.
12421 opens the most recent file, 2 the second most recent one, etc..
12430 opens the tenth most recent file."
1244 (interactive "p")
1245 (cond
1246 ((zerop n) (setq n 10))
1247 ((and (> n 0) (< n 10)))
1248 ((error "Recent file number out of range [0-9], %d" n)))
1249 (let ((file (nth (1- n) (or recentf--files-with-key recentf-list))))
1250 (unless file (error "Not that many recent files"))
1251 ;; Close the open files dialog.
1252 (when recentf--files-with-key
1253 (kill-buffer (current-buffer)))
1254 (funcall recentf-menu-action file)))
1255
1205;;; Save/load/cleanup the recent list 1256;;; Save/load/cleanup the recent list
1206;; 1257;;
1207(defconst recentf-save-file-header 1258(defconst recentf-save-file-header
@@ -1266,6 +1317,9 @@ That is, remove duplicates, non-kept, and excluded files."
1266 (message "Cleaning up the recentf list...done (%d removed)" n) 1317 (message "Cleaning up the recentf list...done (%d removed)" n)
1267 (setq recentf-list (nreverse newlist)))) 1318 (setq recentf-list (nreverse newlist))))
1268 1319
1320(defvar recentf-mode-map (make-sparse-keymap)
1321 "Keymap to use in recentf mode.")
1322
1269;;;###autoload 1323;;;###autoload
1270(define-minor-mode recentf-mode 1324(define-minor-mode recentf-mode
1271 "Toggle recentf mode. 1325 "Toggle recentf mode.
@@ -1273,9 +1327,12 @@ With prefix argument ARG, turn on if positive, otherwise off.
1273Returns non-nil if the new state is enabled. 1327Returns non-nil if the new state is enabled.
1274 1328
1275When recentf mode is enabled, it maintains a menu for visiting files 1329When recentf mode is enabled, it maintains a menu for visiting files
1276that were operated on recently." 1330that were operated on recently.
1331
1332\\{recentf-mode-map}"
1277 :global t 1333 :global t
1278 :group 'recentf 1334 :group 'recentf
1335 :keymap recentf-mode-map
1279 (unless (and recentf-mode (recentf-enabled-p)) 1336 (unless (and recentf-mode (recentf-enabled-p))
1280 (if recentf-mode 1337 (if recentf-mode
1281 (recentf-load-list) 1338 (recentf-load-list)