annotate lisp/recentf.el @ 87647:b04073873562

Merge from gnus--devo--0 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-985
author Miles Bader <miles@gnu.org>
date Tue, 08 Jan 2008 14:16:13 +0000
parents 1b2430509da5
children 107ccd98fa12 14c4a6aac623
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 35971
diff changeset
1 ;;; recentf.el --- setup a menu of recently opened files
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64664
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73413
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
5
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
6 ;; Author: David Ponce <david@dponce.com>
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
7 ;; Created: July 19 1999
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
8 ;; Keywords: files
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
9
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
10 ;; This file is part of GNU Emacs.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
11
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
13 ;; it under the terms of the GNU General Public License as published
78236
9355f9b7bbff Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76773
diff changeset
14 ;; by the Free Software Foundation; either version 3, or (at your
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
15 ;; option) any later version.
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
16
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
17 ;; 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
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
20 ;; GNU General Public License for more details.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
21
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
22 ;; 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
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63781
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63781
diff changeset
25 ;; Boston, MA 02110-1301, USA.
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
26
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
27 ;;; Commentary:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
28
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
29 ;; This package maintains a menu for visiting files that were operated
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
30 ;; on recently. When enabled a new "Open Recent" sub menu is
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
31 ;; displayed in the "Files" menu. The recent files list is
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
32 ;; automatically saved across Emacs sessions. You can customize the
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
33 ;; number of recent files displayed, the location of the menu and
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
34 ;; others options (see the source code for details).
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
35
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
36 ;;; History:
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
37 ;;
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
38
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
39 ;;; Code:
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
40 (require 'easymenu)
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
41 (require 'tree-widget)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
42 (require 'timer)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
43
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
44 ;;; Internal data
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
45 ;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
46 (defvar recentf-list nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
47 "List of recently opened files.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
48
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
49 (defsubst recentf-enabled-p ()
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
50 "Return non-nil if recentf mode is currently enabled."
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
51 (memq 'recentf-save-list kill-emacs-hook))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
52
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
53 ;;; Customization
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
54 ;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
55 (defgroup recentf nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
56 "Maintain a menu of recently opened files."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
57 :version "21.1"
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
58 :group 'files)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
59
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
60 (defgroup recentf-filters nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
61 "Group to customize recentf menu filters.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
62 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
63 :group 'recentf)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
64
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
65 (defcustom recentf-max-saved-items 20
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
66 "Maximum number of items of the recent list that will be saved.
64664
3161d6027fd7 (recentf-menu-append-commands-p): Declare with `define-obsolete-variable-alias'.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
67 A nil value means to save the whole list.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
68 See the command `recentf-save-list'."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
69 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
70 :type 'integer)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
71
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
72 (defcustom recentf-save-file "~/.recentf"
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
73 "File to save the recent list into."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
74 :group 'recentf
76773
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
75 :type 'file
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
76 :initialize 'custom-initialize-default
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
77 :set (lambda (symbol value)
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
78 (let ((oldvalue (eval symbol)))
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
79 (custom-set-default symbol value)
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
80 (and (not (equal value oldvalue))
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
81 recentf-mode
e0a9f7f7486a Stephen Berman <Stephen.Berman at gmx.net>:
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
82 (recentf-load-list)))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
83
65525
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
84 (defcustom recentf-save-file-modes 384 ;; 0600
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
85 "Mode bits of recentf save file, as an integer, or nil.
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
86 If non-nil, after writing `recentf-save-file', set its mode bits to
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
87 this value. By default give R/W access only to the user who owns that
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
88 file. See also the function `set-file-modes'."
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
89 :group 'recentf
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
90 :type '(choice (const :tag "Don't change" nil)
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
91 integer))
81893
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
92
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
93 (defcustom recentf-exclude nil
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
94 "List of regexps and predicates for filenames excluded from the recent list.
52509
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
95 When a filename matches any of the regexps or satisfies any of the
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
96 predicates it is excluded from the recent list.
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
97 A predicate is a function that is passed a filename to check and that
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
98 must return non-nil to exclude it."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
99 :group 'recentf
52509
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
100 :type '(repeat (choice regexp function)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
101
81893
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
102 (defun recentf-keep-default-predicate (file)
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
103 "Return non-nil if FILE should be kept in the recent list.
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
104 It handles the case of remote files as well."
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
105 (cond
81935
66d338352087 * recentf.el (recentf-keep-default-predicate): Adapt call of
Michael Albinus <michael.albinus@gmx.de>
parents: 81893
diff changeset
106 ((file-remote-p file nil t) (file-readable-p file))
81893
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
107 ((file-remote-p file))
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
108 ((file-readable-p file))))
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
109
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
110 (defcustom recentf-keep
81893
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
111 '(recentf-keep-default-predicate)
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
112 "List of regexps and predicates for filenames kept in the recent list.
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
113 Regexps and predicates are tried in the specified order.
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
114 When nil all filenames are kept in the recent list.
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
115 When a filename matches any of the regexps or satisfies any of the
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
116 predicates it is kept in the recent list.
81893
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
117 The default is to keep readable files. Remote files are checked
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
118 for readability only in case a connection is established to that
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
119 remote system, otherwise they are kept in the recent list without
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
120 checking their readability.
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
121 A predicate is a function that is passed a filename to check and that
81893
5608c829dbac * recentf.el (recentf-keep-default-predicate): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 76773
diff changeset
122 must return non-nil to keep it."
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
123 :group 'recentf
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
124 :type '(repeat (choice regexp function)))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
125
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
126 (defun recentf-menu-customization-changed (variable value)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
127 "Function called when the recentf menu customization has changed.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
128 Set VARIABLE with VALUE, and force a rebuild of the recentf menu."
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
129 (if (and (featurep 'recentf) (recentf-enabled-p))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
130 (progn
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
131 ;; Unavailable until recentf has been loaded.
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
132 (recentf-hide-menu)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
133 (set-default variable value)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
134 (recentf-show-menu))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
135 (set-default variable value)))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
136
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
137 (defcustom recentf-menu-title "Open Recent"
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
138 "Name of the recentf menu."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
139 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
140 :type 'string
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
141 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
142
57993
8e7d8d382255 (recentf-menu-path): Use menu item name.
David Ponce <david@dponce.com>
parents: 57451
diff changeset
143 (defcustom recentf-menu-path '("File")
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
144 "Path where to add the recentf menu.
52468
de4ce9c67474 Ensure that recentf correctly update the menu bar:
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
145 If nil add it at top level (see also `easy-menu-add-item')."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
146 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
147 :type '(choice (const :tag "Top Level" nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
148 (sexp :tag "Menu Path"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
149 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
150
44915
ea21866100eb (recentf-menu-before): Use string to specify path in the menu.
Pavel Janík <Pavel@Janik.cz>
parents: 42205
diff changeset
151 (defcustom recentf-menu-before "Open File..."
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
152 "Name of the menu before which the recentf menu will be added.
52468
de4ce9c67474 Ensure that recentf correctly update the menu bar:
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
153 If nil add it at end of menu (see also `easy-menu-add-item')."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
154 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
155 :type '(choice (string :tag "Name")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
156 (const :tag "Last" nil))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
157 :set 'recentf-menu-customization-changed)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
158
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
159 (defcustom recentf-menu-action 'find-file
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
160 "Function to invoke with a filename item of the recentf menu.
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
161 The default is to call `find-file' to edit the selected file."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
162 :group 'recentf
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
163 :type 'function)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
164
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
165 (defcustom recentf-max-menu-items 10
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
166 "Maximum number of items in the recentf menu."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
167 :group 'recentf
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
168 :type 'integer)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
169
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
170 (defcustom recentf-menu-filter nil
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
171 "Function used to filter files displayed in the recentf menu.
64664
3161d6027fd7 (recentf-menu-append-commands-p): Declare with `define-obsolete-variable-alias'.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
172 A nil value means no filter. The following functions are predefined:
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
173
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
174 - `recentf-sort-ascending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
175 Sort menu items in ascending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
176 - `recentf-sort-descending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
177 Sort menu items in descending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
178 - `recentf-sort-basenames-ascending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
179 Sort menu items by filenames sans directory in ascending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
180 - `recentf-sort-basenames-descending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
181 Sort menu items by filenames sans directory in descending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
182 - `recentf-sort-directories-ascending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
183 Sort menu items by directories in ascending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
184 - `recentf-sort-directories-descending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
185 Sort menu items by directories in descending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
186 - `recentf-show-basenames'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
187 Show filenames sans directory in menu items.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
188 - `recentf-show-basenames-ascending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
189 Show filenames sans directory in ascending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
190 - `recentf-show-basenames-descending'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
191 Show filenames sans directory in descending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
192 - `recentf-relative-filter'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
193 Show filenames relative to `default-directory'.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
194 - `recentf-arrange-by-rule'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
195 Show sub-menus following user defined rules.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
196 - `recentf-arrange-by-mode'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
197 Show a sub-menu for each major mode.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
198 - `recentf-arrange-by-dir'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
199 Show a sub-menu for each directory.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
200 - `recentf-filter-changer'
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
201 Manage a menu of filters.
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
202
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
203 The filter function is called with one argument, the list of menu
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
204 elements used to build the menu and must return a new list of menu
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
205 elements (see `recentf-make-menu-element' for menu element form)."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
206 :group 'recentf
49549
99be3a1e2589 Cygwin support patch.
Juanma Barranquero <lekktu@gmail.com>
parents: 44967
diff changeset
207 :type '(radio (const nil)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
208 (function-item recentf-sort-ascending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
209 (function-item recentf-sort-descending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
210 (function-item recentf-sort-basenames-ascending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
211 (function-item recentf-sort-basenames-descending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
212 (function-item recentf-sort-directories-ascending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
213 (function-item recentf-sort-directories-descending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
214 (function-item recentf-show-basenames)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
215 (function-item recentf-show-basenames-ascending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
216 (function-item recentf-show-basenames-descending)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
217 (function-item recentf-relative-filter)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
218 (function-item recentf-arrange-by-rule)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
219 (function-item recentf-arrange-by-mode)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
220 (function-item recentf-arrange-by-dir)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
221 (function-item recentf-filter-changer)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
222 function))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
223
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
224 (defcustom recentf-menu-open-all-flag nil
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
225 "Non-nil means to show an \"All...\" item in the menu.
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
226 This item will replace the \"More...\" item."
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
227 :group 'recentf
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
228 :type 'boolean)
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
229
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
230 (defcustom recentf-menu-append-commands-flag t
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
231 "Non-nil means to append command items to the menu."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
232 :group 'recentf
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
233 :type 'boolean)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
234
64664
3161d6027fd7 (recentf-menu-append-commands-p): Declare with `define-obsolete-variable-alias'.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
235 (define-obsolete-variable-alias 'recentf-menu-append-commands-p
3161d6027fd7 (recentf-menu-append-commands-p): Declare with `define-obsolete-variable-alias'.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
236 'recentf-menu-append-commands-flag
3161d6027fd7 (recentf-menu-append-commands-p): Declare with `define-obsolete-variable-alias'.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
237 "22.1")
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
238
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
239 (defcustom recentf-auto-cleanup 'mode
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
240 "Define when to automatically cleanup the recent list.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
241 The following values can be set:
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
242
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
243 - `mode'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
244 Cleanup when turning the mode on (default).
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
245 - `never'
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
246 Never cleanup the list automatically.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
247 - A number
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
248 Cleanup each time Emacs has been idle that number of seconds.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
249 - A time string
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
250 Cleanup at specified time string, for example at \"11:00pm\".
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
251
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
252 Setting this variable directly does not take effect;
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
253 use \\[customize].
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
254
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
255 See also the command `recentf-cleanup', that can be used to manually
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
256 cleanup the list."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
257 :group 'recentf
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
258 :type '(radio (const :tag "When mode enabled"
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
259 :value mode)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
260 (const :tag "Never"
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
261 :value never)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
262 (number :tag "When idle that seconds"
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
263 :value 300)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
264 (string :tag "At time"
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
265 :value "11:00pm"))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
266 :set (lambda (variable value)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
267 (set-default variable value)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
268 (when (featurep 'recentf)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
269 ;; Unavailable until recentf has been loaded.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
270 (recentf-auto-cleanup))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
271
52638
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
272 (defcustom recentf-initialize-file-name-history t
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
273 "Non-nil means to initialize `file-name-history' with the recent list.
52638
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
274 If `file-name-history' is not empty, do nothing."
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
275 :group 'recentf
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
276 :type 'boolean)
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
277
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
278 (defcustom recentf-load-hook nil
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
279 "Normal hook run at end of loading the `recentf' package."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
280 :group 'recentf
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
281 :type 'hook)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
282
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
283 (defcustom recentf-filename-handlers nil
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
284 "Functions to post process recent file names.
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
285 They are successively passed a file name to transform it."
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
286 :group 'recentf
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
287 :type '(choice
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
288 (const :tag "None" nil)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
289 (repeat :tag "Functions"
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
290 (choice
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
291 (const file-truename)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
292 (const abbreviate-file-name)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
293 (function :tag "Other function")))))
65365
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
294
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
295 (defcustom recentf-show-file-shortcuts-flag t
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
296 "Whether to show ``[N]'' for the Nth item up to 10.
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
297 If non-nil, `recentf-open-files' will show labels for keys that can be
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
298 used as shortcuts to open the Nth file."
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
299 :group 'recentf
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
300 :type 'boolean)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
301
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
302 ;;; Utilities
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
303 ;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
304 (defconst recentf-case-fold-search
49549
99be3a1e2589 Cygwin support patch.
Juanma Barranquero <lekktu@gmail.com>
parents: 44967
diff changeset
305 (memq system-type '(vax-vms windows-nt cygwin))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
306 "Non-nil if recentf searches and matches should ignore case.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
307
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
308 (defsubst recentf-string-equal (s1 s2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
309 "Return non-nil if strings S1 and S2 have identical contents.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
310 Ignore case if `recentf-case-fold-search' is non-nil."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
311 (if recentf-case-fold-search
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
312 (string-equal (downcase s1) (downcase s2))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
313 (string-equal s1 s2)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
314
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
315 (defsubst recentf-string-lessp (s1 s2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
316 "Return non-nil if string S1 is less than S2 in lexicographic order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
317 Ignore case if `recentf-case-fold-search' is non-nil."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
318 (if recentf-case-fold-search
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
319 (string-lessp (downcase s1) (downcase s2))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
320 (string-lessp s1 s2)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
321
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
322 (defun recentf-string-member (elt list)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
323 "Return non-nil if ELT is an element of LIST.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
324 The value is actually the tail of LIST whose car is ELT.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
325 ELT must be a string and LIST a list of strings.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
326 Ignore case if `recentf-case-fold-search' is non-nil."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
327 (while (and list (not (recentf-string-equal elt (car list))))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
328 (setq list (cdr list)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
329 list)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
330
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
331 (defsubst recentf-trunc-list (l n)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
332 "Return from L the list of its first N elements."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
333 (let (nl)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
334 (while (and l (> n 0))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
335 (setq nl (cons (car l) nl)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
336 n (1- n)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
337 l (cdr l)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
338 (nreverse nl)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
339
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
340 (defun recentf-dump-variable (variable &optional limit)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
341 "Insert a \"(setq VARIABLE value)\" in the current buffer.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
342 When the value of VARIABLE is a list, optional argument LIMIT
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
343 specifies a maximum number of elements to insert. By default insert
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
344 the full list."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
345 (let ((value (symbol-value variable)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
346 (if (atom value)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
347 (insert (format "\n(setq %S '%S)\n" variable value))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
348 (when (and (integerp limit) (> limit 0))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
349 (setq value (recentf-trunc-list value limit)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
350 (insert (format "\n(setq %S\n '(" variable))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
351 (dolist (e value)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
352 (insert (format "\n %S" e)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
353 (insert "\n ))\n"))))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
354
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
355 (defvar recentf-auto-cleanup-timer nil
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
356 "Timer used to automatically cleanup the recent list.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
357 See also the option `recentf-auto-cleanup'.")
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
358
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
359 (defun recentf-auto-cleanup ()
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
360 "Automatic cleanup of the recent list."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
361 (when (timerp recentf-auto-cleanup-timer)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
362 (cancel-timer recentf-auto-cleanup-timer))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
363 (when recentf-mode
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
364 (setq recentf-auto-cleanup-timer
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
365 (cond
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
366 ((eq 'mode recentf-auto-cleanup)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
367 (recentf-cleanup)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
368 nil)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
369 ((numberp recentf-auto-cleanup)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
370 (run-with-idle-timer
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
371 recentf-auto-cleanup t 'recentf-cleanup))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
372 ((stringp recentf-auto-cleanup)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
373 (run-at-time
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
374 recentf-auto-cleanup nil 'recentf-cleanup))))))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
375
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
376 ;;; File functions
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
377 ;;
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
378 (defsubst recentf-push (filename)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
379 "Push FILENAME into the recent list, if it isn't there yet.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
380 If it is there yet, move it at the beginning of the list.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
381 If `recentf-case-fold-search' is non-nil, ignore case when comparing
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
382 filenames."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
383 (let ((m (recentf-string-member filename recentf-list)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
384 (and m (setq recentf-list (delq (car m) recentf-list)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
385 (push filename recentf-list)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
386
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
387 (defun recentf-apply-filename-handlers (name)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
388 "Apply `recentf-filename-handlers' to file NAME.
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
389 Return the transformed file name, or NAME if any handler failed, or
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
390 returned nil."
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
391 (or (condition-case nil
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
392 (let ((handlers recentf-filename-handlers)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
393 (filename name))
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
394 (while (and filename handlers)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
395 (setq filename (funcall (car handlers) filename)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
396 handlers (cdr handlers)))
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
397 filename)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
398 (error nil))
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
399 name))
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
400
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
401 (defsubst recentf-expand-file-name (name)
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
402 "Convert file NAME to absolute, and canonicalize it.
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
403 NAME is first passed to the function `expand-file-name', then to
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
404 `recentf-filename-handlers' to post process it."
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
405 (recentf-apply-filename-handlers (expand-file-name name)))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
406
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
407 (defun recentf-include-p (filename)
52509
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
408 "Return non-nil if FILENAME should be included in the recent list.
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
409 That is, if it doesn't match any of the `recentf-exclude' checks."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
410 (let ((case-fold-search recentf-case-fold-search)
52509
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
411 (checks recentf-exclude)
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
412 (keepit t))
52509
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
413 (while (and checks keepit)
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
414 (setq keepit (condition-case nil
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
415 (not (if (stringp (car checks))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
416 ;; A regexp
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
417 (string-match (car checks) filename)
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
418 ;; A predicate
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
419 (funcall (car checks) filename)))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
420 (error nil))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
421 checks (cdr checks)))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
422 keepit))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
423
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
424 (defun recentf-keep-p (filename)
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
425 "Return non-nil if FILENAME should be kept in the recent list.
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
426 That is, if it matches any of the `recentf-keep' checks."
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
427 (let* ((case-fold-search recentf-case-fold-search)
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
428 (checks recentf-keep)
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
429 (keepit (null checks)))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
430 (while (and checks (not keepit))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
431 (setq keepit (condition-case nil
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
432 (if (stringp (car checks))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
433 ;; A regexp
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
434 (string-match (car checks) filename)
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
435 ;; A predicate
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
436 (funcall (car checks) filename))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
437 (error nil))
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
438 checks (cdr checks)))
52509
5308684cd360 David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52468
diff changeset
439 keepit))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
440
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
441 (defsubst recentf-add-file (filename)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
442 "Add or move FILENAME at the beginning of the recent list.
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
443 Does nothing if the name satisfies any of the `recentf-exclude'
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
444 regexps or predicates."
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
445 (setq filename (recentf-expand-file-name filename))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
446 (when (recentf-include-p filename)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
447 (recentf-push filename)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
448
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
449 (defsubst recentf-remove-if-non-kept (filename)
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
450 "Remove FILENAME from the recent list, if file is not kept.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
451 Return non-nil if FILENAME has been removed."
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
452 (unless (recentf-keep-p filename)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
453 (let ((m (recentf-string-member
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
454 (recentf-expand-file-name filename) recentf-list)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
455 (and m (setq recentf-list (delq (car m) recentf-list))))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
456
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
457 (defsubst recentf-directory-compare (f1 f2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
458 "Compare absolute filenames F1 and F2.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
459 First compare directories, then filenames sans directory.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
460 Return non-nil if F1 is less than F2."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
461 (let ((d1 (file-name-directory f1))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
462 (d2 (file-name-directory f2)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
463 (if (recentf-string-equal d1 d2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
464 (recentf-string-lessp (file-name-nondirectory f1)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
465 (file-name-nondirectory f2))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
466 (recentf-string-lessp d1 d2))))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
467
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
468 ;;; Menu building
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
469 ;;
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
470 (defsubst recentf-digit-shortcut-command-name (n)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
471 "Return a command name to open the Nth most recent file.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
472 See also the command `recentf-open-most-recent-file'."
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
473 (intern (format "recentf-open-most-recent-file-%d" n)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
474
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
475 (defvar recentf--shortcuts-keymap
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
476 (let ((km (make-sparse-keymap)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
477 (dolist (k '(0 9 8 7 6 5 4 3 2 1))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
478 (let ((cmd (recentf-digit-shortcut-command-name k)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
479 ;; Define a shortcut command.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
480 (defalias cmd
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
481 `(lambda ()
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
482 (interactive)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
483 (recentf-open-most-recent-file ,k)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
484 ;; Bind it to a digit key.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
485 (define-key km (vector (+ k ?0)) cmd)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
486 km)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
487 "Digit shortcuts keymap.")
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
488
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
489 (defvar recentf-menu-items-for-commands
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
490 (list
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
491 ["Cleanup list"
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
492 recentf-cleanup
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
493 :help "Remove duplicates, and obsoletes files from the recent list"
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
494 :active t]
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
495 ["Edit list..."
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
496 recentf-edit-list
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
497 :help "Manually remove files from the recent list"
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
498 :active t]
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
499 ["Save list now"
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
500 recentf-save-list
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
501 :help "Save the list of recently opened files now"
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
502 :active t]
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
503 ["Options..."
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
504 (customize-group "recentf")
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
505 :help "Customize recently opened files menu and options"
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
506 :active t]
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
507 )
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
508 "List of menu items for recentf commands.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
509
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
510 (defvar recentf-menu-filter-commands nil
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
511 "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
512 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
513 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
514 filter function this variable is reset to nil.")
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
515
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
516 (defsubst recentf-elements (n)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
517 "Return a list of the first N elements of the recent list."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
518 (recentf-trunc-list recentf-list n))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
519
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
520 (defsubst recentf-make-menu-element (menu-item menu-value)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
521 "Create a new menu-element.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
522 A menu element is a pair (MENU-ITEM . MENU-VALUE), where MENU-ITEM is
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
523 the menu item string displayed. MENU-VALUE is the file to be open
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
524 when the corresponding MENU-ITEM is selected. Or it is a
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
525 pair (SUB-MENU-TITLE . MENU-ELEMENTS) where SUB-MENU-TITLE is a
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
526 sub-menu title and MENU-ELEMENTS is the list of menu elements in the
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
527 sub-menu."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
528 (cons menu-item menu-value))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
529
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
530 (defsubst recentf-menu-element-item (e)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
531 "Return the item part of the menu-element E."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
532 (car e))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
533
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
534 (defsubst recentf-menu-element-value (e)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
535 "Return the value part of the menu-element E."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
536 (cdr e))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
537
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
538 (defsubst recentf-set-menu-element-item (e item)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
539 "Change the item part of menu-element E to ITEM."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
540 (setcar e item))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
541
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
542 (defsubst recentf-set-menu-element-value (e value)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
543 "Change the value part of menu-element E to VALUE."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
544 (setcdr e value))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
545
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
546 (defsubst recentf-sub-menu-element-p (e)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
547 "Return non-nil if menu-element E defines a sub-menu."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
548 (consp (recentf-menu-element-value e)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
549
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
550 (defsubst recentf-make-default-menu-element (file)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
551 "Make a new default menu element with FILE.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
552 This a menu element (FILE . FILE)."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
553 (recentf-make-menu-element file file))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
554
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
555 (defsubst recentf-menu-elements (n)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
556 "Return a list of the first N default menu elements from the recent list.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
557 See also `recentf-make-default-menu-element'."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
558 (mapcar 'recentf-make-default-menu-element
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
559 (recentf-elements n)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
560
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
561 (defun recentf-apply-menu-filter (filter l)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
562 "Apply function FILTER to the list of menu-elements L.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
563 It takes care of sub-menu elements in L and recursively apply FILTER
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
564 to them. It is guaranteed that FILTER receives only a list of single
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
565 menu-elements (no sub-menu)."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
566 (if (and l (functionp filter))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
567 (let ((case-fold-search recentf-case-fold-search)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
568 elts others)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
569 ;; split L into two sub-listes, one of sub-menus elements and
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
570 ;; another of single menu elements.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
571 (dolist (elt l)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
572 (if (recentf-sub-menu-element-p elt)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
573 (push elt elts)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
574 (push elt others)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
575 ;; Apply FILTER to single elements.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
576 (when others
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
577 (setq others (funcall filter (nreverse others))))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
578 ;; Apply FILTER to sub-menu elements.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
579 (setq l nil)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
580 (dolist (elt elts)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
581 (recentf-set-menu-element-value
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
582 elt (recentf-apply-menu-filter
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
583 filter (recentf-menu-element-value elt)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
584 (push elt l))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
585 ;; Return the new filtered menu element list.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
586 (nconc l others))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
587 l))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
588
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
589 ;; Count the number of assigned menu shortcuts.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
590 (defvar recentf-menu-shortcuts)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
591
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
592 (defun recentf-make-menu-items (&optional menu)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
593 "Make menu items from the recent list.
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
594 This is a menu filter function which ignores the MENU argument."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
595 (setq recentf-menu-filter-commands nil)
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
596 (let* ((recentf-menu-shortcuts 0)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
597 (file-items
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
598 (condition-case err
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
599 (mapcar 'recentf-make-menu-item
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
600 (recentf-apply-menu-filter
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
601 recentf-menu-filter
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
602 (recentf-menu-elements recentf-max-menu-items)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
603 (error
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
604 (message "recentf update menu failed: %s"
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
605 (error-message-string err))))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
606 (append
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
607 (or file-items
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
608 '(["No files" t
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
609 :help "No recent file to open"
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
610 :active nil]))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
611 (if recentf-menu-open-all-flag
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
612 '(["All..." recentf-open-files
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
613 :help "Open recent files through a dialog"
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
614 :active t])
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
615 (and (< recentf-max-menu-items (length recentf-list))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
616 '(["More..." recentf-open-more-files
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
617 :help "Open files not in the menu through a dialog"
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
618 :active t])))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
619 (and recentf-menu-filter-commands '("---"))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
620 recentf-menu-filter-commands
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
621 (and recentf-menu-items-for-commands '("---"))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
622 recentf-menu-items-for-commands)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
623
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
624 (defun recentf-menu-value-shortcut (name)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
625 "Return a shortcut digit for file NAME.
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
626 Return nil if file NAME is not one of the ten more recent."
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
627 (let ((i 0) k)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
628 (while (and (not k) (< i 10))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
629 (if (string-equal name (nth i recentf-list))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
630 (progn
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
631 (setq recentf-menu-shortcuts (1+ recentf-menu-shortcuts))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
632 (setq k (% (1+ i) 10)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
633 (setq i (1+ i))))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
634 k))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
635
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
636 (defun recentf-make-menu-item (elt)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
637 "Make a menu item from menu element ELT."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
638 (let ((item (recentf-menu-element-item elt))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
639 (value (recentf-menu-element-value elt)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
640 (if (recentf-sub-menu-element-p elt)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
641 (cons item (mapcar 'recentf-make-menu-item value))
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
642 (let ((k (and (< recentf-menu-shortcuts 10)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
643 (recentf-menu-value-shortcut value))))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
644 (vector item
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
645 ;; If the file name is one of the ten more recent, use
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
646 ;; a digit shortcut command to open it, else use an
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
647 ;; anonymous command.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
648 (if k
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
649 (recentf-digit-shortcut-command-name k)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
650 `(lambda ()
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
651 (interactive)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
652 (,recentf-menu-action ,value)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
653 :help (concat "Open " value)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
654 :active t)))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
655
52468
de4ce9c67474 Ensure that recentf correctly update the menu bar:
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
656 (defsubst recentf-menu-bar ()
de4ce9c67474 Ensure that recentf correctly update the menu bar:
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
657 "Return the keymap of the global menu bar."
de4ce9c67474 Ensure that recentf correctly update the menu bar:
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
658 (lookup-key global-map [menu-bar]))
de4ce9c67474 Ensure that recentf correctly update the menu bar:
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
659
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
660 (defun recentf-show-menu ()
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
661 "Show the menu of recently opened files."
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
662 (easy-menu-add-item
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
663 (recentf-menu-bar) recentf-menu-path
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
664 (list recentf-menu-title :filter 'recentf-make-menu-items)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
665 recentf-menu-before))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
666
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
667 (defun recentf-hide-menu ()
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
668 "Hide the menu of recently opened files."
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
669 (easy-menu-remove-item (recentf-menu-bar) recentf-menu-path
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
670 recentf-menu-title))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
671
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
672 ;;; Predefined menu filters
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
673 ;;
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
674 (defsubst recentf-sort-ascending (l)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
675 "Sort the list of menu elements L in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
676 The MENU-ITEM part of each menu element is compared."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
677 (sort (copy-sequence l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
678 #'(lambda (e1 e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
679 (recentf-string-lessp
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
680 (recentf-menu-element-item e1)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
681 (recentf-menu-element-item e2)))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
682
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
683 (defsubst recentf-sort-descending (l)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
684 "Sort the list of menu elements L in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
685 The MENU-ITEM part of each menu element is compared."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
686 (sort (copy-sequence l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
687 #'(lambda (e1 e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
688 (recentf-string-lessp
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
689 (recentf-menu-element-item e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
690 (recentf-menu-element-item e1)))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
691
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
692 (defsubst recentf-sort-basenames-ascending (l)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
693 "Sort the list of menu elements L in ascending order.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
694 Only filenames sans directory are compared."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
695 (sort (copy-sequence l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
696 #'(lambda (e1 e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
697 (recentf-string-lessp
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
698 (file-name-nondirectory (recentf-menu-element-value e1))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
699 (file-name-nondirectory (recentf-menu-element-value e2))))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
700
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
701 (defsubst recentf-sort-basenames-descending (l)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
702 "Sort the list of menu elements L in descending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
703 Only filenames sans directory are compared."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
704 (sort (copy-sequence l)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
705 #'(lambda (e1 e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
706 (recentf-string-lessp
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
707 (file-name-nondirectory (recentf-menu-element-value e2))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
708 (file-name-nondirectory (recentf-menu-element-value e1))))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
709
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
710 (defsubst recentf-sort-directories-ascending (l)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
711 "Sort the list of menu elements L in ascending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
712 Compares directories then filenames to order the list."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
713 (sort (copy-sequence l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
714 #'(lambda (e1 e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
715 (recentf-directory-compare
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
716 (recentf-menu-element-value e1)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
717 (recentf-menu-element-value e2)))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
718
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
719 (defsubst recentf-sort-directories-descending (l)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
720 "Sort the list of menu elements L in descending order.
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
721 Compares directories then filenames to order the list."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
722 (sort (copy-sequence l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
723 #'(lambda (e1 e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
724 (recentf-directory-compare
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
725 (recentf-menu-element-value e2)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
726 (recentf-menu-element-value e1)))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
727
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
728 (defun recentf-show-basenames (l &optional no-dir)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
729 "Filter the list of menu elements L to show filenames sans directory.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
730 When a filename is duplicated, it is appended a sequence number if
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
731 optional argument NO-DIR is non-nil, or its directory otherwise."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
732 (let (filtered-names filtered-list full name counters sufx)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
733 (dolist (elt l (nreverse filtered-list))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
734 (setq full (recentf-menu-element-value elt)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
735 name (file-name-nondirectory full))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
736 (if (not (member name filtered-names))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
737 (push name filtered-names)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
738 (if no-dir
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
739 (if (setq sufx (assoc name counters))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
740 (setcdr sufx (1+ (cdr sufx)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
741 (setq sufx 1)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
742 (push (cons name sufx) counters))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
743 (setq sufx (file-name-directory full)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
744 (setq name (format "%s(%s)" name sufx)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
745 (push (recentf-make-menu-element name full) filtered-list))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
746
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
747 (defsubst recentf-show-basenames-ascending (l)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
748 "Filter the list of menu elements L to show filenames sans directory.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
749 Filenames are sorted in ascending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
750 This filter combines the `recentf-sort-basenames-ascending' and
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
751 `recentf-show-basenames' filters."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
752 (recentf-show-basenames (recentf-sort-basenames-ascending l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
753
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
754 (defsubst recentf-show-basenames-descending (l)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
755 "Filter the list of menu elements L to show filenames sans directory.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
756 Filenames are sorted in descending order.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
757 This filter combines the `recentf-sort-basenames-descending' and
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
758 `recentf-show-basenames' filters."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
759 (recentf-show-basenames (recentf-sort-basenames-descending l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
760
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
761 (defun recentf-relative-filter (l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
762 "Filter the list of menu-elements L to show relative filenames.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
763 Filenames are relative to the `default-directory'."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
764 (mapcar #'(lambda (menu-element)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
765 (let* ((ful (recentf-menu-element-value menu-element))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
766 (rel (file-relative-name ful default-directory)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
767 (if (string-match "^\\.\\." rel)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
768 menu-element
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
769 (recentf-make-menu-element rel ful))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
770 l))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
771
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
772 ;;; Rule based menu filters
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
773 ;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
774 (defcustom recentf-arrange-rules
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
775 '(
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
776 ("Elisp files (%d)" ".\\.el\\'")
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
777 ("Java files (%d)" ".\\.java\\'")
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
778 ("C/C++ files (%d)" "c\\(pp\\)?\\'")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
779 )
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
780 "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
781 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
782 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
783 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
784 or a list of regexps. Items matching one of the regular expressions in
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
785 MATCHER are added to the corresponding sub-menu.
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
786 SUB-MENU-TITLE can be a function. It is passed every items that
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
787 matched the corresponding MATCHER, and it must return a
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
788 pair (SUB-MENU-TITLE . ITEM). SUB-MENU-TITLE is a computed sub-menu
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
789 title that can be another function. ITEM is the received item which
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
790 may have been modified to match another rule."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
791 :group 'recentf-filters
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
792 :type '(repeat (cons (choice string function)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
793 (repeat regexp))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
794
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
795 (defcustom recentf-arrange-by-rule-others "Other files (%d)"
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
796 "Title of the `recentf-arrange-by-rule' sub-menu.
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
797 This is for the menu where items that don't match any
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
798 `recentf-arrange-rules' are displayed. If nil these items are
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
799 displayed in the main recent files menu. A '%d' `format' pattern in
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
800 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
801 :group 'recentf-filters
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
802 :type '(choice (const :tag "Main menu" nil)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
803 (string :tag "Title")))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
804
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
805 (defcustom recentf-arrange-by-rules-min-items 0
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
806 "Minimum number of items in a `recentf-arrange-by-rule' sub-menu.
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
807 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
808 corresponding sub-menu items are displayed in the main recent files
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
809 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
810 defined."
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
811 :group 'recentf-filters
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
812 :type 'number)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
813
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
814 (defcustom recentf-arrange-by-rule-subfilter nil
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
815 "Function called by a rule based filter to filter sub-menu elements.
64664
3161d6027fd7 (recentf-menu-append-commands-p): Declare with `define-obsolete-variable-alias'.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
816 A nil value means no filter. See also `recentf-menu-filter'.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
817 You can't use another rule based filter here."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
818 :group 'recentf-filters
35971
6dd6fce1542a (recentf-menu-filter): Fix :type.
Dave Love <fx@gnu.org>
parents: 33770
diff changeset
819 :type '(choice (const nil) function)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
820 :set (lambda (variable value)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
821 (when (memq value '(recentf-arrange-by-rule
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
822 recentf-arrange-by-mode
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
823 recentf-arrange-by-dir))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
824 (error "Recursive use of a rule based filter"))
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
825 (set-default variable value)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
826
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
827 (defun recentf-match-rule (file)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
828 "Return the rule that match FILE."
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
829 (let ((rules recentf-arrange-rules)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
830 match found)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
831 (while (and (not found) rules)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
832 (setq match (cdar rules))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
833 (when (stringp match)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
834 (setq match (list match)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
835 (while (and match (not (string-match (car match) file)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
836 (setq match (cdr match)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
837 (if match
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
838 (setq found (cons (caar rules) file))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
839 (setq rules (cdr rules))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
840 found))
30416
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 (defun recentf-arrange-by-rule (l)
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
843 "Filter the list of menu-elements L.
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
844 Arrange them in sub-menus following rules in `recentf-arrange-rules'."
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
845 (when recentf-arrange-rules
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
846 (let (menus others menu file min count)
67119
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
847 ;; Put menu items into sub-menus as defined by rules.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
848 (dolist (elt l)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
849 (setq file (recentf-menu-element-value elt)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
850 menu (recentf-match-rule file))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
851 (while (functionp (car menu))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
852 (setq menu (funcall (car menu) (cdr menu))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
853 (if (not (stringp (car menu)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
854 (push elt others)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
855 (setq menu (or (assoc (car menu) menus)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
856 (car (push (list (car menu)) menus))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
857 (recentf-set-menu-element-value
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
858 menu (cons elt (recentf-menu-element-value menu)))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
859 ;; Finalize each sub-menu:
67119
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
860 ;; - truncate it depending on the value of
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
861 ;; `recentf-arrange-by-rules-min-items',
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
862 ;; - replace %d by the number of menu items,
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
863 ;; - apply `recentf-arrange-by-rule-subfilter' to menu items.
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
864 (setq min (if (natnump recentf-arrange-by-rules-min-items)
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
865 recentf-arrange-by-rules-min-items 0)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
866 l nil)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
867 (dolist (elt menus)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
868 (setq menu (recentf-menu-element-value elt)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
869 count (length menu))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
870 (if (< count min)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
871 (setq others (nconc menu others))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
872 (recentf-set-menu-element-item
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
873 elt (format (recentf-menu-element-item elt) count))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
874 (recentf-set-menu-element-value
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
875 elt (recentf-apply-menu-filter
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
876 recentf-arrange-by-rule-subfilter (nreverse menu)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
877 (push elt l)))
67119
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
878 ;; Add the menu items remaining in the `others' bin.
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
879 (when (setq others (nreverse others))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
880 (setq l (nconc
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
881 l
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
882 ;; Put items in an sub menu.
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
883 (if (stringp recentf-arrange-by-rule-others)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
884 (list
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
885 (recentf-make-menu-element
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
886 (format recentf-arrange-by-rule-others
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
887 (length others))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
888 (recentf-apply-menu-filter
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
889 recentf-arrange-by-rule-subfilter others)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
890 ;; Append items to the main menu.
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
891 (recentf-apply-menu-filter
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
892 recentf-arrange-by-rule-subfilter others)))))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
893 l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
894
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
895 ;;; Predefined rule based menu filters
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
896 ;;
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
897 (defun recentf-indirect-mode-rule (file)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
898 "Apply a second level `auto-mode-alist' regexp to FILE."
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
899 (recentf-match-rule (substring file 0 (match-beginning 0))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
900
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
901 (defun recentf-build-mode-rules ()
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
902 "Convert `auto-mode-alist' to menu filter rules.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
903 Rules obey `recentf-arrange-rules' format."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
904 (let ((case-fold-search recentf-case-fold-search)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
905 regexp rule-name rule rules)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
906 (dolist (mode auto-mode-alist)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
907 (setq regexp (car mode)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
908 mode (cdr mode))
67119
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
909 (when mode
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
910 (cond
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
911 ;; Build a special "strip suffix" rule from entries of the
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
912 ;; form (REGEXP FUNCTION NON-NIL). Notice that FUNCTION is
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
913 ;; ignored by the menu filter. So in some corner cases a
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
914 ;; wrong mode could be guessed.
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
915 ((and (consp mode) (cadr mode))
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
916 (setq rule-name 'recentf-indirect-mode-rule))
67119
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
917 ((and mode (symbolp mode))
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
918 (setq rule-name (symbol-name mode))
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
919 (if (string-match "\\(.*\\)-mode$" rule-name)
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
920 (setq rule-name (match-string 1 rule-name)))
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
921 (setq rule-name (concat rule-name " (%d)"))))
c4aae786a4e4 (recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
David Ponce <david@dponce.com>
parents: 66083
diff changeset
922 (setq rule (assoc rule-name rules))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
923 (if rule
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
924 (setcdr rule (cons regexp (cdr rule)))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
925 (push (list rule-name regexp) rules))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
926 ;; It is important to preserve auto-mode-alist order
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
927 ;; to ensure the right file <-> mode association
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
928 (nreverse rules)))
49549
99be3a1e2589 Cygwin support patch.
Juanma Barranquero <lekktu@gmail.com>
parents: 44967
diff changeset
929
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
930 (defun recentf-arrange-by-mode (l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
931 "Split the list of menu-elements L into sub-menus by major mode."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
932 (let ((recentf-arrange-rules (recentf-build-mode-rules))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
933 (recentf-arrange-by-rule-others "others (%d)"))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
934 (recentf-arrange-by-rule l)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
935
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
936 (defun recentf-file-name-nondir (l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
937 "Filter the list of menu-elements L to show filenames sans directory.
32292
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
938 This simplified version of `recentf-show-basenames' does not handle
11bee5bae414 Doc fixes.
Dave Love <fx@gnu.org>
parents: 30778
diff changeset
939 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
940 `recentf-arrange-by-rule-subfilter'."
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
941 (mapcar #'(lambda (e)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
942 (recentf-make-menu-element
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
943 (file-name-nondirectory (recentf-menu-element-value e))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
944 (recentf-menu-element-value e)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
945 l))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
946
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
947 (defun recentf-dir-rule (file)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
948 "Return as a sub-menu, the directory FILE belongs to."
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
949 (cons (file-name-directory file) file))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
950
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
951 (defun recentf-arrange-by-dir (l)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
952 "Split the list of menu-elements L into sub-menus by directory."
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
953 (let ((recentf-arrange-rules '((recentf-dir-rule . ".*")))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
954 (recentf-arrange-by-rule-subfilter 'recentf-file-name-nondir)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
955 recentf-arrange-by-rule-others)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
956 (recentf-arrange-by-rule l)))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
957
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
958 ;;; Menu of menu filters
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
959 ;;
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
960 (defvar recentf-filter-changer-current nil
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
961 "Current filter used by `recentf-filter-changer'.")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
962
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
963 (defcustom recentf-filter-changer-alist
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
964 '(
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
965 (recentf-arrange-by-mode . "Grouped by Mode")
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
966 (recentf-arrange-by-dir . "Grouped by Directory")
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
967 (recentf-arrange-by-rule . "Grouped by Custom Rules")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
968 )
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
969 "List of filters managed by `recentf-filter-changer'.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
970 Each filter is defined by a pair (FUNCTION . LABEL), where FUNCTION is
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
971 the filter function, and LABEL is the menu item displayed to select
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
972 that filter."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
973 :group 'recentf-filters
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
974 :type '(repeat (cons function string))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
975 :set (lambda (variable value)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
976 (setq recentf-filter-changer-current nil)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
977 (set-default variable value)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
978
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
979 (defun recentf-filter-changer-select (filter)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
980 "Select FILTER as the current menu filter.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
981 See `recentf-filter-changer'."
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
982 (setq recentf-filter-changer-current filter))
49549
99be3a1e2589 Cygwin support patch.
Juanma Barranquero <lekktu@gmail.com>
parents: 44967
diff changeset
983
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
984 (defun recentf-filter-changer (l)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
985 "Manage a sub-menu of menu filters.
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
986 `recentf-filter-changer-alist' defines the filters in the menu.
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
987 Filtering of L is delegated to the selected filter in the menu."
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
988 (unless recentf-filter-changer-current
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
989 (setq recentf-filter-changer-current
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
990 (caar recentf-filter-changer-alist)))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
991 (if (not recentf-filter-changer-current)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
992 l
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
993 (setq recentf-menu-filter-commands
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
994 (list
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
995 `("Show files"
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
996 ,@(mapcar
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
997 #'(lambda (f)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
998 `[,(cdr f)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
999 (setq recentf-filter-changer-current ',(car f))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1000 ;;:active t
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1001 :style radio ;;radio Don't work with GTK :-(
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1002 :selected (eq recentf-filter-changer-current
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1003 ',(car f))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1004 ;;:help ,(cdr f)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1005 ])
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1006 recentf-filter-changer-alist))))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1007 (recentf-apply-menu-filter recentf-filter-changer-current l)))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1008
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1009 ;;; Hooks
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1010 ;;
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1011 (defun recentf-track-opened-file ()
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1012 "Insert the name of the file just opened or written into the recent list."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1013 (and buffer-file-name
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1014 (recentf-add-file buffer-file-name))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1015 ;; Must return nil because it is run from `write-file-functions'.
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1016 nil)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1017
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1018 (defun recentf-track-closed-file ()
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1019 "Update the recent list when a buffer is killed.
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
1020 That is, remove a non kept file from the recent list."
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1021 (and buffer-file-name
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
1022 (recentf-remove-if-non-kept buffer-file-name)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1023
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1024 (defconst recentf-used-hooks
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1025 '(
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1026 (find-file-hook recentf-track-opened-file)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1027 (write-file-functions recentf-track-opened-file)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1028 (kill-buffer-hook recentf-track-closed-file)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1029 (kill-emacs-hook recentf-save-list)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1030 )
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1031 "Hooks used by recentf.")
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1032
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1033 ;;; Commands
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1034 ;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1035
66083
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1036 ;;; Common dialog stuff
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1037 ;;
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1038 (defun recentf-cancel-dialog (&rest ignore)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1039 "Cancel the current dialog.
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1040 IGNORE arguments."
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1041 (interactive)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1042 (kill-buffer (current-buffer))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1043 (message "Dialog canceled"))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1044
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1045 (defun recentf-dialog-goto-first (widget-type)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1046 "Move the cursor to the first WIDGET-TYPE in current dialog.
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1047 Go to the beginning of buffer if not found."
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1048 (goto-char (point-min))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1049 (condition-case nil
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1050 (let (done)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1051 (widget-move 1)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1052 (while (not done)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1053 (if (eq widget-type (widget-type (widget-at (point))))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1054 (setq done t)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1055 (widget-move 1))))
67589
afb90762aa99 (recentf-dialog-goto-first): Fix missing error condition.
David Ponce <david@dponce.com>
parents: 67417
diff changeset
1056 (error
afb90762aa99 (recentf-dialog-goto-first): Fix missing error condition.
David Ponce <david@dponce.com>
parents: 67417
diff changeset
1057 (goto-char (point-min)))))
66083
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1058
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1059 (defvar recentf-dialog-mode-map
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1060 (let ((km (copy-keymap recentf--shortcuts-keymap)))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1061 (set-keymap-parent km widget-keymap)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1062 (define-key km "q" 'recentf-cancel-dialog)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1063 (define-key km [follow-link] "\C-m")
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1064 km)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1065 "Keymap used in recentf dialogs.")
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1066
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1067 (define-derived-mode recentf-dialog-mode nil "recentf-dialog"
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1068 "Major mode of recentf dialogs.
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1069
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1070 \\{recentf-dialog-mode-map}"
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1071 :syntax-table nil
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1072 :abbrev-table nil
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1073 (setq truncate-lines t))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1074
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1075 (defmacro recentf-dialog (name &rest forms)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1076 "Show a dialog buffer with NAME, setup with FORMS."
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1077 (declare (indent 1) (debug t))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1078 `(with-current-buffer (get-buffer-create ,name)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1079 ;; Cleanup buffer
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1080 (let ((inhibit-read-only t)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1081 (ol (overlay-lists)))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1082 (mapc 'delete-overlay (car ol))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1083 (mapc 'delete-overlay (cdr ol))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1084 (erase-buffer))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1085 (recentf-dialog-mode)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1086 ,@forms
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1087 (widget-setup)
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1088 (switch-to-buffer (current-buffer))))
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1089
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1090 ;;; Edit list dialog
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1091 ;;
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1092 (defvar recentf-edit-list nil)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1093
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1094 (defun recentf-edit-list-select (widget &rest ignore)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1095 "Toggle a file selection based on the checkbox WIDGET state.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1096 IGNORE other arguments."
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1097 (let ((value (widget-get widget :tag))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1098 (check (widget-value widget)))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1099 (if check
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1100 (add-to-list 'recentf-edit-list value)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1101 (setq recentf-edit-list (delq value recentf-edit-list)))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1102 (message "%s %sselected" value (if check "" "un"))))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1103
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1104 (defun recentf-edit-list-validate (&rest ignore)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1105 "Process the recent list when the edit list dialog is committed.
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1106 IGNORE arguments."
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1107 (if recentf-edit-list
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1108 (let ((i 0))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1109 (dolist (e recentf-edit-list)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1110 (setq recentf-list (delq e recentf-list)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1111 i (1+ i)))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1112 (kill-buffer (current-buffer))
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1113 (message "%S file(s) removed from the list" i))
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1114 (message "No file selected")))
49549
99be3a1e2589 Cygwin support patch.
Juanma Barranquero <lekktu@gmail.com>
parents: 44967
diff changeset
1115
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1116 (defun recentf-edit-list ()
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1117 "Show a dialog to delete selected files from the recent list."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1118 (interactive)
67589
afb90762aa99 (recentf-dialog-goto-first): Fix missing error condition.
David Ponce <david@dponce.com>
parents: 67417
diff changeset
1119 (unless recentf-list
afb90762aa99 (recentf-dialog-goto-first): Fix missing error condition.
David Ponce <david@dponce.com>
parents: 67417
diff changeset
1120 (error "The list of recent files is empty"))
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1121 (recentf-dialog (format "*%s - Edit list*" recentf-menu-title)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1122 (set (make-local-variable 'recentf-edit-list) nil)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1123 (widget-insert
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1124 "Click on OK to delete selected files from the recent list.
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1125 Click on Cancel or type `q' to cancel.\n")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1126 ;; Insert the list of files as checkboxes
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1127 (dolist (item recentf-list)
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1128 (widget-create 'checkbox
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1129 :value nil ; unselected checkbox
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1130 :format "\n %[%v%] %t"
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1131 :tag item
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1132 :notify 'recentf-edit-list-select))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1133 (widget-insert "\n\n")
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1134 (widget-create
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1135 'push-button
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1136 :notify 'recentf-edit-list-validate
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1137 :help-echo "Delete selected files from the recent list"
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1138 "Ok")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1139 (widget-insert " ")
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1140 (widget-create
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1141 'push-button
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1142 :notify 'recentf-cancel-dialog
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1143 "Cancel")
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1144 (recentf-dialog-goto-first 'checkbox)))
66083
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1145
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1146 ;;; Open file dialog
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1147 ;;
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1148 (defun recentf-open-files-action (widget &rest ignore)
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1149 "Open the file stored in WIDGET's value when notified.
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1150 IGNORE other arguments."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1151 (kill-buffer (current-buffer))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1152 (funcall recentf-menu-action (widget-value widget)))
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1153
65365
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1154 ;; List of files associated to a digit shortcut key.
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1155 (defvar recentf--files-with-key nil)
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1156
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1157 (defun recentf-show-digit-shortcut-filter (l)
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1158 "Filter the list of menu-elements L to show digit shortcuts."
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1159 (let ((i 0))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1160 (dolist (e l)
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1161 (setq i (1+ i))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1162 (recentf-set-menu-element-item
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1163 e (format "[%d] %s" (% i 10) (recentf-menu-element-item e))))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1164 l))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1165
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1166 (defun recentf-open-files-item (menu-element)
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1167 "Return a widget to display MENU-ELEMENT in a dialog buffer."
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1168 (if (consp (cdr menu-element))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1169 ;; Represent a sub-menu with a tree widget
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1170 `(tree-widget
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1171 :open t
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1172 :match ignore
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1173 :node (item :tag ,(car menu-element)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1174 :sample-face bold
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1175 :format "%{%t%}:\n")
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1176 ,@(mapcar 'recentf-open-files-item
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1177 (cdr menu-element)))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1178 ;; Represent a single file with a link widget
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1179 `(link :tag ,(car menu-element)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1180 :button-prefix ""
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1181 :button-suffix ""
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1182 :button-face default
69778
6828bafcac8e (recentf-open-files-item): Include newline in button
David Ponce <david@dponce.com>
parents: 68651
diff changeset
1183 :format "%[%t\n%]"
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1184 :help-echo ,(concat "Open " (cdr menu-element))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1185 :action recentf-open-files-action
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1186 ,(cdr menu-element))))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1187
65365
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1188 (defun recentf-open-files-items (files)
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1189 "Return a list of widgets to display FILES in a dialog buffer."
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1190 (set (make-local-variable 'recentf--files-with-key)
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1191 (recentf-trunc-list files 10))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1192 (mapcar 'recentf-open-files-item
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1193 (append
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1194 ;; When requested group the files with shortcuts together
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1195 ;; at the top of the list.
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1196 (when recentf-show-file-shortcuts-flag
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1197 (setq files (nthcdr 10 files))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1198 (recentf-apply-menu-filter
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1199 'recentf-show-digit-shortcut-filter
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1200 (mapcar 'recentf-make-default-menu-element
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1201 recentf--files-with-key)))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1202 ;; Then the other files.
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1203 (recentf-apply-menu-filter
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1204 recentf-menu-filter
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1205 (mapcar 'recentf-make-default-menu-element
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1206 files)))))
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1207
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1208 (defun recentf-open-files (&optional files buffer-name)
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1209 "Show a dialog to open a recent file.
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1210 If optional argument FILES is non-nil, it is a list of recently-opened
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1211 files to choose from. It defaults to the whole recent list.
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1212 If optional argument BUFFER-NAME is non-nil, it is a buffer name to
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1213 use for the dialog. It defaults to \"*`recentf-menu-title'*\"."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1214 (interactive)
67589
afb90762aa99 (recentf-dialog-goto-first): Fix missing error condition.
David Ponce <david@dponce.com>
parents: 67417
diff changeset
1215 (unless (or files recentf-list)
afb90762aa99 (recentf-dialog-goto-first): Fix missing error condition.
David Ponce <david@dponce.com>
parents: 67417
diff changeset
1216 (error "There is no recent file to open"))
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1217 (recentf-dialog (or buffer-name (format "*%s*" recentf-menu-title))
65365
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1218 (widget-insert "Click on a file"
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1219 (if recentf-show-file-shortcuts-flag
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1220 ", or type the corresponding digit key,"
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1221 "")
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1222 " to open it.\n"
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1223 "Click on Cancel or type `q' to cancel.\n")
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1224 ;; Use a L&F that looks like the recentf menu.
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1225 (tree-widget-set-theme "folder")
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1226 (apply 'widget-create
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1227 `(group
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1228 :indent 2
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1229 :format "\n%v\n"
65365
83aa6efe327f (recentf-show-file-shortcuts-flag): New option.
David Ponce <david@dponce.com>
parents: 64762
diff changeset
1230 ,@(recentf-open-files-items (or files recentf-list))))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1231 (widget-create
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1232 'push-button
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1233 :notify 'recentf-cancel-dialog
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1234 "Cancel")
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1235 (recentf-dialog-goto-first 'link)))
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1236
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1237 (defun recentf-open-more-files ()
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1238 "Show a dialog to open a recent file that is not in the menu."
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1239 (interactive)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1240 (recentf-open-files (nthcdr recentf-max-menu-items recentf-list)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1241 (format "*%s - More*" recentf-menu-title)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1242
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1243 (defun recentf-open-most-recent-file (&optional n)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1244 "Open the Nth most recent file.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1245 Optional argument N must be a valid digit number. It defaults to 1.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1246 1 opens the most recent file, 2 the second most recent one, etc..
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1247 0 opens the tenth most recent file."
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1248 (interactive "p")
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1249 (cond
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1250 ((zerop n) (setq n 10))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1251 ((and (> n 0) (< n 10)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1252 ((error "Recent file number out of range [0-9], %d" n)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1253 (let ((file (nth (1- n) (or recentf--files-with-key recentf-list))))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1254 (unless file (error "Not that many recent files"))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1255 ;; Close the open files dialog.
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1256 (when recentf--files-with-key
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1257 (kill-buffer (current-buffer)))
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1258 (funcall recentf-menu-action file)))
66083
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1259
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1260 ;;; Save/load/cleanup the recent list
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1261 ;;
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1262 (defconst recentf-save-file-header
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1263 ";;; Automatically generated by `recentf' on %s.\n"
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1264 "Header to be written into the `recentf-save-file'.")
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1265
61733
34f8bb98e444 (recentf-save-file-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents: 60844
diff changeset
1266 (defconst recentf-save-file-coding-system
34f8bb98e444 (recentf-save-file-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents: 60844
diff changeset
1267 (if (coding-system-p 'utf-8-emacs)
34f8bb98e444 (recentf-save-file-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents: 60844
diff changeset
1268 'utf-8-emacs
34f8bb98e444 (recentf-save-file-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents: 60844
diff changeset
1269 'emacs-mule)
34f8bb98e444 (recentf-save-file-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents: 60844
diff changeset
1270 "Coding system of the file `recentf-save-file'.")
34f8bb98e444 (recentf-save-file-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents: 60844
diff changeset
1271
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1272 (defun recentf-save-list ()
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1273 "Save the recent list.
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1274 Write data into the file specified by `recentf-save-file'."
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1275 (interactive)
55012
13ef2f084366 (recentf-save-list): Catch and warn about errors.
Richard M. Stallman <rms@gnu.org>
parents: 54770
diff changeset
1276 (condition-case error
13ef2f084366 (recentf-save-list): Catch and warn about errors.
Richard M. Stallman <rms@gnu.org>
parents: 54770
diff changeset
1277 (with-temp-buffer
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1278 (erase-buffer)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1279 (set-buffer-file-coding-system recentf-save-file-coding-system)
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1280 (insert (format recentf-save-file-header (current-time-string)))
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1281 (recentf-dump-variable 'recentf-list recentf-max-saved-items)
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1282 (recentf-dump-variable 'recentf-filter-changer-current)
84657
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
1283 (insert "\n \n;; Local Variables:\n"
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
1284 (format ";; coding: %s\n" recentf-save-file-coding-system)
1b2430509da5 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82140
diff changeset
1285 ";; End:\n")
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1286 (write-file (expand-file-name recentf-save-file))
65525
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
1287 (when recentf-save-file-modes
f68d6281086a (recentf-save-file-modes): New option.
David Ponce <david@dponce.com>
parents: 65368
diff changeset
1288 (set-file-modes recentf-save-file recentf-save-file-modes))
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1289 nil)
55012
13ef2f084366 (recentf-save-list): Catch and warn about errors.
Richard M. Stallman <rms@gnu.org>
parents: 54770
diff changeset
1290 (error
13ef2f084366 (recentf-save-list): Catch and warn about errors.
Richard M. Stallman <rms@gnu.org>
parents: 54770
diff changeset
1291 (warn "recentf mode: %s" (error-message-string error)))))
32866
8ef794e21542 (recentf-mode): Variable removed.
Miles Bader <miles@gnu.org>
parents: 32429
diff changeset
1292
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1293 (defun recentf-load-list ()
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1294 "Load a previously saved recent list.
52638
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1295 Read data from the file specified by `recentf-save-file'.
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1296 When `recentf-initialize-file-name-history' is non-nil, initialize an
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1297 empty `file-name-history' with the recent list."
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1298 (interactive)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1299 (let ((file (expand-file-name recentf-save-file)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1300 (when (file-readable-p file)
52638
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1301 (load-file file)
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1302 (and recentf-initialize-file-name-history
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1303 (not file-name-history)
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1304 (setq file-name-history (mapcar 'abbreviate-file-name
2a2c48cb8b59 (recentf-initialize-file-name-history): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents: 52509
diff changeset
1305 recentf-list))))))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1306
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1307 (defun recentf-cleanup ()
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
1308 "Cleanup the recent list.
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
1309 That is, remove duplicates, non-kept, and excluded files."
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1310 (interactive)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1311 (message "Cleaning up the recentf list...")
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
1312 (let ((n 0) newlist)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1313 (dolist (f recentf-list)
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
1314 (setq f (recentf-expand-file-name f))
60740
1e67e22bcc1b (recentf-cleanup-remote): New variable.
Eli Zaretskii <eliz@gnu.org>
parents: 59996
diff changeset
1315 (if (and (recentf-include-p f)
65744
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
1316 (recentf-keep-p f)
4bbd95905599 (recentf-filename-handlers): Rename from
David Ponce <david@dponce.com>
parents: 65525
diff changeset
1317 (not (recentf-string-member f newlist)))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1318 (push f newlist)
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
1319 (setq n (1+ n))
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1320 (message "File %s removed from the recentf list" f)))
60844
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
1321 (message "Cleaning up the recentf list...done (%d removed)" n)
5bb0c1e05b1b (recentf-keep): New option.
David Ponce <david@dponce.com>
parents: 60740
diff changeset
1322 (setq recentf-list (nreverse newlist))))
66083
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1323
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1324 ;;; The minor mode
3ee176d1ff23 (recentf-track-opened-file)
David Ponce <david@dponce.com>
parents: 65894
diff changeset
1325 ;;
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1326 (defvar recentf-mode-map (make-sparse-keymap)
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1327 "Keymap to use in recentf mode.")
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1328
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1329 ;;;###autoload
32866
8ef794e21542 (recentf-mode): Variable removed.
Miles Bader <miles@gnu.org>
parents: 32429
diff changeset
1330 (define-minor-mode recentf-mode
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1331 "Toggle recentf mode.
32866
8ef794e21542 (recentf-mode): Variable removed.
Miles Bader <miles@gnu.org>
parents: 32429
diff changeset
1332 With prefix argument ARG, turn on if positive, otherwise off.
8ef794e21542 (recentf-mode): Variable removed.
Miles Bader <miles@gnu.org>
parents: 32429
diff changeset
1333 Returns non-nil if the new state is enabled.
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1334
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1335 When recentf mode is enabled, it maintains a menu for visiting files
73413
d14b0d59315b (recentf-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 69778
diff changeset
1336 that were operated on recently."
32866
8ef794e21542 (recentf-mode): Variable removed.
Miles Bader <miles@gnu.org>
parents: 32429
diff changeset
1337 :global t
8ef794e21542 (recentf-mode): Variable removed.
Miles Bader <miles@gnu.org>
parents: 32429
diff changeset
1338 :group 'recentf
65894
e0cf1ed38749 (recentf-menu-open-all-flag): New option.
David Ponce <david@dponce.com>
parents: 65744
diff changeset
1339 :keymap recentf-mode-map
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1340 (unless (and recentf-mode (recentf-enabled-p))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1341 (if recentf-mode
67417
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1342 (progn
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1343 (recentf-load-list)
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1344 (recentf-show-menu))
29df8eb9daf1 Improvement of the menu code.
David Ponce <david@dponce.com>
parents: 67119
diff changeset
1345 (recentf-hide-menu)
50715
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1346 (recentf-save-list))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1347 (recentf-auto-cleanup)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1348 (let ((hook-setup (if recentf-mode 'add-hook 'remove-hook)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1349 (dolist (hook recentf-used-hooks)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1350 (apply hook-setup hook)))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1351 (run-hooks 'recentf-mode-hook)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1352 (when (interactive-p)
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1353 (message "Recentf mode %sabled" (if recentf-mode "en" "dis"))))
46229d46cbeb Major rewrite. The code is reordered, cleaner and faster.
Juanma Barranquero <lekktu@gmail.com>
parents: 49549
diff changeset
1354 recentf-mode)
30416
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1355
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1356 (provide 'recentf)
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1357
cc08ed656c8c Fix CRLF eols.
Dave Love <fx@gnu.org>
parents: 30286
diff changeset
1358 (run-hooks 'recentf-load-hook)
61733
34f8bb98e444 (recentf-save-file-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents: 60844
diff changeset
1359
63781
99d460dc50ca Require 'tree-widget instead of 'wid-edit.
David Ponce <david@dponce.com>
parents: 63409
diff changeset
1360 ;; arch-tag: 78f1eec9-0d16-4d19-a4eb-2e4529edb62a
32429
0e626f0c2b8a Maintainer's checkdoc fixes.
Dave Love <fx@gnu.org>
parents: 32292
diff changeset
1361 ;;; recentf.el ends here