emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] shr-fontified ef5a49e 7/7: (shr-insert-table-ruler): Compu


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] shr-fontified ef5a49e 7/7: (shr-insert-table-ruler): Compute the separator pixel width only once.
Date: Sat, 07 Feb 2015 04:09:54 +0000

branch: shr-fontified
commit ef5a49ec183fb673459217c27f22196b4b438602
Author: Lars Magne Ingebrigtsen <address@hidden>
Commit: Lars Magne Ingebrigtsen <address@hidden>

    (shr-insert-table-ruler): Compute the separator pixel width only once.
---
 lisp/ChangeLog  |    1 +
 lisp/net/shr.el |   44 +++++++++++++++++++++++++-------------------
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 708a535..ea5e500 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -2,6 +2,7 @@
 
        * net/shr.el (shr-tag-table-1): Add further caching when computing
        natural and sketch widths.
+       (shr-insert-table-ruler): Compute the separator pixel width only once.
 
 2015-02-06  Lars Ingebrigtsen  <address@hidden>
 
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 5f0465e..b401db8 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -151,6 +151,7 @@ cid: URL as the argument.")
 (defvar shr-target-id nil)
 (defvar shr-inhibit-decoration nil)
 (defvar shr-table-separator-length 1)
+(defvar shr-table-separator-pixel-width 0)
 
 (defvar shr-map
   (let ((map (make-sparse-keymap)))
@@ -210,6 +211,7 @@ DOM should be a parse tree as generated by
        (shr-depth 0)
        (shr-table-id 0)
        (shr-warning nil)
+       (shr-table-separator-pixel-width (shr-string-pixel-width "-"))
        (shr-font-cache (make-hash-table :test 'eq))
        (shr-fill-cache (make-hash-table :test 'equal))
        (shr-internal-width (or shr-width
@@ -503,18 +505,16 @@ size, and full-buffer size."
 
 (defun shr-fold-lines (start end)
   (if (<= shr-internal-width 0)
-      0
-    (let ((max-width 0))
-      (save-restriction
-       (narrow-to-region start end)
+      nil
+    (save-restriction
+      (narrow-to-region start end)
+      (goto-char start)
+      (when (get-text-property (point) 'shr-indentation)
+       (shr-fold-line))
+      (while (setq start (next-single-property-change start 'shr-indentation))
        (goto-char start)
-       (when (get-text-property (point) 'shr-indentation)
-         (shr-fold-line))
-       (while (setq start (next-single-property-change start 'shr-indentation))
-         (goto-char start)
-         (shr-fold-line))
-       (goto-char (point-max))
-       max-width))))
+       (shr-fold-line))
+      (goto-char (point-max)))))
 
 (defun shr-goto-pixel-column (pixels)
   (vertical-motion (cons (/ pixels (frame-char-width)) 0))
@@ -523,13 +523,16 @@ size, and full-buffer size."
   (unless (eolp)
     (forward-char 1)))
 
+(defun shr-vertical-motion (spec)
+  (vertical-motion spec))
+
 (defun shr-fold-line ()
   (let ((indentation (get-text-property (point) 'shr-indentation))
        (spec (cons (/ shr-internal-width (frame-char-width)) 0)))
     (put-text-property (point) (1+ (point)) 'shr-indentation nil)
     (when (> indentation 0)
       (insert (make-string indentation ?\s)))
-    (vertical-motion spec)
+    (shr-vertical-motion spec)
     (unless (eolp)
       (forward-char 1))
     (while (not (eolp))
@@ -539,7 +542,7 @@ size, and full-buffer size."
       (when (= (preceding-char) ?\s)
        (delete-char -1))
       (insert "\n")
-      (vertical-motion spec)
+      (shr-vertical-motion spec)
       (unless (eolp)
        (forward-char 1)))))
 
@@ -1671,7 +1674,7 @@ The preference is a float determined from 
`shr-prefer-media-type'."
       (dotimes (i (length widths))
        (setq total-width (+ total-width (aref widths i) 20))
        (insert (make-string (1+ (/ (aref widths i)
-                                   (shr-string-pixel-width "-")))
+                                   shr-table-separator-pixel-width))
                             shr-table-horizontal-line)
                (propertize " "
                            'display `(space :align-to (,total-width))
@@ -1800,9 +1803,11 @@ The preference is a float determined from 
`shr-prefer-media-type'."
     (nreverse trs)))
 
 (defun shr-pixel-buffer-width ()
-  (save-window-excursion
-    (set-window-buffer nil (current-buffer))
-    (car (window-text-pixel-size nil (point-min) (point-max)))))
+  (if (get-buffer-window)
+      (car (window-text-pixel-size nil (point-min) (point-max)))
+    (save-window-excursion
+      (set-window-buffer nil (current-buffer))
+      (car (window-text-pixel-size nil (point-min) (point-max))))))
 
 (defun shr-render-td (dom width fill)
   (with-temp-buffer
@@ -1824,7 +1829,8 @@ The preference is a float determined from 
`shr-prefer-media-type'."
            (shr-indentation 0))
        (shr-descend dom))
       (let ((shr-internal-width width))
-       (shr-fold-lines (point-min) (point-max))
+       (unless (= shr-internal-width 5000)
+         (shr-fold-lines (point-min) (point-max)))
        (setq max-width (shr-pixel-buffer-width)))
       (goto-char (point-max))
       ;; Delete padding at the bottom of the TDs.
@@ -1866,7 +1872,7 @@ The preference is a float determined from 
`shr-prefer-media-type'."
                                       total-percentage
                                       (- shr-internal-width
                                           (* (1+ (length columns))
-                                            (shr-string-pixel-width "-")))))
+                                            shr-table-separator-pixel-width))))
                          10)))
     widths))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]