annotate lisp/recentf.el @ 32748:e2cb0aef151a

(vc-checkout): Added `-p' suffix in call to vc-make-version-backups-p; use vc-make-version-backup to actually make the backup. (vc-version-other-window, vc-version-backup-file): Handle both automatic and manual backups. (vc-revert-file): Use vc-delete-automatic-version-backups to get rid of all of them.
author André Spiegel <spiegel@gnu.org>
date Sun, 22 Oct 2000 15:37:51 +0000
parents 0e626f0c2b8a
children 8ef794e21542
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1 ;; recentf.el --- setup a menu of recently opened files
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
2
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
4
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
5 ;; Author: David Ponce <david@dponce.com>
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
6 ;; Created: July 19 1999
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
7 ;; Keywords: customization
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
8
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
9 ;; This file is part of GNU Emacs.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
10
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
14 ;; any later version.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
15
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
19 ;; GNU General Public License for more details.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
20
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
21 ;; You should have received a copy of the GNU General Public License
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
24 ;; Boston, MA 02111-1307, USA.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
25
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
26 ;;; Commentary:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
27
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
28 ;; This package maintains a menu for visiting files that were operated
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
29 ;; on recently. When enabled a new "Open Recent" submenu is displayed
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
30 ;; in the "Files" menu. The recent files list is automatically saved
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
31 ;; across Emacs sessions. You can customize the number of recent
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
32 ;; files displayed, the location of the menu and others options (see
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
33 ;; the source code for details). To install and use, put the file on
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
34 ;; your Emacs-Lisp load path and add the following into your ~/.emacs
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
35 ;; startup file:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
36 ;;
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
37 ;; (require 'recentf)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
38 ;; (recentf-mode 1)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
39
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
40 ;;; Code:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
41
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
42 (require 'easymenu)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
43 (require 'wid-edit)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
44
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
45 (defconst recentf-save-file-header
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
46 ";;; Automatically generated by `recentf' on %s.\n"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
47 "Header to be written into the `recentf-save-file'.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
48
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
49 (defvar recentf-list nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
50 "List of recently opened files.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
51
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
52 (defvar recentf-update-menu-p t
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
53 "Non-nil if the recentf menu must be updated.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
54
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
55 (defvar recentf-initialized-p nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
56 "Non-nil if recentf already initialized.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
57
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
58 ;; IMPORTANT: This function must be defined before the following defcustoms
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
59 ;; because it is used in their :set clause. To avoid byte-compiler warnings
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
60 ;; the `symbol-value' function is used to access the `recentf-menu-path'
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
61 ;; and `recentf-menu-title' values.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
62 (defun recentf-menu-customization-changed (sym val)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
63 "Function called when menu customization has changed.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
64 It removes the recentf menu and forces its complete redrawing."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
65 (when recentf-initialized-p
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
66 (easy-menu-remove-item nil
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
67 (symbol-value 'recentf-menu-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
68 (symbol-value 'recentf-menu-title))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
69 (setq recentf-update-menu-p t))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
70 (custom-set-default sym val))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
71
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
72 (defgroup recentf nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
73 "Maintain a menu of recently opened files."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
74 :version "21.1"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
75 :group 'files)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
76
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
77 (defgroup recentf-filters nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
78 "Group to customize recentf menu filters.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
79 You should define the options of your own filters in this group."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
80 :group 'recentf)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
81
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
82 (defcustom recentf-max-saved-items 20
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
83 "*Maximum number of items saved to `recentf-save-file'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
84 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
85 :type 'integer)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
86
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
87 (defcustom recentf-save-file (expand-file-name "~/.recentf")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
88 "*File to save `recentf-list' into."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
89 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
90 :type 'file)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
91
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
92 (defcustom recentf-exclude nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
93 "*List of regexps for filenames excluded from `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
94 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
95 :type '(repeat regexp))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
96
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
97 (defcustom recentf-menu-title "Open Recent"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
98 "*Name of the recentf menu."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
99 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
100 :type 'string
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
101 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
102
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
103 (defcustom recentf-menu-path '("files")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
104 "*Path where to add the recentf menu.
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
105 If nil add it at top level (see also `easy-menu-change')."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
106 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
107 :type '(choice (const :tag "Top Level" nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
108 (sexp :tag "Menu Path"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
109 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
110
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
111 (defcustom recentf-menu-before "open-file"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
112 "*Name of the menu before which the recentf menu will be added.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
113 If nil add it at end of menu (see also `easy-menu-change')."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
114 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
115 :type '(choice (string :tag "Name")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
116 (const :tag "Last" nil))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
117 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
118
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
119 (defcustom recentf-menu-action 'recentf-find-file
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
120 "*Function to invoke with a filename item of the recentf menu.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
121 The default action `recentf-find-file' calls `find-file' to edit an
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
122 existing file. If the file does not exist or is not readable, it is
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
123 not edited and its name is removed from `recentf-list'. You can use
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
124 `find-file' instead to open non-existing files and keep them in the
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
125 list of recently opened files."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
126 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
127 :type 'function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
128 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
129
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
130 (defcustom recentf-max-menu-items 10
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
131 "*Maximum number of items in the recentf menu."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
132 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
133 :type 'integer
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
134 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
135
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
136 (defcustom recentf-menu-filter nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
137 "*Function used to filter files displayed in the recentf menu.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
138 Nil means no filter. The following functions are predefined:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
139
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
140 - - `recentf-sort-ascending' to sort menu items in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
141 - - `recentf-sort-descending' to sort menu items in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
142 - - `recentf-sort-basenames-ascending' to sort file names in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
143 - - `recentf-sort-basenames-descending' to sort file names in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
144 - - `recentf-sort-directories-ascending' to sort directories in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
145 - - `recentf-sort-directories-descending' to sort directories in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
146 - - `recentf-show-basenames' to show file names (no directories) in menu items.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
147 - - `recentf-show-basenames-ascending' to show file names in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
148 - - `recentf-show-basenames-descending' to show file names in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
149 - - `recentf-relative-filter' to show file names relative to `default-directory'.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
150 - - `recentf-arrange-by-rule' to show sub-menus following user defined rules.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
151 - - `recentf-arrange-by-mode' to show a sub-menu for each major mode.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
152 - - `recentf-arrange-by-dir' to show a sub-menu for each directory.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
153 - - `recentf-filter-changer' to manage a ring of filters.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
154
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
155 The filter function is called with one argument, the list of menu elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
156 used to build the menu and must return a new list of menu elements (see
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
157 `recentf-make-menu-element' for menu element form)."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
158 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
159 :type 'function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
160 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
161
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
162 (defcustom recentf-menu-append-commands-p t
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
163 "*If not-nil command items are appended to the menu."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
164 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
165 :type 'boolean
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
166 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
167
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
168 (defcustom recentf-keep-non-readable-files-p nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
169 "*If nil (default), non-readable files are not kept in `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
170 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
171 :type 'boolean
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
172 :require 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
173 :initialize 'custom-initialize-default
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
174 :set (lambda (sym val)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
175 (if val
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
176 (remove-hook 'kill-buffer-hook 'recentf-remove-file-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
177 (add-hook 'kill-buffer-hook 'recentf-remove-file-hook))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
178 (custom-set-default sym val)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
179
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
180 (defcustom recentf-mode nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
181 "Toggle recentf mode.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
182 When recentf mode is enabled, it maintains a menu for visiting files that
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
183 were operated on recently.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
184 Setting this variable directly does not take effect;
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
185 use either \\[customize] or the function `recentf-mode'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
186 :set (lambda (symbol value)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
187 (recentf-mode (or value 0)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
188 :initialize 'custom-initialize-default
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
189 :type 'boolean
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
190 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
191 :require 'recentf)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
192
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
193 (defcustom recentf-load-hook nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
194 "*Normal hook run at end of loading the `recentf' package."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
195 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
196 :type 'hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
197
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
198 ;;;;
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
199 ;;;; Common functions
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
200 ;;;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
201 (defconst recentf-case-fold-search
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
202 (memq system-type '(vax-vms windows-nt))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
203 "Non-nil if recentf searches and matches should ignore case.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
204
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
205 (defun recentf-include-p (filename)
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
206 "Return t if FILENAME match none of the `recentf-exclude' regexps."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
207 (let ((case-fold-search recentf-case-fold-search)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
208 (rl recentf-exclude))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
209 (while (and rl (not (string-match (car rl) filename)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
210 (setq rl (cdr rl)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
211 (null rl)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
212
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
213 (defun recentf-add-file (filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
214 "Add or move FILENAME at the beginning of `recentf-list'.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
215 Does nothing if FILENAME matches one of the `recentf-exclude' regexps."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
216 (let ((filename (expand-file-name filename)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
217 (when (recentf-include-p filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
218 (setq recentf-list (cons filename (delete filename recentf-list)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
219 (setq recentf-update-menu-p t))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
220
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
221 (defun recentf-remove-if-non-readable (filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
222 "Remove FILENAME from `recentf-list' if not readable."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
223 (unless (file-readable-p filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
224 (setq recentf-list (delete filename recentf-list))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
225 (setq recentf-update-menu-p t)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
226
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
227 (defun recentf-find-file (filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
228 "Edit file FILENAME using `find-file'.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
229 If FILENAME is not readable it is removed from `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
230 (if (file-readable-p filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
231 (find-file filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
232 (progn
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
233 (message "File `%s' not found." filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
234 (setq recentf-list (delete filename recentf-list))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
235 (setq recentf-update-menu-p t))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
236
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
237 (defun recentf-trunc-list (l n)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
238 "Return a list of the first N elements of L."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
239 (let ((lh nil))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
240 (while (and l (> n 0))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
241 (setq lh (cons (car l) lh))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
242 (setq n (1- n))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
243 (setq l (cdr l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
244 (nreverse lh)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
245
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
246 (defun recentf-elements (n)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
247 "Return a list of the first N elements of `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
248 (recentf-trunc-list recentf-list n))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
249
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
250 (defun recentf-make-menu-element (menu-item menu-value)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
251 "Create a new menu-element.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
252
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
253 A menu element is a pair (MENU-ITEM . MENU-VALUE) where:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
254
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
255 - - MENU-ITEM is the menu item string displayed.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
256 - - MENU-VALUE is the path used to open the file when the
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
257 corresponding MENU-ITEM is selected. Or it is
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
258 a pair (SUB-MENU-TITLE . MENU-ELEMENTS) where
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
259 SUB-MENU-TITLE is a sub-menu title and
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
260 MENU-ELEMENTS is the list of menu elements in
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
261 the sub-menu."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
262 (cons menu-item menu-value))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
263
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
264 (defun recentf-menu-element-item (e)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
265 "Return the item part of the menu-element E."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
266 (car e))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
267
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
268 (defun recentf-menu-element-value (e)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
269 "Return the value part of the menu-element E."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
270 (cdr e))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
271
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
272 (defun recentf-set-menu-element-item (e item)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
273 "Change the item part of menu-element E to ITEM."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
274 (setcar e item))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
275
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
276 (defun recentf-set-menu-element-value (e value)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
277 "Change the value part of menu-element E to VALUE."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
278 (setcdr e value))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
279
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
280 (defun recentf-sub-menu-element-p (e)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
281 "Return non-nil if menu-element E defines a sub-menu."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
282 (consp (recentf-menu-element-value e)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
283
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
284 (defun recentf-make-default-menu-element (file-path)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
285 "Make a new default menu element (MENU-ITEM . MENU-VALUE).
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
286 Do so for the given recent file path FILE-PATH. MENU-ITEM and
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
287 MENU-VALUE are set to FILE-PATH. See also
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
288 `recentf-make-menu-element'."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
289 (recentf-make-menu-element file-path file-path))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
290
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
291 (defun recentf-menu-elements (n)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
292 "Return a list of the first N default menu elements from `recentf-list'.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
293 See also `recentf-make-default-menu-element'."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
294 (mapcar 'recentf-make-default-menu-element
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
295 (recentf-elements n)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
296
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
297 (defun recentf-apply-menu-filter (filter l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
298 "Apply function FILTER to the list of menu-elements L.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
299 It takes care of sub-menu elements in L and recursively apply FILTER
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
300 to them. It is guaranteed that FILTER receives only a list of single
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
301 menu-elements (no sub-menu)."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
302 (if (and (functionp filter) l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
303 (let ((case-fold-search recentf-case-fold-search)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
304 menu-element sub-menu-elements single-elements)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
305 ;; split L in two sub-listes:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
306 ;; one of sub-menus elements and
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
307 ;; one of single menu elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
308 (while l
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
309 (setq menu-element (car l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
310 (if (recentf-sub-menu-element-p menu-element)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
311 (setq sub-menu-elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
312 (cons menu-element sub-menu-elements))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
313 (setq single-elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
314 (cons menu-element single-elements)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
315 (setq l (cdr l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
316 ;; apply FILTER to the list of single menu elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
317 (if single-elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
318 (setq single-elements (funcall filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
319 (nreverse single-elements))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
320 ;; apply FILTER to sub-menu menu element list
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
321 (setq l sub-menu-elements)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
322 (setq sub-menu-elements nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
323 (while l
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
324 (setq menu-element (car l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
325 (recentf-set-menu-element-value
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
326 menu-element
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
327 (recentf-apply-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
328 filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
329 (recentf-menu-element-value menu-element)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
330 (setq sub-menu-elements (cons menu-element sub-menu-elements))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
331 (setq l (cdr l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
332 ;; build and return the new filtered menu element list
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
333 (nconc sub-menu-elements single-elements))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
334 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
335
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
336 (defvar recentf-menu-items-for-commands
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
337 (list ["Cleanup list" recentf-cleanup t]
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
338 ["Edit list..." recentf-edit-list t]
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
339 ["Save list now" recentf-save-list t]
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
340 (vector "Recentf Options..." '(customize-group "recentf") t))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
341 "List of menu items for recentf commands.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
342
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
343 (defvar recentf-menu-filter-commands nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
344 "This variable can be used by menu filters to setup their own command menu.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
345
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
346 If non-nil it must contain a list of valid menu-items to be appended
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
347 to the recent file list part of the menu. Before calling a menu
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
348 filter function this variable is reset to nil.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
349
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
350 (defun recentf-make-menu-items ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
351 "Make menu items from `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
352 (setq recentf-menu-filter-commands nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
353 (let ((file-items
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
354 (mapcar 'recentf-make-menu-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
355 (recentf-apply-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
356 recentf-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
357 (recentf-menu-elements recentf-max-menu-items)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
358 (append (or file-items (list ["No files" t nil]))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
359 (and (< recentf-max-menu-items (length recentf-list))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
360 (list ["More..." recentf-open-more-files t]))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
361 (and recentf-menu-filter-commands
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
362 (cons "---"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
363 recentf-menu-filter-commands))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
364 (and recentf-menu-append-commands-p
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
365 (cons "---"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
366 recentf-menu-items-for-commands)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
367
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
368 (defun recentf-make-menu-item (menu-element)
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
369 "Make a menu item from MENU-ELEMENT (see `recentf-make-menu-element')."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
370 (let ((menu-item (recentf-menu-element-item menu-element))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
371 (menu-value (recentf-menu-element-value menu-element)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
372 (if (recentf-sub-menu-element-p menu-element)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
373 (cons menu-item (mapcar 'recentf-make-menu-item menu-value))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
374 (vector menu-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
375 (list recentf-menu-action menu-value)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
376 t))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
377
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
378 ;;;;
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
379 ;;;; Predefined menu filter functions
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
380 ;;;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
381
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
382 (defun recentf-sort-ascending (l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
383 "Sort the list of menu elements L in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
384 The MENU-ITEM part of each menu element is compared."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
385 (sort (copy-sequence l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
386 (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
387 (lambda (e1 e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
388 (string-lessp (recentf-menu-element-item e1)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
389 (recentf-menu-element-item e2))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
390
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
391 (defun recentf-sort-descending (l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
392 "Sort the list of menu elements L in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
393 The MENU-ITEM part of each menu element is compared."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
394 (sort (copy-sequence l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
395 (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
396 (lambda (e1 e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
397 (string-lessp (recentf-menu-element-item e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
398 (recentf-menu-element-item e1))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
399
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
400 (defun recentf-sort-basenames-ascending (l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
401 "Sort the list of menu elements L in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
402 Only file names (without directories) are compared."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
403 (sort (copy-sequence l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
404 (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
405 (lambda (e1 e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
406 (string-lessp
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
407 (file-name-nondirectory (recentf-menu-element-value e1))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
408 (file-name-nondirectory (recentf-menu-element-value e2)))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
409
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
410 (defun recentf-sort-basenames-descending (l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
411 "Sort the list of menu elements L in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
412 Only file names (without directories) are compared."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
413 (sort (copy-sequence l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
414 (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
415 (lambda (e1 e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
416 (string-lessp
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
417 (file-name-nondirectory (recentf-menu-element-value e2))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
418 (file-name-nondirectory (recentf-menu-element-value e1)))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
419
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
420 (defun recentf-directory-compare (p1 p2)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
421 "Compare directories then filenames in paths P1 and P2.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
422 Return non-nil if P1 is less than P2."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
423 (let ((d1 (file-name-directory p1))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
424 (f1 (file-name-nondirectory p1))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
425 (d2 (file-name-directory p2))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
426 (f2 (file-name-nondirectory p2)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
427 (if (string= d1 d2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
428 (string-lessp f1 f2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
429 (string-lessp d1 d2))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
430
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
431 (defun recentf-sort-directories-ascending (l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
432 "Sort the list of menu elements L in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
433 Compares directories then filenames to order the list."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
434 (sort (copy-sequence l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
435 (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
436 (lambda (e1 e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
437 (recentf-directory-compare (recentf-menu-element-value e1)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
438 (recentf-menu-element-value e2))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
439
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
440 (defun recentf-sort-directories-descending (l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
441 "Sort the list of menu elements L in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
442 Compares directories then filenames to order the list."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
443 (sort (copy-sequence l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
444 (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
445 (lambda (e1 e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
446 (recentf-directory-compare (recentf-menu-element-value e2)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
447 (recentf-menu-element-value e1))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
448
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
449 (defun recentf-show-basenames (l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
450 "Filter the list of menu elements L to show only file names (no directories)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
451 in the menu. When file names are duplicated their directory component is added."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
452 (let ((names (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
453 (lambda (item)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
454 (file-name-nondirectory
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
455 (recentf-menu-element-value item))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
456 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
457 (dirs (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
458 (lambda (item)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
459 (file-name-directory
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
460 (recentf-menu-element-value item))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
461 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
462 (pathes (mapcar 'recentf-menu-element-value l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
463 (pos -1)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
464 item filtered-items filtered-list)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
465 (while names
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
466 (setq item (car names))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
467 (setq names (cdr names))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
468 (setq pos (1+ pos))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
469 (setq filtered-list
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
470 (cons (recentf-make-menu-element
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
471 (if (or (member item names) (member item filtered-items))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
472 (concat item " (" (nth pos dirs) ")")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
473 item)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
474 (nth pos pathes))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
475 filtered-list))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
476 (setq filtered-items (cons item filtered-items)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
477 (nreverse filtered-list)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
478
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
479 (defun recentf-show-basenames-ascending (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
480 "Filter the list of menu elements L.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
481 Show only file names in the menu, sorted in ascending order. This
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
482 filter combines the `recentf-sort-basenames-ascending' and
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
483 `recentf-show-basenames' filters."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
484 (recentf-show-basenames (recentf-sort-basenames-ascending l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
485
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
486 (defun recentf-show-basenames-descending (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
487 "Filter the list of menu elements L.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
488 Show only file names in the menu, sorted in descending order. This
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
489 filter combines the `recentf-sort-basenames-descending' and
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
490 `recentf-show-basenames' filters."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
491 (recentf-show-basenames (recentf-sort-basenames-descending l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
492
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
493 (defun recentf-relative-filter (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
494 "Filter the list of `recentf-menu-elements' L.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
495 Show filenames relative to `default-directory'."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
496 (setq recentf-update-menu-p t) ; force menu update
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
497 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
498 (lambda (menu-element)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
499 (let* ((ful-path (recentf-menu-element-value menu-element))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
500 (rel-path (file-relative-name ful-path)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
501 (if (string-match "^\\.\\." rel-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
502 menu-element
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
503 (recentf-make-menu-element rel-path ful-path)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
504 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
505
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
506 (defcustom recentf-arrange-rules
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
507 '(
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
508 ("Elisp files (%d)" ".\\.el$")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
509 ("Java files (%d)" ".\\.java$")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
510 ("C/C++ files (%d)" "c\\(pp\\)?$")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
511 )
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
512 "*List of rules used by `recentf-arrange-by-rule' to build sub-menus.
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
513 A rule is a pair (SUB-MENU-TITLE . MATCHER). SUB-MENU-TITLE is the
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
514 displayed title of the sub-menu where a '%d' `format' pattern is
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
515 replaced by the number of items in the sub-menu. MATCHER is a regexp
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
516 or a list of regexps. Items matching one of the regular expressions in
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
517 MATCHER are added to the corresponding sub-menu."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
518 :group 'recentf-filters
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
519 :type '(repeat (cons string (repeat regexp)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
520 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
521
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
522 (defcustom recentf-arrange-by-rule-others "Other files (%d)"
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
523 "*Title of the `recentf-arrange-by-rule' sub-menu.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
524 This is for the menu where items that don't match any
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
525 `recentf-arrange-rules' are displayed. If nil these items are
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
526 displayed in the main recent files menu. A '%d' `format' pattern in
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
527 the title is replaced by the number of items in the sub-menu."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
528 :group 'recentf-filters
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
529 :type '(choice (const :tag "Main menu" nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
530 (string :tag "Title"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
531 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
532
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
533 (defcustom recentf-arrange-by-rules-min-items 0
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
534 "*Minimum number of items in a `recentf-arrange-by-rule' sub-menu.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
535 If the number of items in a sub-menu is less than this value the
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
536 corresponding sub-menu items are displayed in the main recent files
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
537 menu or in the `recentf-arrange-by-rule-others' sub-menu if
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
538 defined."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
539 :group 'recentf-filters
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
540 :type 'number
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
541 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
542
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
543 (defcustom recentf-arrange-by-rule-subfilter nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
544 "*Function used by `recentf-arrange-by-rule' to filter sub-menu elements.
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
545 Nil means no filter. See also `recentf-menu-filter'. You can't use
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
546 `recentf-arrange-by-rule' itself here!"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
547 :group 'recentf-filters
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
548 :type 'function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
549 :set (lambda (sym val)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
550 (if (eq val 'recentf-arrange-by-rule)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
551 (error "Can't use `recentf-arrange-by-rule' itself here!")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
552 (recentf-menu-customization-changed sym val))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
553
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
554 (defun recentf-match-rule-p (matcher file-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
555 "Return non-nil if FILE-PATH match the rule specified by MATCHER.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
556 See `recentf-arrange-rules' for details on MATCHER."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
557 (if (stringp matcher)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
558 (string-match matcher file-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
559 (while (and (consp matcher)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
560 (not (string-match (car matcher) file-path)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
561 (setq matcher (cdr matcher)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
562 matcher))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
563
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
564 (defun recentf-arrange-by-rule (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
565 "Filter the list of menu-elements L.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
566 Arrange them in sub-menus following rules in `recentf-arrange-rules'."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
567 (let ((sub-menus-number (length recentf-arrange-rules)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
568 (if (> sub-menus-number 0)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
569 (let ((sub-menus (apply 'vector
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
570 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
571 (lambda (pair)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
572 (list (car pair))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
573 recentf-arrange-rules)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
574 other-menu-elements index min-size)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
575 (while l
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
576 (let* ((menu-element (car l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
577 (file-path (recentf-menu-element-value menu-element))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
578 (rules recentf-arrange-rules)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
579 (found nil))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
580 (setq index 0)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
581 (while (and (not found) rules)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
582 (if (recentf-match-rule-p (cdar rules) file-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
583 (let ((sub-menu (aref sub-menus index)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
584 (setq found t)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
585 (recentf-set-menu-element-value
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
586 sub-menu
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
587 (cons menu-element (recentf-menu-element-value sub-menu)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
588 ))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
589 (setq index (1+ index))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
590 (setq rules (cdr rules)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
591 (or found
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
592 (setq other-menu-elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
593 (cons menu-element other-menu-elements)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
594 (setq l (cdr l))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
595 (setq index 0)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
596 (setq l nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
597 (setq min-size (if (integerp recentf-arrange-by-rules-min-items)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
598 (max 0 recentf-arrange-by-rules-min-items)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
599 0))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
600 (while (< index sub-menus-number)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
601 (let* ((sub-menu (aref sub-menus index))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
602 (sub-menu-title (recentf-menu-element-item sub-menu))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
603 (sub-menu-elements (recentf-menu-element-value sub-menu))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
604 (sub-menu-length (length sub-menu-elements)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
605 (if (> sub-menu-length 0)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
606 (cond
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
607 ((< sub-menu-length min-size)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
608 (setq other-menu-elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
609 (nconc sub-menu-elements other-menu-elements)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
610 ((>= sub-menu-length min-size)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
611 (recentf-set-menu-element-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
612 sub-menu
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
613 (format sub-menu-title sub-menu-length))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
614 (recentf-set-menu-element-value
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
615 sub-menu
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
616 (recentf-apply-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
617 recentf-arrange-by-rule-subfilter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
618 (nreverse sub-menu-elements)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
619 (setq l (cons sub-menu l)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
620 (setq index (1+ index))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
621 (if (and (stringp recentf-arrange-by-rule-others)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
622 other-menu-elements)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
623 (setq l
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
624 (nreverse
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
625 (cons (recentf-make-menu-element
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
626 (format recentf-arrange-by-rule-others
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
627 (length other-menu-elements))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
628 (recentf-apply-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
629 recentf-arrange-by-rule-subfilter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
630 (nreverse other-menu-elements)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
631 l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
632 (setq l (nconc (nreverse l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
633 (recentf-apply-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
634 recentf-arrange-by-rule-subfilter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
635 (nreverse other-menu-elements)))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
636 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
637
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
638 (defun recentf-build-mode-rules ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
639 "Convert `auto-mode-alist' to `recentf-arrange-rules' format."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
640 (let ((case-fold-search recentf-case-fold-search)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
641 (modes auto-mode-alist)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
642 regexp mode rule-name rule rules)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
643 (while modes
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
644 (setq regexp (caar modes))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
645 (setq mode (cdar modes))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
646 (when (symbolp mode)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
647 (setq rule-name (symbol-name mode))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
648 (if (string-match "\\(.*\\)-mode$" rule-name)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
649 (setq rule-name (match-string 1 rule-name)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
650 (setq rule-name (concat rule-name " (%d)"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
651 (setq rule (assoc rule-name rules))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
652 (if rule
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
653 (setcdr rule (cons regexp (cdr rule)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
654 (setq rules (cons (list rule-name regexp) rules))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
655 (setq modes (cdr modes)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
656 ;; It is important to preserve auto-mode-alist order
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
657 ;; to ensure the right file <-> mode association
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
658 (nreverse rules)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
659
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
660 (defun recentf-arrange-by-mode (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
661 "Filter the list of menu-elements L to build sub-menus for each major mode."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
662 (let ((recentf-arrange-rules (recentf-build-mode-rules))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
663 (recentf-arrange-by-rule-others "others (%d)"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
664 (recentf-arrange-by-rule l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
665
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
666 (defun recentf-build-dir-rules (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
667 "Convert directories in menu-elements L to rules in `recentf-arrange-rules' format."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
668 (let (dirs)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
669 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
670 (lambda (e)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
671 (let ((dir (file-name-directory
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
672 (recentf-menu-element-value e))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
673 (or (member dir dirs)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
674 (setq dirs (cons dir dirs))))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
675 l)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
676 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
677 (lambda (d)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
678 (cons (concat d " (%d)")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
679 (concat "\\`" d))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
680 (nreverse (sort dirs 'string-lessp)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
681
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
682 (defun recentf-file-name-nondir (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
683 "Filter the list of menu-elements L to show only filenames.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
684 This simplified version of `recentf-show-basenames' does not handle
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
685 duplicates. It is used by `recentf-arrange-by-dir' as its
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
686 `recentf-arrange-by-rule-subfilter'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
687 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
688 (lambda (e)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
689 (recentf-make-menu-element
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
690 (file-name-nondirectory (recentf-menu-element-value e))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
691 (recentf-menu-element-value e))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
692 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
693
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
694 (defun recentf-arrange-by-dir (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
695 "Filter the list of menu-elements L to build sub-menus for each directory."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
696 (let ((recentf-arrange-rules (recentf-build-dir-rules l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
697 (recentf-arrange-by-rule-subfilter 'recentf-file-name-nondir)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
698 recentf-arrange-by-rule-others)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
699 (nreverse (recentf-arrange-by-rule l))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
700
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
701 (defvar recentf-filter-changer-state nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
702 "Used by `recentf-filter-changer' to hold its state.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
703
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
704 (defcustom recentf-filter-changer-alist
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
705 '(
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
706 (recentf-arrange-by-mode . "*Files by Mode*")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
707 (recentf-arrange-by-dir . "*Files by Directory*")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
708 (recentf-arrange-by-rule . "*Files by User Rule*")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
709 )
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
710 "*List of filters managed by `recentf-filter-changer'.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
711 Each filter is defined by a pair (FILTER-FUN . FILTER-LBL) where:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
712
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
713 - - FILTER-FUN is the function that filters menu-elements
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
714 - - FILTER-LBL is the menu item used to activate the filter"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
715 :group 'recentf-filters
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
716 :type '(repeat (cons function string))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
717 :set (lambda (sym val)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
718 (setq recentf-filter-changer-state nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
719 (recentf-menu-customization-changed sym val)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
720
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
721 (defun recentf-filter-changer-goto-next ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
722 "Go to the next filter available (see `recentf-filter-changer')."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
723 (and (consp recentf-filter-changer-state)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
724 (setq recentf-filter-changer-state
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
725 (cdr recentf-filter-changer-state)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
726 (setq recentf-update-menu-p t))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
727
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
728 (defun recentf-filter-changer-get-current ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
729 "Get the current filter available (see `recentf-filter-changer')."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
730 (if (null recentf-filter-changer-state)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
731 (setq recentf-filter-changer-state recentf-filter-changer-alist))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
732 (and (consp recentf-filter-changer-state)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
733 (car recentf-filter-changer-state)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
734
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
735 (defun recentf-filter-changer-get-next ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
736 "Get the next filter available (see `recentf-filter-changer')."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
737 (let ((filters recentf-filter-changer-state))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
738 (cond ((consp filters)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
739 (setq filters (cdr filters))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
740 (if (null filters)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
741 (setq filters recentf-filter-changer-alist)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
742 (t
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
743 (setq filters recentf-filter-changer-alist)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
744 (if (consp filters)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
745 (setq filters (cdr filters)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
746 (if (consp filters)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
747 (car filters))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
748
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
749 (defun recentf-filter-changer (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
750 "Manage a ring of filters.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
751 `recentf-filter-changer-alist' defines the filters in the ring.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
752 Actual filtering of L is delegated to the current filter in the
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
753 ring. A filter menu item is displayed allowing to dynamically activate
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
754 the next filter in the ring. If the filter ring is empty L is left
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
755 unchanged."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
756 (let ((current-filter-item (recentf-filter-changer-get-current))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
757 (next-filter-item (recentf-filter-changer-get-next)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
758 (when current-filter-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
759 (setq l (recentf-apply-menu-filter (car current-filter-item) l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
760 (if next-filter-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
761 (setq recentf-menu-filter-commands
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
762 (list (vector (cdr next-filter-item)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
763 '(recentf-filter-changer-goto-next)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
764 t)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
765 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
766
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
767 ;;;;
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
768 ;;;; Dialogs stuff
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
769 ;;;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
770
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
771 (defun recentf-cancel-dialog (&rest ignore)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
772 "Cancel the current dialog.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
773 Used by `recentf-edit-list' and `recentf-open-files' dialogs."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
774 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
775 (kill-buffer (current-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
776 (message "Dialog canceled."))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
777
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
778 (defvar recentf-dialog-mode-map nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
779 "`recentf-dialog-mode' keymap.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
780
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
781 (if recentf-dialog-mode-map
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
782 ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
783 (setq recentf-dialog-mode-map (make-sparse-keymap))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
784 (define-key recentf-dialog-mode-map "q" 'recentf-cancel-dialog)
30778
293a86f4d8aa (recent-dialog-mode-map): Bind down-mouse-1 to
Gerd Moellmann <gerd@gnu.org>
parents: 30416
diff changeset
785 (define-key recentf-dialog-mode-map [down-mouse-1] 'widget-button-click)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
786 (set-keymap-parent recentf-dialog-mode-map widget-keymap))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
787
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
788 (defun recentf-dialog-mode ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
789 "Major mode used in recentf dialogs.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
790
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
791 These are the special commands of `recentf-dialog-mode' mode:
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
792 q -- cancel this dialog."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
793 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
794 (setq major-mode 'recentf-dialog-mode)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
795 (setq mode-name "recentf-dialog")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
796 (use-local-map recentf-dialog-mode-map))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
797
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
798 ;;;;
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
799 ;;;; Hooks and Commands
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
800 ;;;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
801
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
802 (defun recentf-add-file-hook ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
803 "Insert the name of the file just opened or written into `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
804 (and buffer-file-name (recentf-add-file buffer-file-name))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
805 nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
806
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
807 (defun recentf-remove-file-hook ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
808 "When a buffer is killed remove a non readable file from `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
809 (and buffer-file-name (recentf-remove-if-non-readable buffer-file-name))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
810 nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
811
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
812 (defun recentf-update-menu-hook ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
813 "Update the recentf menu from the current `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
814 (when recentf-update-menu-p
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
815 (condition-case nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
816 (progn
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
817 (setq recentf-update-menu-p nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
818 (easy-menu-change recentf-menu-path
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
819 recentf-menu-title
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
820 (recentf-make-menu-items)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
821 recentf-menu-before))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
822 (error nil))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
823
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
824 (defun recentf-dump-variable (variable &optional limit)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
825 "Insert a \"(setq VARIABLE value)\" in the current buffer.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
826 Optional argument LIMIT specifies a maximum length when VARIABLE value
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
827 is a list (default to the full list)."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
828 (let ((value (symbol-value variable)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
829 (insert (format "(setq %S\n '(\n" variable))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
830 (cond ((consp value)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
831 (if (and (integerp limit) (> limit 0))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
832 (setq value (recentf-trunc-list value limit)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
833 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
834 (lambda (e)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
835 (insert (format " %S\n" e))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
836 value))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
837 (t
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
838 (insert (format " %S\n" value))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
839 (insert " ))\n")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
840 ))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
841
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
842 ;;;###autoload
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
843 (defun recentf-save-list ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
844 "Save the current `recentf-list' to the file `recentf-save-file'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
845 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
846 (with-temp-buffer
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
847 (erase-buffer)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
848 (insert (format recentf-save-file-header (current-time-string)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
849 (recentf-dump-variable 'recentf-list recentf-max-saved-items)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
850 (recentf-dump-variable 'recentf-filter-changer-state)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
851 (if (file-writable-p recentf-save-file)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
852 (write-region (point-min) (point-max) recentf-save-file))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
853 (kill-buffer (current-buffer)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
854 nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
855
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
856 (defvar recentf-edit-selected-items nil
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
857 "Used by `recentf-edit-list'.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
858 Holds list of files to be deleted from `recentf-list'.")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
859
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
860 (defun recentf-edit-list-action (widget &rest ignore)
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
861 "Checkbox WIDGET action used by `recentf-edit-list' to select/unselect a file."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
862 (let ((value (widget-get widget ':tag)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
863 ;; if value is already in the selected items
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
864 (if (memq value recentf-edit-selected-items)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
865 ;; then remove it
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
866 (progn
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
867 (setq recentf-edit-selected-items
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
868 (delq value recentf-edit-selected-items))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
869 (message "%s removed from selection." value))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
870 ;; else add it
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
871 (progn
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
872 (setq recentf-edit-selected-items
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
873 (nconc (list value) recentf-edit-selected-items))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
874 (message "%s added to selection." value)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
875
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
876 ;;;###autoload
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
877 (defun recentf-edit-list ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
878 "Allow the user to edit the files that are kept in the recent list."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
879 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
880 (with-current-buffer (get-buffer-create (concat "*" recentf-menu-title " - Edit list*"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
881 (switch-to-buffer (current-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
882 (kill-all-local-variables)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
883 (let ((inhibit-read-only t))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
884 (erase-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
885 (let ((all (overlay-lists)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
886 ;; Delete all the overlays.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
887 (mapcar 'delete-overlay (car all))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
888 (mapcar 'delete-overlay (cdr all)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
889 (setq recentf-edit-selected-items nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
890 ;; Insert the dialog header
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
891 (widget-insert "Select the files to be deleted from the 'recentf-list'.\n\n")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
892 (widget-insert "Click on Ok to update the list. ")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
893 (widget-insert "Click on Cancel or type \"q\" to quit.\n")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
894 ;; Insert the list of files as checkboxes
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
895 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
896 (lambda (item)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
897 (widget-create 'checkbox
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
898 :value nil ; unselected checkbox
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
899 :format "\n %[%v%] %t"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
900 :tag item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
901 :notify 'recentf-edit-list-action)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
902 recentf-list)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
903 (widget-insert "\n\n")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
904 ;; Insert the Ok button
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
905 (widget-create 'push-button
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
906 :notify (lambda (&rest ignore)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
907 (if recentf-edit-selected-items
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
908 (progn (kill-buffer (current-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
909 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
910 (lambda (item)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
911 (setq recentf-list
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
912 (delq item recentf-list))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
913 recentf-edit-selected-items)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
914 (message "%S file(s) removed from the list"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
915 (length recentf-edit-selected-items))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
916 (setq recentf-update-menu-p t))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
917 (message "No file selected.")))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
918 "Ok")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
919 (widget-insert " ")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
920 ;; Insert the Cancel button
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
921 (widget-create 'push-button
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
922 :notify 'recentf-cancel-dialog
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
923 "Cancel")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
924 (recentf-dialog-mode)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
925 (widget-setup)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
926 (goto-char (point-min))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
927
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
928 ;;;###autoload
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
929 (defun recentf-cleanup ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
930 "Remove all non-readable and excluded files from `recentf-list'."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
931 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
932 (let ((count (length recentf-list)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
933 (setq recentf-list
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
934 (delq nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
935 (mapcar (function
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
936 (lambda (filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
937 (and (file-readable-p filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
938 (recentf-include-p filename)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
939 filename)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
940 recentf-list)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
941 (setq count (- count (length recentf-list)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
942 (message "%s removed from the list"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
943 (cond ((= count 0) "No file")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
944 ((= count 1) "One file")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
945 (t (format "%d files" count)))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
946 (setq recentf-update-menu-p t))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
947
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
948 (defun recentf-open-files-action (widget &rest ignore)
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
949 "Button WIDGET action used by `recentf-open-files' to open a file."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
950 (kill-buffer (current-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
951 (funcall recentf-menu-action (widget-value widget)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
952
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
953 (defvar recentf-open-files-item-shift ""
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
954 "String used by `recentf-open-files' to shift right sub-menu items.")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
955
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
956 (defun recentf-open-files-item (menu-element)
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
957 "Insert MENU-ELEMENT item in the current interaction buffer."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
958 (let ((menu-item (car menu-element))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
959 (file-path (cdr menu-element)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
960 (if (consp file-path) ; This is a sub-menu
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
961 (let* ((shift recentf-open-files-item-shift)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
962 (recentf-open-files-item-shift (concat shift " ")))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
963 (widget-create 'item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
964 :tag menu-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
965 :sample-face 'bold
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
966 :format (concat shift "%{%t%}:\n"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
967 (mapcar 'recentf-open-files-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
968 file-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
969 (widget-insert "\n"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
970 (widget-create 'push-button
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
971 :button-face 'default
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
972 :tag menu-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
973 :help-echo (concat "Open " file-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
974 :format (concat recentf-open-files-item-shift "%[%t%]")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
975 :notify 'recentf-open-files-action
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
976 file-path)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
977 (widget-insert "\n"))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
978
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
979 ;;;###autoload
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
980 (defun recentf-open-files (&optional files buffer-name)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
981 "Display buffer allowing user to choose a file from recently-opened list.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
982 The optional argument FILES may be used to specify the list, otherwise
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
983 `recentf-list' is used. The optional argument BUFFER-NAME specifies
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
984 which buffer to use for the interaction."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
985 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
986 (if (null files)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
987 (setq files recentf-list))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
988 (if (null buffer-name)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
989 (setq buffer-name (concat "*" recentf-menu-title "*")))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
990 (with-current-buffer (get-buffer-create buffer-name)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
991 (switch-to-buffer (current-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
992 (kill-all-local-variables)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
993 (let ((inhibit-read-only t))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
994 (erase-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
995 (let ((all (overlay-lists)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
996 ;; Delete all the overlays.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
997 (mapcar 'delete-overlay (car all))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
998 (mapcar 'delete-overlay (cdr all)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
999 ;; Insert the dialog header
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1000 (widget-insert "Click on a file to open it. ")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1001 (widget-insert "Click on Cancel or type \"q\" to quit.\n\n" )
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1002 ;; Insert the list of files as buttons
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1003 (let ((recentf-open-files-item-shift ""))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1004 (mapcar 'recentf-open-files-item
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1005 (recentf-apply-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1006 recentf-menu-filter
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1007 (mapcar 'recentf-make-default-menu-element files))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1008 (widget-insert "\n")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1009 ;; Insert the Cancel button
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1010 (widget-create 'push-button
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1011 :notify 'recentf-cancel-dialog
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1012 "Cancel")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1013 (recentf-dialog-mode)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1014 (widget-setup)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1015 (goto-char (point-min))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1016
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1017 ;;;###autoload
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1018 (defun recentf-open-more-files ()
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1019 "Allow the user to open files that are not in the menu."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1020 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1021 (recentf-open-files (nthcdr recentf-max-menu-items recentf-list)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1022 (concat "*" recentf-menu-title " - More*")))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1023
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1024 ;;;###autoload
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1025 (defun recentf-mode (&optional arg)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1026 "Toggle recentf mode.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1027 With prefix ARG, turn recentf mode on if and only if ARG is positive.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1028 Returns the new status of recentf mode (non-nil means on).
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1029
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1030 When recentf mode is enabled, it maintains a menu for visiting files that
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1031 were operated on recently."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1032 (interactive "P")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1033 (let ((on-p (if arg
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1034 (> (prefix-numeric-value arg) 0)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1035 (not recentf-mode))))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1036 (if on-p
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1037 (unless recentf-initialized-p
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1038 (setq recentf-initialized-p t)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1039 (if (file-readable-p recentf-save-file)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1040 (load-file recentf-save-file))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1041 (setq recentf-update-menu-p t)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1042 (add-hook 'find-file-hooks 'recentf-add-file-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1043 (add-hook 'write-file-hooks 'recentf-add-file-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1044 (add-hook 'menu-bar-update-hook 'recentf-update-menu-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1045 (add-hook 'kill-emacs-hook 'recentf-save-list))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1046 (when recentf-initialized-p
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1047 (setq recentf-initialized-p nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1048 (recentf-save-list)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1049 (easy-menu-remove-item nil recentf-menu-path recentf-menu-title)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1050 (remove-hook 'find-file-hooks 'recentf-add-file-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1051 (remove-hook 'write-file-hooks 'recentf-add-file-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1052 (remove-hook 'menu-bar-update-hook 'recentf-update-menu-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1053 (remove-hook 'kill-emacs-hook 'recentf-save-list)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1054 (setq recentf-mode on-p)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1055
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1056 (provide 'recentf)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1057
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1058 (run-hooks 'recentf-load-hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1059
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
1060 ;;; recentf.el ends here