(when url
(setq url (propertize url 'face 'variable-pitch))
(let* ((parsed (url-generic-parse-url url))
- (host-length (shr-string-pixel-width
+ (host-length (string-pixel-width
(propertize
(format "%s://%s" (url-type parsed)
(url-host parsed))
(cond
;; The host bit is wider than the window, so nix
;; the title.
- ((> (+ host-length (shr-string-pixel-width "xxxxx")) width)
+ ((> (+ host-length (string-pixel-width "xxxxx")) width)
(setq title ""))
;; Trim the title.
- ((> (+ (shr-string-pixel-width (concat title "xx"))
+ ((> (+ (string-pixel-width (concat title "xx"))
host-length)
width)
(setq title
(concat
(eww--limit-string-pixelwise
title (- width host-length
- (shr-string-pixel-width
+ (string-pixel-width
(propertize "...: " 'face
'variable-pitch))))
(propertize "..." 'face 'variable-pitch)))))))
0))
(pixel-fill-width)))
+(defmacro shr-string-pixel-width (string)
+ `(if (not shr-use-fonts)
+ (length ,string)
+ (string-pixel-width ,string)))
+
;;;###autoload
(defun shr-insert-document (dom)
"Render the parsed document DOM into the current buffer.
(goto-char (mark))
(shr-pixel-column))))
-(defun shr-string-pixel-width (string)
- (if (not shr-use-fonts)
- (length string)
- ;; Save and restore point across with-temp-buffer, since
- ;; shr-pixel-column uses save-window-excursion, which can reset
- ;; point to 1.
- (let ((pt (point)))
- (prog1
- (with-temp-buffer
- (insert string)
- (shr-pixel-column))
- (goto-char pt)))))
-
(defsubst shr--translate-insertion-chars ()
;; Remove soft hyphens.
(goto-char (point-min))