From 212b4d631b7604f5e9000de467b1001084a2751f Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 18 Sep 2014 21:18:34 +0200 Subject: [PATCH] Allow users to specify `shr-width' * net/shr.el, net/eww.el: Don't override `shr-width', but introduce a new variable `shr-internal-width'. This allows users to specify a width themselves. --- lisp/ChangeLog | 6 ++++++ lisp/net/eww.el | 1 - lisp/net/shr.el | 22 ++++++++++++---------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 709627ceed3..6f5e70ab6cb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2014-09-18 Ivan Kanis + + * net/shr.el, net/eww.el: Don't override `shr-width', but + introduce a new variable `shr-internal-width'. This allows users + to specify a width themselves. + 2014-09-18 Lars Magne Ingebrigtsen * image-mode.el (image-toggle-display-image): If we have a diff --git a/lisp/net/eww.el b/lisp/net/eww.el index f99148162e4..6e34856a016 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -270,7 +270,6 @@ word(s) will be searched for via `eww-search-prefix'." (setq eww-current-dom document) (let ((inhibit-read-only t) (after-change-functions nil) - (shr-width nil) (shr-target-id (url-target (url-generic-parse-url url))) (shr-external-rendering-functions '((title . eww-tag-title) diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 0138640e9af..878728c9319 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -130,6 +130,7 @@ cid: URL as the argument.") (defvar shr-start nil) (defvar shr-indentation 0) (defvar shr-inhibit-images nil) +(defvar shr-internal-width (or shr-width (1- (window-width)))) (defvar shr-list-mode nil) (defvar shr-content-cache nil) (defvar shr-kinsoku-shorten nil) @@ -197,7 +198,7 @@ DOM should be a parse tree as generated by (shr-state nil) (shr-start nil) (shr-base nil) - (shr-width (or shr-width (1- (window-width))))) + (shr-internal-width (or shr-width (1- (window-width))))) (shr-descend (shr-transform-dom dom)) (shr-remove-trailing-whitespace start (point)))) @@ -471,8 +472,8 @@ size, and full-buffer size." (insert elem) (setq shr-state nil) (let (found) - (while (and (> (current-column) shr-width) - (> shr-width 0) + (while (and (> (current-column) shr-internal-width) + (> shr-internal-width 0) (progn (setq found (shr-find-fill-point)) (not (eolp)))) @@ -486,10 +487,10 @@ size, and full-buffer size." (when (> shr-indentation 0) (shr-indent)) (end-of-line)) - (if (<= (current-column) shr-width) + (if (<= (current-column) shr-internal-width) (insert " ") ;; In case we couldn't get a valid break point (because of a - ;; word that's longer than `shr-width'), just break anyway. + ;; word that's longer than `shr-internal-width'), just break anyway. (insert "\n") (when (> shr-indentation 0) (shr-indent))))) @@ -497,7 +498,7 @@ size, and full-buffer size." (delete-char -1))))) (defun shr-find-fill-point () - (when (> (move-to-column shr-width) shr-width) + (when (> (move-to-column shr-internal-width) shr-internal-width) (backward-char 1)) (let ((bp (point)) failed) @@ -537,7 +538,7 @@ size, and full-buffer size." ;; so we look for the second best position. (while (and (progn (forward-char 1) - (<= (current-column) shr-width)) + (<= (current-column) shr-internal-width)) (progn (setq bp (point)) (shr-char-kinsoku-eol-p (following-char))))) @@ -1344,7 +1345,7 @@ The preference is a float determined from `shr-prefer-media-type'." (defun shr-tag-hr (_cont) (shr-ensure-newline) - (insert (make-string shr-width shr-hr-line) "\n")) + (insert (make-string shr-internal-width shr-hr-line) "\n")) (defun shr-tag-title (cont) (shr-heading cont 'bold 'underline)) @@ -1637,7 +1638,7 @@ The preference is a float determined from `shr-prefer-media-type'." (setq style (nconc (list (cons 'color fgcolor)) style))) (when style (setq shr-stylesheet (append style shr-stylesheet))) - (let ((shr-width width) + (let ((shr-internal-width width) (shr-indentation 0)) (shr-descend (cons 'td cont))) ;; Delete padding at the bottom of the TDs. @@ -1709,7 +1710,8 @@ The preference is a float determined from `shr-prefer-media-type'." (dotimes (i (length columns)) (aset widths i (max (truncate (* (aref columns i) total-percentage - (- shr-width (1+ (length columns))))) + (- shr-internal-width + (1+ (length columns))))) 10))) widths))