Slice images in rss entries for easier scrolling

Can be disabled with +rss-enable-sliced-images.
This commit is contained in:
Henrik Lissner 2018-06-29 14:07:29 +02:00
parent db0ad48e4d
commit ba674c8744
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -11,6 +11,10 @@ absolute paths.")
(defvar +rss-split-direction 'below
"What direction to pop up the entry buffer in elfeed.")
(defvar +rss-enable-sliced-images t
"Automatically slice images shown in elfeed-show-mode buffers, making them
easier to scroll through.")
;;
;; Packages
@ -42,6 +46,25 @@ absolute paths.")
(add-hook! 'elfeed-search-mode-hook
(add-hook 'kill-buffer-hook #'+rss/quit nil t))
;; Large images are annoying to scroll through, because scrolling follows the
;; cursor, so we force shr to insert images in slices.
(when +rss-enable-sliced-images
(defun +rss-put-image (spec alt &optional flags)
(cl-letf (((symbol-function #'insert-image)
(lambda (image &optional alt _area _slice)
(let ((height (cdr (image-size image t))))
(insert-sliced-image image alt nil (max 1 (/ height 20.0)) 1)))))
(shr-put-image spec alt flags)))
(defun +rss-render-image-tag (dom &optional url)
(let ((start (point)))
(shr-tag-img dom url)
;; And remove underlines in case images are links, otherwise we get an
;; underline beneath every slice.
(put-text-property start (point) 'face '(:underline nil))))
(setq-hook! 'elfeed-show-mode-hook
shr-put-image-function #'+rss-put-image
shr-external-rendering-functions '((img . +rss-render-image-tag))))
;; Keybindings
(after! elfeed-show
(define-key! elfeed-show-mode-map