Refactor app/rss & improve kill-buffer process

This commit is contained in:
Henrik Lissner 2018-06-29 15:08:06 +02:00
parent ba674c8744
commit f52008873e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 61 additions and 35 deletions

View file

@ -6,26 +6,6 @@
(interactive)
(call-interactively #'elfeed))
;;;###autoload
(defun +rss/quit ()
"TODO"
(interactive)
(elfeed-db-compact)
(doom-kill-matching-buffers "^\\*elfeed" (delq (current-buffer) (buffer-list)))
(dolist (file +rss-elfeed-files)
(when-let* ((buf (get-file-buffer (expand-file-name file org-directory))))
(kill-buffer buf))))
;;;###autoload
(defun +rss|elfeed-wrap ()
"Enhances an elfeed entry's readability by wrapping it to a width of
`fill-column' and centering it with `visual-fill-column-mode'."
(let ((inhibit-read-only t)
(inhibit-modification-hooks t))
(setq-local truncate-lines nil)
(setq-local shr-width 85)
(set-buffer-modified-p nil)))
;;;###autoload
(defun +rss/delete-pane ()
"Delete the *elfeed-entry* split pane."
@ -63,6 +43,46 @@
(forward-line -1)
(call-interactively '+rss/open)))
;;
;; Hooks
;;
;;;###autoload
(defun +rss|elfeed-wrap ()
"Enhances an elfeed entry's readability by wrapping it to a width of
`fill-column' and centering it with `visual-fill-column-mode'."
(let ((inhibit-read-only t)
(inhibit-modification-hooks t))
(setq-local truncate-lines nil)
(setq-local shr-width 85)
(set-buffer-modified-p nil)))
;;;###autoload
(defun +rss|cleanup ()
"Clean up after an elfeed session. Kills all elfeed and elfeed-org files."
(interactive)
(elfeed-db-compact)
(let ((buf (previous-buffer)))
(when (or (null buf) (not (doom-real-buffer-p buf)))
(switch-to-buffer (doom-fallback-buffer))))
(let ((search-buffers (doom-buffers-in-mode 'elfeed-search-mode))
(show-buffers (doom-buffers-in-mode 'elfeed-show-mode))
kill-buffer-query-functions)
(dolist (file +rss-elfeed-files)
(when-let* ((buf (get-file-buffer (expand-file-name file org-directory))))
(kill-buffer buf)))
(dolist (b search-buffers)
(with-current-buffer b
(remove-hook 'kill-buffer-hook #'+rss|cleanup :local)
(kill-buffer b)))
(mapc #'kill-buffer show-buffers)))
;;
;; Functions
;;
;;;###autoload
(defun +rss-dead-feeds (&optional years)
"Return a list of feeds that haven't posted anything in YEARS."
@ -77,3 +97,21 @@
(cl-loop for url in (elfeed-feed-list)
unless (gethash url living-feeds)
collect url)))
;;;###autoload
(defun +rss-put-sliced-image (spec alt &optional flags)
"TODO"
(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)))
;;;###autoload
(defun +rss-render-image-tag-without-underline (dom &optional url)
"TODO"
(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))))