Fix typo.
[gnus] / lisp / shr.el
index ebd8549..f2d8f84 100644 (file)
@@ -53,17 +53,17 @@ fit these criteria."
   :group 'shr
   :type 'regexp)
 
-(defcustom shr-table-horizontal-line ? 
+(defcustom shr-table-horizontal-line ?\s
   "Character used to draw horizontal table lines."
   :group 'shr
   :type 'character)
 
-(defcustom shr-table-vertical-line ? 
+(defcustom shr-table-vertical-line ?\s
   "Character used to draw vertical table lines."
   :group 'shr
   :type 'character)
 
-(defcustom shr-table-corner ? 
+(defcustom shr-table-corner ?\s
   "Character used to draw table corners."
   :group 'shr
   :type 'character)
@@ -112,6 +112,7 @@ cid: URL as the argument.")
 (defvar shr-table-depth 0)
 (defvar shr-stylesheet nil)
 (defvar shr-base nil)
+(defvar shr-ignore-cache nil)
 
 (defvar shr-map
   (let ((map (make-sparse-keymap)))
@@ -183,14 +184,23 @@ redirects somewhere else."
        (message "No image under point")
       (message "%s" text))))
 
-(defun shr-browse-image ()
-  "Browse the image under point."
-  (interactive)
+(defun shr-browse-image (&optional copy-url)
+  "Browse the image under point.
+If COPY-URL (the prefix if called interactively) is non-nil, copy
+the URL of the image to the kill buffer instead."
+  (interactive "P")
   (let ((url (get-text-property (point) 'image-url)))
-    (if (not url)
-       (message "No image under point")
+    (cond
+     ((not url)
+      (message "No image under point"))
+     (copy-url
+      (with-temp-buffer
+       (insert url)
+       (copy-region-as-kill (point-min) (point-max))
+       (message "Copied %s" url)))
+     (t
       (message "Browsing %s..." url)
-      (browse-url url))))
+      (browse-url url)))))
 
 (defun shr-insert-image ()
   "Insert the image under point into the buffer."
@@ -517,15 +527,18 @@ redirects somewhere else."
          (when (and (> (current-column) 0)
                     (> (car (image-size image t)) 400))
            (insert "\n"))
-         (insert-image image (or alt "*")))
+         (insert-image image (or alt "*"))
+         (when (image-animated-p image)
+           (image-animate image nil 60)))
        image)
     (insert alt)))
 
 (defun shr-rescale-image (data)
   (if (or (not (fboundp 'imagemagick-types))
          (not (get-buffer-window (current-buffer))))
-      (create-image data nil t)
-    (let* ((image (create-image data nil t))
+      (create-image data nil t
+                   :ascent 100)
+    (let* ((image (create-image data nil t :ascent 100))
           (size (image-size image t))
           (width (car size))
           (height (cdr size))
@@ -544,11 +557,9 @@ redirects somewhere else."
       (when (> (car size) window-width)
        (setq image (or
                     (create-image data 'imagemagick t
-                                  :width window-width)
+                                  :width window-width
+                                  :ascent 100)
                     image)))
-      (when (and (fboundp 'create-animated-image)
-                (eq (image-type data nil t) 'gif))
-       (setq image (create-animated-image data 'gif t)))
       image)))
 
 ;; url-cache-extract autoloads url-cache.
@@ -572,7 +583,7 @@ Return a string with image data."
   "Return a function to display an image.
 CONTENT-FUNCTION is a function to retrieve an image for a cid url that
 is an argument.  The function to be returned takes three arguments URL,
-START, and END.  Note that START and END should be merkers."
+START, and END.  Note that START and END should be markers."
   `(lambda (url start end)
      (when url
        (if (string-match "\\`cid:" url)
@@ -751,6 +762,9 @@ ones, in case fg and bg are nil."
 (defun shr-tag-script (cont)
   )
 
+(defun shr-tag-comment (cont)
+  )
+
 (defun shr-tag-sup (cont)
   (let ((start (point)))
     (shr-generic cont)
@@ -883,23 +897,30 @@ ones, in case fg and bg are nil."
            (if (> (string-width alt) 8)
                (shr-insert (truncate-string-to-width alt 8))
              (shr-insert alt))))
-        ((url-is-cached (shr-encode-url url))
+        ((and (not shr-ignore-cache)
+              (url-is-cached (shr-encode-url url)))
          (funcall shr-put-image-function (shr-get-image-data url) alt))
         (t
-         (insert alt)
+         (insert alt " ")
+         (when (and shr-ignore-cache
+                    (url-is-cached (shr-encode-url url)))
+           (let ((file (url-cache-create-filename (shr-encode-url url))))
+             (when (file-exists-p file)
+               (delete-file file))))
          (funcall
           (if (fboundp 'url-queue-retrieve)
               'url-queue-retrieve
             'url-retrieve)
           (shr-encode-url url) 'shr-image-fetched
-          (list (current-buffer) start (point-marker))
+          (list (current-buffer) start (set-marker (make-marker) (1- (point))))
           t)))
-       (put-text-property start (point) 'keymap shr-map)
-       (put-text-property start (point) 'shr-alt alt)
-       (put-text-property start (point) 'image-url url)
-       (put-text-property start (point) 'image-displayer
-                          (shr-image-displayer shr-content-function))
-       (put-text-property start (point) 'help-echo alt)
+       (when (zerop shr-table-depth) ;; We are not in a table.
+         (put-text-property start (point) 'keymap shr-map)
+         (put-text-property start (point) 'shr-alt alt)
+         (put-text-property start (point) 'image-url url)
+         (put-text-property start (point) 'image-displayer
+                            (shr-image-displayer shr-content-function))
+         (put-text-property start (point) 'help-echo alt))
        (setq shr-state 'image)))))
 
 (defun shr-tag-pre (cont)
@@ -1035,44 +1056,53 @@ ones, in case fg and bg are nil."
         (nheader (if header (shr-max-columns header)))
         (nbody (if body (shr-max-columns body)))
         (nfooter (if footer (shr-max-columns footer))))
-    (shr-tag-table-1
-     (nconc
-      (if caption `((tr (td ,@caption))))
-      (if header
-         (if footer
-             ;; hader + body + footer
+    (if (and (not caption)
+            (not header)
+            (not (cdr (assq 'tbody cont)))
+            (not (cdr (assq 'tr cont)))
+            (not footer))
+       ;; The table is totally invalid and just contains random junk.
+       ;; Try to output it anyway.
+       (shr-generic cont)
+      ;; It's a real table, so render it.
+      (shr-tag-table-1
+       (nconc
+       (if caption `((tr (td ,@caption))))
+       (if header
+           (if footer
+               ;; hader + body + footer
+               (if (= nheader nbody)
+                   (if (= nbody nfooter)
+                       `((tr (td (table (tbody ,@header ,@body ,@footer)))))
+                     (nconc `((tr (td (table (tbody ,@header ,@body)))))
+                            (if (= nfooter 1)
+                                footer
+                              `((tr (td (table (tbody ,@footer))))))))
+                 (nconc `((tr (td (table (tbody ,@header)))))
+                        (if (= nbody nfooter)
+                            `((tr (td (table (tbody ,@body ,@footer)))))
+                          (nconc `((tr (td (table (tbody ,@body)))))
+                                 (if (= nfooter 1)
+                                     footer
+                                   `((tr (td (table (tbody ,@footer))))))))))
+             ;; header + body
              (if (= nheader nbody)
-                 (if (= nbody nfooter)
-                     `((tr (td (table (tbody ,@header ,@body ,@footer)))))
-                   (nconc `((tr (td (table (tbody ,@header ,@body)))))
-                          (if (= nfooter 1)
-                              footer
-                            `((tr (td (table (tbody ,@footer))))))))
-               (nconc `((tr (td (table (tbody ,@header)))))
-                      (if (= nbody nfooter)
-                          `((tr (td (table (tbody ,@body ,@footer)))))
-                        (nconc `((tr (td (table (tbody ,@body)))))
-                               (if (= nfooter 1)
-                                   footer
-                                 `((tr (td (table (tbody ,@footer))))))))))
-           ;; header + body
-           (if (= nheader nbody)
-               `((tr (td (table (tbody ,@header ,@body)))))
-             (if (= nheader 1)
-                 `(,@header (tr (td (table (tbody ,@body)))))
-               `((tr (td (table (tbody ,@header))))
-                 (tr (td (table (tbody ,@body))))))))
-       (if footer
-           ;; body + footer
-           (if (= nbody nfooter)
-               `((tr (td (table (tbody ,@body ,@footer)))))
-             (nconc `((tr (td (table (tbody ,@body)))))
-                    (if (= nfooter 1)
-                        footer
-                      `((tr (td (table (tbody ,@footer))))))))
-         (if caption
-             `((tr (td (table (tbody ,@body)))))
-           body)))))
+                 `((tr (td (table (tbody ,@header ,@body)))))
+               (if (= nheader 1)
+                   `(,@header (tr (td (table (tbody ,@body)))))
+                 `((tr (td (table (tbody ,@header))))
+                   (tr (td (table (tbody ,@body))))))))
+         (if footer
+             ;; body + footer
+             (if (= nbody nfooter)
+                 `((tr (td (table (tbody ,@body ,@footer)))))
+               (nconc `((tr (td (table (tbody ,@body)))))
+                      (if (= nfooter 1)
+                          footer
+                        `((tr (td (table (tbody ,@footer))))))))
+           (if caption
+               `((tr (td (table (tbody ,@body)))))
+             body))))))
     (when bgcolor
       (shr-colorize-region start (point) (cdr (assq 'color shr-stylesheet))
                           bgcolor))))