karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.04k stars 113 forks source link

gptel-crowdsourced-prompts-file does not use xdg.el #201

Open yantar92 opened 5 months ago

yantar92 commented 5 months ago

It would be nice if gptel-crowdsourced-prompts-file did not hard-code using environment variables only. xdg.el library (when available) is more accurate. It is enough to call xdg-cache-home.

karthink commented 5 months ago
  1. Does xdg.el support Windows?
  2. I don't know if xdg.el is loaded with Emacs. I would like to avoid requiring the library just to fetch the cache directory. Is the following valid, or do you have any suggestions?

(eval-when-compile (require 'xdg))

(defcustom gptel-crowdsourced-prompts-file
  (expand-file-name "gptel-crowdsourced-prompts.csv" (xdg-cache-home))
  "File used to store crowdsourced system prompts.

These are prompts cached from an online source (see
`gptel--crowdsourced-prompts-url'), and can be set from the
transient menu interface provided by `gptel-menu'."
  :group 'gptel
  :type 'file)
yantar92 commented 5 months ago

karthink @.***> writes:

  1. Does xdg.el support Windows?

XDG does not provide standards for Windows. AFAIU, `xdg-cache-home' will return ~/.cache on Windows.

  1. I don't know if xdg.el is loaded with Emacs. I would like to avoid requiring the library just to fetch the cache directory.

xdg.el is very lightweight. And it is generally a good idea to follow configurable standard that respect user settings rather than not.

... Is the following valid, or do you have any suggestions?



(eval-when-compile (require 'xdg))
(defcustom gptel-crowdsourced-prompts-file
  (expand-file-name "gptel-crowdsourced-prompts.csv" (xdg-cache-home))
  "File used to store crowdsourced system prompts.

Bad idea. xdg.el pulls data from environment variables, when they are defined. If you execute (xdg-cache-home) at compile time, environment variables may not be respected if the user changes them.

-- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92

karthink commented 5 months ago

Bad idea. xdg.el pulls data from environment variables, when they are defined. If you execute (xdg-cache-home) at compile time, environment variables may not be respected if the user changes them.

Noted.