0

I am trying to achieve a slightly smart package management in my init.el file but can't achieve it because of ELisp ignorance. Here is the case.

;; package loader function
(defun load-packages-context-sensitively (plist)
  (dolist (ppack plist) 
    (unless (and ((not window-system) (string= (assoc ppack plist) "GUI")))
      (require '(ppack)))))

(defconst package-assoc-list
  '((package-1 "CLI") ;here
    (package-2 "CLI") ; I 
    (package-3 "GUI") ; declare
    (package-4 "GUI") ; my packages
    (package-5 "CLI")))

(load-packages-context-sensitively (package-assoc-list)) ; here we need a happy ending

I simply want to generate an associated list (I'm not even sure if its the right data structure) and map each package name (provide 'package-x)'ed in another file to "GUI" and "CLI" strings. What I want to achieve is to pass the list to my slightly-smart-function and prevent GUI packages being loaded in CLI environments...

It gives me Symbol's function definition is void: package-assoc-list error now. Yes it looks very self-explanatory, it is well documented but I couldn't find a way to overcome it.

Any help, any correction, any suggestion, any cringe is more than welcome.

1
  • Side note: loading a package should have "no visible effect" (other than defining some functions and variables, that is): any visible effect is usually considered a bug (because Emacs sometimes loads packages for rather frivolous reasons). So most likely you shouldn't be thinking about which packages to load, but about which functionality to enable.
    – Stefan
    Nov 12, 2017 at 1:33

1 Answer 1

1

This question is likely a duplicate, but I don't find it now.

You are using (package-assoc-list), which means to invoke the function package-assoc-list. Just use variable package-assoc-list instead.

(load-packages-context-sensitively package-assoc-list)

As @NickD added, in a comment here:

In addition, the (require '(ppack)) in the definition of load-packages-context-sensitively is wrong I believe: require takes a symbol as argument, not a list.

2
  • In addition, the (require '(ppack)) in the definition of load-packages-context-sensitively is wrong I believe: require takes a symbol as argument, not a list.
    – NickD
    Dec 5, 2023 at 2:34
  • @NickD: Duh. I've added that to this answer. If you prefer to add it as another answer, let me know. Thx.
    – Drew
    Dec 5, 2023 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.