Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / url / url-util.el
index 6fc9944..6bf3a58 100644 (file)
@@ -1,7 +1,6 @@
 ;;; url-util.el --- Miscellaneous helper routines for URL library
 
-;; Copyright (C) 1996, 1997, 1998, 1999, 2001, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1996-1999, 2001, 2004-2011  Free Software Foundation, Inc.
 
 ;; Author: Bill Perry <wmperry@gnu.org>
 ;; Keywords: comm, data, processes
@@ -26,6 +25,7 @@
 ;;; Code:
 
 (require 'url-parse)
+(require 'url-vars)
 (eval-when-compile (require 'cl))
 (autoload 'timezone-parse-date "timezone")
 (autoload 'timezone-make-date-arpa-standard "timezone")
@@ -42,7 +42,7 @@
 
 ;;;###autoload
 (defcustom url-debug nil
-  "*What types of debug messages from the URL library to show.
+  "What types of debug messages from the URL library to show.
 Debug messages are logged to the *URL-DEBUG* buffer.
 
 If t, all messages will be logged.
@@ -140,8 +140,7 @@ Also replaces the \" character, so that the result may be safely used as
     >  ==>  &gt;
     \"  ==>  &quot;"
   (if (string-match "[&<>\"]" string)
-      (save-excursion
-       (set-buffer (get-buffer-create " *entity*"))
+      (with-current-buffer (get-buffer-create " *entity*")
        (erase-buffer)
        (buffer-disable-undo (current-buffer))
        (insert string)
@@ -167,6 +166,8 @@ Strips out default port numbers, etc."
          type (url-type data))
     (if (member type '("www" "about" "mailto" "info"))
        (setq retval url)
+      ;; FIXME all this does, and all this function seems to do in
+      ;; most cases, is remove any trailing "#anchor" part of a url.
       (setf (url-target data) nil)
       (setq retval (url-recreate-url data)))
     retval))
@@ -175,7 +176,9 @@ Strips out default port numbers, etc."
 (defun url-lazy-message (&rest args)
   "Just like `message', but is a no-op if called more than once a second.
 Will not do anything if `url-show-status' is nil."
-  (if (or (null url-show-status)
+  (if (or (and url-current-object
+              (url-silent url-current-object))
+         (null url-show-status)
          (active-minibuffer-window)
          (= url-lazy-message-time
             (setq url-lazy-message-time (nth 1 (current-time)))))
@@ -220,7 +223,9 @@ Will not do anything if `url-show-status' is nil."
 
 ;;;###autoload
 (defun url-display-percentage (fmt perc &rest args)
-  (when url-show-status
+  (when (and url-show-status
+            (or (null url-current-object)
+                (not (url-silent url-current-object))))
     (if (null fmt)
        (if (fboundp 'clear-progress-display)
            (clear-progress-display))
@@ -234,12 +239,15 @@ Will not do anything if `url-show-status' is nil."
       (round (* 100 (/ x (float y))))
     (/ (* x 100) y)))
 
+;;;###autoload
+(defalias 'url-basepath 'url-file-directory)
+
 ;;;###autoload
 (defun url-file-directory (file)
   "Return the directory part of FILE, for a URL."
   (cond
    ((null file) "")
-   ((string-match (eval-when-compile (regexp-quote "?")) file)
+   ((string-match "\\?" file)
     (file-name-directory (substring file 0 (match-beginning 0))))
    (t (file-name-directory file))))
 
@@ -248,7 +256,7 @@ Will not do anything if `url-show-status' is nil."
   "Return the nondirectory part of FILE, for a URL."
   (cond
    ((null file) "")
-   ((string-match (eval-when-compile (regexp-quote "?")) file)
+   ((string-match "\\?" file)
     (file-name-nondirectory (substring file 0 (match-beginning 0))))
    (t (file-name-nondirectory file))))
 
@@ -301,7 +309,7 @@ Will not do anything if `url-show-status' is nil."
 
 ;;;###autoload
 (defun url-unhex-string (str &optional allow-newlines)
-  "Remove %XX embedded spaces, etc in a url.
+  "Remove %XX embedded spaces, etc in a URL.
 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
 decoding of carriage returns and line feeds in the string, which is normally
 forbidden in URL encoding."
@@ -317,10 +325,10 @@ forbidden in URL encoding."
                   tmp (substring str 0 start)
                   (cond
                    (allow-newlines
-                    (char-to-string code))
+                    (byte-to-string code))
                    ((or (= code ?\n) (= code ?\r))
                     " ")
-                   (t (char-to-string code))))
+                   (t (byte-to-string code))))
              str (substring str (match-end 0)))))
     (setq tmp (concat tmp str))
     tmp))
@@ -342,7 +350,7 @@ character in the utf-8 string, those found in `url-unreserved-chars'
 are left as-is, all others are represented as a three-character
 string: \"%\" followed by two lowercase hex digits."
   ;; To go faster and avoid a lot of consing, we could do:
-  ;; 
+  ;;
   ;; (defconst url-hexify-table
   ;;   (let ((map (make-vector 256 nil)))
   ;;     (dotimes (byte 256) (aset map byte
@@ -364,8 +372,8 @@ string: \"%\" followed by two lowercase hex digits."
 ;;;###autoload
 (defun url-file-extension (fname &optional x)
   "Return the filename extension of FNAME.
-If optional variable X is t,
-then return the basename of the file with the extension stripped off."
+If optional argument X is t, then return the basename
+of the file with the extension stripped off."
   (if (and fname
           (setq fname (url-file-nondirectory fname))
           (string-match "\\.[^./]+$" fname))
@@ -382,7 +390,7 @@ then return the basename of the file with the extension stripped off."
 
 ;;;###autoload
 (defun url-truncate-url-for-viewing (url &optional width)
-  "Return a shortened version of URL that is WIDTH characters or less wide.
+  "Return a shortened version of URL that is WIDTH characters wide or less.
 WIDTH defaults to the current frame width."
   (let* ((fr-width (or width (frame-width)))
         (str-width (length url))
@@ -427,10 +435,8 @@ This uses `url-current-object', set locally to the buffer."
        (url-recreate-url url-current-object)
       (message "%s" (url-recreate-url url-current-object)))))
 
-(eval-and-compile
-  (defvar url-get-url-filename-chars "-%.?@a-zA-Z0-9()_/:~=&"
-    "Valid characters in a URL")
-  )
+(defvar url-get-url-filename-chars "-%.?@a-zA-Z0-9()_/:~=&"
+  "Valid characters in a URL.")
 
 (defun url-get-url-at-point (&optional pt)
   "Get the URL closest to point, but don't change position.
@@ -448,8 +454,7 @@ Has a preference for looking backward when not directly on a symbol."
                  (if (not (bobp))
                      (backward-char 1)))))
        (if (and (char-after (point))
-                (string-match (eval-when-compile
-                                (concat "[" url-get-url-filename-chars "]"))
+                (string-match (concat "[" url-get-url-filename-chars "]")
                               (char-to-string (char-after (point)))))
            (progn
              (skip-chars-backward url-get-url-filename-chars)
@@ -471,25 +476,28 @@ Has a preference for looking backward when not directly on a symbol."
 
 (defun url-generate-unique-filename (&optional fmt)
   "Generate a unique filename in `url-temporary-directory'."
-  (if (not fmt)
-      (let ((base (format "url-tmp.%d" (user-real-uid)))
+  ;; This variable is obsolete, but so is this function.
+  (let ((tempdir (with-no-warnings url-temporary-directory)))
+    (if (not fmt)
+       (let ((base (format "url-tmp.%d" (user-real-uid)))
+             (fname "")
+             (x 0))
+         (setq fname (format "%s%d" base x))
+         (while (file-exists-p
+                 (expand-file-name fname tempdir))
+           (setq x (1+ x)
+                 fname (concat base (int-to-string x))))
+         (expand-file-name fname tempdir))
+      (let ((base (concat "url" (int-to-string (user-real-uid))))
            (fname "")
            (x 0))
-       (setq fname (format "%s%d" base x))
+       (setq fname (format fmt (concat base (int-to-string x))))
        (while (file-exists-p
-               (expand-file-name fname url-temporary-directory))
+               (expand-file-name fname tempdir))
          (setq x (1+ x)
-               fname (concat base (int-to-string x))))
-       (expand-file-name fname url-temporary-directory))
-    (let ((base (concat "url" (int-to-string (user-real-uid))))
-         (fname "")
-         (x 0))
-      (setq fname (format fmt (concat base (int-to-string x))))
-      (while (file-exists-p
-             (expand-file-name fname url-temporary-directory))
-       (setq x (1+ x)
-             fname (format fmt (concat base (int-to-string x)))))
-      (expand-file-name fname url-temporary-directory))))
+               fname (format fmt (concat base (int-to-string x)))))
+       (expand-file-name fname tempdir)))))
+(make-obsolete 'url-generate-unique-filename 'make-temp-file "23.1")
 
 (defun url-extract-mime-headers ()
   "Set `url-current-mime-headers' in current buffer."
@@ -523,5 +531,4 @@ Creates FILE and its parent directories if they do not exist."
 
 (provide 'url-util)
 
-;; arch-tag: 24352abc-5a5a-412e-90cd-313b26bed5c9
 ;;; url-util.el ends here