aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2013-06-17 10:51:54 +0000
committerKatsumi Yamaoka2013-06-17 10:51:54 +0000
commit544d4594cb3e9945dc3a512e619d3cf2759fc86a (patch)
tree877df50cc596fcb4bc0e8b8342cff66d9a66fdd7
parent372c83bad63caefa7cd111acc1af63378fee2418 (diff)
downloademacs-544d4594cb3e9945dc3a512e619d3cf2759fc86a.tar.gz
emacs-544d4594cb3e9945dc3a512e619d3cf2759fc86a.zip
lisp/gnus/mm-decode.el (mm-convert-shr-links): Override the shr local map, so that Gnus commands work
lisp/gnus/shr.el (shr-render-td): Support horizontal alignment Make eww use `add-face-text-property', too lisp/gnus/shr.el (shr-make-overlay): Obsolete function lisp/gnus/eww.el (eww-put-color): Removed (eww-colorize-region): Use `add-face-text-property' Get correct presedence for font data lisp/gnus/shr.el (shr-add-font): Append face data, so that we get the correct presedence: The innermost value (which is applied first) wins
-rw-r--r--lisp/gnus/ChangeLog12
-rw-r--r--lisp/gnus/eww.el9
-rw-r--r--lisp/gnus/mm-decode.el1
-rw-r--r--lisp/gnus/shr.el85
4 files changed, 46 insertions, 61 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index 9552078ddb8..7ceaac31e7e 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,5 +1,17 @@
12013-06-17 Lars Magne Ingebrigtsen <larsi@gnus.org> 12013-06-17 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 2
3 * mm-decode.el (mm-convert-shr-links): Override the shr local map, so
4 that Gnus commands work.
5
6 * shr.el (shr-render-td): Support horizontal alignment.
7
8 * eww.el (eww-put-color): Removed.
9 (eww-colorize-region): Use `add-face-text-property'.
10
11 * shr.el (shr-add-font): Append face data, so that we get the correct
12 presedence: The innermost value (which is applied first) wins.
13 (shr-make-overlay): Obsolete function.
14
3 * mm-decode.el (mm-convert-shr-links): New function to convert 15 * mm-decode.el (mm-convert-shr-links): New function to convert
4 new-style shr URL links into widgets. 16 new-style shr URL links into widgets.
5 (mm-shr): Use it. 17 (mm-shr): Use it.
diff --git a/lisp/gnus/eww.el b/lisp/gnus/eww.el
index 6460ee79604..fc0e413248a 100644
--- a/lisp/gnus/eww.el
+++ b/lisp/gnus/eww.el
@@ -172,12 +172,11 @@
172 (let ((new-colors (shr-color-check fg bg))) 172 (let ((new-colors (shr-color-check fg bg)))
173 (when new-colors 173 (when new-colors
174 (when fg 174 (when fg
175 (eww-put-color start end :foreground (cadr new-colors))) 175 (add-face-text-property start end
176 (list :foreground (cadr new-colors))))
176 (when bg 177 (when bg
177 (eww-put-color start end :background (car new-colors))))))) 178 (add-face-text-property start end
178 179 (list :background (car new-colors))))))))
179(defun eww-put-color (start end type color)
180 (shr-put-color-1 start end type color))
181 180
182(defun eww-display-raw (charset) 181(defun eww-display-raw (charset)
183 (let ((data (buffer-substring (point) (point-max)))) 182 (let ((data (buffer-substring (point) (point-max))))
diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el
index 521251845da..971c26e200a 100644
--- a/lisp/gnus/mm-decode.el
+++ b/lisp/gnus/mm-decode.el
@@ -1831,6 +1831,7 @@ If RECURSIVE, search recursively."
1831 :help-echo (get-text-property start 'help-echo) 1831 :help-echo (get-text-property start 'help-echo)
1832 :keymap shr-map 1832 :keymap shr-map
1833 (get-text-property start 'shr-url)) 1833 (get-text-property start 'shr-url))
1834 (put-text-property start end 'local-map nil)
1834 (setq start end))))) 1835 (setq start end)))))
1835 1836
1836(defun mm-handle-filename (handle) 1837(defun mm-handle-filename (handle)
diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el
index b394607dbff..d3b9a362a0b 100644
--- a/lisp/gnus/shr.el
+++ b/lisp/gnus/shr.el
@@ -609,11 +609,6 @@ size, and full-buffer size."
609 (dolist (type types) 609 (dolist (type types)
610 (shr-add-font (or shr-start (point)) (point) type)))) 610 (shr-add-font (or shr-start (point)) (point) type))))
611 611
612(defun shr-make-overlay (beg end &optional buffer front-advance rear-advance)
613 (let ((overlay (make-overlay beg end buffer front-advance rear-advance)))
614 (overlay-put overlay 'evaporate t)
615 overlay))
616
617;; Add face to the region, but avoid putting the font properties on 612;; Add face to the region, but avoid putting the font properties on
618;; blank text at the start of the line, and the newline at the end, to 613;; blank text at the start of the line, and the newline at the end, to
619;; avoid ugliness. 614;; avoid ugliness.
@@ -623,7 +618,7 @@ size, and full-buffer size."
623 (while (< (point) end) 618 (while (< (point) end)
624 (when (bolp) 619 (when (bolp)
625 (skip-chars-forward " ")) 620 (skip-chars-forward " "))
626 (add-face-text-property (point) (min (line-end-position) end) type) 621 (add-face-text-property (point) (min (line-end-position) end) type t)
627 (if (< (line-end-position) end) 622 (if (< (line-end-position) end)
628 (forward-line 1) 623 (forward-line 1)
629 (goto-char end))))) 624 (goto-char end)))))
@@ -843,32 +838,11 @@ ones, in case fg and bg are nil."
843 (let ((new-colors (shr-color-check fg bg))) 838 (let ((new-colors (shr-color-check fg bg)))
844 (when new-colors 839 (when new-colors
845 (when fg 840 (when fg
846 (shr-put-color start end :foreground (cadr new-colors))) 841 (shr-add-font start end (list :foreground (cadr new-colors))))
847 (when bg 842 (when bg
848 (shr-put-color start end :background (car new-colors)))) 843 (shr-add-font start end (list :background (car new-colors)))))
849 new-colors))) 844 new-colors)))
850 845
851;; Put a color in the region, but avoid putting colors on blank
852;; text at the start of the line, and the newline at the end, to avoid
853;; ugliness. Also, don't overwrite any existing color information,
854;; since this can be called recursively, and we want the "inner" color
855;; to win.
856(defun shr-put-color (start end type color)
857 (save-excursion
858 (goto-char start)
859 (while (< (point) end)
860 (when (and (bolp)
861 (not (eq type :background)))
862 (skip-chars-forward " "))
863 (when (> (line-end-position) (point))
864 (shr-put-color-1 (point) (min (line-end-position) end) type color))
865 (if (< (line-end-position) end)
866 (forward-line 1)
867 (goto-char end)))
868 (when (and (eq type :background)
869 (= shr-table-depth 0))
870 (shr-expand-newlines start end color))))
871
872(defun shr-expand-newlines (start end color) 846(defun shr-expand-newlines (start end color)
873 (save-restriction 847 (save-restriction
874 ;; Skip past all white space at the start and ends. 848 ;; Skip past all white space at the start and ends.
@@ -919,24 +893,6 @@ ones, in case fg and bg are nil."
919 'before-string))))) 893 'before-string)))))
920 (+ width previous-width)))) 894 (+ width previous-width))))
921 895
922(defun shr-put-color-1 (start end type color)
923 (let* ((old-props (get-text-property start 'face))
924 (do-put (and (listp old-props)
925 (not (memq type old-props))))
926 change)
927 (while (< start end)
928 (setq change (next-single-property-change start 'face nil end))
929 (when do-put
930 (add-face-text-property start change (list type color)))
931 (setq old-props (get-text-property change 'face))
932 (setq do-put (and (listp old-props)
933 (not (memq type old-props))))
934 (setq start change))
935 (when (and do-put
936 (> end start))
937 (put-text-property start end 'face
938 (nconc (list type color old-props))))))
939
940;;; Tag-specific rendering rules. 896;;; Tag-specific rendering rules.
941 897
942(defun shr-tag-body (cont) 898(defun shr-tag-body (cont)
@@ -1381,7 +1337,8 @@ ones, in case fg and bg are nil."
1381 (insert (make-string (string-width (car lines)) ? ) 1337 (insert (make-string (string-width (car lines)) ? )
1382 shr-table-vertical-line) 1338 shr-table-vertical-line)
1383 (when (nth 4 column) 1339 (when (nth 4 column)
1384 (shr-put-color start (1- (point)) :background (nth 4 column)))) 1340 (shr-add-font start (1- (point))
1341 (list :background (nth 4 column)))))
1385 (forward-line 1))))) 1342 (forward-line 1)))))
1386 (shr-insert-table-ruler widths))) 1343 (shr-insert-table-ruler widths)))
1387 1344
@@ -1492,11 +1449,23 @@ ones, in case fg and bg are nil."
1492 (if (zerop (buffer-size)) 1449 (if (zerop (buffer-size))
1493 (insert (make-string width ? )) 1450 (insert (make-string width ? ))
1494 ;; Otherwise, fill the buffer. 1451 ;; Otherwise, fill the buffer.
1495 (while (not (eobp)) 1452 (let ((align (cdr (assq :align cont)))
1496 (end-of-line) 1453 length)
1497 (when (> (- width (current-column)) 0) 1454 (while (not (eobp))
1498 (insert (make-string (- width (current-column)) ? ))) 1455 (end-of-line)
1499 (forward-line 1))) 1456 (setq length (- width (current-column)))
1457 (when (> length 0)
1458 (cond
1459 ((equal align "right")
1460 (beginning-of-line)
1461 (insert (make-string length ? )))
1462 ((equal align "center")
1463 (insert (make-string (/ length 2) ? ))
1464 (beginning-of-line)
1465 (insert (make-string (- length (/ length 2)) ? )))
1466 (t
1467 (insert (make-string length ? )))))
1468 (forward-line 1))))
1500 (when style 1469 (when style
1501 (setq actual-colors 1470 (setq actual-colors
1502 (shr-colorize-region 1471 (shr-colorize-region
@@ -1567,7 +1536,7 @@ ones, in case fg and bg are nil."
1567 1536
1568;; Emacs less than 24.3 1537;; Emacs less than 24.3
1569(unless (fboundp 'add-face-text-property) 1538(unless (fboundp 'add-face-text-property)
1570 (defun add-face-text-property (beg end face) 1539 (defun add-face-text-property (beg end face &optional appendp object)
1571 "Combine FACE BEG and END." 1540 "Combine FACE BEG and END."
1572 (let ((b beg)) 1541 (let ((b beg))
1573 (while (< b end) 1542 (while (< b end)
@@ -1578,9 +1547,13 @@ ones, in case fg and bg are nil."
1578 face) 1547 face)
1579 ((and (consp oldval) 1548 ((and (consp oldval)
1580 (not (keywordp (car oldval)))) 1549 (not (keywordp (car oldval))))
1581 (cons face oldval)) 1550 (if appendp
1551 (nconc oldval (list face))
1552 (cons face oldval)))
1582 (t 1553 (t
1583 (list face oldval))))))))) 1554 (if appendp
1555 (list oldval face)
1556 (list face oldval))))))))))
1584 1557
1585(provide 'shr) 1558(provide 'shr)
1586 1559