annotate lisp/url/url-history.el @ 104559:5341a7b533a2

(Quick start): Don't refer to nonexistent epa-mode. (Mail-mode integration): Mention epa-mail-mode and epa-global-mail-mode. Reported by Jari Aalto (Bug#4211).
author Daiki Ueno <ueno@unixuser.org>
date Sun, 23 Aug 2009 16:23:57 +0000
parents a9dc0e7c3f2b
children 1d1d5d9bd884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; url-history.el --- Global history tracking for URL package
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
2
64748
875dcc490074 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64084
diff changeset
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 94668
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
5
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Keywords: comm, data, processes, hypermedia
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
8 ;; This file is part of GNU Emacs.
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
9 ;;
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
13 ;; (at your option) any later version.
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
14
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
18 ;; GNU General Public License for more details.
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
19
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
22
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
23 ;;; Commentary:
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
24
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
25 ;;; Code:
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27 ;; This can get a recursive require.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28 ;;(require 'url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 (require 'url-parse)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30 (autoload 'url-do-setup "url")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 (defgroup url-history nil
63991
03160396e8bc (url-history): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents: 63416
diff changeset
33 "History variables in the URL package."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 :prefix "url-history"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35 :group 'url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 (defcustom url-history-track nil
67237
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
38 "*Controls whether to keep a list of all the URLs being visited.
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
39 If non-nil, the URL package will keep track of all the URLs visited.
63991
03160396e8bc (url-history): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents: 63416
diff changeset
40 If set to t, then the list is saved to disk at the end of each Emacs
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41 session."
67237
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
42 :set #'(lambda (var val)
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
43 (set-default var val)
67240
fb7449e080a0 (url-history-track): Fix last change.
Kim F. Storm <storm@cua.dk>
parents: 67237
diff changeset
44 (and (bound-and-true-p url-setup-done)
67237
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
45 (url-history-setup-save-timer)))
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
46 :type '(choice (const :tag "off" nil)
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
47 (const :tag "on" t)
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
48 (const :tag "within session" 'session))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 :group 'url-history)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 (defcustom url-history-file nil
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 "*The global history file for the URL package.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 This file contains a list of all the URLs you have visited. This file
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 is parsed at startup and used to provide URL completion."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 :type '(choice (const :tag "Default" :value nil) file)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 :group 'url-history)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 (defcustom url-history-save-interval 3600
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 "*The number of seconds between automatic saves of the history list.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 Default is 1 hour. Note that if you change this variable outside of
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 the `customize' interface after `url-do-setup' has been run, you need
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62 to run the `url-history-setup-save-timer' function manually."
67310
e6faadb77218 (url-history-list): Var deleted.
Richard M. Stallman <rms@gnu.org>
parents: 67240
diff changeset
63 :set #'(lambda (var val)
e6faadb77218 (url-history-list): Var deleted.
Richard M. Stallman <rms@gnu.org>
parents: 67240
diff changeset
64 (set-default var val)
e6faadb77218 (url-history-list): Var deleted.
Richard M. Stallman <rms@gnu.org>
parents: 67240
diff changeset
65 (if (bound-and-true-p url-setup-done)
e6faadb77218 (url-history-list): Var deleted.
Richard M. Stallman <rms@gnu.org>
parents: 67240
diff changeset
66 (url-history-setup-save-timer)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 :type 'integer
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 :group 'url-history)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 (defvar url-history-timer nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 (defvar url-history-changed-since-last-save nil
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 "Whether the history list has changed since the last save operation.")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
75 (defvar url-history-hash-table (make-hash-table :size 31 :test 'equal)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 "Hash table for global history completion.")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
79
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 (defun url-history-setup-save-timer ()
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81 "Reset the history list timer."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 (interactive)
86949
5befb2f1ec98 (top-level): Don't require cl when compiling.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
83 (condition-case nil
5befb2f1ec98 (top-level): Don't require cl when compiling.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
84 (cancel-timer url-history-timer)
5befb2f1ec98 (top-level): Don't require cl when compiling.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
85 (error nil))
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
86 (setq url-history-timer nil)
67237
40f77d1e999e (url-history-track): Call url-history-setup-save-timer in :set function.
Richard M. Stallman <rms@gnu.org>
parents: 64748
diff changeset
87 (if (and (eq url-history-track t) url-history-save-interval)
67310
e6faadb77218 (url-history-list): Var deleted.
Richard M. Stallman <rms@gnu.org>
parents: 67240
diff changeset
88 (setq url-history-timer (run-at-time url-history-save-interval
e6faadb77218 (url-history-list): Var deleted.
Richard M. Stallman <rms@gnu.org>
parents: 67240
diff changeset
89 url-history-save-interval
e6faadb77218 (url-history-list): Var deleted.
Richard M. Stallman <rms@gnu.org>
parents: 67240
diff changeset
90 'url-history-save-history))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 (defun url-history-parse-history (&optional fname)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 "Parse a history file stored in FNAME."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 ;; Parse out the mosaic global history file for completions, etc.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 (or fname (setq fname (expand-file-name url-history-file)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 (cond
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 ((not (file-exists-p fname))
68054
30042a8370ce (url-history-parse-history): Don't complain if the file is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 67367
diff changeset
98 ;; It's completely normal for this file not to exist, so don't complain.
30042a8370ce (url-history-parse-history): Don't complain if the file is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 67367
diff changeset
99 ;; (message "%s does not exist." fname)
30042a8370ce (url-history-parse-history): Don't complain if the file is missing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 67367
diff changeset
100 )
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 ((not (file-readable-p fname))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 (message "%s is unreadable." fname))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103 (t
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104 (condition-case nil
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 (load fname nil t)
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
106 (error (message "Could not load %s" fname))))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
107
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108 (defun url-history-update-url (url time)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 (setq url-history-changed-since-last-save t)
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
110 (puthash (if (vectorp url) (url-recreate-url url) url) time
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
111 url-history-hash-table))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112
79557
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
113 (autoload 'url-make-private-file "url-util")
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
114
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
115 (defun url-history-save-history (&optional fname)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 "Write the global history file into `url-history-file'.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 The type of data written is determined by what is in the file to begin
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 with. If the type of storage cannot be determined, then prompt the
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 user for what type to save as."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120 (interactive)
79557
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
121 (when url-history-changed-since-last-save
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
122 (or fname (setq fname (expand-file-name url-history-file)))
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
123 (if (condition-case nil
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
124 (progn
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
125 (url-make-private-file fname)
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
126 nil)
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
127 (error t))
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
128 (message "Error accessing history file `%s'" fname)
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
129 (let ((make-backup-files nil)
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
130 (version-control nil)
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
131 (require-final-newline t)
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
132 (count 0))
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
133 (with-temp-buffer
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
134 (maphash (lambda (key value)
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
135 (while (string-match "[\r\n]+" key)
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
136 (setq key (concat (substring key 0 (match-beginning 0))
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
137 (substring key (match-end 0) nil))))
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
138 (setq count (1+ count))
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
139 (insert "(puthash \"" key "\""
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
140 (if (not (stringp value)) " '" "")
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
141 (prin1-to-string value)
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
142 " url-history-hash-table)\n"))
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
143 url-history-hash-table)
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
144 ;; We used to add this in the file, but it just makes the code
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
145 ;; more complex with no benefit. Worse: it makes it harder to
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
146 ;; preserve preexisting history when loading the history file.
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
147 ;; (goto-char (point-min))
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
148 ;; (insert (format
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
149 ;; "(setq url-history-hash-table (make-hash-table :size %d :test 'equal))\n"
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
150 ;; (/ count 4)))
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
151 ;; (goto-char (point-max))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
152 (insert "\n")
87258
949eabfded89 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 86949
diff changeset
153 (write-file fname)))
79557
3d0d9d7bb356 (url-history-save-history): Use url-make-private-file and with-temp-buffer.
Glenn Morris <rgm@gnu.org>
parents: 78222
diff changeset
154 (setq url-history-changed-since-last-save nil))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
155
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
156 (defun url-have-visited-url (url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
157 (url-do-setup)
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
158 (gethash url url-history-hash-table nil))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
159
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160 (defun url-completion-function (string predicate function)
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
161 ;; Completion function to complete urls from the history.
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
162 ;; This is obsolete since we can now pass the hash-table directly as a
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
163 ;; completion table.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 (url-do-setup)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 (cond
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 ((eq function nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 (let ((list nil))
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
168 (maphash (lambda (key val) (push key list))
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
169 url-history-hash-table)
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
170 ;; Not sure why we bother reversing the list. --Stef
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 (try-completion string (nreverse list) predicate)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 ((eq function t)
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
173 (let ((stub (concat "\\`" (regexp-quote string)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 (retval nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 (maphash
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
176 (lambda (url time)
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
177 (if (string-match stub url) (push url retval)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 url-history-hash-table)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 retval))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
180 ((eq function 'lambda)
68056
2396bdbbc2bb (url-history-hash-table): Initialize in declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68054
diff changeset
181 (and (gethash string url-history-hash-table) t))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 (t
63416
ed3a1f593d3c (url-completion-function): Follow error conventions.
Juanma Barranquero <lekktu@gmail.com>
parents: 60258
diff changeset
183 (error "url-completion-function very confused"))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185 (provide 'url-history)
54699
7784ae10206d Resolve CVS conflicts
Miles Bader <miles@gnu.org>
parents: 54695
diff changeset
186
54797
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
187 ;; arch-tag: fbbbaf63-db36-4e88-bc9f-2939aa93afb2
c70e18f19b9c (url-history-setup-save-timer): Avoid warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
188 ;;; url-history.el ends here