diff options
| author | Stefan Monnier | 2006-01-05 22:28:16 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2006-01-05 22:28:16 +0000 |
| commit | 176c99dca23ca4d5e5e0b29124527276c82c5200 (patch) | |
| tree | ad1263389906790927869b4b711085c2f2948e4f | |
| parent | 72a30be46bf58322dd4885266d57932e429e1b15 (diff) | |
| download | emacs-176c99dca23ca4d5e5e0b29124527276c82c5200.tar.gz emacs-176c99dca23ca4d5e5e0b29124527276c82c5200.zip | |
(url-history-hash-table): Initialize in declaration.
(url-history-parse-history): Don't reset the history.
(url-history-save-history): Create parent dir if necessary.
(url-history-save-history): Don't write the initialization of
url-history-hash-table into the history file.
(url-have-visited-url): Simplify since url-history-hash-table is non-nil.
(url-completion-function): Simplify.
| -rw-r--r-- | lisp/url/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/url/url-history.el | 73 |
2 files changed, 44 insertions, 37 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 3a560e7bb68..d30534ec6be 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2006-01-05 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2006-01-05 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * url-history.el (url-history-hash-table): Initialize in declaration. | ||
| 4 | (url-history-parse-history): Don't reset the history. | ||
| 5 | (url-history-save-history): Create parent dir if necessary. | ||
| 6 | (url-history-save-history): Don't write the initialization of | ||
| 7 | url-history-hash-table into the history file. | ||
| 8 | (url-have-visited-url): Simplify since url-history-hash-table is non-nil. | ||
| 9 | (url-completion-function): Simplify. | ||
| 10 | |||
| 3 | * url-cookie.el (url-cookie-parse-file): Don't complain of missing file. | 11 | * url-cookie.el (url-cookie-parse-file): Don't complain of missing file. |
| 4 | (url-cookie-parse-file, url-cookie-write-file, url-cookie-retrieve) | 12 | (url-cookie-parse-file, url-cookie-write-file, url-cookie-retrieve) |
| 5 | (url-cookie-generate-header-lines, url-cookie-handle-set-cookie) | 13 | (url-cookie-generate-header-lines, url-cookie-handle-set-cookie) |
diff --git a/lisp/url/url-history.el b/lisp/url/url-history.el index 8ed9f1d8171..0cdfe329bc2 100644 --- a/lisp/url/url-history.el +++ b/lisp/url/url-history.el | |||
| @@ -75,7 +75,7 @@ to run the `url-history-setup-save-timer' function manually." | |||
| 75 | (defvar url-history-changed-since-last-save nil | 75 | (defvar url-history-changed-since-last-save nil |
| 76 | "Whether the history list has changed since the last save operation.") | 76 | "Whether the history list has changed since the last save operation.") |
| 77 | 77 | ||
| 78 | (defvar url-history-hash-table nil | 78 | (defvar url-history-hash-table (make-hash-table :size 31 :test 'equal) |
| 79 | "Hash table for global history completion.") | 79 | "Hash table for global history completion.") |
| 80 | 80 | ||
| 81 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 81 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -105,13 +105,12 @@ to run the `url-history-setup-save-timer' function manually." | |||
| 105 | (t | 105 | (t |
| 106 | (condition-case nil | 106 | (condition-case nil |
| 107 | (load fname nil t) | 107 | (load fname nil t) |
| 108 | (error (message "Could not load %s" fname))))) | 108 | (error (message "Could not load %s" fname)))))) |
| 109 | (if (not url-history-hash-table) | ||
| 110 | (setq url-history-hash-table (make-hash-table :size 31 :test 'equal)))) | ||
| 111 | 109 | ||
| 112 | (defun url-history-update-url (url time) | 110 | (defun url-history-update-url (url time) |
| 113 | (setq url-history-changed-since-last-save t) | 111 | (setq url-history-changed-since-last-save t) |
| 114 | (puthash (if (vectorp url) (url-recreate-url url) url) time url-history-hash-table)) | 112 | (puthash (if (vectorp url) (url-recreate-url url) url) time |
| 113 | url-history-hash-table)) | ||
| 115 | 114 | ||
| 116 | (defun url-history-save-history (&optional fname) | 115 | (defun url-history-save-history (&optional fname) |
| 117 | "Write the global history file into `url-history-file'. | 116 | "Write the global history file into `url-history-file'. |
| @@ -120,6 +119,8 @@ with. If the type of storage cannot be determined, then prompt the | |||
| 120 | user for what type to save as." | 119 | user for what type to save as." |
| 121 | (interactive) | 120 | (interactive) |
| 122 | (or fname (setq fname (expand-file-name url-history-file))) | 121 | (or fname (setq fname (expand-file-name url-history-file))) |
| 122 | (unless (file-directory-p (file-name-directory fname)) | ||
| 123 | (ignore-errors (make-directory (file-name-directory fname)))) | ||
| 123 | (cond | 124 | (cond |
| 124 | ((not url-history-changed-since-last-save) nil) | 125 | ((not url-history-changed-since-last-save) nil) |
| 125 | ((not (file-writable-p fname)) | 126 | ((not (file-writable-p fname)) |
| @@ -128,26 +129,27 @@ user for what type to save as." | |||
| 128 | (let ((make-backup-files nil) | 129 | (let ((make-backup-files nil) |
| 129 | (version-control nil) | 130 | (version-control nil) |
| 130 | (require-final-newline t)) | 131 | (require-final-newline t)) |
| 131 | (save-excursion | 132 | (with-current-buffer (get-buffer-create " *url-tmp*") |
| 132 | (set-buffer (get-buffer-create " *url-tmp*")) | ||
| 133 | (erase-buffer) | 133 | (erase-buffer) |
| 134 | (let ((count 0)) | 134 | (let ((count 0)) |
| 135 | (maphash (function | 135 | (maphash (lambda (key value) |
| 136 | (lambda (key value) | 136 | (while (string-match "[\r\n]+" key) |
| 137 | (while (string-match "[\r\n]+" key) | 137 | (setq key (concat (substring key 0 (match-beginning 0)) |
| 138 | (setq key (concat (substring key 0 (match-beginning 0)) | 138 | (substring key (match-end 0) nil)))) |
| 139 | (substring key (match-end 0) nil)))) | 139 | (setq count (1+ count)) |
| 140 | (setq count (1+ count)) | 140 | (insert "(puthash \"" key "\"" |
| 141 | (insert "(puthash \"" key "\"" | 141 | (if (not (stringp value)) " '" "") |
| 142 | (if (not (stringp value)) " '" "") | 142 | (prin1-to-string value) |
| 143 | (prin1-to-string value) | 143 | " url-history-hash-table)\n")) |
| 144 | " url-history-hash-table)\n"))) | 144 | url-history-hash-table) |
| 145 | url-history-hash-table) | 145 | ;; We used to add this in the file, but it just makes the code |
| 146 | (goto-char (point-min)) | 146 | ;; more complex with no benefit. Worse: it makes it harder to |
| 147 | (insert (format | 147 | ;; preserve preexisting history when loading the history file. |
| 148 | "(setq url-history-hash-table (make-hash-table :size %d :test 'equal))\n" | 148 | ;; (goto-char (point-min)) |
| 149 | (/ count 4))) | 149 | ;; (insert (format |
| 150 | (goto-char (point-max)) | 150 | ;; "(setq url-history-hash-table (make-hash-table :size %d :test 'equal))\n" |
| 151 | ;; (/ count 4))) | ||
| 152 | ;; (goto-char (point-max)) | ||
| 151 | (insert "\n") | 153 | (insert "\n") |
| 152 | (write-file fname)) | 154 | (write-file fname)) |
| 153 | (kill-buffer (current-buffer)))))) | 155 | (kill-buffer (current-buffer)))))) |
| @@ -155,33 +157,30 @@ user for what type to save as." | |||
| 155 | 157 | ||
| 156 | (defun url-have-visited-url (url) | 158 | (defun url-have-visited-url (url) |
| 157 | (url-do-setup) | 159 | (url-do-setup) |
| 158 | (and url-history-hash-table | 160 | (gethash url url-history-hash-table nil)) |
| 159 | (gethash url url-history-hash-table nil))) | ||
| 160 | 161 | ||
| 161 | (defun url-completion-function (string predicate function) | 162 | (defun url-completion-function (string predicate function) |
| 163 | ;; Completion function to complete urls from the history. | ||
| 164 | ;; This is obsolete since we can now pass the hash-table directly as a | ||
| 165 | ;; completion table. | ||
| 162 | (url-do-setup) | 166 | (url-do-setup) |
| 163 | (cond | 167 | (cond |
| 164 | ((eq function nil) | 168 | ((eq function nil) |
| 165 | (let ((list nil)) | 169 | (let ((list nil)) |
| 166 | (maphash (function (lambda (key val) | 170 | (maphash (lambda (key val) (push key list)) |
| 167 | (setq list (cons (cons key val) | 171 | url-history-hash-table) |
| 168 | list)))) | 172 | ;; Not sure why we bother reversing the list. --Stef |
| 169 | url-history-hash-table) | ||
| 170 | (try-completion string (nreverse list) predicate))) | 173 | (try-completion string (nreverse list) predicate))) |
| 171 | ((eq function t) | 174 | ((eq function t) |
| 172 | (let ((stub (concat "^" (regexp-quote string))) | 175 | (let ((stub (concat "\\`" (regexp-quote string))) |
| 173 | (retval nil)) | 176 | (retval nil)) |
| 174 | (maphash | 177 | (maphash |
| 175 | (function | 178 | (lambda (url time) |
| 176 | (lambda (url time) | 179 | (if (string-match stub url) (push url retval))) |
| 177 | (if (string-match stub url) | ||
| 178 | (setq retval (cons url retval))))) | ||
| 179 | url-history-hash-table) | 180 | url-history-hash-table) |
| 180 | retval)) | 181 | retval)) |
| 181 | ((eq function 'lambda) | 182 | ((eq function 'lambda) |
| 182 | (and url-history-hash-table | 183 | (and (gethash string url-history-hash-table) t)) |
| 183 | (gethash string url-history-hash-table) | ||
| 184 | t)) | ||
| 185 | (t | 184 | (t |
| 186 | (error "url-completion-function very confused")))) | 185 | (error "url-completion-function very confused")))) |
| 187 | 186 | ||