comparison lisp/recentf.el @ 27920:8f8b86890eb3

(recentf): Added version tag to the defgroup of recentf. (recentf-cleanup): Changed to remove excluded file too. (recentf-edit-list-action): `recentf-edit-list' checkbox widget action to select/unselect a file. (recentf-edit-list): Code cleanup and improvement. (recentf-open-more-files-action): `recentf-open-more-files' button widget action to open a file. (recentf-open-more-files): No more use standard completion but widgets. (recentf-more-collection): Deleted. (recentf-more-history): Deleted. (recentf-setup-more-completion): Deleted. (recentf-mode): No more needs that Emacs is running under a window-system. (recentf-edit-list): New command to edit the recent list which allow the user to remove files. (recentf-edit-selected-items): New global variable, used by `recentf-edit-list' to hold the list of files to be removed from the recent list. (recentf-make-menu-items): Updated to display a "Edit list..." menu item. Minor code cleanup. (recentf-open-more-files): New command to open files that are not displayed in the menu. (recentf-more-collection): New global variable holding the set of permissible completions used by `recentf-open-more-files'. (recentf-more-history): New global variable holding the history list used by `recentf-open-more-files' completion. (recentf-setup-more-completion): New function to setup completion for `recentf-open-more-files'. (recentf-make-menu-items): Updated to display a "More..." menu item. * recentf.el (recentf-menu-action): Doc fixed. (recentf-menu-filter): Doc updated. (recentf-update-menu-hook): Allow menu filters to force menu update. (recentf-make-menu-items): New menu filter handling. (recentf-make-menu-item): New helper function. (recentf-menu-elements): New menu handling function. (recentf-sort-ascending): Updated to new menu filter handling. (recentf-sort-descending): Updated to new menu filter handling. (recentf-sort-basenames-ascending): New menu filter function. (recentf-sort-basenames-descending): New menu filter function. (recentf-show-basenames): New menu filter function. (recentf-show-basenames-ascending): New menu filter function. (recentf-show-basenames-descending): New menu filter function.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 01 Mar 2000 12:46:12 +0000
parents b84ee89aaf37
children 27dffce74906
comparison
equal deleted inserted replaced
27919:aff9b488af48 27920:8f8b86890eb3
26 ;;; Commentary: 26 ;;; Commentary:
27 27
28 ;;; Code: 28 ;;; Code:
29 29
30 (require 'easymenu) 30 (require 'easymenu)
31 (require 'widget)
32 (eval-when-compile
33 (require 'wid-edit))
31 34
32 (defconst recentf-save-file-header 35 (defconst recentf-save-file-header
33 ";;; Automatically generated by `recentf' on %s.\n" 36 ";;; Automatically generated by `recentf' on %s.\n"
34 "Header to be written into the `recentf-save-file'.") 37 "Header to be written into the `recentf-save-file'.")
35 38
101 (defcustom recentf-menu-action 'recentf-find-file 104 (defcustom recentf-menu-action 'recentf-find-file
102 "*Function to invoke with a filename item of the recentf menu. 105 "*Function to invoke with a filename item of the recentf menu.
103 The default action `recentf-find-file' calls `find-file' to edit an 106 The default action `recentf-find-file' calls `find-file' to edit an
104 existing file. If the file does not exist or is not readable, it is 107 existing file. If the file does not exist or is not readable, it is
105 not edited and its name is removed from `recentf-list'. You can use 108 not edited and its name is removed from `recentf-list'. You can use
106 `find-file' instead to open non-existing files and keep them is the 109 `find-file' instead to open non-existing files and keep them in the
107 list of recently opened files." 110 list of recently opened files."
108 :group 'recentf 111 :group 'recentf
109 :type 'function 112 :type 'function
110 :set 'recentf-menu-customization-changed) 113 :set 'recentf-menu-customization-changed)
111 114
169 Returns the new status of recentf mode (non-nil means on). 172 Returns the new status of recentf mode (non-nil means on).
170 173
171 When recentf mode is enabled, it maintains a menu for visiting files that 174 When recentf mode is enabled, it maintains a menu for visiting files that
172 were operated on recently." 175 were operated on recently."
173 (interactive "P") 176 (interactive "P")
174 (when window-system 177 (let ((on-p (if arg
175 (let ((on-p (if arg 178 (> (prefix-numeric-value arg) 0)
176 (> (prefix-numeric-value arg) 0) 179 (not recentf-mode))))
177 (not recentf-mode)))) 180 (if on-p
178 (if on-p 181 (unless recentf-initialized-p
179 (unless recentf-initialized-p 182 (setq recentf-initialized-p t)
180 (setq recentf-initialized-p t) 183 (if (file-readable-p recentf-save-file)
181 (if (file-readable-p recentf-save-file) 184 (load-file recentf-save-file))
182 (load-file recentf-save-file)) 185 (setq recentf-update-menu-p t)
183 (setq recentf-update-menu-p t) 186 (add-hook 'find-file-hooks 'recentf-add-file-hook)
184 (add-hook 'find-file-hooks 'recentf-add-file-hook) 187 (add-hook 'write-file-hooks 'recentf-add-file-hook)
185 (add-hook 'write-file-hooks 'recentf-add-file-hook) 188 ;; (add-hook 'activate-menubar-hook 'recentf-update-menu-hook)
186 ;; (add-hook 'activate-menubar-hook 'recentf-update-menu-hook) 189 (add-hook 'menu-bar-update-hook 'recentf-update-menu-hook)
187 (add-hook 'menu-bar-update-hook 'recentf-update-menu-hook) 190 (add-hook 'kill-emacs-hook 'recentf-save-list))
188 (add-hook 'kill-emacs-hook 'recentf-save-list)) 191 (when recentf-initialized-p
189 (when recentf-initialized-p 192 (setq recentf-initialized-p nil)
190 (setq recentf-initialized-p nil) 193 (recentf-save-list)
191 (recentf-save-list) 194 (easy-menu-remove-item nil recentf-menu-path recentf-menu-title)
192 (easy-menu-remove-item nil recentf-menu-path recentf-menu-title) 195 (remove-hook 'find-file-hooks 'recentf-add-file-hook)
193 (remove-hook 'find-file-hooks 'recentf-add-file-hook) 196 (remove-hook 'write-file-hooks 'recentf-add-file-hook)
194 (remove-hook 'write-file-hooks 'recentf-add-file-hook) 197 ;; (remove-hook 'activate-menubar-hook 'recentf-update-menu-hook)
195 ;; (remove-hook 'activate-menubar-hook 'recentf-update-menu-hook) 198 (remove-hook 'menu-bar-update-hook 'recentf-update-menu-hook)
196 (remove-hook 'menu-bar-update-hook 'recentf-update-menu-hook) 199 (remove-hook 'kill-emacs-hook 'recentf-save-list)))
197 (remove-hook 'kill-emacs-hook 'recentf-save-list))) 200 (setq recentf-mode on-p)))
198 (setq recentf-mode on-p))))
199 201
200 (defun recentf-add-file-hook () 202 (defun recentf-add-file-hook ()
201 "Insert the name of the file just opened or written into `recentf-list'." 203 "Insert the name of the file just opened or written into `recentf-list'."
202 (and buffer-file-name (recentf-add-file buffer-file-name)) 204 (and buffer-file-name (recentf-add-file buffer-file-name))
203 nil) 205 nil)
235 (if (file-writable-p recentf-save-file) 237 (if (file-writable-p recentf-save-file)
236 (write-region (point-min) (point-max) recentf-save-file)) 238 (write-region (point-min) (point-max) recentf-save-file))
237 (kill-buffer (current-buffer)))) 239 (kill-buffer (current-buffer))))
238 nil) 240 nil)
239 241
242 (defvar recentf-edit-selected-items nil
243 "Used by `recentf-edit-list' to hold the list of files to be deleted
244 from `recentf-list'.")
245
246 (defun recentf-edit-list-action (widget &rest ignore)
247 "Checkbox widget action used by `recentf-edit-list' to select/unselect a file."
248 (let ((value (widget-get widget ':tag)))
249 ;; if value is already in the selected items
250 (if (memq value recentf-edit-selected-items)
251 ;; then remove it
252 (progn
253 (setq recentf-edit-selected-items
254 (delq value recentf-edit-selected-items))
255 (message "%s removed from selection." value))
256 ;; else add it
257 (progn
258 (setq recentf-edit-selected-items
259 (nconc (list value) recentf-edit-selected-items))
260 (message "%s added to selection." value)))))
261
262 ;;;###autoload
263 (defun recentf-edit-list ()
264 "Allow the user to edit the files that are kept in the recent list."
265 (interactive)
266 (with-current-buffer (get-buffer-create (concat "*" recentf-menu-title " - Edit list*"))
267 (switch-to-buffer (current-buffer))
268 (kill-all-local-variables)
269 (let ((inhibit-read-only t))
270 (erase-buffer))
271 (let ((all (overlay-lists)))
272 ;; Delete all the overlays.
273 (mapcar 'delete-overlay (car all))
274 (mapcar 'delete-overlay (cdr all)))
275 (setq recentf-edit-selected-items nil)
276 ;; Insert the dialog header
277 (widget-insert "Select the files to be deleted from the 'recentf-list'.\n\n")
278 (widget-insert "Click on Ok to update the list or on Cancel to quit.\n" )
279 ;; Insert the list of files as checkboxes
280 (mapcar '(lambda (item)
281 (widget-create 'checkbox
282 :value nil ; unselected checkbox
283 :format "\n %[%v%] %t"
284 :tag item
285 :notify 'recentf-edit-list-action))
286 recentf-list)
287 (widget-insert "\n\n")
288 ;; Insert the Ok button
289 (widget-create 'push-button
290 :notify (lambda (&rest ignore)
291 (if recentf-edit-selected-items
292 (progn (kill-buffer (current-buffer))
293 (mapcar '(lambda (item)
294 (setq recentf-list
295 (delq item recentf-list)))
296 recentf-edit-selected-items)
297 (message "%S file(s) removed from the list"
298 (length recentf-edit-selected-items))
299 (setq recentf-update-menu-p t))
300 (message "No file selected.")))
301 "Ok")
302 (widget-insert " ")
303 ;; Insert the Cancel button
304 (widget-create 'push-button
305 :notify (lambda (&rest ignore)
306 (kill-buffer (current-buffer))
307 (message "Command canceled."))
308 "Cancel")
309 (use-local-map widget-keymap)
310 (widget-setup)))
311
240 ;;;###autoload 312 ;;;###autoload
241 (defun recentf-cleanup () 313 (defun recentf-cleanup ()
242 "Remove all non-readable files from `recentf-list'." 314 "Remove all non-readable and excluded files from `recentf-list'."
243 (interactive) 315 (interactive)
244 (setq recentf-list (delq nil (mapcar '(lambda (f) 316 (setq recentf-list
245 (and (file-readable-p f) f)) 317 (delq nil
246 recentf-list))) 318 (mapcar '(lambda (filename)
319 (and (file-readable-p filename)
320 (recentf-include-p filename)
321 filename))
322 recentf-list)))
247 (setq recentf-update-menu-p t)) 323 (setq recentf-update-menu-p t))
324
325 (defun recentf-open-more-files-action (widget &rest ignore)
326 "Button widget action used by `recentf-open-more-files' to open a file."
327 (kill-buffer (current-buffer))
328 (funcall recentf-menu-action (widget-value widget)))
329
330 ;;;###autoload
331 (defun recentf-open-more-files ()
332 "Allow the user to open files that are not in the menu."
333 (interactive)
334 (with-current-buffer (get-buffer-create (concat "*" recentf-menu-title " - More*"))
335 (switch-to-buffer (current-buffer))
336 (kill-all-local-variables)
337 (let ((inhibit-read-only t))
338 (erase-buffer))
339 (let ((all (overlay-lists)))
340 ;; Delete all the overlays.
341 (mapcar 'delete-overlay (car all))
342 (mapcar 'delete-overlay (cdr all)))
343 ;; Insert the dialog header
344 (widget-insert "Click on a file to open it or on Cancel to quit.\n\n")
345 ;; Insert the list of files as buttons
346 (mapcar '(lambda (menu-element)
347 (let ((menu-item (car menu-element))
348 (file-path (cdr menu-element)))
349 (widget-create 'push-button
350 :button-face 'default
351 :tag menu-item
352 :help-echo (concat "Open " file-path)
353 :format "%[%t%]"
354 :notify 'recentf-open-more-files-action
355 file-path)
356 (widget-insert "\n")))
357 (funcall (or recentf-menu-filter 'identity)
358 (mapcar '(lambda (item) (cons item item))
359 (nthcdr recentf-max-menu-items recentf-list))))
360 (widget-insert "\n")
361 ;; Insert the Cancel button
362 (widget-create 'push-button
363 :notify (lambda (&rest ignore)
364 (kill-buffer (current-buffer))
365 (message "Command canceled."))
366 "Cancel")
367 (use-local-map widget-keymap)
368 (widget-setup)))
248 369
249 (defvar recentf-menu-items-for-commands 370 (defvar recentf-menu-items-for-commands
250 (list ["Cleanup list" recentf-cleanup t] 371 (list ["Cleanup list" recentf-cleanup t]
372 ["Edit list..." recentf-edit-list t]
251 ["Save list now" recentf-save-list t] 373 ["Save list now" recentf-save-list t]
252 (vector (format "Recentf Options...") 374 (vector "Recentf Options..." '(customize-group "recentf") t))
253 '(customize-group "recentf") t))
254 "List of menu items for recentf commands.") 375 "List of menu items for recentf commands.")
255 376
256 (defun recentf-make-menu-items () 377 (defun recentf-make-menu-items ()
257 "Make menu items from `recentf-list'." 378 "Make menu items from `recentf-list'."
258 (let ((file-items 379 (let ((file-items
259 (mapcar '(lambda (entry) 380 (mapcar '(lambda (entry)
260 (vector entry (list recentf-menu-action entry) t)) 381 (vector entry (list recentf-menu-action entry) t))
261 (funcall (or recentf-menu-filter 'identity) 382 (funcall (or recentf-menu-filter 'identity)
262 (recentf-elements recentf-max-menu-items))))) 383 (recentf-elements recentf-max-menu-items)))))
263 (append (or file-items (list ["No files" t nil])) 384 (append (or file-items (list ["No files" t nil]))
385 (and (< recentf-max-menu-items (length recentf-list))
386 (list ["More..." recentf-open-more-files t]))
264 (and recentf-menu-append-commands-p 387 (and recentf-menu-append-commands-p
265 (cons ["---" nil nil] 388 (cons ["---" nil nil]
266 recentf-menu-items-for-commands))))) 389 recentf-menu-items-for-commands)))))
267 390
268 (defun recentf-add-file (filename) 391 (defun recentf-add-file (filename)