Speed up shr-string-pixel-width
* lisp/net/eww.el (eww-update-header-line-format): Use string-pixel-width (since we don't care about shr-use-fonts here). * lisp/net/shr.el (shr-string-pixel-width): Use `string-pixel-width', which should be faster.
This commit is contained in:
parent
dc6157bef7
commit
c0c538b392
2 changed files with 9 additions and 17 deletions
|
@ -833,7 +833,7 @@ The renaming scheme is performed in accordance with
|
|||
(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))
|
||||
|
@ -842,17 +842,17 @@ The renaming scheme is performed in accordance with
|
|||
(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)))))))
|
||||
|
|
|
@ -337,6 +337,11 @@ and other things:
|
|||
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.
|
||||
|
@ -677,19 +682,6 @@ size, and full-buffer size."
|
|||
(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))
|
||||
|
|
Loading…
Add table
Reference in a new issue