alphapapa / pocket-reader.el

Emacs client for Pocket reading list (getpocket.com)
GNU General Public License v3.0
223 stars 12 forks source link

Example of storing/loading individual articles with personal edits #47

Open leshy opened 1 year ago

leshy commented 1 year ago

Hey just to share a very hacky code, didn't write much emacs-lisp before. I'd like to keep notes on articles I read or optionally save articles for offline reading.

Without building some fancy sync system I made reader open an article in a buffer that has a specific file assigned to it on disk, so while reading one can choose to edit, comment etc and/or save. If file is found next time you try to read the article, it will be read from the disk directly. Maybe this is interesting to someone or as an idea for some better implemented feature.

This hooks it only to "TAB" pocket-reader-pop-to-url

(Would be nice if pocket-reader-pop-to-url-default-function had an optional argument of title, pocket id etc provided to it, so I could name the file better)

  (defun pop-to-buffer-with-file (buffer file)
    (with-current-buffer (get-buffer-create buffer)
      (setq buffer-file-name file))
    (pop-to-buffer buffer))

  (defun encode-url-to-filename (url)
    (let ((filename (replace-regexp-in-string "https?://" "" url)))
      (setq filename (replace-regexp-in-string "www." "" filename))
      (setq filename (replace-regexp-in-string "/" "-" filename))
      filename))

  (defun get-pocket-filename (url)
    (concat "~/txt/pocket/" (encode-url-to-filename url) ".org"))

  (defun my-pocket-reader-pop-to-url (url)
    (let ((filename (get-pocket-filename url)))
      (if (file-exists-p filename)
          (pop-to-buffer (find-file-noselect filename))
        (org-web-tools-read-url-as-org
         url
         :show-buffer-fn
         (lambda (url)
           (pop-to-buffer-with-file url filename))))))

  (customize-set-variable 'pocket-reader-pop-to-url-default-function
                          #'my-pocket-reader-pop-to-url)
alphapapa commented 1 year ago

Thanks, that's cool. If I were to enable the wiki for this repo, would you contribute it there?

leshy commented 1 year ago

I would! Thanks for the great project btw