[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
shr.el: add linebreaks to mouse-over tooltips (title attributes)
From: |
Adam Sjøgren |
Subject: |
shr.el: add linebreaks to mouse-over tooltips (title attributes) |
Date: |
Fri, 12 Dec 2014 22:29:21 +0100 |
User-agent: |
Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (gnu/linux) |
When reading nntp+news.gwene.org:gwene.com.xkcd there are often long
title attributes on the comic image, and when shown on one line, the
text does not fit on my tiny screen.
I guess the correct solution would be for Emacs to wrap the "help-echo"
to fit the screen automatically.
The second best thing would be if shr.el wrapped the text to fit the
screen.
And here is what I crudely whipped up, a regex to sort-of-wrap at 72
chars:
--- shr.el.orig 2014-12-12 22:21:34.271477782 +0100
+++ shr.el 2014-12-12 22:20:44.652962400 +0100
@@ -1248,10 +1248,13 @@
(put-text-property start (point) 'image-displayer
(shr-image-displayer shr-content-function))
(put-text-property start (point) 'help-echo
- (or (cdr (assq :title cont))
- alt)))
+ (shr-linebreak (or (cdr (assq :title cont))
+ alt))))
(setq shr-state 'image)))))
+(defun shr-linebreak (line)
+ (replace-regexp-in-string "\\(.\\{72\\}\s\\)" "\\1\n" line))
+
(defun shr-tag-pre (cont)
(let ((shr-folding-mode 'none))
(shr-ensure-newline)
--
"If you don't run, you rust." Adam Sjøgren
address@hidden
- shr.el: add linebreaks to mouse-over tooltips (title attributes),
Adam Sjøgren <=