repelliuss / org-gamedb

A game API client for Emacs org-mode.
GNU General Public License v3.0
7 stars 1 forks source link

org-gamedb + steam.el #1

Open Kungsgeten opened 3 years ago

Kungsgeten commented 3 years ago

Hi! I just wanted to say that I like the idea of this project. I've written a package named steam.el which lets you organize your Steam library from org-mode. I haven't tried combining org-gamedb with it yet, but plan to do so and if I get it to work I'll update the project README with information on how the packages can be used together.

repelliuss commented 3 years ago

Thanks Erik!

I would be glad to see this happening. If you do, let me know so I can update README and reference to steam.el. If you ever want to, I would like to hear your idea so maybe I can help with it, or, you can create issues or PRs if you encounter something so we can work from it. I'm open to all.

Kungsgeten commented 3 years ago

I've now tried org-gamedb and it seems to work nice along steam.el. I wrote the following command:

(defun steam-org-gamedb ()
    (interactive)
    (save-excursion
      (steam-to-heading-link)
      (let ((org-gamedb-correct-headline nil))
        (org-gamedb-games-query
         (steam-link-description)))))

This looks for the title of the game in the steam.el link and queries org-gamedb for information. However I had to set org-gamedb-correct-headline to nil since it would overwrite the headline otherwise. I thought it would work to let-bind the variable around the function call (like I've done above), but it didn't work for me. Perhaps I'm mistaken that this should be possible in Emacs lisp code, but if I remember correctly I've done so before (wanting to temporarily change a variable when calling a function, and then setting it to its original value).

repelliuss commented 3 years ago

Yes, it looks like it should and it is possible in Emacs Lisp but not in this case. org-gamedb makes asynchronous requests using url.el which means url.el will make a function call to callback function org-gamedb provides when response is ready. This function call happens in a different scope so lexical binding doesn't take effect. Also, saving and restoring variable won't work reliably either, maybe never, because restoration will happen probably earlier than where variable is used internally, org-gamedb-correct-headline in this case.

So we have two option here,

  1. I can implement optional synchronous requests.
  2. You can maybe let it as an option to users if its not surprising and it integrates well.

Which one would you prefer? Or do you have any other idea?

Kungsgeten commented 3 years ago

Okay, I see. I think its okay to tell users to set org-gamedb-correct-headline to nil in their config in order for the packages to work together. Here's the config I currently use:

(use-package org-gamedb
  :quelpa (org-gamedb
           :fetcher github
           :repo "repelliuss/org-gamedb")
  :commands org-gamedb-games-query
  :init
  (defun steam-org-gamedb ()
    (interactive)
    (save-excursion
      (steam-to-heading-link)
      (org-gamedb-games-query (steam-link-description))))
  :config
  (setq org-gamedb-api-key "mykey")
  (setq org-gamedb-correct-headline nil)
  (setq org-gamedb-cache-dir-generator
        (lambda () (expand-file-name "steamlogos/" org-directory))))

Is the "cache" used for anything else other than the images? I'm using the same directory as the Steam logos that steam.el can download.

repelliuss commented 3 years ago

I added support for lexical binding without breaking async functionality. Basically, I carry bindings and evaluate them at right time. This was a limitation by my side if users wanted custom functions with temporarily different behaviors.

So in your case you can prefer,

(defun steam-org-gamedb ()
  (interactive)
  (save-excursion
    (steam-to-heading-link)
    (org-gamedb-make-query "games"
                           (steam-link-description)
                           '((org-gamedb-correct-headline nil)))))

over :config solution. One would take effect dynamically and once, other lexically and each time. I let the choice to you. Notice I use org-gamedb-make-query.

No, it is only used for images. Though, I don't really do caching. I will at least add checking if image is already there.

BTW, I will hopefully apply to MELPA this week to make installation easier.