使用 Emacs 阅读邮件与 RSS

4赞

最近加了两个函数,实现自定义 tag 的导出与导入,方便备份。目前导出的两个 tag。(依赖:https://github.com/rejeep/f.el)

  • +starred 加星的
  • -unread 已经读过的
(defun my/elfeed-export (output)
  (interactive "fOutput: ")
  (let* ((sf (elfeed-search-parse-filter "+starred"))
	     (uf (elfeed-search-parse-filter "-unread"))
	     (starred-entries '())
	     (read-entries '())
	     (hash-table (make-hash-table)))
    (with-elfeed-db-visit (entry feed)
	  (when (elfeed-search-filter sf entry feed)
	    (add-to-list 'starred-entries (elfeed-entry-link entry)))
	  (when (elfeed-search-filter uf entry feed)
	    (add-to-list 'read-entries (elfeed-entry-link entry))))

    (puthash :starred starred-entries hash-table)
    (puthash :read read-entries hash-table)
    (f-write-text (prin1-to-string hash-table) 'utf-8 output)

    (message "Export to %s. starred: %d, read: %d" output (length starred-entries) (length read-entries))))

(defun my/elfeed-import (f)
  (interactive "fInput: ")
  (let* ((hash-table (read (f-read-text f)))
         (starred-entries (gethash :starred hash-table))
         (read-entries (gethash :read hash-table)))
    (with-elfeed-db-visit (entry feed)
      (let* ((link (elfeed-entry-link entry)))
        (when (member link starred-entries)
          (elfeed-tag entry (intern "starred")))
        (when (member link read-entries)
          (elfeed-untag entry (intern "unread")))))

    (message "Import starred: %d, read: %d" (length starred-entries) (length read-entries))))
1赞