Refactor app/rss & improve kill-buffer process
This commit is contained in:
parent
ba674c8744
commit
f52008873e
2 changed files with 61 additions and 35 deletions
|
@ -6,26 +6,6 @@
|
||||||
(interactive)
|
(interactive)
|
||||||
(call-interactively #'elfeed))
|
(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
|
;;;###autoload
|
||||||
(defun +rss/delete-pane ()
|
(defun +rss/delete-pane ()
|
||||||
"Delete the *elfeed-entry* split pane."
|
"Delete the *elfeed-entry* split pane."
|
||||||
|
@ -63,6 +43,46 @@
|
||||||
(forward-line -1)
|
(forward-line -1)
|
||||||
(call-interactively '+rss/open)))
|
(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
|
;;;###autoload
|
||||||
(defun +rss-dead-feeds (&optional years)
|
(defun +rss-dead-feeds (&optional years)
|
||||||
"Return a list of feeds that haven't posted anything in 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)
|
(cl-loop for url in (elfeed-feed-list)
|
||||||
unless (gethash url living-feeds)
|
unless (gethash url living-feeds)
|
||||||
collect url)))
|
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))))
|
||||||
|
|
|
@ -44,26 +44,14 @@ easier to scroll through.")
|
||||||
;; Enhance readability of a post
|
;; Enhance readability of a post
|
||||||
(add-hook 'elfeed-show-mode-hook #'+rss|elfeed-wrap)
|
(add-hook 'elfeed-show-mode-hook #'+rss|elfeed-wrap)
|
||||||
(add-hook! 'elfeed-search-mode-hook
|
(add-hook! 'elfeed-search-mode-hook
|
||||||
(add-hook 'kill-buffer-hook #'+rss/quit nil t))
|
(add-hook 'kill-buffer-hook #'+rss|cleanup nil t))
|
||||||
|
|
||||||
;; Large images are annoying to scroll through, because scrolling follows the
|
;; Large images are annoying to scroll through, because scrolling follows the
|
||||||
;; cursor, so we force shr to insert images in slices.
|
;; cursor, so we force shr to insert images in slices.
|
||||||
(when +rss-enable-sliced-images
|
(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
|
(setq-hook! 'elfeed-show-mode-hook
|
||||||
shr-put-image-function #'+rss-put-image
|
shr-put-image-function #'+rss-put-sliced-image
|
||||||
shr-external-rendering-functions '((img . +rss-render-image-tag))))
|
shr-external-rendering-functions '((img . +rss-render-image-tag-without-underline))))
|
||||||
|
|
||||||
;; Keybindings
|
;; Keybindings
|
||||||
(after! elfeed-show
|
(after! elfeed-show
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue