* shr.el (shr-render-td): Use a cache for the table rendering function
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 7 Oct 2010 13:10:01 +0000 (15:10 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 7 Oct 2010 13:10:01 +0000 (15:10 +0200)
to avoid getting an exponential rendering behaviour in nested tables.

lisp/ChangeLog
lisp/shr.el

index eeb3973..92b3b5b 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-07  Lars Magne Ingebrigtsen  <larsi@gnus.org>
+
+       * shr.el (shr-render-td): Use a cache for the table rendering function
+       to avoid getting an exponential rendering behaviour in nested tables.
+
 2010-10-07  Katsumi Yamaoka  <yamaoka@jpl.org>
 
        * gnus-gravatar.el (gnus-gravatar-too-ugly): New user option.
index ffbb430..73011af 100644 (file)
@@ -68,6 +68,7 @@ cid: URL as the argument.")
 (defvar shr-indentation 0)
 (defvar shr-inhibit-images nil)
 (defvar shr-list-mode nil)
+(defvar shr-content-cache nil)
 
 (defvar shr-map
   (let ((map (make-sparse-keymap)))
@@ -83,6 +84,7 @@ cid: URL as the argument.")
 
 ;;;###autoload
 (defun shr-insert-document (dom)
+  (setq shr-content-cache nil)
   (let ((shr-state nil)
        (shr-start nil))
     (shr-descend (shr-transform-dom dom))))
@@ -135,6 +137,17 @@ redirects somewhere else."
       (message "Browsing %s..." url)
       (browse-url url))))
 
+(defun shr-insert-image ()
+  "Insert the image under point into the buffer."
+  (interactive)
+  (let ((url (get-text-property (point) 'shr-image)))
+    (if (not url)
+       (message "No image under point")
+      (message "Inserting %s..." url)
+      (url-retrieve url 'shr-image-fetched
+                   (list (current-buffer) (1- (point)) (point-marker))
+                   t))))
+
 ;;; Utility functions.
 
 (defun shr-transform-dom (dom)
@@ -570,13 +583,18 @@ Return a string with image data."
 
 (defun shr-render-td (cont width fill)
   (with-temp-buffer
-    (let ((shr-width width)
-         (shr-indentation 0))
-      (shr-generic cont))
-    (delete-region
-     (point)
-     (+ (point)
-       (skip-chars-backward " \t\n")))
+    (let ((cache (cdr (assoc (cons width cont) shr-content-cache))))
+      (if cache
+         (insert cache)
+       (let ((shr-width width)
+             (shr-indentation 0))
+         (shr-generic cont))
+       (delete-region
+        (point)
+        (+ (point)
+           (skip-chars-backward " \t\n")))
+       (push (cons (cons width cont) (buffer-string))
+             shr-content-cache)))
     (goto-char (point-min))
     (let ((max 0))
       (while (not (eobp))