diff options
| author | Katsumi Yamaoka | 2010-10-19 07:57:50 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2010-10-19 07:57:50 +0000 |
| commit | 83ffd5713dc075600abc9ddca56cddbe852b81ff (patch) | |
| tree | cc7bd8108dbece270128204798ca9e10b45464fb | |
| parent | a04f9e264c9d5db87ba730951c7ff6bcc7a3412a (diff) | |
| download | emacs-83ffd5713dc075600abc9ddca56cddbe852b81ff.tar.gz emacs-83ffd5713dc075600abc9ddca56cddbe852b81ff.zip | |
shr.el: Improve kinsoku and table rendering.
| -rw-r--r-- | lisp/gnus/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/gnus/shr.el | 71 |
2 files changed, 51 insertions, 32 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 870e41e4996..fbbed031efe 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2010-10-19 Katsumi Yamaoka <yamaoka@jpl.org> | ||
| 2 | |||
| 3 | * shr.el: Load kinsoku. | ||
| 4 | (shr-kinsoku-shorten): New internal variable. | ||
| 5 | (shr-find-fill-point): Make kinsoku shorten text line if | ||
| 6 | shr-kinsoku-shorten is bound to non-nil. | ||
| 7 | (shr-tag-table): Bild shr-kinsoku-shorten to t; refer to | ||
| 8 | shr-indentation too when testing if table is wider than frame width. | ||
| 9 | (shr-insert-table): Use `string-width' instead of `length' to measure | ||
| 10 | text width. | ||
| 11 | (shr-insert-table-ruler): Make sure indentation is done at bol. | ||
| 12 | |||
| 1 | 2010-10-19 Stefan Monnier <monnier@iro.umontreal.ca> | 13 | 2010-10-19 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 14 | ||
| 3 | * nnimap.el (nnimap-request-move-article, nnimap-parse-line) | 15 | * nnimap.el (nnimap-request-move-article, nnimap-parse-line) |
diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el index 8641c196236..50e75323dba 100644 --- a/lisp/gnus/shr.el +++ b/lisp/gnus/shr.el | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | 32 | ||
| 33 | (eval-when-compile (require 'cl)) | 33 | (eval-when-compile (require 'cl)) |
| 34 | (require 'browse-url) | 34 | (require 'browse-url) |
| 35 | (load "kinsoku" nil t) | ||
| 35 | 36 | ||
| 36 | (defgroup shr nil | 37 | (defgroup shr nil |
| 37 | "Simple HTML Renderer" | 38 | "Simple HTML Renderer" |
| @@ -87,6 +88,7 @@ cid: URL as the argument.") | |||
| 87 | (defvar shr-inhibit-images nil) | 88 | (defvar shr-inhibit-images nil) |
| 88 | (defvar shr-list-mode nil) | 89 | (defvar shr-list-mode nil) |
| 89 | (defvar shr-content-cache nil) | 90 | (defvar shr-content-cache nil) |
| 91 | (defvar shr-kinsoku-shorten nil) | ||
| 90 | 92 | ||
| 91 | (defvar shr-map | 93 | (defvar shr-map |
| 92 | (let ((map (make-sparse-keymap))) | 94 | (let ((map (make-sparse-keymap))) |
| @@ -247,36 +249,37 @@ redirects somewhere else." | |||
| 247 | (unless (string-match "[ \t\n]\\'" text) | 249 | (unless (string-match "[ \t\n]\\'" text) |
| 248 | (delete-char -1))))) | 250 | (delete-char -1))))) |
| 249 | 251 | ||
| 250 | (eval-and-compile (autoload 'kinsoku-longer "kinsoku")) | ||
| 251 | |||
| 252 | (defun shr-find-fill-point () | 252 | (defun shr-find-fill-point () |
| 253 | (let ((found nil)) | 253 | (when (> (move-to-column shr-width) shr-width) |
| 254 | (while (and (not found) | 254 | (backward-char 1)) |
| 255 | (> (current-column) shr-indentation)) | 255 | (let (failed) |
| 256 | (when (and (or (eq (preceding-char) ? ) | 256 | (while (not |
| 257 | (aref fill-find-break-point-function-table | 257 | (or (setq failed (= (current-column) shr-indentation)) |
| 258 | (preceding-char))) | 258 | (eq (preceding-char) ? ) |
| 259 | (<= (current-column) shr-width)) | 259 | (eq (following-char) ? ) |
| 260 | (setq found t)) | 260 | (aref fill-find-break-point-function-table (preceding-char)))) |
| 261 | (backward-char 1) | 261 | (backward-char 1)) |
| 262 | (when (bolp) | 262 | (if failed |
| 263 | ;; There's no breakable point, so we give it up. | 263 | ;; There's no breakable point, so we give it up. |
| 264 | (end-of-line) | 264 | (progn |
| 265 | (while (aref fill-find-break-point-function-table | 265 | (end-of-line) |
| 266 | (preceding-char)) | 266 | (while (aref fill-find-break-point-function-table (preceding-char)) |
| 267 | (backward-char 1)) | 267 | (backward-char 1)) |
| 268 | (setq found 'failed))) | 268 | nil) |
| 269 | (cond ((eq found t) | 269 | (or (eolp) |
| 270 | ;; Don't put kinsoku-bol characters at the beginning of a line. | 270 | ;; Don't put kinsoku-bol characters at the beginning of a line, |
| 271 | (or (eobp) | 271 | ;; or kinsoku-eol characters at the end of a line, |
| 272 | (kinsoku-longer) | 272 | (let ((count 4)) |
| 273 | (not (aref fill-find-break-point-function-table | 273 | (if shr-kinsoku-shorten |
| 274 | (following-char))) | 274 | (while (and |
| 275 | (forward-char 1))) | 275 | (> count 0) |
| 276 | (found t) | 276 | (or (aref (char-category-set (preceding-char)) ?<) |
| 277 | (t | 277 | (aref (char-category-set (following-char)) ?>))) |
| 278 | (end-of-line) | 278 | (backward-char 1)) |
| 279 | nil)))) | 279 | (while (and (> count 0) |
| 280 | (aref (char-category-set (following-char)) ?>)) | ||
| 281 | (forward-char 1))) | ||
| 282 | t))))) | ||
| 280 | 283 | ||
| 281 | (defun shr-ensure-newline () | 284 | (defun shr-ensure-newline () |
| 282 | (unless (zerop (current-column)) | 285 | (unless (zerop (current-column)) |
| @@ -545,6 +548,7 @@ Return a string with image data." | |||
| 545 | (setq cont (or (cdr (assq 'tbody cont)) | 548 | (setq cont (or (cdr (assq 'tbody cont)) |
| 546 | cont)) | 549 | cont)) |
| 547 | (let* ((shr-inhibit-images t) | 550 | (let* ((shr-inhibit-images t) |
| 551 | (shr-kinsoku-shorten t) | ||
| 548 | ;; Find all suggested widths. | 552 | ;; Find all suggested widths. |
| 549 | (columns (shr-column-specs cont)) | 553 | (columns (shr-column-specs cont)) |
| 550 | ;; Compute how many characters wide each TD should be. | 554 | ;; Compute how many characters wide each TD should be. |
| @@ -555,8 +559,9 @@ Return a string with image data." | |||
| 555 | (sketch (shr-make-table cont suggested-widths)) | 559 | (sketch (shr-make-table cont suggested-widths)) |
| 556 | (sketch-widths (shr-table-widths sketch suggested-widths))) | 560 | (sketch-widths (shr-table-widths sketch suggested-widths))) |
| 557 | ;; This probably won't work very well. | 561 | ;; This probably won't work very well. |
| 558 | (when (> (1+ (loop for width across sketch-widths | 562 | (when (> (+ (loop for width across sketch-widths |
| 559 | summing (1+ width))) | 563 | summing (1+ width)) |
| 564 | shr-indentation 1) | ||
| 560 | (frame-width)) | 565 | (frame-width)) |
| 561 | (setq truncate-lines t)) | 566 | (setq truncate-lines t)) |
| 562 | ;; Then render the table again with these new "hard" widths. | 567 | ;; Then render the table again with these new "hard" widths. |
| @@ -607,12 +612,14 @@ Return a string with image data." | |||
| 607 | ;; possibly. | 612 | ;; possibly. |
| 608 | (dotimes (i (- height (length lines))) | 613 | (dotimes (i (- height (length lines))) |
| 609 | (end-of-line) | 614 | (end-of-line) |
| 610 | (insert (make-string (length (car lines)) ? ) "|") | 615 | (insert (make-string (string-width (car lines)) ? ) "|") |
| 611 | (forward-line 1))))) | 616 | (forward-line 1))))) |
| 612 | (shr-insert-table-ruler widths))) | 617 | (shr-insert-table-ruler widths))) |
| 613 | 618 | ||
| 614 | (defun shr-insert-table-ruler (widths) | 619 | (defun shr-insert-table-ruler (widths) |
| 615 | (shr-indent) | 620 | (when (and (bolp) |
| 621 | (> shr-indentation 0)) | ||
| 622 | (shr-indent)) | ||
| 616 | (insert shr-table-corner) | 623 | (insert shr-table-corner) |
| 617 | (dotimes (i (length widths)) | 624 | (dotimes (i (length widths)) |
| 618 | (insert (make-string (aref widths i) shr-table-line) shr-table-corner)) | 625 | (insert (make-string (aref widths i) shr-table-line) shr-table-corner)) |