Mercurial > emacs
comparison lisp/recentf.el @ 83364:46dfd959d88a
Merged in changes from CVS trunk.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-404
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Fri, 09 Sep 2005 20:52:13 +0000 |
parents | 532e0a9335a9 792e39b7cf7e |
children | d84f940244dc |
comparison
equal
deleted
inserted
replaced
83363:3d2bc61f2da0 | 83364:46dfd959d88a |
---|---|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | 4 ;; 2005 Free Software Foundation, Inc. |
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. |
12 | 11 |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
256 "Function to call to process filename handled by recentf. | 255 "Function to call to process filename handled by recentf. |
257 It is passed a filename to give a chance to transform it. | 256 It is passed a filename to give a chance to transform it. |
258 If it returns nil, the filename is left unchanged." | 257 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) |
260 (const abbreviate-file-name) | |
261 function)) | 261 function)) |
262 | |
263 (defcustom recentf-show-file-shortcuts-flag t | |
264 "Whether to show ``[N]'' for the Nth item up to 10. | |
265 If non-nil, `recentf-open-files' will show labels for keys that can be | |
266 used as shortcuts to open the Nth file." | |
267 :group 'recentf | |
268 :type 'boolean) | |
269 | |
262 | 270 |
263 ;;; Utilities | 271 ;;; Utilities |
264 ;; | 272 ;; |
265 (defconst recentf-case-fold-search | 273 (defconst recentf-case-fold-search |
266 (memq system-type '(vax-vms windows-nt cygwin)) | 274 (memq system-type '(vax-vms windows-nt cygwin)) |
347 | 355 |
348 (defsubst recentf-expand-file-name (name) | 356 (defsubst recentf-expand-file-name (name) |
349 "Convert filename NAME to absolute, and canonicalize it. | 357 "Convert filename NAME to absolute, and canonicalize it. |
350 See also the function `expand-file-name'. | 358 See also the function `expand-file-name'. |
351 If defined, call the function `recentf-filename-handler' | 359 If defined, call the function `recentf-filename-handler' |
352 to postprocess the canonical name." | 360 to post process the canonical name." |
353 (let* ((filename (expand-file-name name))) | 361 (let* ((filename (expand-file-name name))) |
354 (or (and recentf-filename-handler | 362 (or (and recentf-filename-handler |
355 (funcall recentf-filename-handler filename)) | 363 (funcall recentf-filename-handler filename)) |
356 filename))) | 364 filename))) |
357 | 365 |
924 (defvar recentf-dialog-mode-map | 932 (defvar recentf-dialog-mode-map |
925 (let ((km (make-sparse-keymap))) | 933 (let ((km (make-sparse-keymap))) |
926 (set-keymap-parent km widget-keymap) | 934 (set-keymap-parent km widget-keymap) |
927 (define-key km "q" 'recentf-cancel-dialog) | 935 (define-key km "q" 'recentf-cancel-dialog) |
928 (define-key km [down-mouse-1] 'widget-button-click) | 936 (define-key km [down-mouse-1] 'widget-button-click) |
937 ;; Keys in reverse order of appearence in help. | |
938 (dolist (k '("0" "9" "8" "7" "6" "5" "4" "3" "2" "1")) | |
939 (define-key km k 'recentf-open-file-with-key)) | |
929 km) | 940 km) |
930 "Keymap used in recentf dialogs.") | 941 "Keymap used in recentf dialogs.") |
931 | 942 |
932 (define-derived-mode recentf-dialog-mode nil "recentf-dialog" | 943 (define-derived-mode recentf-dialog-mode nil "recentf-dialog" |
933 "Major mode of recentf dialogs. | 944 "Major mode of recentf dialogs. |
1061 "Open the file stored in WIDGET's value when notified. | 1072 "Open the file stored in WIDGET's value when notified. |
1062 IGNORE other arguments." | 1073 IGNORE other arguments." |
1063 (kill-buffer (current-buffer)) | 1074 (kill-buffer (current-buffer)) |
1064 (funcall recentf-menu-action (widget-value widget))) | 1075 (funcall recentf-menu-action (widget-value widget))) |
1065 | 1076 |
1077 ;; List of files associated to a digit shortcut key. | |
1078 (defvar recentf--files-with-key nil) | |
1079 | |
1080 (defun recentf-show-digit-shortcut-filter (l) | |
1081 "Filter the list of menu-elements L to show digit shortcuts." | |
1082 (let ((i 0)) | |
1083 (dolist (e l) | |
1084 (setq i (1+ i)) | |
1085 (recentf-set-menu-element-item | |
1086 e (format "[%d] %s" (% i 10) (recentf-menu-element-item e)))) | |
1087 l)) | |
1088 | |
1066 (defun recentf-open-files-item (menu-element) | 1089 (defun recentf-open-files-item (menu-element) |
1067 "Return a widget to display MENU-ELEMENT in a dialog buffer." | 1090 "Return a widget to display MENU-ELEMENT in a dialog buffer." |
1068 (if (consp (cdr menu-element)) | 1091 (if (consp (cdr menu-element)) |
1069 ;; Represent a sub-menu with a tree widget | 1092 ;; Represent a sub-menu with a tree widget |
1070 `(tree-widget | 1093 `(tree-widget |
1083 :format "%[%t%]\n" | 1106 :format "%[%t%]\n" |
1084 :help-echo ,(concat "Open " (cdr menu-element)) | 1107 :help-echo ,(concat "Open " (cdr menu-element)) |
1085 :action recentf-open-files-action | 1108 :action recentf-open-files-action |
1086 ,(cdr menu-element)))) | 1109 ,(cdr menu-element)))) |
1087 | 1110 |
1111 (defun recentf-open-files-items (files) | |
1112 "Return a list of widgets to display FILES in a dialog buffer." | |
1113 (set (make-local-variable 'recentf--files-with-key) | |
1114 (recentf-trunc-list files 10)) | |
1115 (mapcar 'recentf-open-files-item | |
1116 (append | |
1117 ;; When requested group the files with shortcuts together | |
1118 ;; at the top of the list. | |
1119 (when recentf-show-file-shortcuts-flag | |
1120 (setq files (nthcdr 10 files)) | |
1121 (recentf-apply-menu-filter | |
1122 'recentf-show-digit-shortcut-filter | |
1123 (mapcar 'recentf-make-default-menu-element | |
1124 recentf--files-with-key))) | |
1125 ;; Then the other files. | |
1126 (recentf-apply-menu-filter | |
1127 recentf-menu-filter | |
1128 (mapcar 'recentf-make-default-menu-element | |
1129 files))))) | |
1130 | |
1088 (defun recentf-open-files (&optional files buffer-name) | 1131 (defun recentf-open-files (&optional files buffer-name) |
1089 "Show a dialog to open a recent file. | 1132 "Show a dialog to open a recent file. |
1090 If optional argument FILES is non-nil, it is a list of recently-opened | 1133 If optional argument FILES is non-nil, it is a list of recently-opened |
1091 files to choose from. It defaults to the whole recent list. | 1134 files to choose from. It defaults to the whole recent list. |
1092 If optional argument BUFFER-NAME is non-nil, it is a buffer name to | 1135 If optional argument BUFFER-NAME is non-nil, it is a buffer name to |
1093 use for the dialog. It defaults to \"*`recentf-menu-title'*\"." | 1136 use for the dialog. It defaults to \"*`recentf-menu-title'*\"." |
1094 (interactive) | 1137 (interactive) |
1095 (recentf-dialog (or buffer-name (format "*%s*" recentf-menu-title)) | 1138 (recentf-dialog (or buffer-name (format "*%s*" recentf-menu-title)) |
1096 (widget-insert "Click on a file to open it. | 1139 (widget-insert "Click on a file" |
1097 Click on Cancel or type `q' to cancel.\n" ) | 1140 (if recentf-show-file-shortcuts-flag |
1141 ", or type the corresponding digit key," | |
1142 "") | |
1143 " to open it.\n" | |
1144 "Click on Cancel or type `q' to cancel.\n") | |
1098 ;; Use a L&F that looks like the recentf menu. | 1145 ;; Use a L&F that looks like the recentf menu. |
1099 (tree-widget-set-theme "folder") | 1146 (tree-widget-set-theme "folder") |
1100 (apply 'widget-create | 1147 (apply 'widget-create |
1101 `(group | 1148 `(group |
1102 :indent 2 | 1149 :indent 2 |
1103 :format "\n%v\n" | 1150 :format "\n%v\n" |
1104 ,@(mapcar 'recentf-open-files-item | 1151 ,@(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 | 1152 (widget-create |
1110 'push-button | 1153 'push-button |
1111 :notify 'recentf-cancel-dialog | 1154 :notify 'recentf-cancel-dialog |
1112 "Cancel") | 1155 "Cancel") |
1113 (recentf-dialog-goto-first 'link))) | 1156 (recentf-dialog-goto-first 'link))) |
1157 | |
1158 (defun recentf-open-file-with-key (n) | |
1159 "Open the recent file with the shortcut numeric key N. | |
1160 N must be a valid digit. | |
1161 `1' opens the first file, `2' the second file, ... `9' the ninth file. | |
1162 `0' opens the tenth file." | |
1163 (interactive | |
1164 (list | |
1165 (let ((n (string-to-number (this-command-keys)))) | |
1166 (cond | |
1167 ((zerop n) 10) | |
1168 ((and (> n 0) (< n 10)) n) | |
1169 ((error "Invalid digit key %d" n)))))) | |
1170 (when recentf--files-with-key | |
1171 (let ((file (nth (1- n) recentf--files-with-key))) | |
1172 (unless file (error "Not that many recent files")) | |
1173 (kill-buffer (current-buffer)) | |
1174 (funcall recentf-menu-action file)))) | |
1114 | 1175 |
1115 (defun recentf-open-more-files () | 1176 (defun recentf-open-more-files () |
1116 "Show a dialog to open a recent file that is not in the menu." | 1177 "Show a dialog to open a recent file that is not in the menu." |
1117 (interactive) | 1178 (interactive) |
1118 (recentf-open-files (nthcdr recentf-max-menu-items recentf-list) | 1179 (recentf-open-files (nthcdr recentf-max-menu-items recentf-list) |