pocket-reader.el icon indicating copy to clipboard operation
pocket-reader.el copied to clipboard

Example of storing/loading individual articles with personal edits

Open leshy opened this issue 2 years ago • 2 comments

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)

leshy avatar Sep 06 '23 17:09 leshy

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

alphapapa avatar Sep 06 '23 17:09 alphapapa

I would! Thanks for the great project btw

leshy avatar Sep 06 '23 20:09 leshy