Commit 9824ded5 authored by Glenn Morris's avatar Glenn Morris

(url-history-save-history): Use url-make-private-file and with-temp-buffer.

parent 4e44324a
2007-12-11 Glenn Morris <rgm@gnu.org>
* url.el (url-configuration-directory): Make it a defcustom.
* url-util.el (url-make-private-file): New function.
* url-cookie.el (url-cookie-write-file):
* url-history.el (url-history-save-history):
Use url-make-private-file and with-temp-buffer.
2007-12-06 Glenn Morris <rgm@gnu.org> 2007-12-06 Glenn Morris <rgm@gnu.org>
* url-file.el, url-mailto.el: Remove directory part from filenames * url-file.el, url-mailto.el: Remove directory part from filenames
......
...@@ -112,29 +112,28 @@ to run the `url-history-setup-save-timer' function manually." ...@@ -112,29 +112,28 @@ to run the `url-history-setup-save-timer' function manually."
(puthash (if (vectorp url) (url-recreate-url url) url) time (puthash (if (vectorp url) (url-recreate-url url) url) time
url-history-hash-table)) url-history-hash-table))
(autoload 'url-make-private-file "url-util")
(defun url-history-save-history (&optional fname) (defun url-history-save-history (&optional fname)
"Write the global history file into `url-history-file'. "Write the global history file into `url-history-file'.
The type of data written is determined by what is in the file to begin The type of data written is determined by what is in the file to begin
with. If the type of storage cannot be determined, then prompt the with. If the type of storage cannot be determined, then prompt the
user for what type to save as." user for what type to save as."
(interactive) (interactive)
(or fname (setq fname (expand-file-name url-history-file))) (when url-history-changed-since-last-save
(unless (file-directory-p (file-name-directory fname)) (or fname (setq fname (expand-file-name url-history-file)))
(condition-case nil (if (condition-case nil
(make-directory (file-name-directory fname)) (progn
(error nil))) (url-make-private-file fname)
(cond nil)
((not url-history-changed-since-last-save) nil) (error t))
((not (file-writable-p fname)) (message "Error accessing history file `%s'" fname)
(message "%s is unwritable." fname)) (let ((make-backup-files nil)
(t (version-control nil)
(let ((make-backup-files nil) (require-final-newline t)
(version-control nil) (count 0))
(require-final-newline t)) (with-temp-buffer
(with-current-buffer (get-buffer-create " *url-tmp*") (maphash (lambda (key value)
(erase-buffer)
(let ((count 0))
(maphash (lambda (key value)
(while (string-match "[\r\n]+" key) (while (string-match "[\r\n]+" key)
(setq key (concat (substring key 0 (match-beginning 0)) (setq key (concat (substring key 0 (match-beginning 0))
(substring key (match-end 0) nil)))) (substring key (match-end 0) nil))))
...@@ -153,9 +152,8 @@ user for what type to save as." ...@@ -153,9 +152,8 @@ user for what type to save as."
;; (/ count 4))) ;; (/ count 4)))
;; (goto-char (point-max)) ;; (goto-char (point-max))
(insert "\n") (insert "\n")
(write-file fname)) (write-file fname)))
(kill-buffer (current-buffer)))))) (setq url-history-changed-since-last-save nil))))
(setq url-history-changed-since-last-save nil))
(defun url-have-visited-url (url) (defun url-have-visited-url (url)
(url-do-setup) (url-do-setup)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment