]> code.delx.au - gnu-emacs/blobdiff - lisp/url/url-history.el
Bump version to 23.2.
[gnu-emacs] / lisp / url / url-history.el
index 1ed3c71174ede4cc0e914ca1d90889db554621a2..5b4f330ed2e35f56f2aa61f3e99d077f1264fcd2 100644 (file)
@@ -1,26 +1,24 @@
 ;;; url-history.el --- Global history tracking for URL package
 
 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004,
-;;   2005, 2006, 2007 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Keywords: comm, data, processes, hypermedia
 
 ;; This file is part of GNU Emacs.
 ;;
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
-;;
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
-;;
+
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -28,7 +26,6 @@
 
 ;; This can get a recursive require.
 ;;(require 'url)
-(eval-when-compile (require 'cl))
 (require 'url-parse)
 (autoload 'url-do-setup "url")
 
@@ -83,8 +80,9 @@ to run the `url-history-setup-save-timer' function manually."
 (defun url-history-setup-save-timer ()
   "Reset the history list timer."
   (interactive)
-  (ignore-errors
-   (cancel-timer url-history-timer))
+  (condition-case nil
+      (cancel-timer url-history-timer)
+    (error nil))
   (setq url-history-timer nil)
   (if (and (eq url-history-track t) url-history-save-interval)
       (setq url-history-timer (run-at-time url-history-save-interval
@@ -112,27 +110,28 @@ to run the `url-history-setup-save-timer' function manually."
   (puthash (if (vectorp url) (url-recreate-url url) url) time
            url-history-hash-table))
 
+(autoload 'url-make-private-file "url-util")
+
 (defun url-history-save-history (&optional fname)
   "Write the global history file into `url-history-file'.
 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
 user for what type to save as."
   (interactive)
-  (or fname (setq fname (expand-file-name url-history-file)))
-  (unless (file-directory-p (file-name-directory fname))
-    (ignore-errors (make-directory (file-name-directory fname))))
-  (cond
-   ((not url-history-changed-since-last-save) nil)
-   ((not (file-writable-p fname))
-    (message "%s is unwritable." fname))
-   (t
-    (let ((make-backup-files nil)
-         (version-control nil)
-         (require-final-newline t))
-      (with-current-buffer (get-buffer-create " *url-tmp*")
-       (erase-buffer)
-       (let ((count 0))
-         (maphash (lambda (key value)
+  (when url-history-changed-since-last-save
+    (or fname (setq fname (expand-file-name url-history-file)))
+    (if (condition-case nil
+            (progn
+              (url-make-private-file fname)
+              nil)
+          (error t))
+        (message "Error accessing history file `%s'" fname)
+      (let ((make-backup-files nil)
+            (version-control nil)
+            (require-final-newline t)
+            (count 0))
+        (with-temp-buffer
+          (maphash (lambda (key value)
                      (while (string-match "[\r\n]+" key)
                        (setq key (concat (substring key 0 (match-beginning 0))
                                          (substring key (match-end 0) nil))))
@@ -151,9 +150,8 @@ user for what type to save as."
          ;;          (/ count 4)))
          ;; (goto-char (point-max))
          (insert "\n")
-         (write-file fname))
-       (kill-buffer (current-buffer))))))
-  (setq url-history-changed-since-last-save nil))
+         (write-file fname)))
+      (setq url-history-changed-since-last-save nil))))
 
 (defun url-have-visited-url (url)
   (url-do-setup)