emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r101997: shr.el: Improve kinsoku and


From: Katsumi Yamaoka
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r101997: shr.el: Improve kinsoku and table rendering.
Date: Tue, 19 Oct 2010 07:57:50 +0000
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 101997
committer: Katsumi Yamaoka <address@hidden>
branch nick: trunk
timestamp: Tue 2010-10-19 07:57:50 +0000
message:
  shr.el: Improve kinsoku and table rendering.
modified:
  lisp/gnus/ChangeLog
  lisp/gnus/shr.el
=== modified file 'lisp/gnus/ChangeLog'
--- a/lisp/gnus/ChangeLog       2010-10-19 00:13:27 +0000
+++ b/lisp/gnus/ChangeLog       2010-10-19 07:57:50 +0000
@@ -1,3 +1,15 @@
+2010-10-19  Katsumi Yamaoka  <address@hidden>
+
+       * shr.el: Load kinsoku.
+       (shr-kinsoku-shorten): New internal variable.
+       (shr-find-fill-point): Make kinsoku shorten text line if
+       shr-kinsoku-shorten is bound to non-nil.
+       (shr-tag-table): Bild shr-kinsoku-shorten to t; refer to
+       shr-indentation too when testing if table is wider than frame width.
+       (shr-insert-table): Use `string-width' instead of `length' to measure
+       text width.
+       (shr-insert-table-ruler): Make sure indentation is done at bol.
+
 2010-10-19  Stefan Monnier  <address@hidden>
 
        * nnimap.el (nnimap-request-move-article, nnimap-parse-line)

=== modified file 'lisp/gnus/shr.el'
--- a/lisp/gnus/shr.el  2010-10-18 05:45:06 +0000
+++ b/lisp/gnus/shr.el  2010-10-19 07:57:50 +0000
@@ -32,6 +32,7 @@
 
 (eval-when-compile (require 'cl))
 (require 'browse-url)
+(load "kinsoku" nil t)
 
 (defgroup shr nil
   "Simple HTML Renderer"
@@ -87,6 +88,7 @@
 (defvar shr-inhibit-images nil)
 (defvar shr-list-mode nil)
 (defvar shr-content-cache nil)
+(defvar shr-kinsoku-shorten nil)
 
 (defvar shr-map
   (let ((map (make-sparse-keymap)))
@@ -247,36 +249,37 @@
     (unless (string-match "[ \t\n]\\'" text)
       (delete-char -1)))))
 
-(eval-and-compile (autoload 'kinsoku-longer "kinsoku"))
-
 (defun shr-find-fill-point ()
-  (let ((found nil))
-    (while (and (not found)
-               (> (current-column) shr-indentation))
-      (when (and (or (eq (preceding-char) ? )
-                    (aref fill-find-break-point-function-table
-                          (preceding-char)))
-                (<= (current-column) shr-width))
-       (setq found t))
-      (backward-char 1)
-      (when (bolp)
+  (when (> (move-to-column shr-width) shr-width)
+    (backward-char 1))
+  (let (failed)
+    (while (not
+           (or (setq failed (= (current-column) shr-indentation))
+               (eq (preceding-char) ? )
+               (eq (following-char) ? )
+               (aref fill-find-break-point-function-table (preceding-char))))
+      (backward-char 1))
+    (if failed
        ;; There's no breakable point, so we give it up.
-       (end-of-line)
-       (while (aref fill-find-break-point-function-table
-                    (preceding-char))
-         (backward-char 1))
-       (setq found 'failed)))
-    (cond ((eq found t)
-          ;; Don't put kinsoku-bol characters at the beginning of a line.
-          (or (eobp)
-              (kinsoku-longer)
-              (not (aref fill-find-break-point-function-table
-                         (following-char)))
-              (forward-char 1)))
-         (found t)
-         (t
-          (end-of-line)
-          nil))))
+       (progn
+         (end-of-line)
+         (while (aref fill-find-break-point-function-table (preceding-char))
+           (backward-char 1))
+         nil)
+      (or (eolp)
+         ;; Don't put kinsoku-bol characters at the beginning of a line,
+         ;; or kinsoku-eol characters at the end of a line,
+         (let ((count 4))
+           (if shr-kinsoku-shorten
+               (while (and
+                       (> count 0)
+                       (or (aref (char-category-set (preceding-char)) ?<)
+                           (aref (char-category-set (following-char)) ?>)))
+                 (backward-char 1))
+             (while (and (> count 0)
+                         (aref (char-category-set (following-char)) ?>))
+               (forward-char 1)))
+           t)))))
 
 (defun shr-ensure-newline ()
   (unless (zerop (current-column))
@@ -545,6 +548,7 @@
   (setq cont (or (cdr (assq 'tbody cont))
                 cont))
   (let* ((shr-inhibit-images t)
+        (shr-kinsoku-shorten t)
         ;; Find all suggested widths.
         (columns (shr-column-specs cont))
         ;; Compute how many characters wide each TD should be.
@@ -555,8 +559,9 @@
         (sketch (shr-make-table cont suggested-widths))
         (sketch-widths (shr-table-widths sketch suggested-widths)))
     ;; This probably won't work very well.
-    (when (> (1+ (loop for width across sketch-widths
-                      summing (1+ width)))
+    (when (> (+ (loop for width across sketch-widths
+                     summing (1+ width))
+               shr-indentation 1)
             (frame-width))
       (setq truncate-lines t))
     ;; Then render the table again with these new "hard" widths.
@@ -607,12 +612,14 @@
          ;; possibly.
          (dotimes (i (- height (length lines)))
            (end-of-line)
-           (insert (make-string (length (car lines)) ? ) "|")
+           (insert (make-string (string-width (car lines)) ? ) "|")
            (forward-line 1)))))
     (shr-insert-table-ruler widths)))
 
 (defun shr-insert-table-ruler (widths)
-  (shr-indent)
+  (when (and (bolp)
+            (> shr-indentation 0))
+    (shr-indent))
   (insert shr-table-corner)
   (dotimes (i (length widths))
     (insert (make-string (aref widths i) shr-table-line) shr-table-corner))


reply via email to

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