[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] shr-fontified fe9660e 1/9: Rework the indentation to work
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] shr-fontified fe9660e 1/9: Rework the indentation to work more generally |
Date: |
Mon, 09 Feb 2015 10:39:07 +0000 |
branch: shr-fontified
commit fe9660ec03d3de385f8848a263fa1e3464747b29
Author: Lars Magne Ingebrigtsen <address@hidden>
Commit: Lars Magne Ingebrigtsen <address@hidden>
Rework the indentation to work more generally
---
lisp/net/shr.el | 86 ++++++++++++++++++++++++++++---------------------------
1 files changed, 44 insertions(+), 42 deletions(-)
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index de8f015..263bf16 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -138,7 +138,6 @@ cid: URL as the argument.")
;;; Internal variables.
(defvar shr-folding-mode nil)
-(defvar shr-state nil)
(defvar shr-start nil)
(defvar shr-font-cache nil)
(defvar shr-fill-cache nil)
@@ -213,7 +212,6 @@ DOM should be a parse tree as generated by
`libxml-parse-html-region' or similar."
(setq shr-content-cache nil)
(let ((start (point))
- (shr-state nil)
(shr-start nil)
(shr-base nil)
(shr-depth 0)
@@ -222,7 +220,10 @@ DOM should be a parse tree as generated by
(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
+ (shr-internal-width (or (and shr-width
+ (if (not shr-use-fonts)
+ shr-width
+ (* shr-width (frame-char-width))))
(if (not shr-use-fonts)
(- (window-width) 2)
(- (window-pixel-width)
@@ -439,7 +440,6 @@ size, and full-buffer size."
text
(with-temp-buffer
(let ((shr-indentation 0)
- (shr-state nil)
(shr-start nil)
(shr-internal-width (- (window-pixel-width)
(* (frame-fringe-width) 2))))
@@ -478,16 +478,16 @@ size, and full-buffer size."
(car (window-text-pixel-size nil (line-beginning-position) (point))))))
(defun shr-string-pixel-width (string)
- (with-temp-buffer
- (insert string)
- (shr-pixel-column)))
+ (if (not shr-use-fonts)
+ (length string)
+ (with-temp-buffer
+ (insert string)
+ (shr-pixel-column))))
(defun shr-insert (text)
- (when (and (eq shr-state 'image)
- (not (bolp))
- (not (string-match "\\`[ \t\n]+\\'" text)))
- (insert "\n")
- (setq shr-state nil))
+ (when (and (not (bolp))
+ (get-text-property (1- (point)) 'image-url))
+ (insert "\n"))
(cond
((eq shr-folding-mode 'none)
(insert text))
@@ -512,8 +512,8 @@ size, and full-buffer size."
(unless (= start (point))
;; Mark all lines that should possibly be folded afterwards.
(when bolp
- (put-text-property start (1+ start)
- 'shr-indentation shr-indentation))
+ (shr-indent)
+ (shr-mark-fill start))
(when shr-use-fonts
(put-text-property start (point) 'face
(or shr-current-font 'variable-pitch))))))))
@@ -543,6 +543,7 @@ size, and full-buffer size."
(defun shr-fold-line ()
(let ((shr-indentation (get-text-property (point) 'shr-indentation)))
(put-text-property (point) (1+ (point)) 'shr-indentation nil)
+ (shr-indent)
(shr-vertical-motion shr-internal-width)
(while (not (eolp))
;; We have to do some folding. First find the first
@@ -717,8 +718,8 @@ size, and full-buffer size."
(propertize " "
'display
`(space :width (,(if (not shr-use-fonts)
- (* shr-indentation (frame-char-width))
- shr-indentation)))))))
+ (* shr-indentation (frame-char-width))
+ shr-indentation)))))))
(defun shr-fontize-dom (dom &rest types)
(let (shr-start)
@@ -1125,13 +1126,11 @@ ones, in case fg and bg are nil."
(defun shr-tag-p (dom)
(shr-ensure-paragraph)
- (shr-indent)
(shr-generic dom)
(shr-ensure-paragraph))
(defun shr-tag-div (dom)
(shr-ensure-newline)
- (shr-indent)
(shr-generic dom)
(shr-ensure-newline))
@@ -1151,7 +1150,8 @@ ones, in case fg and bg are nil."
(shr-fontize-dom dom 'italic))
(defun shr-tag-strong (dom)
- (shr-fontize-dom dom 'bold))
+ (let ((shr-current-font '(variable-pitch (:weight bold))))
+ (shr-fontize-dom dom 'bold)))
(defun shr-tag-u (dom)
(shr-fontize-dom dom 'underline))
@@ -1301,8 +1301,7 @@ The preference is a float determined from
`shr-prefer-media-type'."
(when (or url
(and dom
(> (length (dom-attr dom 'src)) 0)))
- (when (and (> (current-column) 0)
- (not (eq shr-state 'image)))
+ (when (> (current-column) 0)
(insert "\n"))
(let ((alt (dom-attr dom 'alt))
(url (shr-expand-url (or url (dom-attr dom 'src)))))
@@ -1332,10 +1331,9 @@ The preference is a float determined from
`shr-prefer-media-type'."
(and shr-blocked-images
(string-match shr-blocked-images url)))
(setq shr-start (point))
- (let ((shr-state 'space))
- (if (> (string-width alt) 8)
- (shr-insert (truncate-string-to-width alt 8))
- (shr-insert alt))))
+ (if (> (string-width alt) 8)
+ (shr-insert (truncate-string-to-width alt 8))
+ (shr-insert alt)))
((and (not shr-ignore-cache)
(url-is-cached (shr-encode-url url)))
(funcall shr-put-image-function (shr-get-image-data url) alt))
@@ -1357,24 +1355,24 @@ The preference is a float determined from
`shr-prefer-media-type'."
(put-text-property start (point) 'image-displayer
(shr-image-displayer shr-content-function))
(put-text-property start (point) 'help-echo
- (shr-fold-text (or (dom-attr dom 'title) alt))))
- (setq shr-state 'image)))))
+ (shr-fold-text
+ (or (dom-attr dom 'title) alt))))))))
(defun shr-tag-pre (dom)
(let ((shr-folding-mode 'none)
(shr-current-font 'default))
(shr-ensure-newline)
- (shr-indent)
(shr-generic dom)
(shr-ensure-newline)))
(defun shr-tag-blockquote (dom)
(shr-ensure-paragraph)
- (shr-indent)
- (let ((shr-indentation (+ shr-indentation
- (* 4 shr-table-separator-pixel-width))))
- (shr-generic dom))
- (shr-ensure-paragraph))
+ (let ((start (point)))
+ (let ((shr-indentation (+ shr-indentation
+ (* 4 shr-table-separator-pixel-width))))
+ (shr-generic dom)
+ (shr-ensure-paragraph)
+ (shr-mark-fill start))))
(defun shr-tag-dl (dom)
(shr-ensure-paragraph)
@@ -1407,7 +1405,6 @@ The preference is a float determined from
`shr-prefer-media-type'."
(defun shr-tag-li (dom)
(shr-ensure-newline)
(let ((start (point)))
- (shr-indent)
(let* ((bullet
(if (numberp shr-list-mode)
(prog1
@@ -1418,8 +1415,11 @@ The preference is a float determined from
`shr-prefer-media-type'."
(shr-string-pixel-width bullet))))
(insert bullet)
(shr-generic dom)
- (put-text-property start (1+ start)
- 'shr-indentation shr-indentation))))
+ (shr-mark-fill start))))
+
+(defun shr-mark-fill (start)
+ (put-text-property start (1+ start)
+ 'shr-indentation shr-indentation))
(defun shr-tag-br (dom)
(when (and (not (bobp))
@@ -1428,8 +1428,7 @@ The preference is a float determined from
`shr-prefer-media-type'."
(or (not (bolp))
(and (> (- (point) 2) (point-min))
(not (= (char-after (- (point) 2)) ?\n)))))
- (insert "\n")
- (shr-indent))
+ (insert "\n"))
(shr-generic dom))
(defun shr-tag-span (dom)
@@ -1752,7 +1751,7 @@ The preference is a float determined from
`shr-prefer-media-type'."
widths))
(defun shr-make-table (dom widths &optional fill storage-attribute)
- (or (cadr (assoc (list dom widths fill) shr-content-cache))
+ (or (and nil (cadr (assoc (list dom widths fill) shr-content-cache)))
(let ((data (shr-make-table-1 dom widths fill)))
(push (list (list dom widths fill) data)
shr-content-cache)
@@ -1910,9 +1909,12 @@ The preference is a float determined from
`shr-prefer-media-type'."
(shr-dom-max-natural-width dom 0))))
(dom-set-attribute dom 'shr-td-cache-natural natural)
natural))))
- (let ((shr-internal-width width))
- (shr-fold-lines (point-min) (point-max))
- (setq max-width (shr-pixel-buffer-width))))
+ (if (and natural-width
+ (<= natural-width width))
+ (setq max-width natural-width)
+ (let ((shr-internal-width width))
+ (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.
(delete-region
- [Emacs-diffs] shr-fontified updated (70199c1 -> 35d95a2), Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified 1376a51 2/9: shr/Gnus face fixup and <li> rendering fix, Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified fe9660e 1/9: Rework the indentation to work more generally,
Lars Ingebrigtsen <=
- [Emacs-diffs] shr-fontified b0e3d92 3/9: (shr-fold-line): Handle lines that end with a space at the fill point., Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified 217e202 5/9: Further colspan fixes, Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified 659202a 6/9: Fix up last change to really get colspans right, Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified 8180e53 7/9: (shr-fold-line): Keep breaking unbreakable text., Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified 1d5d72e 4/9: shr filling fix-ups, Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified 25f55f7 8/9: Don't infloop on unbreakable, indented lines, Lars Ingebrigtsen, 2015/02/09
- [Emacs-diffs] shr-fontified 35d95a2 9/9: (shr-insert-table): Expand table alignments in any buffer at the end., Lars Ingebrigtsen, 2015/02/09