Ihor Radchenko [2023-08-16 11:08:15] wrote: > Ihor Radchenko <yanta...@posteo.net> writes: >> Stefan Monnier <monn...@iro.umontreal.ca> writes: >>> BTW, rather than unloading, `package.el` relies on forcibly "re"loading >>> from the new version the already loaded files from the old version. >>> It suffers from a different set of problem :-( >>> [ I suspect `defvar` is the main problem for that solution. ] >> >> Could it be possible to force require use certain package version and >> automatically re-load a package when older version is being loaded? > > After trying several more approaches,
[ Side note: did you keep notes about the various approaches you tried and their respective downsides? E.g. I'm curious what were the problems linked to my proposal of using a `require-with-check` like the one below my sig. ] > I now came up with yet another idea. Instead of fiddling with load > internals, compilation, or load-path, what about making sure that Org > libraries include version info directly? That should work. It implies a fair bit more churn in the code, tho, but I guess you plan to automate it via some scripts? Stefan (defun require-with-check (feature &optional filename noerror) "If FEATURE is not already loaded, load it from FILENAME. This is like `require' except if FEATURE is already a member of the list ‘features’, then we check if this was provided by a different file than the one that we would load now (presumably because `load-path' has been changed since the file was loaded)." (let ((lh load-history) (res (require feature filename noerror))) ;; If the `feature' was not yet provided, `require' just loaded the right ;; file, so we're done. (if (not (eq lh load-history)) res ;; If `require' did nothing, we need to make sure that was warranted. (let ((fn (locate-file (or filename (symbol-name feature)) load-path (get-load-suffixes)))) ;; If the right file was indeed loaded already, we're done. (if (assoc fn load-history) res (funcall (if noerror #'warn #'error) "Feature provided by other file: %S" feature) res)))))